發表文章

javascript JS 物件陣列 數量加總

            // 資料陣列             var array = [                 { Name : 'Apple' , Price : 300 },                 { Name : 'Orange' , Price : 180 }             ]             // es2015 計算加總             var total = array . reduce ( function ( a , b ) {                 return a + b . Price ;             },0);             // 顯示總和             console . log ( "es2015=>" + total );                         // es2016 計算加總             var total2 = array . reduce (( a , b ) => {                 re...

JS 時間格式化擴充 Date.prototype.format

/**  * 對Date的擴充套件,將 Date 轉化為指定格式的String  * 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符,  * 年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字)  * 例子:  * (new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423  * (new Date()).format("yyyy-M-d hⓜ️s.S")   ==> 2006-7-2 8:9:4.18  * @param {*} fmt  * @returns  */   Date . prototype . format = function ( fmt ) {     var o = {         "M+" : this . getMonth () + 1 , //月份                 "d+" : this . getDate (), //日                 "h+" : this . getHours () % 12 == 0 ? 12 : this . getHours () % 12 , //小时                 "H+" : this . getHours (), //小时                 "m+" : this . getMinutes (), //分                 "s+" : this . ge...

C# EF 依據資料新增或是更新原有資料

關鍵在於紅色底的字。 當有產品ID相符時,則更新產品,否則新增產品 Entities entities = new Entities(); List<ProductViewModel> products = ...; // 由外部帶入資料 foreach(ProductViewModel p in products){   Product tmp = new Product();   tmp.ID = p.ID ?? GUID,NewID().toString();   tmp.Name = p.Name;   tmp.Code = p.Code;  if (entities.Product.Any(x => x.ID == tmp .ID))  {     entities.Product .Attach(tmp);     entities.Entry(tmp).State = EntityState.Modified;   }    else    {        entities.Product .Add(tmp);    } }

mssql procedure try catch

BEGIN  BEGIN TRY         -- do someting  END TRY  BEGIN CATCH   --DB查詢用   SELECT ERROR_NUMBER() AS ErrorNumber,       ERROR_MESSAGE() AS ErrorMessage,       ERROR_LINE() AS ErrorLine,       ERROR_PROCEDURE() AS ErrorProcedure,       ERROR_SEVERITY() AS ErrorSeverity,       ERROR_STATE() AS ErrorState   --系統拋回訊息用   DECLARE @ErrorMessage As NVARCHAR(1000) = N'錯誤代碼:' +CAST(ERROR_NUMBER() AS VARCHAR) + ';'             +N'錯誤程序名稱:'+ ISNULL(ERROR_PROCEDURE(),'')+ ';'             +N'錯誤行號:'+ CAST(ERROR_LINE() AS VARCHAR)+ ';'             +N'錯誤訊息:'+ ERROR_MESSAGE()   DECLARE @ErrorSeverity As Numeric = ERROR_SEVERITY()   DECLARE @ErrorState As Numeric = ERROR_STATE()   RAISERROR( @ErrorMessage, @ErrorSeverity, @ErrorState);--回傳錯誤資訊  END CATCH END

執行須Admin權限的執行檔

轉寫一個BAT內容如下 runas /profile /savecred /user:Administrator "cmd /c C:\Program\program.exe " 執行後輸入一次密碼之後,後面使用就不需要再輸入密碼了。

Javascript first day of month and end day of month

     const   today  =  new   Date ();      let   beginDate  =  new   Date ();      let   endDate  =  new   Date ();      // fist date of montg      beginDate  =  new   Date (        ` ${ today . getFullYear () } - ${ today . getMonth () +          1 } -01 00:00:00`     );      // end date of month       // set next Month first Date      endDate  =  new   Date (        ` ${ today . getFullYear () } - ${ today . getMonth () +          2 } -01 :23:59:59`   ...

HTML attributes Order

Attribute order HTML attributes should come in this particular order for easier reading of code. class id ,  name data-* src ,  for ,  type ,  href ,  value title ,  alt role ,  aria-* Classes make for great reusable components, so they come first. Ids are more specific and should be used sparingly (e.g., for in-page bookmarks), so they come second. FROM http://codeguide.co/#html-attribute-order