2014年7月10日 星期四
使用 DirectoryInfo().Getfiles("*.xls") 會將 *.xlsx 列出來 ???
今天有朋友問我一個問題,使用 DirectoryInfo().Getfiles("*.xls") ,該目錄中若有檔案為 *.xlsx ,則連 *.xlsx 都會一起 list 出來
寫法如下,一般都是這樣子寫,看起來沒什麼異狀...
DirectoryInfo di = new DirectoryInfo(@"d:\temp");
FileInfo[] files = di.GetFiles("*.xls");
foreach (FileInfo fi in files)
{
string sfullname = fi.FullName;
}
後來改為以下的寫法,用 Where 下檔名的條件就可以解決了...
List<string> sfiles = Directory.GetFiles(@"d:\temp", "*.*").Where(file => file.ToLower().EndsWith("xls")).ToList();
foreach (string file in sfiles)
{
FileInfo fi = new FileInfo(file);
//(.....)
}
舉一反三,若要取得二個以上的副檔名檔案列表呢? Where 條件中加個 || (OR) 條件就好了
List<string> sfiles = Directory.GetFiles(@"d:\temp", "*.*").Where(file => file.ToLower().EndsWith("xls") || file.ToLower().EndsWith("html") ).ToList();
2014年5月17日 星期六
庫存不足,不允許過帳還原
2014年5月2日 星期五
IIS7 + dotNetFramework 4.5.1 不能運行
IIS7 + dotNetFramework 4.5.1 不能運行
執行了 v4.xxx.xxx aspnet_regiis -i 仍不能運行,後來再重啟 IIS 及應用程式集區之後就可以執行了,在 Server 顯示正常,但從本機瀏覽網頁卻變成 下圖,格式都跑掉了
修改加入了以下這行後顯示就正常了
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
2014年4月29日 星期二
[EFGP] FormScript with jQuery
今天在測試 EasyFlow GP 透過 jQuery 使用 C# 寫的 Webservice
在 VisualStudio 中用 c# 寫的程式可以正常呼叫,但是透過 EFGP 就不能
試了半天之後終於得到答案了,在這裡做個筆記
1. jQuery.noConflict(); //避免 $ 與其他 jQuery UI 的衝突 ,在這個範例上沒有設也ok
2. jQuery.support.cors = true; // 跨網域要把它設為 true , 就是這一點搞了非常久
範例如下:
FormScript :
在 VisualStudio 中用 c# 寫的程式可以正常呼叫,但是透過 EFGP 就不能
試了半天之後終於得到答案了,在這裡做個筆記
1. jQuery.noConflict(); //避免 $ 與其他 jQuery UI 的衝突 ,在這個範例上沒有設也ok
2. jQuery.support.cors = true; // 跨網域要把它設為 true , 就是這一點搞了非常久
範例如下:
FormScript :
document.write('<script type="text/javascript" src="../../js/jquery-1.7.1.min.js"></script>');
function GetInfo() { //jQuery.noConflict(); jQuery.support.cors = true; //var jq = jQuery.noConflict(); var $res; $.ajax({ type: "POST", url: "http://10.1.10.103:8888/JsonServiceSample.asmx/GetOneUserInfo", contentType: "application/json; charset=utf-8", async: false, cache: false, dataType: 'json', data: "{name:'Test',age:29}", success: function (data) { if (data.hasOwnProperty("d")) { $res = data.d; } else $res = data; }, error: function (xhr, ajaxOptions, thrownError) { alert('WS status = ' + xhr.status ); alert('WS Error =' + thrownError); } }); return $res; }
function btnEdit_onclick() { var res = GetInfo(); alert(res.Name); alert(res.Age); }WebService
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Services; using System.Web.Services; using System.Web.Services.Protocols; //加上這個預備給 Java Call namespace JQueryWebService { public class User { public string Name { get; set; } public int Age { get; set; } } /// <summary> /// 移除 NameSpace /// 每一個 Methods 上面必須加上 /// [ScriptMethod(ResponseFormat = ResponseFormat.Json)] /// </summary> [WebService(Namespace = "", Description = "For Donma Test")] [System.ComponentModel.ToolboxItem(false)] [ScriptService] public class JsonServiceSample : System.Web.Services.WebService { [WebMethod] [SoapRpcMethod(Use = System.Web.Services.Description.SoapBindingUse.Literal)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string GetUserInfoString(string name, int age) { return name + "," + age; } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public User GetOneUserInfo(string name, int age) { return (new User { Name = name, Age = age }); } [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public User[] GetUsers(string name, int age) { List<User> res = new List<User>(); res.Add(new User { Name = name + "1", Age = age }); res.Add(new User { Name = name + "2", Age = age }); return res.ToArray(); } } }
2014年2月9日 星期日
第一個可能發生的例外狀況類型 'System.Threading.ThreadAbortException' 發生於 mscorlib.dll
從 VS2010 到 VS2013後,原來的程式碼發生了一個錯誤訊息:
Server.Transfer("url", true);
第一個可能發生的例外狀況類型 'System.Threading.ThreadAbortException' 發生於 mscorlib.dll
其他資訊: 執行緒已經中止。
要改成為
Response.Redirect("url",false);
這樣子就沒問題了。
2014年1月6日 星期一
T-SQL 日期格式轉換成文字
每次到了要轉換日期格式的時候都會特別想念 Oracle ,只要下 to_char(date, format) 指令就可以輕鬆完成日期轉成文字
但沒辦法,手上的專案就是使用 SQL Server ,該來的還是躲不掉,只是每次都會忘,忘了就要查 Google ,
Will 大的這一篇寫得非常完整,就拿來引用
http://blog.miniasp.com/post/2008/02/27/Use-CONVERT-function-to-deal-with-SQL-Server-Datetime.aspx
摘錄其範例如下:
輸出格式:2008-02-27 00:25:13
SELECT CONVERT(char(19), getdate(), 120)
輸出格式:2008-02-27
SELECT CONVERT(char(10), getdate(), 20)
輸出格式:2008.02.27
SELECT CONVERT(char(10), getdate(), 102)
輸出格式:08.02.27
SELECT CONVERT(char(8), getdate(), 2)
輸出格式:2008/02/27
SELECT CONVERT(char(10), getdate(), 111)
輸出格式:08/02/27
SELECT CONVERT(char(8), getdate(), 11)
輸出格式:20080227
SELECT CONVERT(char(8), getdate(), 112)
輸出格式:080227
SELECT CONVERT(char(6), getdate(), 12)
以下摘錄 MSDN 的樣式說明
http://msdn.microsoft.com/zh-tw/library/ms187928.aspx
當 expression 是日期或時間資料類型時, style 就可以是下表所列的其中一個值。 其他值則當做 0 處理。 從 SQL Server 2012 開始,當從日期和時間類型轉換為datetimeoffset 時,唯一支援的樣式為 0 或 1。 所有其他轉換樣式都會傳回錯誤 9809。
1 這些樣式值會傳回不具決定性的結果。 其中包括所有 (yy) (不含世紀) 樣式和 (yyyy) (含世紀) 樣式的子集。
4 專為了 XML 而設計。 如果是從 datetime 或 smalldatetime 轉換成字元資料,輸出格式會符合上表的描述。
5 回曆是有多種變化的日曆系統 SQL Server 使用科威特演算法。
6 只有在從字元資料轉換為 datetime 或 smalldatetime 時才支援。 當只代表日期或只代表時間元件的字元資料轉換為 datetime 或 smalldatetime 資料類型時,未指定的時間元件會設定為 00:00:00.000,而未指定的日期元件則會設定為 1900-01-01。
7 選擇性的時區指標 Z 可用來輕鬆地將具有時區資訊的 XML datetime 值對應到沒有時區的 SQL Server datetime 值。 Z 是時區 UTC - 0 的指標。 其他的時區是以 + 或 - 方向位移的 HH:MM 來代表。 例如:2006-12-12T23:45:12-08:00。
當您從 smalldatetime 轉換成字元資料時,包括秒或毫秒的樣式會在這些位置顯示零。 當您從 datetime 或 smalldatetime 值轉換時,您可以利用適當的 char 或 varchar資料類型長度來截斷不需要的日期部分。
但沒辦法,手上的專案就是使用 SQL Server ,該來的還是躲不掉,只是每次都會忘,忘了就要查 Google ,
Will 大的這一篇寫得非常完整,就拿來引用
http://blog.miniasp.com/post/2008/02/27/Use-CONVERT-function-to-deal-with-SQL-Server-Datetime.aspx
摘錄其範例如下:
輸出格式:2008-02-27 00:25:13
SELECT CONVERT(char(19), getdate(), 120)
輸出格式:2008-02-27
SELECT CONVERT(char(10), getdate(), 20)
輸出格式:2008.02.27
SELECT CONVERT(char(10), getdate(), 102)
輸出格式:08.02.27
SELECT CONVERT(char(8), getdate(), 2)
輸出格式:2008/02/27
SELECT CONVERT(char(10), getdate(), 111)
輸出格式:08/02/27
SELECT CONVERT(char(8), getdate(), 11)
輸出格式:20080227
SELECT CONVERT(char(8), getdate(), 112)
輸出格式:080227
SELECT CONVERT(char(6), getdate(), 12)
以下摘錄 MSDN 的樣式說明
http://msdn.microsoft.com/zh-tw/library/ms187928.aspx
日期和時間樣式
SQL Server 利用科威特演算法來支援阿拉伯文樣式的日期格式。
不含世紀 (yy) (1)
|
含世紀 (yyyy)
|
標準
|
輸入/輸出 (3)
| ||
---|---|---|---|---|---|
-
|
0 或 100 (1,2)
|
預設
|
mon dd yyyy hh:miAM (或 PM)
| ||
1
|
101
|
美式英文
|
1 = mm/dd/yy
101 = mm/dd/yyyy
| ||
2
|
102
|
ANSI
|
2 = yy.mm.dd
102 = yyyy.mm.dd
| ||
3
|
103
|
英式英文/法文
|
3 = dd/mm/yy
103 = dd/mm/yyyy
| ||
4
|
104
|
德文
|
4 = dd.mm.yy
104 = dd.mm.yyyy
| ||
5
|
105
|
義大利文
|
5 = dd-mm-yy
105 = dd-mm-yyyy
| ||
6
|
-
|
6 = dd mon yy
106 = dd mon yyyy
| |||
7
|
-
|
7 = Mon dd, yy
107 = Mon dd, yyyy
| |||
8
|
108
|
-
|
hh:mi:ss
| ||
-
|
9 或 109 (1,2)
|
預設值 + 毫秒
|
mon dd yyyy hh:mi:ss:mmmAM (或 PM)
| ||
10
|
110
|
美國
|
10 = mm-dd-yy
110 = mm-dd-yyyy
| ||
11
|
111
|
日本
|
11 = yy/mm/dd
111 = yyyy/mm/dd
| ||
12
|
112
|
ISO
|
12 = yymmdd
112 = yyyymmdd
| ||
-
|
13 或 113(1、2)
|
歐洲預設值 + 毫秒
|
dd mon yyyy hh:mi:ss:mmm(24h)
| ||
14
|
114
|
-
|
hh:mi:ss:mmm(24h)
| ||
-
|
20 或 120 (2)
|
ODBC 標準
|
yyyy-mm-dd hh:mi:ss(24h)
| ||
-
|
21 或 121 (2)
|
ODBC 標準 (含毫秒)
|
yyyy-mm-dd hh:mi:ss.mmm(24h)
| ||
-
|
126 (4)
|
ISO8601
|
yyyy-mm-ddThh:mi:ss.mmm (無空格)
| ||
-
|
127(6, 7)
|
具有時區 Z 的 ISO8601。
|
yyyy-mm-ddThh:mi:ss.mmmZ (無空格)
| ||
-
|
130 (1,2)
|
回曆 (5)
|
dd mon yyyy hh:mi:ss:mmmAM
| ||
-
|
131 (2)
|
回曆 (5)
|
dd/mm/yyyy hh:mi:ss:mmmAM
|
2 預設值 (style0 或 100、9 或 109、13 或 113、20 或 120 及 21 或 121) 一律會傳回世紀 (yyyy)。
3 當轉換成 datetime 時輸入;當轉換成字元資料時輸出。
![]() |
---|
當您從含有時間之樣式的字元資料轉換成 datetimeoffset 時,時區時差就會附加至結果。
訂閱:
文章 (Atom)