902 lines
43 KiB
C#
902 lines
43 KiB
C#
using DocumentFormat.OpenXml;
|
|
//using DocumentFormat.OpenXml.Drawing.Charts;
|
|
//using DocumentFormat.OpenXml.Office2010.PowerPoint;
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
//using DocumentFormat.OpenXml.Spreadsheet;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using PagedList;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.UI.WebControls.WebParts;
|
|
|
|
/// <summary>
|
|
/// shuwensController 的摘要描述
|
|
/// </summary
|
|
[ezAuthorize]
|
|
public class shuwensController : BaseApiController
|
|
{
|
|
public shuwensController()
|
|
{
|
|
//
|
|
// TODO: 在這裡新增建構函式邏輯
|
|
//
|
|
}
|
|
[HttpPost]
|
|
[Route("api/shuwens/GetActShuwen")]
|
|
public IHttpActionResult GetActShuwen([FromBody] Model.activity_shuwen temp)
|
|
{
|
|
var qry = _db.activity_shuwen.AsQueryable();
|
|
if (temp.act_num > 0)
|
|
{
|
|
qry = qry.Where(x => x.act_num == temp.act_num);
|
|
}
|
|
if (!string.IsNullOrEmpty(temp.shuwen_type))
|
|
{
|
|
qry = qry.Where(x => x.shuwen_type == temp.shuwen_type);
|
|
}
|
|
return Ok(new
|
|
{
|
|
result = "Y",
|
|
data = qry.Select(x => new
|
|
{
|
|
x.act_num,
|
|
x.shuwen_type,
|
|
x.shuwen_num,
|
|
x.contents,
|
|
x.paper_size,
|
|
x.direction
|
|
}).FirstOrDefault()
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/shuwens/GetShuwenTemplate")]
|
|
public IHttpActionResult GetShuwenTemplate([FromBody] Model.shuwen_temp temp)
|
|
{
|
|
var qry = _db.shuwen_temp.AsQueryable();
|
|
if (temp.num > 0)
|
|
{
|
|
qry = qry.Where(x => x.num == temp.num);
|
|
}
|
|
return Ok(new { result = "Y", data = qry.Select(x => new
|
|
{
|
|
x.num, x.shuwen_type, x.name, x.contents
|
|
}).FirstOrDefault() });
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/shuwens/ListShuwenTemplate")]
|
|
public IHttpActionResult ListShuwenTemplate([FromBody] Model.shuwen_temp temp)
|
|
{
|
|
var qry = _db.shuwen_temp.AsQueryable();
|
|
if (temp != null && !string.IsNullOrEmpty(temp.shuwen_type))
|
|
{
|
|
qry = qry.Where(x => x.shuwen_type == temp.shuwen_type);
|
|
}
|
|
return Ok(new
|
|
{
|
|
result = "Y",
|
|
data = qry.Select(x => new
|
|
{
|
|
x.num,
|
|
x.shuwen_type,
|
|
x.name,
|
|
x.contents
|
|
}).ToList()
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/shuwens/SaveActShuwen")]
|
|
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();
|
|
if (d != null)
|
|
{
|
|
d.contents = s.contents;
|
|
d.direction = s.direction;
|
|
d.paper_size = s.paper_size;
|
|
d.reg_time = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
s.reg_time = DateTime.Now;
|
|
_db.activity_shuwen.Add(s);
|
|
}
|
|
|
|
_db.SaveChanges();
|
|
return Ok();
|
|
}
|
|
|
|
[HttpPost]
|
|
[Route("api/shuwens/SaveAsShuwenTemplate")]
|
|
public IHttpActionResult SaveAsShuwenTemplate([FromBody] Model.shuwen_temp t)
|
|
{
|
|
if (t.num > 0)
|
|
{//跑更新
|
|
var qry = _db.shuwen_temp.AsQueryable();
|
|
qry = qry.Where(x => x.num == t.num);
|
|
var d = qry.FirstOrDefault();
|
|
if (d != null)
|
|
{
|
|
d.contents = t.contents;
|
|
d.name = t.name;
|
|
d.reg_time = DateTime.Now;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
t.reg_time = DateTime.Now;
|
|
_db.shuwen_temp.Add(t);
|
|
}
|
|
_db.SaveChanges();
|
|
|
|
return Ok();
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
[Route("api/shuwen/RenderShuWenByGong")]
|
|
public IHttpActionResult RenderShuWenByGong([FromBody] dynamic data)
|
|
{
|
|
var jsonData = data;
|
|
var nums = (string)jsonData.activitynum;
|
|
string[] numSplit = nums.Split(',');
|
|
|
|
var mode=(string)jsonData.mode;
|
|
var xStart=(jsonData==null||jsonData.xStart==null)?"":(string)jsonData.xStart;
|
|
var sStart = (jsonData == null || jsonData.sStart==null) ? "" : (string)jsonData.sStart;
|
|
mode = "A";
|
|
StringBuilder sb= new StringBuilder();
|
|
List<int> args = new List<int>();
|
|
List<string> parameters =new List<string>();
|
|
List<SqlParameter> parameterList = new List<SqlParameter>();
|
|
int a = 1;
|
|
foreach (var num in numSplit)
|
|
{
|
|
args.Append(int.Parse(num));
|
|
parameterList.Add(new SqlParameter($"num{a}", num));
|
|
parameters.Add($"@num{a}");
|
|
a++;
|
|
}
|
|
|
|
|
|
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 ({string.Join(",",parameters.ToArray())})) ");
|
|
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)) ");
|
|
Console.WriteLine(sb.ToString());
|
|
var list=_db.Database.SqlQuery<Model.pro_order_detail>(sb.ToString(), parameterList.ToArray()).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() { };
|
|
if( !Directory.Exists( Path.Combine(HttpContext.Current.Server.MapPath("~/rpt"), "shuwen")))
|
|
{
|
|
Directory.CreateDirectory(Path.Combine(HttpContext.Current.Server.MapPath("~/rpt"), "shuwen"));
|
|
}
|
|
string templatePath = Path.Combine(HttpContext.Current.Server.MapPath("~/rpt"), "shuwen", "template.docx");
|
|
using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(templatePath, WordprocessingDocumentType.Document))
|
|
{
|
|
// Add a main document part
|
|
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
|
|
mainPart.Document = new Document();
|
|
Body body = mainPart.Document.AppendChild(new Body());
|
|
|
|
List<string> result = new List<string>();
|
|
var nowContent = new List<string>();
|
|
|
|
Paragraph para0 = new Paragraph();
|
|
Run run0 = new Run();
|
|
RunProperties runProps0 = new RunProperties(
|
|
new Bold(),
|
|
new FontSize() { Val = "36" },
|
|
new RunFonts()
|
|
{
|
|
Ascii = "DFKai-SB", // 英數字型使用標楷體
|
|
EastAsia = "DFKai-SB" // 中文字型使用標楷體
|
|
}
|
|
);
|
|
run0.Append(runProps0);
|
|
for (int gg=1;gg<=12;gg++)
|
|
{
|
|
Text txt = new Text($" ") { Space = DocumentFormat.OpenXml.SpaceProcessingModeValues.Preserve };
|
|
run0.AppendChild(txt);
|
|
}
|
|
run0.AppendChild(new Text($"消災祈福名單"));
|
|
para0.Append(run0);
|
|
body.AppendChild(para0);
|
|
foreach (var item in head_list)
|
|
{
|
|
//消災牌位
|
|
var detail_list = list.Where(x => x.parent_num == item.num && x.print_id.Contains(xStart)).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<dynamic>(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 > 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 = 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();
|
|
}
|
|
|
|
Paragraph pageBreakParagraph = new Paragraph(
|
|
new Run(
|
|
new Break() { Type = BreakValues.Page }
|
|
)
|
|
);
|
|
|
|
// 將這個段落附加到文件的 Body 中
|
|
body.Append(pageBreakParagraph);
|
|
//先強制換頁
|
|
//在處理超薦牌位
|
|
Paragraph para9 = new Paragraph();
|
|
Run run9 = new Run();
|
|
RunProperties runProps9 = new RunProperties(
|
|
new Bold(),
|
|
new FontSize() { Val = "36" },
|
|
new RunFonts()
|
|
{
|
|
Ascii = "DFKai-SB", // 英數字型使用標楷體
|
|
EastAsia = "DFKai-SB" // 中文字型使用標楷體
|
|
}
|
|
);
|
|
run9.Append(runProps9);
|
|
for (int gg = 1; gg <= 12; gg++)
|
|
{
|
|
Text txt= new Text($" ") { Space = DocumentFormat.OpenXml.SpaceProcessingModeValues.Preserve };
|
|
run9.AppendChild(txt);
|
|
}
|
|
run9.AppendChild(new Text($"佛力超薦名單"));
|
|
para9.Append(run9);
|
|
body.AppendChild(para9);
|
|
result = new List<string>();
|
|
foreach (var item in head_list)
|
|
{
|
|
//S要參數化
|
|
var detail_list = list.Where(x => x.parent_num == item.num && x.print_id.Contains(sStart)).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<dynamic>(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<string>();
|
|
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 txt1 in splits)
|
|
{
|
|
run1.Append(new Text($"{string.Join(" ", txt1)}"));
|
|
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);
|
|
Text txt = new Text($"陽上報恩人 ") { Space = DocumentFormat.OpenXml.SpaceProcessingModeValues.Preserve };
|
|
run2.AppendChild(txt);
|
|
|
|
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<DocumentFormat.OpenXml.Wordprocessing.SectionProperties>().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,
|
|
filePath="/rpt/shuwen/template.docx"
|
|
});
|
|
}
|
|
} |