From dfb6a8e6a4da2bdebfbbf67cd11fdf063a90a930 Mon Sep 17 00:00:00 2001 From: minom Date: Fri, 11 Sep 2026 15:43:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=96=8F=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/App_Code/api/ShuWenController.cs | 2 + web/App_Code/api/shuwensController.cs | 849 +++++++++++++++++++++++++- web/admin/shuwen/shuwen.aspx | 56 +- 銷帳查詢.sql | 4 +- 4 files changed, 886 insertions(+), 25 deletions(-) diff --git a/web/App_Code/api/ShuWenController.cs b/web/App_Code/api/ShuWenController.cs index b9173f4..866e442 100644 --- a/web/App_Code/api/ShuWenController.cs +++ b/web/App_Code/api/ShuWenController.cs @@ -264,6 +264,8 @@ public class ShuWenController : ApiController } + + public void GenerateShuWenWord_OpenXml(string json, Stream outputStream, string ActivityName ="") { JObject root = JObject.Parse(json); diff --git a/web/App_Code/api/shuwensController.cs b/web/App_Code/api/shuwensController.cs index d677f32..83fd470 100644 --- a/web/App_Code/api/shuwensController.cs +++ b/web/App_Code/api/shuwensController.cs @@ -1,6 +1,15 @@ -using System; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Drawing.Charts; +using DocumentFormat.OpenXml.Office2010.PowerPoint; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PagedList; +using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Web; using System.Web.Http; @@ -8,7 +17,7 @@ using System.Web.Http; /// shuwensController 的摘要描述 /// x.num == temp.num); } - return Ok(new {result="Y", data = qry.Select(x => new + return Ok(new { result = "Y", data = qry.Select(x => new { - x.num,x.shuwen_type,x.name,x.contents + x.num, x.shuwen_type, x.name, x.contents }).FirstOrDefault() }); } @@ -64,7 +73,7 @@ public class shuwensController: BaseApiController public IHttpActionResult ListShuwenTemplate([FromBody] Model.shuwen_temp temp) { var qry = _db.shuwen_temp.AsQueryable(); - if (temp!=null&& !string.IsNullOrEmpty(temp.shuwen_type )) + if (temp != null && !string.IsNullOrEmpty(temp.shuwen_type)) { qry = qry.Where(x => x.shuwen_type == temp.shuwen_type); } @@ -86,14 +95,14 @@ public class shuwensController: BaseApiController public IHttpActionResult SaveActShuwen([FromBody] Model.activity_shuwen s) { var qry = _db.activity_shuwen.AsQueryable(); - qry=qry.Where(x => x.act_num == s.act_num && x.shuwen_type == s.shuwen_type); - var d=qry.FirstOrDefault(); + qry = qry.Where(x => x.act_num == s.act_num && x.shuwen_type == s.shuwen_type); + var d = qry.FirstOrDefault(); if (d != null) { d.contents = s.contents; d.direction = s.direction; d.paper_size = s.paper_size; - d.reg_time=DateTime.Now; + d.reg_time = DateTime.Now; } else { @@ -102,7 +111,7 @@ public class shuwensController: BaseApiController } _db.SaveChanges(); - return Ok(); + return Ok(); } [HttpPost] @@ -111,9 +120,9 @@ public class shuwensController: BaseApiController { if (t.num > 0) {//跑更新 - var qry=_db.shuwen_temp.AsQueryable(); + var qry = _db.shuwen_temp.AsQueryable(); qry = qry.Where(x => x.num == t.num); - var d=qry.FirstOrDefault(); + var d = qry.FirstOrDefault(); if (d != null) { d.contents = t.contents; @@ -123,12 +132,826 @@ public class shuwensController: BaseApiController } else { - t.reg_time=DateTime.Now; + t.reg_time = DateTime.Now; _db.shuwen_temp.Add(t); } _db.SaveChanges(); - return Ok(); + return Ok(); } + + [HttpPost] + [Route("api/shuwen/RenderShuWenByGong")] + public IHttpActionResult RenderShuWenByGong([FromBody] dynamic data) + { + var jsonData = data; + var mode=(string)jsonData.mode; + mode = "A"; + StringBuilder sb= new StringBuilder(); + sb.Append("with gong as (select* from pro_order_detail "); + sb.Append("where order_no in (select order_no from pro_order "); + sb.Append("where activity_num in (72, 73)) "); + sb.Append("and(actItem_num in "); + sb.Append("(select item_num from act_bom a "); + sb.Append("left join actItem b on a.item_num = b.num "); + sb.Append("where a.package_num is null)) "); + sb.Append(") "); + sb.Append("select * from pro_order_detail a "); + sb.Append("where (num in (select num from gong) "); + sb.Append("or parent_num in (select num from gong)) "); + var list=_db.Database.SqlQuery(sb.ToString()).ToList(); + var head_list=list.Where(x=>x.parent_num==null).ToList();//消災,要參數化 + + var qry = _db.TabletStyleDetail.AsQueryable(); + var styles = qry.ToList(); + var ret = new object() { }; + using (WordprocessingDocument wordDocument = WordprocessingDocument.Create("d://HelloWorld.docx", WordprocessingDocumentType.Document)) + { + // Add a main document part + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + Body body = mainPart.Document.AppendChild(new Body()); + + List result = new List(); + var nowContent = new List(); + foreach (var item in head_list) + { + //消災牌位 + var detail_list = list.Where(x => x.parent_num == item.num && x.print_id.Contains("X")).ToList(); + + foreach (var d in detail_list) + { + + //因為有分身 福德正神 福德夫人這種,所以還要考慮位置關係,才知道 mid right mid_items mid_left的順序 + var style=styles.Where(y=>y.StyleID==d.style).ToList(); + var leftTitle = style.Where(z => z.ElementID == "lefttitle").FirstOrDefault(); + var midTitle = style.Where(z=>z.ElementID=="title1").FirstOrDefault(); + var rightTitle = style.Where(z => z.ElementID == "righttitle").FirstOrDefault(); + + var json = JsonConvert.DeserializeObject(d.f_num_tablet); + // 1. 先安全地把 mid_items 轉成 JArray + Newtonsoft.Json.Linq.JArray midItemsArray = json.mid_items as Newtonsoft.Json.Linq.JArray; + Newtonsoft.Json.Linq.JArray leftItemsArray = json.mid_left as Newtonsoft.Json.Linq.JArray; + Newtonsoft.Json.Linq.JArray rightItemsArray = json.mid_right as Newtonsoft.Json.Linq.JArray; + + //如果字數超過6個字要強制換行 + //前面先截掉,後面也重新開始 + + var orderType = "A";//右中左 + if (midTitle.StartX.CompareTo(rightTitle.StartX) > 0 && rightTitle.StartX.CompareTo(leftTitle.StartX) > 0) + { + orderType = "B";//中右左 + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s + ";" + m["fam_name"] + ";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (rightItemsArray != null&&rightItemsArray.Count>0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (leftItemsArray != null&&leftItemsArray.Count>0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))+";"); + } + else if (leftTitle.StartX.CompareTo(midTitle.StartX) > 0 && midTitle.StartX.CompareTo(rightTitle.StartX) > 0) + { + orderType = "C";//左中右 + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s +";" + m["fam_name"] +";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", ""))) + ";"); + + } + else if (rightTitle.StartX.CompareTo(midTitle.StartX) > 0 && leftTitle.StartX.CompareTo(midTitle.StartX) > 0) + { + orderType = "D";//右左中 + + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s + ";" + m["fam_name"] + ";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + } + else if (midTitle.StartX.CompareTo(leftTitle.StartX) > 0 && leftTitle.StartX.CompareTo(rightTitle.StartX) > 0) + { + orderType = "E";//中左右 + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s + ";" + m["fam_name"] + ";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", ""))) + ";"); + + } + + else if (leftTitle.StartX.CompareTo(rightTitle.StartX) > 0 && rightTitle.StartX.CompareTo(midTitle.StartX) > 0) + { + orderType = "F";//左右中 + + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s + ";" + m["fam_name"] + ";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + } + else + {//右中左 + + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length >= 6) + { + s = s + ";" + m["fam_name"] + ";"; + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", ""))) + ";"); + } + //if (nowContent.Count > 6) + //{ + // Paragraph para1 = new Paragraph(); + // //Run run1 = para1.AppendChild(new Run()); + // Run run1 = new Run(); + // RunProperties runProps1 = new RunProperties( + // //new Bold(), + // //new Italic(), + // new FontSize() { Val = "36" }, // 12 pt + // //new Color() { Val = "FF0000" }, // Red Text + // new RunFonts() + // { + // Ascii = "DFKai-SB", // 英數字型使用標楷體 + // EastAsia = "DFKai-SB" // 中文字型使用標楷體 + // } + // ); + + // // 建立段落屬性 + // ParagraphProperties pPr1 = new ParagraphProperties(); + // pPr1.Append(new TextDirection() { Val = TextDirectionValues.TopToBottomRightToLeft }); + // // 建立縮排物件 + // // 設定左縮排為 0,首行縮排 480 dxa (約 2 中文字寬) + // Indentation ind = new Indentation() { Left = "720", LeftChars = 300 }; + + // // 將縮排加入段落屬性 + // pPr1.Append(ind); + // para1.Append(pPr1); + // run1.Append(runProps1); + // string[] splits = string.Join("", nowContent).Split(';'); + // int j = 0; + // foreach (var txt in splits) + // { + // run1.Append(new Text($"{string.Join(" ", txt)}")); + // if (j != splits.Length - 1) + // { + // run1.Append(new Break()); + // } + // j++; + // } + // para1.Append(run1); + // body.AppendChild(para1); + // nowContent.Clear(); + //} + //if(string.Join(" ",nowContent).Length > 6) + //{ + // if (result.Count > 0) + // { + // Paragraph para = body.AppendChild(new Paragraph()); + // Run run = para.AppendChild(new Run()); + // RunProperties runProps = new RunProperties( + // //new Bold(), + // //new Italic(), + // new FontSize() { Val = "36" }, // 12 pt + // //new Color() { Val = "FF0000" }, // Red Text + // new RunFonts() + // { + // Ascii = "DFKai-SB", // 英數字型使用標楷體 + // EastAsia = "DFKai-SB" // 中文字型使用標楷體 + // } + // ); + // run.Append(runProps); + // run.AppendChild(new Text($"{string.Join(" ", result)}")); + // } + // result = new List(); + + + // Paragraph para1 = body.AppendChild(new Paragraph()); + // Run run1 = para1.AppendChild(new Run()); + // RunProperties runProps1 = new RunProperties( + // //new Bold(), + // //new Italic(), + // new FontSize() { Val = "36" }, // 12 pt + // //new Color() { Val = "FF0000" }, // Red Text + // new RunFonts() + // { + // Ascii = "DFKai-SB", // 英數字型使用標楷體 + // EastAsia = "DFKai-SB" // 中文字型使用標楷體 + // } + // ); + // run1.Append(runProps1); + // run1.AppendChild(new Text($"{string.Join(" ", nowContent)}")); + //} + //else + //{ + // result.AddRange(nowContent); + //} + + + } + //if (result.Count > 5) + //{ + // Paragraph para = body.AppendChild(new Paragraph()); + // Run run = para.AppendChild(new Run()); + // RunProperties runProps = new RunProperties( + // //new Bold(), + // //new Italic(), + // new FontSize() { Val = "36" }, // 12 pt + // //new Color() { Val = "FF0000" }, // Red Text + // new RunFonts() + // { + // Ascii = "DFKai-SB", // 英數字型使用標楷體 + // EastAsia = "DFKai-SB" // 中文字型使用標楷體 + // } + // ); + // run.Append(runProps); + // run.AppendChild(new Text($"{string.Join(" ", result)}")); + + // result = new List(); + //} + if (nowContent.Count > 10000) + { + Paragraph para1 = new Paragraph(); + //Run run1 = para1.AppendChild(new Run()); + Run run1 = new Run(); + RunProperties runProps1 = new RunProperties( + //new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + + // 建立段落屬性 + ParagraphProperties pPr1 = new ParagraphProperties(); + pPr1.Append(new TextDirection() { Val = TextDirectionValues.TopToBottomRightToLeft }); + // 建立縮排物件 + // 設定左縮排為 0,首行縮排 480 dxa (約 2 中文字寬) + Indentation ind = new Indentation() { Left = "720", LeftChars = 300 }; + + // 將縮排加入段落屬性 + pPr1.Append(ind); + para1.Append(pPr1); + run1.Append(runProps1); + string[] splits = string.Join("", nowContent).Split(';'); + int j = 0; + foreach (var txt in splits) + { + if (!string.IsNullOrWhiteSpace(txt)) + { + if (txt.Length>=6&&j!=0) + { + run1.Append(new Break()); + } + run1.Append(new Text($"{string.Join(" ", txt)}")); + //if (j != splits.Length - 1) + //{ + // run1.Append(new Break()); + //} + + } + j++; + } + para1.Append(run1); + body.AppendChild(para1); + nowContent.Clear(); + } + } + if (nowContent.Count > 0) + { + Paragraph para1 = new Paragraph(); + //Run run1 = para1.AppendChild(new Run()); + Run run1 = new Run(); + RunProperties runProps1 = new RunProperties( + //new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + + // 建立段落屬性 + ParagraphProperties pPr1 = new ParagraphProperties(); + pPr1.Append(new TextDirection() { Val = TextDirectionValues.TopToBottomRightToLeft }); + // 建立縮排物件 + // 設定左縮排為 0,首行縮排 480 dxa (約 2 中文字寬) + Indentation ind = new Indentation() { Left = "720", LeftChars = 300 }; + + // 將縮排加入段落屬性 + pPr1.Append(ind); + para1.Append(pPr1); + run1.Append(runProps1); + string[] splits = string.Join("", nowContent).Split(';'); + int j = 0; + foreach (var txt in splits) + { + if (!string.IsNullOrWhiteSpace(txt)) + { + if (txt.Length >= 6&&j!=0) + { + run1.Append(new Break()); + } + run1.Append(new Text($"{string.Join(" ", txt)}")); + //if (j != splits.Length - 1) + //{ + // run1.Append(new Break()); + //} + + } + j++; + } + para1.Append(run1); + body.AppendChild(para1); + nowContent.Clear(); + } + //if (result.Count > 0) + //{ + // Paragraph para = body.AppendChild(new Paragraph()); + // Run run = para.AppendChild(new Run()); + // RunProperties runProps = new RunProperties( + // //new Bold(), + // //new Italic(), + // new FontSize() { Val = "36" }, // 12 pt + // //new Color() { Val = "FF0000" }, // Red Text + // new RunFonts() + // { + // Ascii = "DFKai-SB", // 英數字型使用標楷體 + // EastAsia = "DFKai-SB" // 中文字型使用標楷體 + // } + // ); + // run.Append(runProps); + // run.AppendChild(new Text($"{string.Join(" ", result)}")); + + // result = new List(); + //} + + Paragraph pageBreakParagraph = new Paragraph( + new Run( + new Break() { Type = BreakValues.Page } + ) + ); + + // 將這個段落附加到文件的 Body 中 + body.Append(pageBreakParagraph); + //先強制換頁 + //在處理超薦牌位 + result = new List(); + foreach (var item in head_list) + { + //S要參數化 + var detail_list = list.Where(x => x.parent_num == item.num && x.print_id.Contains("S")).ToList(); + + //分兩種,一種每一張呈現,一種同樣陽上的拚在一起 + foreach(var d in detail_list) + { + var style = styles.Where(y => y.StyleID == d.style).ToList(); + var addr= style.Where(z => z.ElementID == "address").FirstOrDefault(); + var leftTitle = style.Where(z => z.ElementID == "lefttitle").FirstOrDefault(); + var midTitle = style.Where(z => z.ElementID == "title1").FirstOrDefault(); + var rightTitle = style.Where(z => z.ElementID == "righttitle").FirstOrDefault(); + var alive = style.Where(z => z.ElementID == "alive").FirstOrDefault(); + + var json = JsonConvert.DeserializeObject(d.f_num_tablet); + // 1. 先安全地把 mid_items 轉成 JArray + Newtonsoft.Json.Linq.JArray midItemsArray = json.mid_items as Newtonsoft.Json.Linq.JArray; + Newtonsoft.Json.Linq.JArray leftItemsArray = json.mid_left as Newtonsoft.Json.Linq.JArray; + Newtonsoft.Json.Linq.JArray rightItemsArray = json.mid_right as Newtonsoft.Json.Linq.JArray; + string addrItemsArray =json.addr_items==null?"":(string )json.addr_items; + Newtonsoft.Json.Linq.JArray aliveItemsArray = json.left_items as Newtonsoft.Json.Linq.JArray; + if (mode=="A") + {//一張一張 + //地址 正名 陽上 + nowContent = new List(); + var orderType = "A";//右中左 + if (midTitle.StartX.CompareTo(rightTitle.StartX) > 0 && rightTitle.StartX.CompareTo(leftTitle.StartX) > 0) + { + orderType = "B";//中右左 + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s = s + m["fam_name"] + (i != midItemsArray.Count - 1 ? ";" : ""); + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + } + else if (leftTitle.StartX.CompareTo(midTitle.StartX) > 0 && midTitle.StartX.CompareTo(rightTitle.StartX) > 0) + { + orderType = "C";//左中右 + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s = s + m["fam_name"] + (i != midItemsArray.Count - 1 ? ";" : ""); + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + + } + else if (rightTitle.StartX.CompareTo(midTitle.StartX) > 0 && leftTitle.StartX.CompareTo(midTitle.StartX) > 0) + { + orderType = "D";//右左中 + + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s = s + m["fam_name"] + (i != midItemsArray.Count - 1 ? ";" : ""); + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + } + else if (midTitle.StartX.CompareTo(leftTitle.StartX) > 0 && leftTitle.StartX.CompareTo(rightTitle.StartX) > 0) + { + orderType = "E";//中左右 + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s = s + m["fam_name"] + (i != midItemsArray.Count - 1 ? ";" : ""); + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + + } + + else if (leftTitle.StartX.CompareTo(rightTitle.StartX) > 0 && rightTitle.StartX.CompareTo(midTitle.StartX) > 0) + { + orderType = "F";//左右中 + + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach (var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s = s + m["fam_name"] + (i != midItemsArray.Count - 1 ? ";" : ""); + } + else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + } + else + {//右中左 + + if (rightItemsArray != null && rightItemsArray.Count > 0) + nowContent.Add(string.Join(" ", rightItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (midItemsArray != null && midItemsArray.Count > 0) + { + string s = string.Empty; + int i = 0; + foreach(var m in midItemsArray) + { + if (m["fam_name"]?.ToString().Length > 6) + { + s=s+m["fam_name"]+ (i != midItemsArray.Count-1 ? ";" : ""); + }else + { + s = s + " " + m["fam_name"]; + } + i++; + } + nowContent.Add(s); + } + //nowContent.Add(string.Join(" ", midItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + if (leftItemsArray != null && leftItemsArray.Count > 0) + nowContent.Add(string.Join(" ", leftItemsArray.Select(token => token["fam_name"]?.ToString().Replace("\r", "").Replace("\n", "")))); + } + + Paragraph para3 = body.AppendChild(new Paragraph()); + Run run3 = para3.AppendChild(new Run()); + RunProperties runProps3 = new RunProperties( + new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + run3.Append(runProps3); + run3.AppendChild(new Text($"佛力超薦")); + + if (!string.IsNullOrWhiteSpace(addrItemsArray)) + { + Paragraph para = body.AppendChild(new Paragraph()); + Run run = para.AppendChild(new Run()); + RunProperties runProps = new RunProperties( + //new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + run.Append(runProps); + run.AppendChild(new Text($"地址 {string.Join(" ", addrItemsArray?.ToString())}")); + } + + + Paragraph para1 = new Paragraph(); + //Run run1 = para1.AppendChild(new Run()); + Run run1 = new Run(); + RunProperties runProps1 = new RunProperties( + //new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + + // 建立段落屬性 + ParagraphProperties pPr1 = new ParagraphProperties(); + pPr1.Append(new TextDirection() { Val = TextDirectionValues.TopToBottomRightToLeft }); + // 建立縮排物件 + // 設定左縮排為 0,首行縮排 480 dxa (約 2 中文字寬) + Indentation ind = new Indentation() { Left = "720", LeftChars = 300 }; + + // 將縮排加入段落屬性 + pPr1.Append(ind); + para1.Append(pPr1); + run1.Append(runProps1); + string[] splits = string.Join("", nowContent).Split(';'); + int j = 0; + foreach (var txt in splits) + { + run1.Append(new Text($"{string.Join(" ", txt)}")); + if (j != splits.Length - 1) + { + run1.Append(new Break()); + } + j++; + } + para1.Append(run1); + body.AppendChild(para1); + + + Paragraph para2 = body.AppendChild(new Paragraph()); + ParagraphProperties pPr2 = new ParagraphProperties(); + // 2. 建立段落邊框物件 + ParagraphBorders pBdr = new ParagraphBorders(); + + // 在直書中,BottomBorder 會變成「段落左側的垂直分隔線」 + BottomBorder bottomBorder = new BottomBorder() + { + Val = BorderValues.Dashed, // 單實線 + Size = 12, // 線條粗細 (1/8 點,12 代表 1.5 點) + Space = 4, // 線條與文字的間距 + Color = "000000" // 黑色 + }; + pBdr.Append(bottomBorder); + pPr2.Append(pBdr); + para2.Append(pPr2); + + Run run2 = para2.AppendChild(new Run()); + RunProperties runProps2 = new RunProperties( + new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + run2.Append(runProps2); + run2.AppendChild(new Text($"陽上報恩人 ")); + + Run run4 = para2.AppendChild(new Run()); + RunProperties runProps4 = new RunProperties( + //new Bold(), + //new Italic(), + new FontSize() { Val = "36" }, // 12 pt + //new Color() { Val = "FF0000" }, // Red Text + new RunFonts() + { + Ascii = "DFKai-SB", // 英數字型使用標楷體 + EastAsia = "DFKai-SB" // 中文字型使用標楷體 + } + ); + + + run4.Append(runProps4); + run4.AppendChild(new Text($" {string.Join(" ", aliveItemsArray.Select(token => token["fam_name"]?.ToString()))}")); + run4.Append(new Break()); + } + else + {//同樣陽上合併 + + } + } + } + + + // 3. 設定【整頁直書】的重要步驟: + // 檢查 Body 最後有沒有 SectionProperties,沒有就新增一個 + DocumentFormat.OpenXml.Wordprocessing.SectionProperties sectionProps = body.Elements().LastOrDefault(); + if (sectionProps == null) + { + sectionProps = new DocumentFormat.OpenXml.Wordprocessing.SectionProperties(); + body.AppendChild(sectionProps); // 必須是 Body 的最後一個子元素 + } + // 2. 建立頁面大小物件 (PageSize) + PageSize pageSize = new PageSize(); + + // 3. 設定為 A4 橫向 (把原本縱向的寬高數值對調,並指定 Orient) + pageSize.Width = 16838; // A4 橫向寬度 (Twips) + pageSize.Height = 11906; // A4 橫向高度 (Twips) + pageSize.Orient = PageOrientationValues.Landscape; + + // 4. 將設定附加到章節屬性中 + sectionProps.AppendChild(pageSize); + // 4. 將直書屬性套用到章節中 (TopToBottomRightToLeft) + sectionProps.AppendChild(new TextDirection() { Val = TextDirectionValues.TopToBottomRightToLeft }); + } + return Ok(new + { + list= head_list + }); + } } \ No newline at end of file diff --git a/web/admin/shuwen/shuwen.aspx b/web/admin/shuwen/shuwen.aspx index 53b7c48..5b24d9d 100644 --- a/web/admin/shuwen/shuwen.aspx +++ b/web/admin/shuwen/shuwen.aspx @@ -3,26 +3,54 @@ -
- 查看疏文 + <%--
--%> + <%--查看疏文 + --%> +

- {{latest ? '當前疏文是最新版本': '當前疏文不是最新版本'}} + <%--{{latest ? '當前疏文是最新版本': '當前疏文不是最新版本'}}--%>

-
+ -
+ <%--
--%> + + <%-- +
--%>
-
+ + + + <%--

消災疏文

報名信眾:{{ item[Object.keys(item)[0]].user.name }}

@@ -48,7 +76,7 @@
-
+
--%>
@@ -65,7 +93,13 @@ ShuWenJson: {}, ShuWenItem: '', updateShuWenLoading: false, - latest: false + latest: false, + query: { + start_date: '', + end_date: '', + xStart: '', + sSatrt: '' + }, } }, methods: { @@ -100,7 +134,7 @@ }, getShuWen() { if (this.currentActivityNum) { - axios.get(HTTP_HOST + 'api/shuwen/getshuwen', { + axios.post(HTTP_HOST + 'api/shuwen/RenderShuWenByGong', { params: { activitynum: this.currentActivityNum } diff --git a/銷帳查詢.sql b/銷帳查詢.sql index 359f6d7..a9dee50 100644 --- a/銷帳查詢.sql +++ b/銷帳查詢.sql @@ -11,7 +11,8 @@ WITH Combined_JSON_Details AS ( items.[activity_name], items.[register_date], items.[order_no], - items.[price] + items.[price], + t.check_date FROM [transfer_register] AS t -- 動態判定外殼:有 pro_order_detail_items 就走特定路徑,沒有就直接解析陣列根目錄 CROSS APPLY OPENJSON(t.[draft], CASE WHEN t.[draft] LIKE '%pro_order_detail_items%' THEN '$.pro_order_detail_items' ELSE '$' END) @@ -36,6 +37,7 @@ Unique_Order_Activity AS ( SELECT t.id AS [轉帳序號], t.pay_mode AS [沖帳型態], + convert(varchar(10),t.check_date,120) AS [沖帳日期], t.name AS [主要付款人], t.phone AS [付款人電話], t.amount AS [主單總金額],