diff --git a/web/App_Code/Model/ViewModel/order.cs b/web/App_Code/Model/ViewModel/order.cs index 472f6c1..20fc2ad 100644 --- a/web/App_Code/Model/ViewModel/order.cs +++ b/web/App_Code/Model/ViewModel/order.cs @@ -1,15 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Data; -using System.Configuration; +using Newtonsoft.Json; +using System; //using System.Data.OleDb; //using System.Data.SqlClient; using System.Collections; -using Newtonsoft.Json; +using System.Collections.Generic; using System.ComponentModel; +using System.Configuration; +using System.Data; using System.Globalization; +using System.Linq; +using System.Text.RegularExpressions; +using System.Web; namespace Model.ViewModel { @@ -96,5 +97,7 @@ namespace Model.ViewModel public List mid_items { get; set; } public List left_items { get; set; } + + } } \ No newline at end of file diff --git a/web/App_Code/api/orderController.cs b/web/App_Code/api/orderController.cs index d07af05..9079577 100644 --- a/web/App_Code/api/orderController.cs +++ b/web/App_Code/api/orderController.cs @@ -17,6 +17,7 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Text; +using System.Text.RegularExpressions; using System.Web.Helpers; using System.Web.Http; using static TreeView; @@ -224,6 +225,7 @@ public class orderController : ApiController var act=_db.activities.Where(x=>x.num==po.activity_num).FirstOrDefault(); var hasList = _db.pro_order.AsNoTracking().Where(x => x.activity_num == po.activity_num).AsNoTracking().ToList(); + var actItemList=_db.activity_relating.AsNoTracking().Where(x=>x.activity_num==po.activity_num).AsNoTracking().ToList(); List rp=new List(); //要檢查是否已經報名 foreach (var item in list) @@ -257,6 +259,13 @@ public class orderController : ApiController orders.Add(item); foreach (var detail in item.pro_order_detail) { + //要檢查功德項目在這次的法會有沒有 + var actItem = actItemList.Where(y => y.actItem_num == detail.actItem_num).FirstOrDefault(); + if (actItem==null) + { + continue; + } + //Model.pro_order_detail order_detail = new Model.pro_order_detail(); //order_detail.order_no = order.order_no; //order_detail.actItem_num = detail.actItem_num; @@ -276,6 +285,9 @@ public class orderController : ApiController detail.UpdateTime= DateTime.Now; detail.start_date= act.startDate_solar; detail.due_date= act.endDate_solar; + detail.printed_files = ""; + detail.print_id= GenerateSequentialId(detail, item); + _db.pro_order_detail.Add(detail); } @@ -988,11 +1000,12 @@ public class orderController : ApiController detail.from_id = (item1.change_item_num != null && item1.change_item_num != 0) ? item.f_num: last_detail.from_id; detail.price = (item1.change_item_num != null && item1.change_item_num != 0) ? item1.price : last_detail.price; detail.qty = (item1.change_item_num != null && item1.change_item_num != 0) ? item1.qty : last_detail.qty; - detail.printed_files = (item1.change_item_num != null && item1.change_item_num != 0) ? item1.printed_files : last_detail.printed_files; + detail.printed_files = "";//(item1.change_item_num != null && item1.change_item_num != 0) ? item1.printed_files : last_detail.printed_files; detail.style = (item1.change_item_num != null && item1.change_item_num != 0) ? item1.style : last_detail.style; detail.UpdateTime = DateTime.Now; detail.start_date = DateTime.Now;//這兩個要用活動的 detail.due_date = DateTime.Now;// + detail.print_id= GenerateSequentialId(detail, new_pro_order); _db.pro_order_detail.Add(detail); } _db.SaveChanges(); @@ -1021,6 +1034,132 @@ public class orderController : ApiController } } + + public string GenerateSequentialId(pro_order_detail detail,pro_order order) + { + Model.ezEntities _db = new Model.ezEntities(); + string r = detail.print_id; + try + { + bool chk = true; + actItem actitem = null; + int? actitem_id = null; + + // 處理子項目的ID生成 + if (!(detail.parent_num == null || detail.parent_num == 0)) + { + // 1. 查找父項目的資料 + var parent_order_item = _db.pro_order_detail.Where( + q => q.num == detail.parent_num).FirstOrDefault(); + + // 2. 確認父項目存在且當前項目還沒有 print_id + if (parent_order_item != null && string.IsNullOrEmpty(detail.print_id)) + { + actitem_id = parent_order_item.actItem_num; + string parent_print_id = parent_order_item.print_id; + + // 1. 獲取當前子項目的品項前綴 + var currentActItem = _db.actItems + .Where(q => q.num == detail.actItem_num) + .FirstOrDefault(); + + if (currentActItem != null && !string.IsNullOrEmpty(currentActItem.print_init)) + { + var itemPrefix = currentActItem.print_init.Trim(); + + // 2. 獲取同父項目且同品項的子項目編號 + var siblings = _db.pro_order_detail + .Where(q => q.parent_num == detail.parent_num) // 找出同一個父項目的子項目 + .Where(q => q.actItem_num == detail.actItem_num) // 同品項 + .Where(q => q.print_id != null) // Ensure print_id is not null + .Select(q => q.print_id) // Just select the print_id + .AsEnumerable() // ✅ 合理使用:EF 無法轉換 StartsWith/Contains/Replace 到 SQL + .Where(q => q.StartsWith(parent_print_id)) // Now do string operations in memory + .Where(q => q.Contains(itemPrefix)) + .Select(q => q.Trim().Replace("\t", "")) + .Select(q => q.Replace($"{parent_print_id}-{itemPrefix}", "")) + .ToList(); + + // 3. 將所有序號轉換為數字陣列並過濾無效值 + int[] intArray = siblings + .Select(s => + { + int result; + return int.TryParse(s, out result) ? (int?)result : null; + }) + .Where(i => i.HasValue && i.Value != 0) + .Select(i => i.Value) + .ToArray(); + + // 4. 生成新的序號(最大序號+1,並格式化為兩位數) + int maxNum = 1 + (intArray.Any() ? intArray.Max() : 0); + string formattedNum = maxNum < 10 ? "0" + maxNum : maxNum.ToString(); + + // 5. 組合新的 print_id(父項目ID-品項前綴序號) + r = $"{parent_print_id}-{itemPrefix}{formattedNum}"; + } + } + } + // 處理主項目的ID生成 + else + { + actitem_id = detail.actItem_num; + actitem = _db.actItems + .Where(q => q.num == actitem_id).FirstOrDefault(); + //var proorder = _db.pro_order.Where(q => q.order_no == detail.order_no).FirstOrDefault(); + + // 檢查是否需要生成新的 print_id + chk = String.IsNullOrEmpty(r) && + //actitem != null && + //proorder != null && + !string.IsNullOrEmpty(actitem.print_init); + if (chk) + { + // 1. 組合活動和品項的前綴 + var print_init = string.IsNullOrEmpty(order?.activity?.print_init) ? "" : order?.activity?.print_init.Trim(); + var actitem_print_init = actitem.print_init.Trim(); + var combinedPrintInit = print_init + actitem_print_init; + + // 2. 查找相同活動和品項的已存在編號 + var actitems = _db.pro_order_detail + .Where(q => q.pro_order.activity_num == order.activity_num) + .Where(q => q.actItem_num == detail.actItem_num) + .Where(q => !string.IsNullOrEmpty(q.print_id)) + .Where(q => q.print_id.StartsWith(combinedPrintInit)) + .Where(q => q.parent_num == 0 || q.parent_num == null) + .Select(q => q.print_id) + .ToList(); + + // 3. 獲取最大序號 + var maxNum = actitems + .Select(item => + { + var match = Regex.Match(item, @"\d+"); + return match.Success ? (int?)int.Parse(match.Value.TrimStart('0')) : null; + }) + .Where(num => num.HasValue) + .DefaultIfEmpty(0) + .Max() ?? 0; + + // 4. 生成新的序號(四位數格式) + int newNum = maxNum + 1; + string formattedNum = newNum.ToString().PadLeft(4, '0'); + + // 5. 組合最終的 print_id + r = $"{combinedPrintInit}{formattedNum}"; + } + } + } + catch (Exception ex) + { + // 異常處理:記錄錯誤並返回原始 print_id + Console.WriteLine($"Error generating sequential ID: {ex.Message} {ex.StackTrace}"); + r = detail.print_id; + } + + return r; + } + protected string createOrderNumber() { //Application.Lock(); diff --git a/web/admin/Templates/TBS5ADM001/MasterPage.master b/web/admin/Templates/TBS5ADM001/MasterPage.master index b3d6410..abfe1a3 100644 --- a/web/admin/Templates/TBS5ADM001/MasterPage.master +++ b/web/admin/Templates/TBS5ADM001/MasterPage.master @@ -29,7 +29,7 @@ -
+ <%-- ScriptManager 必需移除 --%>
diff --git a/web/admin/Templates/TBS5ADM001/js/Script.js b/web/admin/Templates/TBS5ADM001/js/Script.js index c4bcf45..bd7f913 100644 --- a/web/admin/Templates/TBS5ADM001/js/Script.js +++ b/web/admin/Templates/TBS5ADM001/js/Script.js @@ -8,6 +8,7 @@ window.addEventListener('DOMContentLoaded', event => { // document.body.classList.toggle('sb-sidenav-toggled'); //} sidebarToggle.addEventListener('click', event => { + console.log("QQ"); event.preventDefault(); document.body.classList.toggle('sb-sidenav-toggled'); localStorage.setItem('sb|sidebar-toggle', document.body.classList.contains('sb-sidenav-toggled')); diff --git a/web/admin/Templates/TBS5ADM001/uc/nav.ascx b/web/admin/Templates/TBS5ADM001/uc/nav.ascx index 6451ab2..9ead74b 100644 --- a/web/admin/Templates/TBS5ADM001/uc/nav.ascx +++ b/web/admin/Templates/TBS5ADM001/uc/nav.ascx @@ -1,7 +1,7 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeFile="nav.ascx.cs" Inherits="admin_Templates_TBS5ADM001_uc_nav" %>
- 列印 + 列印 @@ -72,7 +72,7 @@ .catch(error => console.log(error)) }, yulan_print() { - _url = HTTP_HOST + '/admin/printpw/index.aspx'; + _url = HTTP_HOST + 'admin/printpw/index.aspx'; var form = document.createElement("form"); form.method = "POST"; form.action = _url; @@ -86,7 +86,14 @@ hiddenField.value = value; form.appendChild(hiddenField); }; - addHiddenField("activity_num", this.selected_activity); + let orders=[] + this.order_data.selected.forEach(x => { + orders.push(x.order_no) + }) + if (orders.length==0) { + return false; + } + addHiddenField("orders", orders); document.body.appendChild(form); // Not entirely sure if this is necessary form.submit(); document.body.removeChild(form); @@ -143,9 +150,9 @@ v-model="order_data.selected" :items="order_data.list" item-key="order_no" + show-select :headers="order_data.header" :loading="order_data.loading" - show-select class="elevation-1">