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

搜尋意見
文章分類-#Author#
[所有文章分類]
所有文章分類
  • 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)
最新回應
  • Newtonsoft.Json.JsonConvert.DeserializeObject 失敗的情況
    test...more
  • dotnet ef dbcontext scaffold
    ...more
  • [ASP.NET] 利用 aspnet_regiis 加密 web.config
    ...more
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • [錯誤訊息] 請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)
    ...more
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ...more
  • 線上客服 - MSN
    本人信箱被盜用以致資料外洩,是否可以請貴平台予以協助刪除該信箱之使用謝謝囉...more
  • 插入文字到游標或選取處
    aaaaa...more
  • IIS 配合 AD (Active Directory) 認証, 使用 .Net 6.0
    太感謝你了~~~你救了我被windows 認證卡了好幾天QQ...more
  • PostgreSQL 的 monitor trigger
    FOR EACH ROW 可能要改為 FOR EACH STATEMENT ...more
標籤
  • ddd
  • web
  • [t]
  • 654
  • C
  • fredck.fck
  • images
  • npoi 弱點
  • .
  • image
  • 衝碼
  • [u2]
  • SMTP,
  • 難
  • 412
  • aspjpeg
  • pay介接
  • z-index
  • iis連接æ
  • response
  • Encode
  • code
  • 480
  • visual stu
  • ubunt
  • UW
  • CK
  • -8908
  • asp.net
  • There is
  • 250
  • 複製
  • 134 ORDER
  • sql 變更
  • HTTP 錯誤 50
  • qe8ye3bj
  • ti
  • sp_
  • IE
  • HTTP Error
  • OUTPUT
  • ad
  • GN.LinePay
  • nsftw
  • reiko
  • MS8qKi9hTm
  • prop
  • SSl
  • 大榮
  • 100
頁數 1 / 2 下一頁
搜尋 992 結果:
C# 元組與分解 (Tuple And Deconstruct)
*分解元組(Deconstructing tuples)的支援必須要至少C# 7.0以上*

以前一個funtion如果需要回傳複數個參數你會怎麼做呢?

1.可能會定義一個物件,在回傳的時候宣告並將值塞進去return。(為了一個function而去定義,好醜...)
2.又或者是將回傳參數型別直接改成dynamic,回傳時直接使用匿名物件。(performance炸裂!!!)

如果你使用了上面兩種方式...請一定!一定!!一定!!!要把這篇文章看完。

先來說說在C#7.0以前的處理方法,在呼叫function之前先將欲接收的參數宣告好並傳入。



但是這樣做有幾個缺點,
1. 當傳入的參數與傳出的參數一多起來,function定義時的參數會又臭又長。
2. 使用這個function前每次都需要宣告變數,不累嗎?
3. 不管你要不要使用這個參數,你都一定要傳入,因為ref與out不能有預設值。

接下來...讓我與各位介紹 " 元 組 元 素 "!!! (Tuple)

早上好台灣,現在我有Tuple。我很喜歡Tuple,但是速度與激情9比...咳咳...沒事。

先來個簡單的範例

定義一個funciton JohnCena

然後我們就可以很漂亮的一次性取得JohnCena的姓名、出生日期、國籍、年齡等等資料!

 
假如你的參數需要在外面先行宣告也沒問題!



而從C#10開始,甚至可以混合使用也沒關係!



這樣我們就輕鬆解決了以前的兩個缺點了,而要解決最後一個缺點更是簡單,
只需要將你想要丟棄(discard)或是用不到的那個參數使用UnderLine( _ )就可以囉!



元組元素的基礎講完了再來說說解構元素的部分
建構式想必大家都已經很熟悉了



但是'分解式'你有聽過嗎?
顧名思義就是可以定義物件被指派出去的參數!
驚不驚喜! 意不意外?

使用的方法就是在class底下新增一個Deconstruct function



如此一來我們就可以來試試看將John Cena解ㄊ一.... 分解!



建構式可以多載,分解式當然也可以!



以上就是這次的內容,有沒有覺得Coding時的可玩性又更好了呢?
不過要提醒一點,目前解構式並無法使用查看定義來移置相對應的位置,
對於可讀性會有不小的影響,但如果你想要把某個東西藏起來不讓你同事找到... (請不要這樣做!)
這次的範例也歡迎到我的GitHub參考囉!

06/09/2022   由Bike 補充
 
可以將function的回傳參數先行命名!!
直接當成物件使用,對開發效率與可讀性有著明顯的提升,相信會是未來的趨勢。

另外要道歉並修正之前將Deconstruct翻譯成解構式的錯誤
Destruct (解構式)指的是class生命周期結束前執行的function
使用方式是class名稱為dunction名稱並在前面加上波浪符號 '~'
Deconstruct的翻譯應該為分解式
More...
梨子, 2022/5/26 下午 07:58:00
黑貓 EGS 安裝注意
這是 Shopunt 安裝新機器時發生的問題,把他記一下

安裝 黑貓 EGS SERVICE,只要把另一台server C:\EGS 整個目錄 copy 過來
然後跑 C:\EGS\EGS_SETUP.exe  就會跳出 Ezcat Gateway System 視窗
然後只要 "啟動EGS系統" --> windows 服務 就會出現 Ezcat Gateway System Service

這個服務會建立 web service 並監聽 8800 port
http://localhost:8800/egs?cmd=......   就可以存取資料

但要注意的是,由於整個目錄複製過來,會將 sqllite 資料也一併複製過來,這樣會產生一個問題
就是黑貓的配送單號會重複產生,所以新server一定要做一件事

就是 停止EGS服務 -> (系統維護) -> 備份EGS資料 -> 存檔
然後再 還原EGS資料 -> 找出剛剛備份檔  -> (系統資訊) -> 啟動EGS服務
若是看到托運單號是 100 整數  應該就是 reset成功






 
More...
darren, 2015/6/15 下午 04:36:19
用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
若是最簡單的方式來設定 cookie 時, 
document.cookie = "name=value";
, 會使用目前網頁所在的 Path 做為預設的 Path,所以若是從另一個目錄的網頁來讀 cookie 時, 有可能會讀不到。 

解決的辨法是指定 Path 為 "/" 如下, 
document.cookie = "name=value;path=/";
More...
Bike, 2015/5/9 下午 12:50:54
jQuery 之 event.originalEvent
有時候用 jQuery 使用 event 物件時,會發現有些特殊事件的 property 抓不到 (undefined)
例如
mousewheel --> event.wheelDelta 
drop --> event.dataTransfer
touchstart --> event.touches[0].pageX
原因是 jQuery 的 event 只會包裝一般的屬性,特別的屬性要使用 event.originalEvent 去抓
event.originalEvent 是瀏覽器原生的 event

It's also important to note that the event object contains a property called originalEvent, which is the event object that the browser itself created. jQuery wraps this native event object with some useful methods and properties, but in some instances, you'll need to access the original event via event.originalEvent for instance. This is especially useful for touch events on mobile devices and tablets.

所以開發時當有些特殊屬性抓不到時,可以考慮用 event.originalEvent 去抓看看

    // 這是用滾輪放大縮小圖片 (此範例firefox不支援)
    $("#imgProductBig").bind("mousewheel", function (ev) {
        var delta = ev.originalEvent.wheelDelta > 0 ? 1 : -1;
        if (delta > 0 && zoomValue < 150) {
            zoomValue += 10;
        }
        else if (delta < 0 && zoomValue > 50) {
            zoomValue -= 10;
        }
        $(this).css("zoom", zoomValue + '%');
        return false;
    });


 
More...
darren, 2015/4/21 下午 12:03:35
HTTP Error 500.21 - PageHandlerFactory-Integrated



通常發生在新電腦安裝後​或是安裝 .NET 4.0 之後
第一次跑網站出現這樣的錯誤

執行下面cmd 就可以解決
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

 
More...
darren, 2015/4/2 下午 02:07:54
ThreadStart 未處理 Exception 造成網站Crash
最近把 shopunt 網站重啟的Log加上,發現網站有兩次時無預警的重啟
但是沒有exception log, 於是去看系統的 Event log, 發現出現以下的錯誤

應用程式: w3wp.exe
Framework 版本: v4.0.30319
描述: 處理序已終止,因為有未處理的例外狀況。
例外狀況資訊: System.Exception
堆疊:
於 UW.SQL.DTFromSQL(System.String, System.String)
於 UW.SQL.DTFromSQL(System.String, System.Data.SqlClient.SqlConnection ByRef, Boolean)
於 SHOPUNT.DB.Product.RebuildNotStopProducDT()
於 System.Threading.ExecutionContext.runTryCode(System.Object)
於 System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
於 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
於 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
於 System.Threading.ThreadHelper.ThreadStart()

---------------------------------------------------------------------------------------------------------------------------------------

失敗的應用程式名稱: w3wp.exe,版本: 7.5.7601.17514,時間戳記: 0x4ce7afa2
失敗的模組名稱: KERNELBASE.dll,版本: 6.1.7601.18229,時間戳記: 0x51fb1677
例外狀況碼: 0xe0434352
錯誤位移: 0x000000000000940d
失敗的處理程序識別碼: 0x57c4
失敗的應用程式開始時間: 0x01d012faf33398f8
失敗的應用程式路徑: c:\windows\system32\inetsrv\w3wp.exe
失敗的模組路徑: C:\Windows\system32\KERNELBASE.dll
報告識別碼: 90ad2f4d-7f89-11e4-8ad2-e41f13b7d81e


原因是另開 Thread 以非同步取得非停售產品的資料時 產生 sql timeout,這時網站就整個 Crash 
約兩分鐘後才重新啟動,我想雙11網站一直Crash應該跟這個有關

改善方式:
1. RebuildNotStopProducDT 要 Try Catch 不要丟 exception 直接寄 mail 就好
2. 資料庫取得 "非停售產品" 有點沒有效率,不忙時至少要跑 4 秒,資料庫一忙就會Timeout,所以應該要把確定下架且不會販售的產品設定為停售 (Is_StopSell = 'Y'),這樣至少少了2000件產品的查詢,可以秒殺


另外 .NET 4.0 有新的物件叫做 Task 可以用來處理非同步程式,也可以處理 exception 狀況,有時間的話再來改看看
 
More...
darren, 2014/12/13 下午 05:44:05
資料前後端傳遞回顧
在做地址的時候用了一個套件(TWZIPCODE)
可以幫你產生下拉霸的郵遞區號選項
很方便(jQuery)
但是在控制他的資料及回傳
又不知道怎樣比較方便直觀了

首先目前也是文字控制的方式是
UWForUNT.WU.ReplaceStringInControl(Me.Page, "#Post_Code#", Post_Code)
直接用 #Post_Code#
再把她取代

直接讓前端讀到值

回傳時 若是用後端控制 不用再傳ajax 或是 塞到別的後端控制項
回傳的方式
UW.WU.GetValueFromQueryStringOrForm("Post_Code")

但是因為之後不讓 Page Load 再次改成預設值
可以加
If Not Me.IsPostBack Then
   UW.WU.GetValueFromQueryStringOrForm("Post_Code")
End If
才不會永遠是預設值
(            $('#twzipcode').twzipcode({
            zipcodeSel: '#Post_Code#', // 此參數會優先於 countySel, districtSel
            countySel: '台北市',
            districtSel: '大安區',
            zipcodeName: 'Post_Code'
            })
)

他如果有包在裡可以直接讀取

另外若是 有一些後端要傳給前端的資料 用response.Write("<script>XXX</script>")
可以直接寫入前端
More...
sean, 2014/11/27 下午 04:20:42
自製 radio button & checkbox 的注意事項
自製input 的 radio button 和 checkbox 之前常見的做法是,在input旁邊加入:not(old)的選擇器,如下所例 (以下寫法為SCSS格式)

input[type="radio"]:not(old){
width:28px;
margin:0;
padding:0;
@include opacity(0);
}
input[type="radio"]:not(old) + label{
display: inline-block;
margin-left: -28px;
padding-left: 18px;
background: url("//www.shopunt.com/images/eng/btn/radio.png") no-repeat;
width:auto;
line-height: 12px;
}
input[type="radio"]:not(old):checked + label{
background: url("//www.shopunt.com/images/eng/btn/radio-r.png") no-repeat;
width:auto;
}


但是chrome的新版本(39版)後開始,不能直接在input旁邊加:not(old),這段語法,點擊後,會無法正常顯示,所以解決的方法有兩個
1. 要使用:not(old)這段語法,不能在input旁邊加,必須是在他的外層上加,如下所例

.r-btn:not(old){
    input[type="radio"]{
     width:28px;
     margin:0;
     padding:0;
     @include opacity(0);
    }
    input[type="radio"] + label{
     display: inline-block;
     margin-left: -28px;
     padding-left: 18px;
     background: url("//www.shopunt.com/images/eng/btn/radio.png") no-repeat;
     width:auto;
     line-height: 12px;
    }
    input[type="radio"]:checked + label{
     background: url("//www.shopunt.com/images/eng/btn/radio-r.png") no-repeat;
     width:auto;
    }
}


2. 不使用:not(old),改用:not(:checked)寫法,Selectors 4也建議使用此語法,如下所例
input[type="radio"]:not(:checked), input[type="radio"]:checked {
    position: absolute;
    left: -9999px;
}
input[type="radio"]:not(checked) + label{
display: inline-block;
margin-left: 4px;
padding-left: 18px;
background: url("//www.shopunt.com/images/eng/btn/radio.png") no-repeat;
width:auto;
line-height: 12px;
}
input[type="radio"]:checked + label{
background: url("//www.shopunt.com/images/eng/btn/radio-r.png") no-repeat;
width:auto;
}


 
More...
nelson, 2014/11/21 下午 07:04:21
在頁面上呈現 圓形圖片加外框的小技巧
HTML:

<ul class="aaa">
<li><img src="http://placehold.it/150x150" /></li>
</ul>

<ul class="bbb">
<li><div><img src="http://placehold.it/150x150" /></div></li>
</ul>


CSS:
.aaa li{
display: inline-block;
width: 160px;
}

.aaa li img{
width: 150px;
border: 5px solid #ececec;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
}


CSS:
.bbb li{
display: inline-block;
width: 160px;
}
​.bbb li div{
width: 150px;
padding: 5px;
background: #ececec;
overflow: hidden;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
}
.bbb li img{
width: 150px;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
border-radius: 50%;
}


​


Safari OUTPUT:

aaa:



bbb:




 
More...
nelson, 2014/11/10 下午 03:48:03
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
|< 12 >|
頁數 1 / 2 下一頁
~ Uwinfo ~