發表文章

目前顯示的是 2024的文章

使用 FontAwesome Icon

圖片
使用 FontAwesome Icon 下載檔案: https://fontawesome.com/download 在網頁上引用icon js (依下戴檔案解壓縮後存放路徑修改) <script src="~/Content/fontawesome-free-6.4.2-web/js/all.min.js"></script> <link rel="stylesheet" href="~/Content/fontawesome-free-6.4.2-web/css/all.min.css"> 在官方網站尋找要的ICON, 網址: https://fontawesome.com/search 把class貼到HTML按鈕class上 <button type='button' class=btn btn-success' id='btn_AAA'>   <span style='margin-right:5px; font-size:24px;' class="fa-solid fa-user"></span>   some text </button> 打完收工!!

好用的前端資料清單顯示 JQuery datatables 套件

圖片
好用的前端資料清單顯示 JQuery datatables 套件 官網: https://datatables.net/ 套件引用 <script src="https://code.jquery.com/jquery-3.7.1.js"></script> <script src="https://cdn.datatables.net/2.0.3/js/dataTables.js"></script> <link rel="stylesheet" href="https://cdn.datatables.net/2.0.3/css/dataTables.dataTables.css" /> HTML範例資料 <table id="example" class="display" style="width:100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Salary</th> </tr> </thead> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td>

好用的sweetalert2 (前端Javascript訊息彈跳視窗)

圖片
好用的sweetalert2 (前端Javascript訊息彈跳視窗) 官方網頁: sweetalert2 美化原來Javascript [alert]視窗, 沒辦法取代alert可以暫時停住程式執行的特性, 但是支援執行對應按鈕後個別執行不同程式邏輯。 另外, 它不支援IE sweetalert2共有4個按鈕可用, 分別為 OK Button (confirm button) NO Button (deny button) Cancel Button Close Button (右上X按鈕) JS及CSS引用 <script src="https://code.jquery.com/jquery-3.7.1.js"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.10.7/dist/sweetalert2.all.min.js"></script> <link href="https://cdn.jsdelivr.net/npm/sweetalert2@11.10.7/dist/sweetalert2.min.css" rel="stylesheet"> sweetalert2 JS Code Swal.fire({ title: "這是[title]", text: "這是內文[text]", icon: "warning", //success(綠色打勾), error(紅色打叉), warning(黃色金探號), info(藍色i), question(灰色問號) showConfirmButton: true, //OK Button, 預設顯示 showDenyButton: true, //NO Button, 預設隱藏 showCancelButton: true, //Cancel Button, 預設隱藏 showCloseButton: true, //右上X Button, 預設隱藏 conf

Oracle 修改Sequence的數值

Oracle 修改Sequence的數值 假設目前有一個Sequence名為[seq_test], 修改數值的方法有下列2種, 方法1 : drop後重建, 並指定起始值 DROP SEQUENCE seq_test; CREATE SEQUENCE seq_test START WITH 100; 方法2 : 修改增加值的區間, 取號後, 再改回來原本的區間 --修改為1000 ALTER SEQUENCE seq_test INCREMENT BY 1000; --取下一個值 SELECT seq_test.NextVal FROM dual; --修改回1 ALTER SEQUENCE seq_test INCREMENT BY 1;  

利用Javascript把數字進行小數位數補零

利用Javascript把數字進行小數位數補零 利用 Number.toFixed() 是 JavaScript 中用於將數字格式化為指定小數位數的方法。它接受一個參數,即要保留的小數位數,並返回一個代表該數字的字符串,帶有指定的小數位數。 const number = 1.23456; const result = number.toFixed(2); console.log(result); // 會輸出 "1.23" 在這個例子中, toFixed(2) 將 1.23456 格式化為帶有兩位小數的字符串 "1.23" 。(直接去除後面位數, 不是四捨五入) 如果指定的小數位數比原始數字的小數位數多,則會在數字後面補零。如果指定的小數位數比原始數字的小數位數少,則會進行四捨五入。 下面這個例子是寫成一個function, 可以重覆利用 function padZero(number, decimalPlaces) { // 確保 number 是數字 if (typeof number !== 'number') { return '第一個參數必須是數字'; } // 確保 decimalPlaces 是正整數 if (!Number.isInteger(decimalPlaces) || decimalPlaces < 0) { return '第二個參數必須是非負整數'; } // 轉換為帶有固定小數位數的字符串 const result = number.toFixed(decimalPlaces); return result; } console.log(padZero(1.1, 3)); // 1.100 console.log(padZero(10, 4)); // 10.0000 網路上找到的另一個補零的寫法, 範例如下, function Pubfunc_DecimalLength(Number, Length) { let nums = (Number || 0).toStrin

MSSQL, 查詢的欄位不存在索引和索引的[包含的資料行], 兩者把欄位加入的差別

MSSQL, 查詢的欄位不存在索引和索引的[包含的資料行], 兩者把欄位加入的差別 對於非聚集索引而言,如果查詢的結果欄位不在索引中,可以考慮兩種方式來提升查詢效率:將欄位加入索引和將欄位加入索引的「包含的資料行」。這兩種方法有不同的影響: 將欄位加入索引 : 當你將欄位加入索引時,這些欄位會成為索引的一部分,這意味著 SQL Server 在查詢時可以使用這些欄位來進行索引掃描和查詢結果的篩選。 這種方式適用於需要在查詢條件中使用這些欄位進行篩選和排序的情況,例如 WHERE 條件中使用了這些欄位。 添加欄位到索引中可能會增加索引的大小和維護成本,因此需要權衡索引效能和成本之間的關係。 將欄位加入索引的「包含的資料行」 : 在建立索引時,可以使用「包含的資料行」來將非索引鍵的欄位包含在索引中,但不是索引的排序鍵。這些欄位只是附加到索引頁面中,不會用於索引的排序或搜索。 使用「包含的資料行」適用於那些不需要用於索引搜索但在查詢中仍然需要的欄位,例如 SELECT 列表中的欄位。 這種方式不會對索引的搜索和排序行為產生直接影響,但可以提高查詢效率,特別是當這些欄位被頻繁地使用於查詢結果的檢索時。 總之,將欄位加入索引和加入索引的「包含的資料行」都可以提高查詢效率,但它們的適用場景和影響不同。通常來說,如果欄位需要用於索引的搜索和排序,則將其加入索引;如果欄位只是需要在查詢結果中使用,則將其作為「包含的資料行」加入索引可能更合適。  

Microsoft SQL Server 中,資料儲存與索引儲存的說明

Microsoft SQL Server 中,資料儲存與索引儲存的說明 資料頁面(Data Pages) : 資料頁面是用來存儲資料表中實際資料的地方。 每個資料頁面的大小通常是 8KB。 資料頁面以頁的形式存儲在資料檔案(Data Files)中,每個資料檔案可以包含多個資料頁面。 資料頁面中的資料按照資料表的結構進行組織和存儲。每列資料都以固定長度或變動長度的格式存儲在資料頁面上。 索引頁面(Index Pages) : 索引頁面是用來存儲索引數據的地方。索引可以是聚集索引或非聚集索引。 每個索引頁面的大小也通常是 8KB。 索引頁面包含索引鍵和指向資料頁面或下一級索引頁面的指標。 聚集索引的索引頁面與資料頁面結構相似,因為聚集索引的結構與資料表的結構相同,所以索引頁面包含資料本身。 非聚集索引的索引頁面僅包含索引鍵和指向資料頁面或下一級索引頁面的指標,而不包含實際資料。 這些頁面的組織和管理是 SQL Server 效能和資料存取的關鍵部分。資料頁面和索引頁面的分配、讀取、寫入和維護受到 SQL Server 引擎的管理和優化,以確保高效率和可靠性。理解這些頁面的結構和運作方式對於設計和管理資料庫是非常重要的。 當查詢結果的資料跨越多個不連續的索引頁面且取得的欄位並不在索引鍵中時,非聚集索引的工作方式如下 索引掃描 : SQL Server 首先根據查詢條件使用索引來定位符合條件的記錄。這可能涉及到索引的搜索和篩選。 如果查詢的條件無法利用索引進行快速定位,則可能會採用索引的全掃描,也就是對整個索引進行遍歷,以找出符合條件的資料。 資料檢索 : 當索引定位到符合查詢條件的資料頁面時,SQL Server 需要讀取這些頁面上的資料行以滿足查詢需求。 如果資料行不在索引中,SQL Server 必須通過資料頁面的指標找到對應的資料頁面,然後從中讀取所需的資料行。 由於資料行不在索引中,這可能需要額外的 IO 操作,因為 SQL Server 需要訪問資料檔案中的不同頁面來檢索完整的資料。 資料合併與排序 : 當從不同的資料頁面檢索資料後,SQL Server 需要將這些資料合併並進行排序(如果需要)以生成查詢結果。 這可能涉及到將資料行按照查詢需求進行組合、排序和過濾,以生成

在 Microsoft SQL Server 中建立索引, 關於「包含的資料行」

在 Microsoft SQL Server 中建立索引, 關於「包含的資料行」 在 Microsoft SQL Server 中,當建立索引時,可以使用「包含的資料行」來增強查詢效能。包含的資料行是索引的一部分,但不會用來定義索引的排序鍵。它們僅包含在索引頁面中,並且不影響索引的排序方式。這些資料行對於包含在查詢的 SELECT 列表中但不是 WHERE 或 JOIN 條件的欄位特別有用。 透過使用包含的資料行,你可以達到以下幾個目的: 覆蓋索引(Covering Index) :當所有查詢需要的資料都可以從索引中獲取時,可以避免查詢需要訪問資料庫表格。這可以減少 IO 成本,提高查詢效能。 減少索引大小 :索引的大小直接影響到查詢效能。通過只包含必要的資料行,可以減小索引的大小,進而提高查詢效能。 減少索引碎片 :如果索引包含了大量不需要的資料行,當進行更新或插入操作時,可能會產生較多的索引碎片。只包含必要的資料行可以減少這種情況的發生。 要使用包含的資料行,可以在建立索引或修改現有索引時,使用 INCLUDE 子句指定要包含的資料行。例如: CREATE NONCLUSTERED INDEX IX_IndexName ON TableName (IndexedColumn) INCLUDE (Column1, Column2, ...); CREATE INDEX IX_IndexName ON TableName (IndexedColumn) INCLUDE (Column1, Column2, ...); 這樣做將指示 SQL Server 在索引中包含指定的資料行,以提高查詢效能。 若多個查詢SQL使用到同一個索引,但其 SELECT 欄位不同,可以考慮將常用的欄位作為「包含的資料行」。這樣做的好處是可以減少查詢所需的 IO 成本,提高查詢效能,尤其是當索引包含了大量不需要的資料行時。 然而,將所有欄位都設定為「包含的資料行」可能不是一個理想的做法。這會增加索引的大小,可能導致性能下降。因此,建議只包含那些經常用於查詢的欄位,以保持索引的精簡且高效。 在決定要包含哪些資料行時,可以考慮以下因素: 查詢的使用情況 :分析常用的查詢,確定哪些欄位是經常被使用的。將這些欄位作為包含的資料行可能會提高查詢效能。 資料行的大小

網頁載入後, 將自己網頁關閉, 使用Javascript

網頁載入後, 將自己網頁關閉, 使用Javascript HTML+Javascript <script> //window.close(); //會顯示詢問訊息 //利用執行自己, 達到javascript關閉自已(不會顯示詢問訊息)。 //第二次執行因為有傳參數, 後端判斷不執行 window.onload = function () { open(location + 'is_close=Y', '_self').close(); }; </script> Server Side (C#, MVC Action) public ActionResult ServerAction(string is_close) { //直接結束作業 if (is_close == "Y") { return View(); } //要執行的CODE }    測試使用IE和Edge有效

C# 建立物件的淺層複製(Shallow Clone/Copy)及深層複製(Deep Clone/Copy)

C# 建立物件的淺層複製(Shallow Clone/Copy)及深層複製(Deep Clone/Copy) 在C#中,物件的淺層複製(Shallow Copy)和深層複製(Deep Copy)是兩種不同的複製方式,它們在複製物件時的行為和結果有所不同。 淺層複製(Shallow Copy) 淺層複製是指創建一個新的物件,並將原物件的值類型字段複製到新物件中。然而,當數據是參考類型時,只有參考本身被複製,而不是被參考的物件本身。因此,原物件和複製物件將指向同一個物件。這意味著,如果修改了複製物件中的參考類型字段,原物件中的相同字段也會被修改。 在C#中,可以使用 MemberwiseClone() 方法來實現淺層複製。這個方法會創建一個新的物件,並將原物件的所有字段複製到新物件中。但是,如果字段是參考類型,則只複製參考,而不是參考的物件本身。 public object Shallowcopy() { return this.MemberwiseClone(); } 深層複製(Deep Copy) 深層複製則是創建一個新的物件,並將原物件的所有字段(包括參考類型字段)複製到新物件中。這意味著,即使是參考類型字段,也會創建一個新的物件來替換原物件中的參考。因此,原物件和複製物件之間的參考類型字段是完全獨立的,修改其中一個不會影響另一個。 在C#中,實現深層複製需要手動實現。這通常涉及到創建一個新的物件,並將原物件的所有字段(包括參考類型字段)複製到新物件中,並確保參考類型字段也被複製。 深層複製的寫法有很多種, 方法1: 二進制序列化(Binary Serialization) 複製對象 Class 必需標記 [Serializable] 標籤 [Serializable] public class Person { public string Name { get; set; } public int Age { get; set; } } public static T DeepClone<T>(this T source) { if (!typeof(T).IsSerializable) { throw new ArgumentException("

C# Entityframework, mssql, decimal精準度問題

C# Entityframework, mssql, decimal精準度問題 This is because Entity Framework, by default, maps the .NET decimal type to SQL Server's decimal(18,2) data type, which might not match the precision and scale you require for your specific use case. 由於Entity Framework, .Net decimal型別, 預計對應MSSQL decimal型別的精準度為decimal(18, 2), 所以當C#寫入資料包含小數第3位時, 寫入資料庫後會被截掉。 解決方案如下, 使用Fluent API:如果您使用的是Entity Framework 6,您可以在OnModelCreating方法中使用Fluent API來設定資料庫欄位的精確度和小數位數 protected override void OnModelCreating(DbModelBuilder modelBuilder) { //指定所有decimal欄位轉換 modelBuilder.Properties<decimal>().Configure(config => config.HasPrecision(18, 5)); //指定特定欄位轉換 modelBuilder.Entity<YourEntity>().Property(e => e.YourDecimalProperty).HasPrecision(18, 5); } 若為 Entity Framework Core, 也可使用下面2個寫法 (未實際驗證過是否可行) public Class YourEntity { [Column(TypeName = "decimal(18,5)")] public decimal YourDecimalProperty {get; set;} } protected override void OnModelCreating(ModelBuil

Git commit錯誤, Failed to get unRev file listfatal: unsafe repository

Git commit錯誤, Failed to get unRev file listfatal: unsafe repository 錯誤訊息: Failed to get UnRev file listfatal: unsafe repository ( D./****/****' is owned by someonelse) To add an exception for this directory, call: git config --global --add safe.directoryD:/****/**** Set the enwironment variableGIT TEST DEBUG UNSAFE DIRECTORIES=true and runagain for more information. 可能原因: Git版本更新後, 增加新的資料夾安全限制, 造成進行Git操作找不到git文件 解決方法: 指定資料夾 git config --global --add safe.directory D:/****/**** 全域設定 git config --global --add safe.directory "*"    

C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpWebRequest]

C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpWebRequest] void Main() { string apiUrl = "http://aaa/bbb/ccc?x=11&y=222"; string Msg = ""; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(apiUrl); req.Method = "GET"; req.ContentType = "application/json"; req.Timeout = 3000000; //以毫秒為單位 using (HttpWebResponse wr = (HttpWebResponse)req.GetResponse()) { if (wr.StatusCode == HttpStatusCode.OK) { using (Stream stream = wr.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { Msg = reader.ReadToEnd(); } } } RDataSS RData = JsonConvert.DeserializeObject<RDataSS>(Msg); RData.Dump(); } // Define other methods and classes here public class RDataSS { public string ReturnCode { get; set; } public string Message { get; set; } public string StorageID { get; set; } }  

ASP.Net WebForm JQuery 呼叫 CodeBehind方法 (手動postback)

ASP.Net WebForm JQuery 呼叫 CodeBehind方法 (手動postback) JQuery $('#myTextBoxB').keypress(function (e) { if (event.which == 13) { blockUI(); var param = '{ ' + '"Event":"keypress", ' + '"A":"' + $("#myTextBoxA").val() + '", ' + '"B":"' + $("#myTextBoxB").val() + '"' + ' }'; //第1個參數 eventTarget, 第2個參數 eventArgument __doPostBack("<%=this.myTextBoxB.ClientID%>", param); } }); Code Behind protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } else { string eventTarget = Request.Params.Get("__EVENTTARGET"); string eventArgument = Request.Params.Get("__EVENTARGUMENT"); ParamData PData = Newtonsoft.Json.JsonConvert.DeserializeObject<ParamData>(p_EventArgument

Query dialog 基本語法

JQuery dialog 基本語法 寫法1 $("#myDialog").dialog({ resizable: false, height: "auto", width: 800, modal: true, buttons: { "OK": function() { // 這裡是 OK 按鈕的功能 }, "Cancel": function() { $(this).dialog("close"); } }, open: function() { // 當對話框打開時,為對話框添加 keydown 事件處理器 $(this).keydown(function(event) { // 如果按下的是 Enter 鍵,則阻止其預設行為 if (event.keyCode === 13) { event.preventDefault(); } }); } }); 寫法2 $("#myDialog").dialog({ resizable: false, height: "auto", width: 800, modal: true, buttons: { "OK": myDialog_OK, "Cancel": myDialog_Cancel }, open: function() { // 當對話框打開時,為對話框添加 keydown 事件處理器 $(this).keydown(function(event) { // 如果按下的是 Enter 鍵,則阻止其預設行為 if (event.keyCod

JQuery .each 用法

JQuery .each 用法 對象Array var array = [1, 2, 3, 4, 5]; $.each(array, function(index, value) { console.log(index + ": " + value); }); 結果: 0: 1 1: 2 2: 3 3: 4 4: 5 對象Json var people = [ { name: "John", age: 30, city: "New York" }, { name: "Jane", age: 25, city: "Chicago" }, { name: "Mike", age: 35, city: "Los Angeles" } ]; $.each(people, function(index, person) { console.log("Name: " + person.name + ", Age: " + person.age + ", City: " + person.city); }); 結果: Name: John, Age: 30, City: New York Name: Jane, Age: 25, City: Chicago Name: Mike, Age: 35, City: Los Angeles 列出JSon每個屬性 var data = {}; data.name = 'Alex'; data.id = "1"; $.each(data, function (key, value) { alert('key=' + key); alert('value=' + value); }); 結果: key=name value=Alex  

C# MVC Razsor 下拉選單(單選)(多選)(篩選) using [select2]套件

C# MVC Razsor 下拉選單(單選)(多選)(篩選) using [select2]套件 C# List<SelectListItem> list_SelectListItem = new List<SelectListItem>(); list_SelectListItem.Add(new SelectListItem() { Text = "", Value = "" }); foreach (var ima in list_Data) { SelectListItem sli = new SelectListItem(); sli.Value = ima.Data01; sli.Text = $"{ima.Data01} | {ima.Data02}"; list_SelectListItem.Add(sli); } ViewBag.list_SelectListItem = list_SelectListItem; HTML <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script> <div> @Html.DropDownList("DropDownList_Data1", list_SelectListItem, "", new { @class = "form-control js-example-basic-single", style = "max-width:1000px;width:1000px;" }) <button type="button&qu

MVC BootStrap Modal開啟時, Focus指定欄位

MVC BootStrap Modal開啟時, Focus指定欄位 $('#modalA').on('shown.bs.modal', function () { $('#textbox1').focus(); })  

C# WebAPI 傳入JSON, 回傳資料格式為文字 [GET]

C# WebAPI 傳入JSON, 回傳資料格式為文字 [GET] API Code public IHttpActionResult Get(string param1, string param2) { string result = ""; try { // 檢查參數是否合法 if (string.IsNullOrEmpty(param1)) { throw new Exception("param1 參數不能為空。"); } if (string.IsNullOrEmpty(param2)) { throw new Exception("param2 參數不能為空。"); } // 進行資料處理邏輯,這裡假設將兩個參數結合成一個字串 result = $"OK,[GET]result is {param1}-{param2}"; // 返回結果 return Ok(result); } catch (Exception exp) { result = $"NG,{exp.Message}"; } return Ok(result); ; } 呼叫時在網址後加?param1=&param2= 回傳結果如下, 失敗: "NG,參數不可為空" 成功: "OK,result is value1-value2"  

C# WebAPI 傳入JSON, 回傳資料格式為文字 [POST]

C# WebAPI 傳入JSON, 回傳資料格式為文字 [POST] API Code public IHttpActionResult Post([FromBody] Api_TESTPData parameters) { string result = ""; try { if (parameters == null) { throw new Exception("參數不可為空"); } /* 資料處理邏輯 */ result = $"OK,result is {parameters.Param1}-{parameters.Param2}"; } catch (Exception exp) { result = $"NG,{exp.Message}"; } return Ok(result); ; } Paramter Code public class Api_TESTPData { public string Param1 { get; set; } public string Param2 { get; set; } } 回傳結果如下, 失敗: "NG,參數不可為空" 成功: "OK,result is value1-value2"  

C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpClient ]

C# 使用Get取得網頁執行結果資料(資料格式為JSON) [HttpClient]  void Main() { string apiUrl = "http://aaa/bbb/ccc?x=11&y=222"; using (HttpClient client = new HttpClient()) { // 執行GET請求並取得回應 HttpResponseMessage response = client.GetAsync(apiUrl).Result; // 確認回應是否成功 response.EnsureSuccessStatusCode(); // 讀取回應內容並解析成字串 string responseBody = response.Content.ReadAsStringAsync().Result; responseBody.Dump(); // 將JSON字串轉換成物件,假設回傳的JSON結構是一個物件的話 // 如果是陣列或其他結構,請使用相對應的方法進行解析 // 你需要使用Json.NET或System.Text.Json等套件進行解析 // 這裡以Json.NET為例 RDataSS responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject<RDataSS>(responseBody); responseObject.Dump(); } } // Define other methods and classes here public class RDataSS { public string ReturnCode { get; set; } public string Message { get; set; } public string AAAA { get; set; } }  

MVC Action直接在網頁上回傳Class to Json資料

MVC Action直接在網頁上回傳Class to Json資料 [HttpGet] public JsonResult SampleAction() { UserData udata = new UserData(); using (ssEntities ssDBContext = new ssEntities()) { var query = from t1 in ssDBContext.UserData select t1; udata = query.FirstOrDefault(); } /* 回傳是一個字串, 內容都是文字 "{\"PKID\":1,\"UserName\":\"彼得\",\"UserName_Eng\":\"Peter\",\"Sex\":\"Male\",\"Birthday\":\"1980-04-04T00:00:00\",\"MobilePhoneNo\":\"0968123123\",\"Interest\":\"Movie\",\"DeleteDate\":null,\"DeleteUserID\":null,\"DeleteUserName\":null,\"InterestText\":null,\"BirthdayString\":null}" */ string json = JsonConvert.

C# 變數, 兩種宣告類型

C# 變數, 兩種宣告類型 基本資料型別(Primitive data types) int, decimal 宣告方式為 int a = 0; DateTime是一個Struct, 所以屬於基本資料型別 宣告方式為DateTime dt = DateTime.Now; 參考型別(Reference types) object, File 宣告方式為 object o = new object 宣告要使用new, 來實體化後, 再放入左方變更, 若沒new, 變數初始值為null    

利用批次指令清理檔案及資料夾

利用批次指令清理檔案及資料夾 利用forfile刪除指定路徑下的所有符合條件的檔案 forfiles /p "D:\Dir1\Dir2" /s /m *.* /d -14 /c "cmd /c del /q @path"   forfile指令參數說明 : forfiles [/p <Path>] [/m <SearchMask>] [/s] [/c "<Command>"] [/d <Date>] [/l] [/b] /p <Path> :指定要搜索的根目錄。 /m <SearchMask> :指定要搜索的檔案的檔名模式。例如, *.txt 。 /s :包括子目錄中的所有檔案。 /c "<Command>" :指定要對每個找到的檔案執行的命令。使用 @file 代表檔案名稱, @path 代表檔案的完整路徑, @relpath 代表相對於指定根目錄的檔案路徑, @isdir 為 TRUE 表示找到的是資料夾。 /d <Date> :選擇最後修改日期在指定日期之前的檔案。日期格式為 MM/dd/yyyy 或 dd.MM.yyyy 。 /l :以小寫形式顯示或比較日期和時間。 /b :使用簡單的檔案名稱而不是完整的路徑。 刪除指定路徑下所有空資料夾 for /f "delims=" %%d in ('dir /ad /s /b "D:\Dir1\Dir2" ^| sort /r') do rd "%%d"      

Windows 2012 Server以上版本新增使用者

 Windows 2012 Server以上版本新增使用者 在「 電腦管理 」頁面的導覽窗格中,展開 本機使用者和群組 ,然後按一下 使用者

C#, LINQ, 利用group new 來取得多欄位group by

圖片
C#, LINQ, 利用group new 來取得多欄位group by void Main() { // 建立 ClassA 的 List List<ClassA> classAList = new List<ClassA> { new ClassA("A1", 10), new ClassA("A2", 20), new ClassA("A3", 30), new ClassA("A1", 15), new ClassA("A2", 25), new ClassA("A3", 35) }; // 建立 ClassB 的 List List<ClassB> classBList = new List<ClassB> { new ClassB("A1", "C1"), new ClassB("A2", "C2") }; //classAList.Dump(); //classBList.Dump(); // 使用 LINQ 進行關聯和分組 var query = from a in classAList join b in classBList on a.A equals b.A select a; query.Dump(); var query2 = from a in query group new { a.A, a.B } by a.A into grouped select new { A = grouped.Key, SumB = grouped.Sum(item => item.B) }; query2.Dump(); } // Define other methods and classes here // ClassA 定義 class ClassA { public string A { g

ASP.Net WebForm實作Open Dialog視窗互動

ASP.Net WebForm實作Open Dialog視窗互動 aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>彈跳視窗範例</title> <style> #popup { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); border: 1px solid #ccc; background-color: #fff; padding: 20px; z-index: 1000; width: 300px; /* 調整寬度 */ } #popupTitle { font-size: 18px; font-weight: bold; margin-bottom: 10px; } #popupContent { margin-bottom: 20px; } #popupButtons { text-align: right; } #popupButtons button

使用EntityFramework批次刪除資料

使用EntityFramework批次刪除資料 using (EntitiesContext db = new EntitiesContext(connString)) { // Retrieve all records from database for deletion IEnumerable<entity> entityList = db.entity.where(x => x.id == id).toList(); // Use Remove Range function to delete all records at once db.entity.RemoveRange(entityList); // Save changes db.SaveChanges(); }  

LINQ, 依筆數切分Datatable為多個Datatable

LINQ, 依筆數切分Datatable為多個Datatable using System; using System.Data; using System.Linq; class Program { static void Main() { // 假設有一個包含資料的 DataTable DataTable originalDataTable = GetOriginalDataTable(); // 指定每個小 DataTable 的大小 int batchSize = 1000; // 使用 LINQ 拆解 DataTable var smallDataTables = originalDataTable.AsEnumerable() .Select((row, index) => new { row, index }) .GroupBy(x => x.index / batchSize) .Select(group => group.Select(x => x.row) .CopyToDataTable()) .ToList(); // 打印結果,這裡只是簡單的範例,實際上你可能需要對 smallDataTables 做進一步的處理 foreach (var smallDataTable in smallDataTables) { PrintDataTable(smallDataTable); } } static DataTable GetOriginalDataTable() { // 這裡假設你有一個包含資料的 DataTable,你可以根據實際需求修改 DataTable originalDataTable = new DataTable(); // 假設有一個 "ID"

C#, Datatable, Join, LINQ, 子查詢

C#, Datatable, Join, LINQ, 子查詢 void Main() { DataTable dt1 = new DataTable(); dt1.Columns.Add("A", typeof(string)); dt1.Columns.Add("B", typeof(string)); dt1.Columns.Add("C", typeof(string)); dt1.Columns.Add("D", typeof(int)); // 資料填充 DataRow dr1 = dt1.NewRow(); dr1["A"] = "A1"; dr1["B"] = "B1"; dr1["C"] = "C1"; dr1["D"] = "1"; dt1.Rows.Add(dr1); dr1 = dt1.NewRow(); dr1["A"] = "A2"; dr1["B"] = "B2"; dr1["C"] = "C2"; dr1["D"] = "2"; dt1.Rows.Add(dr1); DataTable dt2 = new DataTable(); dt2.Columns.Add("E", typeof(string)); dt2.Columns.Add("F", typeof(string)); dt2.Columns.Add("G", typeof(int)); // 資料填充 DataRow dr2 = dt2.NewRow(); dr2["E"] = "A1"; dr2["F"] = "B1"; dr2["G"] = "10

C# 撰寫擴展CLASS - DistinctBy

C# 撰寫擴展CLASS - DistinctBy void Main() { List<ClassA> list = new List<UserQuery.ClassA>(); list.Add(new ClassA() { strA = "A", strB = "A1" }); list.Add(new ClassA() { strA = "B", strB = "B1" }); list.Add(new ClassA() { strA = "B", strB = "C1" }); var a = list.DistinctBy(x => x.strA).ToList(); // strA , strB // A, A1 // B, B1 var b = list.DistinctBy(x => x.strB).ToList(); // strA , strB // A, A1 // B, B1 // B, C1 } public class ClassA { public string strA {get;set;} public string strB {get;set;} } //撰寫一個擴展CLASS public static class DistinctByClass { //方法套用在列舉上 public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { HashSet<TKey> seenKeys = new HashSet<TKey>(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(el