DataTable dt = ((DataTable)tCourse).DefaultView.ToTable(true,
new string[] {
"CourseID",
"CourseName",
"CourseClass",
"CourseStart",
"CourseEnd",
"CourseStatus" });
星期三, 4月 28, 2010
[Asp.Net] 一行搞定DataTable Distinct
今天剛好用到,沒有用新的linq來做。
星期二, 4月 27, 2010
[Asp.Net] 防止頁面重覆刷新執行的方法
#region check page refresh
/// <summary>
/// 處裡 PreRender 事件,在網頁初次載入時設置戳記,
/// 且每次載入執行時會把該戳記存放到 HiddenField 裡。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Page_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.SetActionStamp();
}
if (Session["actionStamp"] != null)
this.ClientScript.RegisterHiddenField("actionStamp", Session["actionStamp"].ToString());
}
/// <summary>
/// 設置戳記
/// </summary>
private void SetActionStamp()
{
this.Session["actionStamp"] = Server.UrlEncode(DateTime.Now.ToString("yyyy-MM-dd.hh-mm-ss.FF"));
}
/// <summary>
/// 取得值,指出網頁是否經由重新整理動作回傳 (PostBack)
/// </summary>
protected bool IsRefresh
{
get
{
if (HttpContext.Current.Request["actionStamp"] as string ==
Session["actionStamp"] as string)
{
this.SetActionStamp();
return false;
}
return true;
}
}
#endregion
星期三, 4月 21, 2010
星期四, 4月 15, 2010
星期二, 4月 13, 2010
Google map Click
function SearchMap(address)
{
var marker
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_"));
var geocoder = new GClientGeocoder();
map.setUIToDefault();
geocoder.getLatLng(address, function(point) {
if (!point)
{
alert('Google Maps 找不到該地址,無法顯示地圖!'); //如果Google Maps無法顯示該地址的警示文字
}
else
{
$(".latlng_").text(point.lat()+","+point.lng());
map.setCenter(point, 13);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
});
GEvent.addListener(map,"click", function(overlay,latlng) {
map.removeOverlay(marker);
if (overlay) {
// ignore if we click on the info window
return;
}
var tileCoordinate = new GPoint();
var tilePoint = new GPoint();
var currentProjection = G_NORMAL_MAP.getProjection();
var geoPoint0= new GLatLng(latlng.lat(),latlng.lng());
var myLatLng = new GLatLng(latlng.lat(), latlng.lng());
//移動地圖中心點
map.panTo( myLatLng );
//設定標註座標
marker.setLatLng( myLatLng );
var myGeocoder = new GClientGeocoder();
myGeocoder.getLocations(myLatLng, function(addresses) {
if(addresses.Status.code != 200) {
//alert("此座標沒有找到對應的地址 " + myLatLng.toUrlValue());
alert("此座標沒有找到對應的地址,請重新點選其他地方!");
}
else
{
var result = addresses.Placemark[0];
marker= new GMarker(geoPoint0, { title:latlng.lat()+","+ latlng.lng()});
map.addOverlay(marker);
marker.openInfoWindowHtml( result.address );
$(".latlng_").text(latlng.lat()+","+latlng.lng());
}
});
});
}
}
{
var marker
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_"));
var geocoder = new GClientGeocoder();
map.setUIToDefault();
geocoder.getLatLng(address, function(point) {
if (!point)
{
alert('Google Maps 找不到該地址,無法顯示地圖!'); //如果Google Maps無法顯示該地址的警示文字
}
else
{
$(".latlng_").text(point.lat()+","+point.lng());
map.setCenter(point, 13);
marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
});
GEvent.addListener(map,"click", function(overlay,latlng) {
map.removeOverlay(marker);
if (overlay) {
// ignore if we click on the info window
return;
}
var tileCoordinate = new GPoint();
var tilePoint = new GPoint();
var currentProjection = G_NORMAL_MAP.getProjection();
var geoPoint0= new GLatLng(latlng.lat(),latlng.lng());
var myLatLng = new GLatLng(latlng.lat(), latlng.lng());
//移動地圖中心點
map.panTo( myLatLng );
//設定標註座標
marker.setLatLng( myLatLng );
var myGeocoder = new GClientGeocoder();
myGeocoder.getLocations(myLatLng, function(addresses) {
if(addresses.Status.code != 200) {
//alert("此座標沒有找到對應的地址 " + myLatLng.toUrlValue());
alert("此座標沒有找到對應的地址,請重新點選其他地方!");
}
else
{
var result = addresses.Placemark[0];
marker= new GMarker(geoPoint0, { title:latlng.lat()+","+ latlng.lng()});
map.addOverlay(marker);
marker.openInfoWindowHtml( result.address );
$(".latlng_").text(latlng.lat()+","+latlng.lng());
}
});
});
}
}
星期一, 4月 12, 2010
Lazarus(1999) 情緒字詞分類
Lazarus(1999)則將十七種常見的情緒辭彙分成五大類,結果如下:
1.不愉快的情緒(nasty emotion)-氣憤、羨慕、嫉妒;
2.存在的情緒(existential emotion)-焦慮、驚嚇、自責、羞愧;
3.被不利生存條件所引發的情緒(emotion provoked by unfavourable)-安心、希望、悲傷、沮喪;
4.移情作用的情緒(empathic emotion)-感激、同情;
5.被有利生存條件所引發的情緒(emotion provoked by favourable life condition)-快樂、高興、驕傲、愛。
1.不愉快的情緒(nasty emotion)-氣憤、羨慕、嫉妒;
2.存在的情緒(existential emotion)-焦慮、驚嚇、自責、羞愧;
3.被不利生存條件所引發的情緒(emotion provoked by unfavourable)-安心、希望、悲傷、沮喪;
4.移情作用的情緒(empathic emotion)-感激、同情;
5.被有利生存條件所引發的情緒(emotion provoked by favourable life condition)-快樂、高興、驕傲、愛。
星期三, 4月 07, 2010
[Jquery API] Disabled and Readonly Input
常常會到用input的disabled與readonly的控制。
$("#control").toggle(
function ()
{
$('#target').attr("disabled", true);
},
function ()
{
$('#target').removeAttr("disabled");
}
);
jQuery: Disabled and ReadOnly Inputs
Jquery 取得 iframe 內的Dom物件
在取iframe裡面的值時要注意,
而注意iframe頁面的元素是否載入完成,
否則會導致設定iframe值的失敗。
var iframe = document.getElementById("boxyFrame");
[jQuery]獲取iframe內的DOM物件
而注意iframe頁面的元素是否載入完成,
否則會導致設定iframe值的失敗。
var iframe = document.getElementById("boxyFrame");
$(iframe).load(function(){
iframe.contentDocument.getElementById("hiddenUID").value = uid;//dom api
});
Reference:[jQuery]獲取iframe內的DOM物件
javascript html encoder , decoder
<script type="text/javascript">
function htmlEncode (str){
var div = document.createElement("div");
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
function htmlDecode (str){
var div = document.createElement("div");
div.innerHTML = str;
return div.innerText;
}
</script>
function htmlEncode (str){
var div = document.createElement("div");
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
function htmlDecode (str){
var div = document.createElement("div");
div.innerHTML = str;
return div.innerText;
}
</script>
星期二, 4月 06, 2010
Jquery MonthPicker
最近有個需求需要使用一個只能選擇月份的選擇器,
從google大神找到有相同需求的人,利用原本的Jquery UI date picker就可以很快實現。
以下是詳細解法:
<script type="text/javascript">
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
</script>
從google大神找到有相同需求的人,利用原本的Jquery UI date picker就可以很快實現。
以下是詳細解法:
<script type="text/javascript">
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});
</script>
修改原本date picker的css讓calendar不要顯示:.ui-datepicker-calendar { display: none; }
頁面配置:<label for="startDate">Date :</label>
<input name="startDate" id="startDate" class="date-picker" /> Reference:jquery date picker to show month year only
星期一, 4月 05, 2010
asp.net chart controls
Reference: 介紹好用元件:Microsoft Chart Controls for .NET 3.5 By Will
Microsoft Chart Controls for Microsoft .NET Framework 3.5包含 ASP.NET 和 Windows Form 圖表控制項的組件。
Microsoft Chart Controls for Microsoft .NET Framework 3.5 語言套件 (繁體中文)
Microsoft Chart Controls Add-on for Microsoft Visual Studio 2008
安裝後可以方便的在 VS2008 SP1 中拖曳控制項與使用 IntelliSense (含 ASP.NET 與 WinForm )
Microsoft Chart Controls for .NET Framework Documentation
此文件包括安裝說明與完整的 API 說明文件。
Samples Environment for Microsoft Chart Controls
這裡提供超過 200 個範例,讓你快速上手如何開發!
Windows Forms/ASP.NET Chart Control 論壇
各種與此控制項相關的討論都可以在此進行
P.S. 最後提醒,請務必安裝至 .NET 3.5 SP1 才能正確使用該元件。
[Asp.Net] 實作下載檔案連結與檔名編輯問題解決
下載檔案連結實作如下:
gfa = new Module_Command.GetFileAttach(this.supportFileID, "2");
Attach = gfa.Execute();
gfa.UnExecute();
if (Attach != null)
{
dtOneFile = (DataTable)Attach;
filePath = "course/"
+ dtOneFile.Rows[0]["CourseID"].ToString()
+"/"
+ dtOneFile.Rows[0]["HomeWorkID"].ToString()
+"/attachment/"
+ dtOneFile.Rows[0]["SupportFileName"].ToString();
filename = dtOneFile.Rows[0]["SupportFileName"].ToString();
filename = filename.Replace(" ", "%20");
//if (context.Request.Browser.Browser == "IE")
userAgent = context.Request.Headers.Get("User-Agent");
if (userAgent.Contains("MSIE 7.0"))
filename = context.Server.UrlPathEncode(dtOneFile.Rows[0]["SupportFileName"].ToString());
context.Response.ContentType = "application/download";
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ";");
Reference:
ASP.NET 如何設定強制下載檔案並正確處理中文檔名的問題
【茶包射手專欄】Cassini's Response Header Encoding
gfa = new Module_Command.GetFileAttach(this.supportFileID, "2");
Attach = gfa.Execute();
gfa.UnExecute();
if (Attach != null)
{
dtOneFile = (DataTable)Attach;
filePath = "course/"
+ dtOneFile.Rows[0]["CourseID"].ToString()
+"/"
+ dtOneFile.Rows[0]["HomeWorkID"].ToString()
+"/attachment/"
+ dtOneFile.Rows[0]["SupportFileName"].ToString();
filename = dtOneFile.Rows[0]["SupportFileName"].ToString();
filename = filename.Replace(" ", "%20");
//if (context.Request.Browser.Browser == "IE")
userAgent = context.Request.Headers.Get("User-Agent");
if (userAgent.Contains("MSIE 7.0"))
filename = context.Server.UrlPathEncode(dtOneFile.Rows[0]["SupportFileName"].ToString());
context.Response.ContentType = "application/download";
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ";");
ASP.NET 如何設定強制下載檔案並正確處理中文檔名的問題
【茶包射手專欄】Cassini's Response Header Encoding
星期四, 4月 01, 2010
星期三, 3月 31, 2010
javascript keycode
Key CodesThis document is written by Helge Willum Larsen
It contains a list of all "onkeypress", "onkeydown" and "onkeyup" KeyCodes in JavaScript,
that can be typed with a DANISH KEYBOARD !!!
Other keyboards probably have other KeyCodes.
The first section is tested with the Microsoft Internet Explore 5.0 and the Netscape
Communicator 4.51. At this time, Netscape didn't support "onkeydown" and "onkeyup".
I strongly recommend that you use the "onkeypress" function.
It has the greatest browser-compatibility.
Otherwise, you can maybe use some of the codes in the bottom of the page:
____________________________________________________________________________________________
KeyCodes (ALL keyboards): onkeypress Tested with Internet Explore 5.0
By: Helge Willum Larsen and Netscape Communicator 4.51
on a DANISH keyboard
____________________________________________________________________________________________
SUPPORTS MULTIPLE KEYPRESSES:
[A] = [a]
[Shift] + [A] = [A]
[CapsLock] + [A] = [A]
[Shift] + [CapsLock] + [A] = [a]
ALL KEYS THAT CREATES THE SAME OUTPUT, HAVE THE SAME KEYCODES !
[NumPad 1] is the same as [1] (if NumLock)
[NumPad +] is the same as [+]
DOES NOT SUPPORT ARROW-KEYS, DELETE, INSERT, SHIFT, ALT, CTRL, TAB, ESC...........!
But it supports [Return / Enter] and [Backspace]
____________________________________________________________________________________________
Button: keyCode:
[BackSpace] 8
[Return / Enter] 13
[!] 33
["] 34
[#] 35
[$] 36
[%] 37
[&] 38
['] 39
[(] 40
[)] 41
[*] 42
[+] 43
[,] 44
[-] 45
[.] 46
[/] 47
[0] 48
[1] 49
[2] 50
[3] 51
[4] 52
[5] 53
[6] 54
[7] 55
[8] 56
[9] 57
[:] 58
[;] 59
[<] 60
[=] 61
[>] 62
[?] 63
[@] 64
[A] 65
[B] 66
[C] 67
[D] 68
[E] 69
[F] 70
[G] 71
[H] 72
[I] 73
[J] 74
[K] 75
[L] 76
[M] 77
[N] 78
[O] 79
[P] 80
[Q] 81
[R] 82
[S] 83
[T] 84
[U] 85
[V] 86
[W] 87
[X] 88
[Y] 89
[Z] 90
[[] 91
[\] 92
[]] 93
[^] 94
[_] 95
[`] 96
[a] 97
[b] 98
[c] 99
[d] 100
[e] 101
[f] 102
[g] 103
[h] 104
[i] 105
[j] 106
[k] 107
[l] 108
[m] 109
[n] 110
[o] 111
[p] 112
[q] 113
[r] 114
[s] 115
[t] 116
[u] 117
[v] 118
[w] 119
[x] 120
[y] 121
[z] 122
[{] 123
[|] 124
[}] 125
[~] 126
[£] 163
[¤] 164
[§] 167
[¨] 168
[´] 180
[½] 189
[Å] 197
[Æ] 198
[Ø] 216
[å] 229
[æ] 230
[ø] 248
____________________________________________________________________________________________
KeyCodes (DANISH keyboard): onkeydown / onkeyup Tested with Internet Explore 5.0)
By: Helge Willum Larsen
____________________________________________________________________________________________
DOES NOT SUPPORT MULTIPLE KEYPRESSES !
ALL KEYS HAVE THEIR OWN, INDIVIDUAL KEYCODE !
[NumPad 1] is NOT the same as [1]
[NumPad +] is NOT the same as [+]
____________________________________________________________________________________________
Button: keyCode: NumLock: CapsLock: ScrollLock:
[BackSpace] 8 - - -
[Tab] 9 - - -
[NumPad 5] 12 no - -
[Return / Enter] 13 - - -
[Shift] 16 - - -
[Ctrl] 17 - - -
[Alt] 18 - - -
[Pause / Break] 19 - - -
[CapsLock] 20 - - -
[Esc] 27 - - -
[Space] 32 - - -
[Page Up] 33 - - -
[Page Down] 34 - - -
[End] 35 - - -
[Home] 36 - - -
[LeftArrow] 37 - - -
[UpArrow] 38 - - -
[RightArrow] 39 - - -
[DownArrow] 40 - - -
[PrintScreen / SysRq] 44 - - -
[Insert] 45 - - -
[Delete] 46 - - -
[0] 48 - - -
[1] 49 - - -
[2] 50 - - -
[3] 51 - - -
[4] 52 - - -
[5] 53 - - -
[6] 54 - - -
[7] 55 - - -
[8] 56 - - -
[9] 57 - - -
[A] 65 - - -
[B] 66 - - -
[C] 67 - - -
[D] 68 - - -
[E] 69 - - -
[F] 70 - - -
[G] 71 - - -
[H] 72 - - -
[I] 73 - - -
[J] 74 - - -
[K] 75 - - -
[L] 76 - - -
[M] 77 - - -
[N] 78 - - -
[O] 79 - - -
[P] 80 - - -
[Q] 81 - - -
[R] 82 - - -
[S] 83 - - -
[T] 84 - - -
[U] 85 - - -
[V] 86 - - -
[W] 87 - - -
[X] 88 - - -
[Y] 89 - - -
[Z] 90 - - -
[Turn Off] (special) 94 - - -
[Sleep] (special) 95 - - -
[NumPad 0] 96 yes - -
[NumPad 1] 97 yes - -
[NumPad 2] 98 yes - -
[NumPad 3] 99 yes - -
[NumPad 4] 100 yes - -
[NumPad 5] 101 yes - -
[NumPad 6] 102 yes - -
[NumPad 7] 103 yes - -
[NumPad 8] 104 yes - -
[NumPad 9] 105 yes - -
[NumPad *] 106 - - -
[NumPad +] 107 - - -
[NumPad -] 109 - - -
[NumPad ,] 110 - - -
[NumPad /] 111 - - -
[F1] 112 - - -
[F2] 113 - - -
[F3] 114 - - -
[F4] 115 - - -
[F5] 116 - - -
[F6] 117 - - -
[F7] 118 - - -
[F8] 119 - - -
[F9] 120 - - -
[F10] 121 - - -
[F11] 122 - - -
[F12] 123 - - -
[NumLock] 144 - - -
[ScrollLock] 145 - - -
[+] (next to [0]) 187 - - -
[,] 188 - - -
[-] (next to [.]) 189 - - -
[.] 190 - - -
[Æ] 192 - - -
[´] (next to [+]) 219 - - -
[½] (next to [1]) 220 - - -
[Å] 221 - - -
[Ø] 222 - - -
[<] (next to [Z]) 226 - - -
[Wake Up] (special) 255 - - -
____________________________________________________________________________________________
____________________________________________________________________________________________
Functions: Tested with Internet Explore 5.0
By: Helge Willum Larsen and Netscape Communicator 4.51
____________________________________________________________________________________________ |
星期二, 3月 30, 2010
星期三, 3月 24, 2010
星期一, 3月 22, 2010
星期日, 3月 21, 2010
sql 指定日期查詢
串接字串以達到指定查詢日期的效果
SELECT * FROM vw_CourseList
WHERE (CourseStart BETWEEN CONVERT(datetime, STR(YEAR(GETDATE())) + '/03/01') AND CONVERT(datetime, STR(YEAR(DATEADD(year, 1, GETDATE())))
SELECT * FROM vw_CourseList
WHERE (CourseStart BETWEEN CONVERT(datetime, STR(YEAR(GETDATE())) + '/03/01') AND CONVERT(datetime, STR(YEAR(DATEADD(year, 1, GETDATE())))
+ '/02/28'))
[MS SQL] 日期處理方法
--檢查是否為SQL SERVER合法日期格式
SELECT ISDATE('2004-03-01')
--1 (int)正確
SELECT ISDATE('2004-02-33')
--0 (int)錯誤
--取得現在時間GETDATE()
select GETDATE()
--2008-04-26 03:25:31.900
訂閱:
意見 (Atom)