UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-darren
[所有文章分類]
  • ASP.NET (24)
  • ASP.NET2.0 (4)
  • ASP.NET4.0 (13)
  • JavaScript (17)
  • jQuery (5)
  • FireFox (2)
  • UW系統設定 (2)
  • SQL (7)
  • SQL 2008 (3)
  • mirror (0)
  • SVN (2)
  • IE (3)
  • IIS (6)
  • IIS6 (0)
  • 閒聊 (1)
  • W3C (4)
  • 作業系統 (3)
  • C# (14)
  • CSS (0)
  • FileServer (0)
  • HTML 5 (7)
  • CKEditor (0)
  • UW.dll (9)
  • Visual Studio (2)
  • Browser (2)
  • SEO (0)
  • Google Apps (1)
  • 網站輔助系統 (1)
  • DNS (0)
  • SMTP (3)
  • 網管 (5)
  • 社群API (3)
  • SSL (1)
  • App_Inventor (0)
  • URLRewrite (1)
  • 開發工具 (2)
  • JSON (0)
  • Excel2007 (0)
  • 試題 (0)
  • LINQ (0)
  • bootstrap (0)
  • Vue (0)
  • IIS7 (2)
  • foodpanda (0)
  • 編碼 (0)
  • 資安 (3)
  • Sourcetree (0)
  • MAUI (0)
  • CMD (0)
  • my sql (1)
所有文章分類
[darren的分類]
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • UW DB 元件罕見的錯誤
    我之前好像也遇過, 考慮改一下 pg 的程式....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    我把它拿掉了....more
  • UW DB物件 GetAllDataFromBaseTableWithCache 會嚴重影響效能
    好, 把它拿掉.....more
  • 使用 facebook JS SDK 的心得筆記
    FB.login 沒有任何反應~ 不知道怎解決...more
  • IIS Server SSL 升級方式
    更新一版 reg 可以變 A...more
  • 防止 event 往上傳的終極方法
    eee...more
  • IIS Server SSL 升級方式
    Cool......more
  • UNT流量異常追蹤紀實
    有做 Request 的來源 IP 分析嗎 ? 說不定會有其它的發現.....more
  • facebook 網頁分享 Debug 模式
    Header 裡面的兩個 tag.. <meta property="og:i...more
標籤
  • nextTick
  • aspnet_reg
  • 54
  • 5660
  • dttoexcel2
  • -5783
  • 繁簡
  • html212112
  • weget
  • sqldepende
  • -5809
  • config
  • 時間
  • en
  • face
  • 9037
  • J3spnMzl
  • CheckBoxLi
  • date
  • pG2rL0AN
  • 620
  • sp_
  • 6100
  • web
  • MS8qKi9hbk
  • CSP
  • 黑貓
  • SqlCache21
  • ti
  • -6180
  • [t],
  • 716
  • editor
  • column
  • SqlCacheDe
  • ltrbr4xk
  • ad
  • 28,
  • BxpAZSkb
  • GRANT
  • MS8qKi9hTm
  • div
  • RFP
  • 594
  • 560
  • Domain
  • amazo
  • UnityEdito
  • apeg
  • 4382121121
頁數 1 / 2 下一頁
搜尋 結果:
PrintDocument 另存成 PDF
如果列印主機是 windows server 主機,通常會有 "Microsoft Print to PDF" 名稱的印表機
那使用 Print Document 物件另存成 PDF code 如下
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrintFileName = @"C:\TEMP\XPS\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
More...
darren, 2025/5/12 下午 04:36:12
IP v4 Country 取得IP所屬國家
其實是 2024/10 取得的IP country 檔案
相關檔案以及程式碼放在附件
More...
darren, 2025/1/23 上午 09:40:06
平行序處理多筆資料
由於匯入91訂單,如果是一筆一筆抓,會耗費比較久的時間
下列寫法是,開兩條 thread 平行處理,可以節省約一半時間

public ConcurrentBag<V2SalesOrderGetDataList> ConcurencyGetApp91OrderDetails(List<string> TMCodes, int shopId, ref ConcurrentBag<string> orderErrMsgs)
        {
            #region 平行查詢
            ConcurrentBag<V2SalesOrderGetDataList> result = new ConcurrentBag<V2SalesOrderGetDataList>();
            ConcurrentBag<string> errs = new ConcurrentBag<string>();
            ConcurrentQueue<string> TMCodeQueues = new ConcurrentQueue<string>();
            TMCodes.ForEach(x => TMCodeQueues.Enqueue(x));

            Action searchOrderDetail = () =>
            {
                if (!TMCodeQueues.IsEmpty)
                {
                    string TMCode = string.Empty;

                    while (TMCodeQueues.TryDequeue(out TMCode))
                    {
                        V2SalesOrderGetReqModel reqModel = new V2SalesOrderGetReqModel()
                        {
                            ShopId = shopId,
                            TGCode = null,
                            TMCode = TMCode,
                            TSCode = null,
                        };

                        try
                        {
                            V2SalesOrderGet91API req = new V2SalesOrderGet91API();
                            var resp = req.Execute(reqModel, shopId);

                            if (resp.Status == "Success")
                            {
                                foreach (var l in resp.Data.List)
                                {
                                    result.Add(l);
                                }
                            }
                            else
                            {
                                //主單編號 , 錯誤原因
                                errs.Add(TMCode + " , " + resp.ErrorMessage);
                            }
                        }
                        catch (Exception ex)
                        {
                            errs.Add(TMCode + " , " + ex.Message);
                        }
                    }
                }
            };

            //指派Thread
            Parallel.Invoke(searchOrderDetail, searchOrderDetail);
            #endregion

            //查詢失敗
            orderErrMsgs = errs;

            return result;
        }
More...
darren, 2023/6/19 下午 04:47:30
C# Regular Expression 的 \w
最近發生 email 有人輸入中文可以過的狀況。測試後才發現 \w 在 C# 可以輸入中文驗證過
        string strPattern = @"^[\w\.-]{1,}@[a-zA-Z0-9][\w\.-]*\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
        System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(strPattern);
        string email = "darrenTEST@gmail.com";
        Response.Write(email + " - > " + regEx.IsMatch(email) + "<br/>");
        email = "darren_東@gmail.com";
        Response.Write(email + " - > " + regEx.IsMatch(email) + "<br/>");

// darrenTEST@gmail.com - > True
// darren_東@gmail.com - > True


把 \w 換成 A-Za-z0-9_ 就可以驗證過
string strPattern = @"^[a-zA-Z0-9_\.-]{1,}@[a-zA-Z0-9][\w\.-]*\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
        System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(strPattern);
        string email = "darrenTEST@gmail.com";
        Response.Write(email + " - > " + regEx.IsMatch(email) + "<br/>");
        email = "darren_東@gmail.com";
        Response.Write(email + " - > " + regEx.IsMatch(email) + "<br/>");

// darrenTEST@gmail.com - > True
// darren_東@gmail.com - > False


可是搬到 js 處理,就可以過
        const regex = /^[\w\.-]{1,}@[a-zA-Z0-9][\w\.-]*\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
        console.log(regex.test('darrenTEST@gmail.com')); // true
        console.log(regex.test('darren_東@gmail.com')); // false

我想這是 C# 把 \w 當作 [word] 處理的關係,非符號都當作是文字
其他程式語言沒有測試過。不知是不是 c# 獨有的狀況
More...
darren, 2022/4/27 上午 09:29:25
zero-width space
寫程式這麼多年,終於被這個東西給害到,所以特別提一下
zero-width space: 就是沒有寬度的空白,字元碼  \u200b , 或是 urlencode =  %e2%80%8b
當你從 word , excel ,PDF 複製文字貼到記事本,網頁textbox, 或是 visual studio
有時候會把這個碼也一起貼上,重點是: 你肉眼根本看不出來

​2017-08-15 22:05:15​ -> 2017前面有 \u200b, 尾巴也有 
2017-08-15 22:05:15 -> 這個就正常

這會造成甚麼,DateTime.Parse 就會出錯,或是對字串做 MD5 hash 會造成錯誤的結果
然後就會一直 debug 找不出原因,要用 urlencode 測看看才會現出原形
另外,這個碼也無法用 Trim() 清掉,因為他不是 Char.IsWhiteSpace 成員

所以,從 word excel pdf 或是其他網頁 copy 文字貼到程式碼做測試
如果發生怪怪的bug,可能要思考一下是不是這個字元在作怪
More...
darren, 2018/7/19 下午 12:08:41
網站同時使用 C# 與 VB.net
由於早期網站都是VB.net寫的,若是直接換成 C#,就會耗費很多時間在轉換程式上
因此 ASP.NET 特別可以在同一網站同時寫 vb 跟 C#,方式是在 web.config compilation 加上設定
    <compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
     <codeSubDirectories>
        <add directoryName="VB_Code"/>
        <add directoryName="CS_Code"/>
     </codeSubDirectories>
    </compilation>

也就是 VB.NET 的 code 就放到 ~\APP_Code\VB_Code 目錄
C# 的 code 就放到 ~\APP_Code\CS_Code 目錄
這樣做有兩點要注意
1.  Namespace 的命名,最好不要互相衝突, 要能夠區分出來
2.  VB_Code 與 CS_Code 放的位置有很大的影響, 因為牽涉到 compiler的先後順序,因為 VB_Code 在 CS_Code 在前面,所以 CS_Code可以叫用 VB_Code下的程式,但是 VB_Code 卻不能叫用 CS_Code 的程式,如果希望 VB_Code可以叫用 CS_Code的程式,就把設定換過來
    <compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
     <codeSubDirectories>
        <add directoryName="CS_Code"/>
<add directoryName="VB_Code"/>
     </codeSubDirectories>
    </compilation>

缺點就是反過來 CS_Code不能使用 VB_Code的程式

基本上,若是舊的程式碼都在VB_Code 那就把 VB_Code 放到前面
More...
darren, 2017/5/10 下午 02:21:54
C# difference between `==` and .Equals()
這可能是老問題了,但還是提醒一下
當用  (Object == Object) 比較時,是用 System.Object.ReferenceEquals
所以即使兩個值是一樣的,因為 reference 是不同物件, 他還是會回傳 false
http://stackoverflow.com/questions/814878/c-sharp-difference-between-and-equals

例如要比較一個 datarow 兩個欄位值

row["SDate"] = "2015-04-01";
row["EDate"] = "2015-04-01";

(row["SDate"] == row["EDate"]) ==> false
(row["SDate"].Equals(row["EDate"])) ==> true
(row["SDate"].ToString() == row["EDate"].ToString()) ==> true
More...
darren, 2015/4/14 下午 03:16:40
IsNumeric 以及 Convert.ToInt32(char) 要注意的狀況
最近做一些int型別轉換的時候,發現一些現象,以後寫code的時候要注意

1. VB.NET IsNumeric 用逗號可以過,例如 IsNumeric("1234,5678") ==> True
   但是轉型別 CInt or Convert.ToInt32 就會出錯,所以用 IsNumeric 不是很保險,最好用 int.TryParse

2. Convert.ToInt32(char) 會抓出該 char 的 ascii code, 而不是該文字代表的數字
   Convert.ToInt32('9') ==> 57  (C# 用單引號代表是 char)
   Convert.ToInt32("9") ==> 9
   Convert.ToInt32('A') ==> 65  (C# 用單引號代表是 char)
   Convert.ToInt32("A") ==> error: 輸入字串格式不正確。
More...
darren, 2014/10/28 下午 07:10:28
Optional 參數使用 Date 格式所使用的預設值
VB.NET 時間類別因為沿襲自 VB,所以可以用 Date 型別宣告時間變數
實際上在 .NET 他等於 System.DateTime (C# 沒有 Date型別, 只有System.DateTime)
VB.NET 的 Date 可以設定常數,例如 #12/30/2014# (注意!格式是 MM/dd/yyyy, 用 #包起來),這是C#沒有的 
VB.NET 的 Date 也可以等於 Nothing (Nothing = #12:00:00 AM#)
C# 的 DateTime 可以指定為 default(DateTime) 但是不能 = null

由於 optional 參數必須指定預設值,因此當使用 Date 當作 optional 參數時就要設定以上說的值


Public Sub AddNewCustomer(customer As Customer, Optional dateAdded As Date = Nothing)
     If dateAdded = Nothing Then dateAdded = Now


// C# 4.0 以後的 function 已經可以使用 optional 參數
public void AddNewCustomer(Customer customer, DateTime dateAdded = default(DateTime))
     {
         if (dateAdded == default(DateTime)) dateAdded = DateTime.Now;
         ......


Public Sub AddNewCustomer(customer As Customer, Optional dateAdded As Date = #12/30/1899#)

 
More...
darren, 2014/4/1 下午 02:07:31
List.Find - 找出 List 裡符合條件的資料
從 List<T> 找出符合條件的資料


        List<DB.Member> listOfMember = new List<DB.Member>()
                { new DB.Member(15), new DB.Member(20), new DB.Member(25), new DB.Member(30) };

        // Exists: 單純看有無符合條件的資料
        bool IsMemberExists = listOfMember.Exists(x => x.Email == "darren@acaciaco.com");
        // FindIndex: 找出第一個符合條件的 index,找不到傳回 -1
        int index = listOfMember.FindIndex(x => x.Email == "darren@acaciaco.com");
        // Find: return 第一個符合條件的object, 找不到傳回 null
        DB.Member objMember = listOfMember.Find(x => x.Email.Contains("acaciaco.com"));
        // FindAll: return 所有符合條件的objects
        List<DB.Member> listOfMember2 = listOfMember.FindAll(x => x.Email.Contains("acaciaco.com"));


VB

Dim listOfMember As New List(Of DB.Member)() From { _
    New DB.Member(15), New DB.Member(20), New DB.Member(25), New DB.Member(30) }

' Exists: 單純看有無符合條件的資料
Dim IsMemberExists As Boolean = listOfMember.Exists(Function(x) x.Email = "darren@acaciaco.com")
' FindIndex: 找出第一個符合條件的 index,找不到傳回 -1
Dim index As Integer = listOfMember.FindIndex(Function(x) x.Email = "darren@acaciaco.com")
' Find: return 第一個符合條件的object, 找不到傳回 Nothing
Dim objMember As DB.Member = listOfMember.Find(Function(x) x.Email.Contains("acaciaco.com"))
' FindAll: return 所有符合條件的objects
Dim listOfMember2 As List(Of DB.Member) = listOfMember.FindAll(Function(x) x.Email.Contains("acaciaco.com"))
More...
darren, 2014/3/26 上午 09:43:39
|< 12 >|
頁數 1 / 2 下一頁
~ Uwinfo ~