OrderSendBillExport.cs 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Abp.Extensions;
  8. using Abp.Timing;
  9. using IwbZero.IdentityFramework;
  10. using NPOI.HSSF.UserModel;
  11. using NPOI.HSSF.Util;
  12. using NPOI.SS.UserModel;
  13. using NPOI.SS.Util;
  14. using NPOI.XSSF.UserModel;
  15. using ShwasherSys.CustomerInfo;
  16. using ShwasherSys.Inspection;
  17. using ShwasherSys.OrderSendInfo;
  18. using static System.Double;
  19. namespace ShwasherSys.Common
  20. {
  21. public class OrderSendBillExport
  22. {
  23. /// <summary>
  24. /// 艾维尼尔森(伍尔特(上海)工业紧固件有限公司浙江分公司)
  25. /// </summary>
  26. /// <param name="bill"></param>
  27. /// <param name="orderSends"></param>
  28. /// <param name="customer"></param>
  29. /// <param name="templateInfo"></param>
  30. /// <returns></returns>
  31. public string ExportTempAwens(OrderSendBill bill,List<ViewOrderSend> orderSends,Customer customer,TemplateInfo templateInfo)
  32. {
  33. string path = AppDomain.CurrentDomain.BaseDirectory +templateInfo.FilePath;
  34. var savePath = "Download/Excel/OrderSendBill";
  35. var work = ExcelHelper.CreateWorkBook07(path);
  36. var sheet1 = work.GetSheet("Sheet1");
  37. sheet1.GenerateCell(7, 2).SetCellValue(bill.SendDate?.ToString("D"));
  38. sheet1.GenerateCell(9, 2).SetCellValue("");
  39. int index = 0;
  40. foreach (var send in orderSends)
  41. {
  42. sheet1.GenerateCell(19+index, 1).SetCellValue(send.StockNo);
  43. sheet1.GenerateCell(19+index, 2).SetCellValue(send.PartNo);
  44. sheet1.GenerateCell(19+index, 3).SetCellValue((send.Model??"")+","+(send.ProductName ?? "") + ","+(send.SurfaceColor ?? "") + ","+(send.Rigidity ?? ""));
  45. sheet1.GenerateCell(19+index, 4).SetCellValue(send.ProductBatchNum);
  46. var sendQuantity = Math.Floor(send.SendQuantity * 1000) / 1000;//发货数量
  47. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0)*1000)/1000;
  48. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  49. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  50. var sysl = sendQuantity - quantityPerPack * packageCount;
  51. sheet1.GenerateCell(19+index, 5).SetValue<decimal>(sendQuantity*1000);
  52. sheet1.GenerateCell(19+index, 8).SetValue<decimal>(quantityPerPack * 1000);
  53. sheet1.GenerateCell(19+index, 9).SetValue<decimal>(packageCount);
  54. sheet1.GenerateCell(19+index, 10).SetValue<decimal>(sysl * 1000);
  55. index++;
  56. }
  57. var fileName = $"艾维尼尔森-{Clock.Now:yyMMddHHmmss}.xlsx";
  58. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  59. if (!result.IsNullOrEmpty())
  60. {
  61. //CheckErrors(IwbIdentityResult.Failed(result));
  62. return null;
  63. }
  64. return $"/{savePath}/{fileName}";
  65. }
  66. /// <summary>
  67. /// 伍尔特贸易有限公司
  68. /// </summary>
  69. /// <param name="bill"></param>
  70. /// <param name="orderSends"></param>
  71. /// <param name="customer"></param>
  72. /// <param name="templateInfo"></param>
  73. /// <returns></returns>
  74. public string ExportTempWET(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  75. {
  76. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  77. var savePath = "Download/Excel/OrderSendBill";
  78. var work = ExcelHelper.CreateWorkBook07(path);
  79. var sheet1 = work.GetSheet("Sheet1");
  80. sheet1.GenerateCell(5, 2).SetCellValue(customer.CustomerName);
  81. sheet1.GenerateCell(7, 2).SetCellValue(bill.SendDate?.ToString("D"));
  82. sheet1.GenerateCell(9, 2).SetCellValue("");
  83. int index = 0;
  84. foreach (var send in orderSends)
  85. {
  86. sheet1.GenerateCell(19 + index, 1).SetCellValue(send.StockNo);
  87. sheet1.GenerateCell(19 + index, 2).SetCellValue(send.PartNo);
  88. sheet1.GenerateCell(19 + index, 3).SetCellValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," + (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  89. sheet1.GenerateCell(19 + index, 4).SetCellValue(send.ProductBatchNum);
  90. var sendQuantity = Math.Floor(send.SendQuantity * 1000) / 1000;//发货数量
  91. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  92. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  93. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  94. var sysl = sendQuantity - quantityPerPack * packageCount;
  95. sheet1.GenerateCell(19 + index, 5).SetValue<decimal>(sendQuantity * 1000);
  96. sheet1.GenerateCell(19 + index, 8).SetValue<decimal>(quantityPerPack * 1000);
  97. sheet1.GenerateCell(19 + index, 9).SetValue<decimal>(packageCount);
  98. sheet1.GenerateCell(19 + index, 10).SetValue<decimal>(sysl * 1000);
  99. index++;
  100. }
  101. var fileName = $"伍尔特贸易有限公司-{Clock.Now:yyMMddHHmmss}.xlsx";
  102. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  103. if (!result.IsNullOrEmpty())
  104. {
  105. //CheckErrors(IwbIdentityResult.Failed(result));
  106. return null;
  107. }
  108. return $"/{savePath}/{fileName}";
  109. }
  110. /// <summary>
  111. /// 美国柏中
  112. /// </summary>
  113. /// <param name="bill"></param>
  114. /// <param name="orderSends"></param>
  115. /// <param name="customer"></param>
  116. /// <param name="templateInfo"></param>
  117. /// <returns></returns>
  118. public string ExportTempMgbz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  119. {
  120. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  121. var savePath = "Download/Excel/OrderSendBill";
  122. var work = ExcelHelper.CreateWorkBook07(path);
  123. var sheet1 = work.GetSheet("Sheet1");
  124. sheet1.GenerateCell(5, 1).SetCellValue("发货日期"+bill.SendDate?.ToString("yyyy-MM-dd"));
  125. for (int i = 8; i <= 14; i++)
  126. {
  127. sheet1.RemoveRow(sheet1.GenerateRow(i));
  128. //RemoveMergedRegion(sheet1, i);
  129. }
  130. for (int i = 0; i < 6; i++)
  131. {
  132. RemoveMergedRegion(sheet1, 8 + i);
  133. }
  134. int index = 0;
  135. decimal totalCount = 0;
  136. decimal allTotalPrice = 0;
  137. ICellStyle style1 = SetCellStyle(work,fontHeightInPoints:10,horizontalAlignment:HorizontalAlignment.Left);
  138. ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal,fontHeightInPoints:10);
  139. foreach (var send in orderSends)
  140. {
  141. sheet1.GenerateCell(7 + index, 1).SetValue<int>(index+1, style1);
  142. sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo??"", style11);
  143. sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo??"", style11);
  144. sheet1.GenerateCell(7 + index, 4).SetValue(send.ProductName??"", style11);
  145. sheet1.GenerateCell(7 + index, 5).SetValue(send.SurfaceColor??"", style11);
  146. sheet1.GenerateCell(7 + index, 6).SetValue<decimal>("", style11);
  147. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  148. sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(sendQuantity * 1000, style11);
  149. totalCount += sendQuantity * 1000;
  150. sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(send.Price / 10, style11);
  151. var afterTotalPrice = send.AfterTaxPrice * send.SendQuantity;
  152. sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(afterTotalPrice, style11);
  153. allTotalPrice += afterTotalPrice;
  154. sheet1.GenerateCell(7 + index, 10).SetValue(send.ProductBatchNum??"", style11);
  155. index++;
  156. }
  157. ICellStyle style2 = SetCellStyle(work, fontHeightInPoints: 11);
  158. ICellStyle style3 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow,borderStyle:BorderStyle.None, fontHeightInPoints: 9);
  159. ICellStyle style4 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 9);
  160. ICellStyle style5 = SetCellStyle(work,fillBackgroundColor: (short)ColorType.Yellow, fontHeightInPoints: 11,horizontalAlignment: HorizontalAlignment.Left);
  161. sheet1.GenerateCell(7 + index, 1).SetValue("", style2);
  162. sheet1.GenerateCell(7 + index, 2).SetValue("合计", style2);
  163. sheet1.GenerateCell(7 + index, 3).SetValue("", style2);
  164. sheet1.GenerateCell(7 + index, 4).SetValue("", style2);
  165. sheet1.GenerateCell(7 + index, 5).SetValue("", style2);
  166. sheet1.GenerateCell(7 + index, 6).SetValue("", style2);
  167. sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(totalCount, style2);
  168. sheet1.GenerateCell(7 + index, 8).SetValue("", style2);
  169. sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(allTotalPrice, style2);
  170. sheet1.GenerateCell(7 + index, 10).SetValue("", style2);
  171. for (int i =9; i <= 14; i++)
  172. {
  173. sheet1.GenerateCell(i + index, 1).SetValue("", style3);
  174. sheet1.GenerateCell(i + index, 2).SetValue("", style3);
  175. sheet1.GenerateCell(i + index, 3).SetValue("", style3);
  176. sheet1.GenerateCell(i + index, 4).SetValue("", style5);
  177. sheet1.GenerateCell(i + index, 5).SetValue("", style5);
  178. sheet1.GenerateCell(i + index, 6).SetValue("", style4);
  179. sheet1.MergedRegion(i + index, i + index, 7, 8);
  180. sheet1.GenerateCell(i + index, 7).SetValue("", style4);
  181. sheet1.GenerateCell(i + index, 8).SetValue("", style4);
  182. sheet1.GenerateCell(i + index, 9).SetValue("", style3);
  183. }
  184. sheet1.GenerateCell(9 + index, 4).SetValue("品名:");
  185. sheet1.GenerateCell(9 + index, 6).SetValue("重量 KG");
  186. sheet1.GenerateCell(9 + index, 7).SetValue("数量 PCS");
  187. sheet1.GenerateCell(10 + index, 4).SetValue("垫片类:");
  188. sheet1.GenerateCell(10 + index, 6).SetValue("垫片类:");
  189. sheet1.GenerateCell(11 + index, 4).SetValue("总数量");
  190. sheet1.GenerateCell(11 + index, 6).SetValue("总数量");
  191. sheet1.GenerateCell(11 + index,7).SetValue(totalCount+"PCS");
  192. sheet1.GenerateCell(12 + index, 4).SetValue("总重量:");
  193. sheet1.GenerateCell(12 + index, 6).SetValue("总重量公斤:");
  194. sheet1.GenerateCell(13 + index, 4).SetValue("总件数:");
  195. sheet1.GenerateCell(13 + index, 6).SetValue("总件数:");
  196. sheet1.GenerateCell(14 + index, 4).SetValue("送货司机:");
  197. sheet1.GenerateCell(14 + index, 6).SetValue("车牌号:");
  198. var fileName = $"柏中专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  199. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  200. if (!result.IsNullOrEmpty())
  201. {
  202. //CheckErrors(IwbIdentityResult.Failed(result));
  203. return null;
  204. }
  205. return $"/{savePath}/{fileName}";
  206. }
  207. /// <summary>
  208. /// 天津柏中
  209. /// </summary>
  210. /// <param name="bill"></param>
  211. /// <param name="orderSends"></param>
  212. /// <param name="customer"></param>
  213. /// <param name="templateInfo"></param>
  214. /// <returns></returns>
  215. public string ExportTempTjbz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer, TemplateInfo templateInfo)
  216. {
  217. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  218. var savePath = "Download/Excel/OrderSendBill";
  219. var work = ExcelHelper.CreateWorkBook07(path);
  220. var sheet1 = work.GetSheet("Sheet1");
  221. sheet1.GenerateCell(5, 1).SetCellValue("发货日期" + bill.SendDate?.ToString("yyyy-MM-dd"));
  222. for (int i = 8; i <= 14; i++)
  223. {
  224. sheet1.RemoveRow(sheet1.GenerateRow(i));
  225. //RemoveMergedRegion(sheet1, i);
  226. }
  227. for (int i = 0; i < 6; i++)
  228. {
  229. RemoveMergedRegion(sheet1, 8 + i);
  230. }
  231. int index = 0;
  232. decimal totalCount = 0;
  233. decimal allTotalPrice = 0;
  234. ICellStyle style1 = SetCellStyle(work, fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left);
  235. ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 10);
  236. foreach (var send in orderSends)
  237. {
  238. sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1, style1);
  239. sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo ?? "", style11);
  240. sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo ?? "", style11);
  241. sheet1.GenerateCell(7 + index, 4).SetValue(send.ProductName ?? "", style11);
  242. sheet1.GenerateCell(7 + index, 5).SetValue(send.SurfaceColor ?? "", style11);
  243. sheet1.GenerateCell(7 + index, 6).SetValue<decimal>("", style11);
  244. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  245. sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(sendQuantity * 1000, style11);
  246. totalCount += sendQuantity * 1000;
  247. sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(send.Price / 10, style11);
  248. var afterTotalPrice = send.AfterTaxPrice * send.SendQuantity;
  249. sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(afterTotalPrice, style11);
  250. allTotalPrice += afterTotalPrice;
  251. sheet1.GenerateCell(7 + index, 10).SetValue(send.ProductBatchNum ?? "", style11);
  252. index++;
  253. }
  254. ICellStyle style2 = SetCellStyle(work, fontHeightInPoints: 11);
  255. ICellStyle style3 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, borderStyle: BorderStyle.None, fontHeightInPoints: 9);
  256. ICellStyle style4 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 9);
  257. ICellStyle style5 = SetCellStyle(work, fillBackgroundColor: (short)ColorType.Yellow, fontHeightInPoints: 11, horizontalAlignment: HorizontalAlignment.Left);
  258. sheet1.GenerateCell(7 + index, 1).SetValue("", style2);
  259. sheet1.GenerateCell(7 + index, 2).SetValue("合计", style2);
  260. sheet1.GenerateCell(7 + index, 3).SetValue("", style2);
  261. sheet1.GenerateCell(7 + index, 4).SetValue("", style2);
  262. sheet1.GenerateCell(7 + index, 5).SetValue("", style2);
  263. sheet1.GenerateCell(7 + index, 6).SetValue("", style2);
  264. sheet1.GenerateCell(7 + index, 7).SetValue<decimal>(totalCount, style2);
  265. sheet1.GenerateCell(7 + index, 8).SetValue("", style2);
  266. sheet1.GenerateCell(7 + index, 9).SetValue<decimal>(allTotalPrice, style2);
  267. sheet1.GenerateCell(7 + index, 10).SetValue("", style2);
  268. for (int i = 9; i <= 14; i++)
  269. {
  270. sheet1.GenerateCell(i + index, 1).SetValue("", style3);
  271. sheet1.GenerateCell(i + index, 2).SetValue("", style3);
  272. sheet1.GenerateCell(i + index, 3).SetValue("", style3);
  273. sheet1.GenerateCell(i + index, 4).SetValue("", style5);
  274. sheet1.GenerateCell(i + index, 5).SetValue("", style5);
  275. sheet1.GenerateCell(i + index, 6).SetValue("", style4);
  276. sheet1.MergedRegion(i + index, i + index, 7, 8);
  277. sheet1.GenerateCell(i + index, 7).SetValue("", style4);
  278. sheet1.GenerateCell(i + index, 8).SetValue("", style4);
  279. sheet1.GenerateCell(i + index, 9).SetValue("", style3);
  280. }
  281. sheet1.GenerateCell(9 + index, 4).SetValue("品名:");
  282. sheet1.GenerateCell(9 + index, 6).SetValue("重量 KG");
  283. sheet1.GenerateCell(9 + index, 7).SetValue("数量 PCS");
  284. sheet1.GenerateCell(10 + index, 4).SetValue("垫片类:");
  285. sheet1.GenerateCell(10 + index, 6).SetValue("垫片类:");
  286. sheet1.GenerateCell(11 + index, 4).SetValue("总数量");
  287. sheet1.GenerateCell(11 + index, 6).SetValue("总数量");
  288. sheet1.GenerateCell(11 + index, 7).SetValue(totalCount + "PCS");
  289. sheet1.GenerateCell(12 + index, 4).SetValue("总重量:");
  290. sheet1.GenerateCell(12 + index, 6).SetValue("总重量公斤:");
  291. sheet1.GenerateCell(13 + index, 4).SetValue("总件数:");
  292. sheet1.GenerateCell(13 + index, 6).SetValue("总件数:");
  293. sheet1.GenerateCell(14 + index, 4).SetValue("送货司机:");
  294. sheet1.GenerateCell(14 + index, 6).SetValue("车牌号:");
  295. var fileName = $"天津柏中专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  296. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  297. if (!result.IsNullOrEmpty())
  298. {
  299. //CheckErrors(IwbIdentityResult.Failed(result));
  300. return null;
  301. }
  302. return $"/{savePath}/{fileName}";
  303. }
  304. /// <summary>
  305. /// 杭州西门子
  306. /// </summary>
  307. /// <param name="bill"></param>
  308. /// <param name="orderSends"></param>
  309. /// <param name="customer"></param>
  310. /// <param name="templateInfo"></param>
  311. /// <returns></returns>
  312. public string ExportTempHzxmz(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  313. TemplateInfo templateInfo)
  314. {
  315. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  316. var savePath = "Download/Excel/OrderSendBill";
  317. var work = ExcelHelper.CreateWorkBook07(path);
  318. var sheet1 = work.GetSheet("Sheet1");
  319. sheet1.GenerateCell(5, 3).SetCellValue(bill.SendDate?.ToString("yyyy/MM/dd"));
  320. int index = 0;
  321. ICellStyle style1 = SetCellStyle(work, fontName: "Arial", horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal,borderColor:(short)ColorType.Black);
  322. // ICellStyle style11 = SetCellStyle(work, boldWeight: (short)FontBoldWeight.Normal, fontHeightInPoints: 10);
  323. foreach (var send in orderSends)
  324. {
  325. sheet1.GenerateCell(8 + index, 1).SetValue<int>(index + 1, style1);
  326. sheet1.GenerateCell(8 + index, 2).SetValue(send?.StockNo??"", style1);
  327. sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  328. sheet1.GenerateCell(8 + index, 4).SetValue(send?.PartNo??"", style1);
  329. sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  330. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  331. sheet1.GenerateCell(8 + index, 6).SetValue<decimal>(sendQuantity * 1000, style1);
  332. sheet1.GenerateCell(8 + index, 7).SetValue(send?.Model??"", style1);
  333. sheet1.GenerateCell(8 + index, 8).SetValue((send?.ProductName ?? "") + "," + (send?.SurfaceColor ?? "") + "," + (send?.Rigidity ?? "") + "", style1);
  334. sheet1.GenerateCell(8 + index, 9).SetValue("", style1);
  335. sheet1.GenerateCell(8 + index, 10).SetValue(send?.Remark??"", style1);
  336. index++;
  337. }
  338. for (int i = index+1; i <= 13; i++)
  339. {
  340. sheet1.GenerateCell(8 + index, 1).SetValue("", style1);
  341. sheet1.GenerateCell(8 + index, 2).SetValue("", style1);
  342. sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  343. sheet1.GenerateCell(8 + index, 4).SetValue("", style1);
  344. sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  345. sheet1.GenerateCell(8 + index, 6).SetValue("", style1);
  346. sheet1.GenerateCell(8 + index, 7).SetValue("", style1);
  347. sheet1.GenerateCell(8 + index, 8).SetValue("", style1);
  348. sheet1.GenerateCell(8 + index, 9).SetValue("", style1);
  349. sheet1.GenerateCell(8 + index, 10).SetValue("", style1);
  350. index++;
  351. }
  352. ICellStyle style2 = SetCellStyle(work, fontName: "宋体", fontHeightInPoints: 11, horizontalAlignment: HorizontalAlignment.Center,borderColor:(short)ColorType.Grey25Percent);
  353. sheet1.GenerateCell(8 + index, 1).SetValue("", style2);
  354. sheet1.GenerateCell(8 + index, 2).SetValue("", style2);
  355. sheet1.GenerateCell(8 + index, 3).SetValue("", style2);
  356. sheet1.GenerateCell(8 + index, 4).SetValue("", style2);
  357. sheet1.GenerateCell(8 + index, 5).SetValue("", style2);
  358. sheet1.GenerateCell(8 + index, 6).SetValue("", style2);
  359. sheet1.GenerateCell(8 + index, 7).SetValue("", style2);
  360. sheet1.GenerateCell(8 + index, 8).SetValue("", style2);
  361. sheet1.MergedRegion(8 + index, 8 + index, 9, 10);
  362. sheet1.GenerateCell(8 + index, 9).SetValue("合计_箱", style2);
  363. ICellStyle style3 = SetCellStyle(work, fontName: "宋体", horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  364. sheet1.MergedRegion(9 + index, 9 + index, 1, 2);
  365. sheet1.GenerateCell(9 + index, 1).SetValue(" 送货人:沈", style3);
  366. sheet1.GenerateCell(9 + index, 3).SetValue("", style3);
  367. sheet1.GenerateCell(9 + index, 4).SetValue("", style3);
  368. sheet1.GenerateCell(9 + index, 5).SetValue("签收人:", style3);
  369. sheet1.GenerateCell(9 + index, 6).SetValue("", style3);
  370. sheet1.GenerateCell(9 + index, 7).SetValue("", style3);
  371. sheet1.GenerateCell(9 + index, 8).SetValue("签收日期:", style3);
  372. sheet1.GenerateCell(9 + index, 9).SetValue("", style3);
  373. sheet1.GenerateCell(9 + index, 10).SetValue("", style3);
  374. ICellStyle style4 = SetCellStyle(work, fontName: "Arial",fontHeightInPoints: 10,horizontalAlignment: HorizontalAlignment.Left, borderStyle: BorderStyle.Thin, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  375. sheet1.GenerateCell(10 + index, 1).SetValue("Comments:备注", style4);
  376. sheet1.GenerateCell(10 + index, 2).SetValue("", style4);
  377. sheet1.GenerateCell(10 + index, 3).SetValue("", style4);
  378. sheet1.GenerateCell(10 + index, 4).SetValue("", style4);
  379. sheet1.GenerateCell(10 + index, 5).SetValue("", style4);
  380. sheet1.GenerateCell(10 + index, 6).SetValue("", style4);
  381. sheet1.GenerateCell(10 + index, 7).SetValue("", style4);
  382. sheet1.GenerateCell(10 + index, 8).SetValue("", style4);
  383. sheet1.GenerateCell(10 + index, 9).SetValue("", style4);
  384. sheet1.GenerateCell(10 + index, 10).SetValue("", style4);
  385. for (int i = 0; i < 5; i++)
  386. {
  387. sheet1.GenerateCell(11 +index+ i, 1).SetValue("", style4);
  388. sheet1.GenerateCell(11 +index+ i, 2).SetValue("", style4);
  389. sheet1.GenerateCell(11 +index+ i, 3).SetValue("", style4);
  390. sheet1.GenerateCell(11 +index+ i, 4).SetValue("", style4);
  391. sheet1.GenerateCell(11 +index+ i, 5).SetValue("", style4);
  392. sheet1.GenerateCell(11 +index+ i, 6).SetValue("", style4);
  393. sheet1.GenerateCell(11 +index+ i, 7).SetValue("", style4);
  394. sheet1.GenerateCell(11 +index+ i, 8).SetValue("", style4);
  395. sheet1.GenerateCell(11 +index+ i, 9).SetValue("", style4);
  396. sheet1.GenerateCell(11 +index+ i, 10).SetValue("", style4);
  397. }
  398. ICellStyle style5 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, borderStyle: BorderStyle.Thin,borderColor: (short)ColorType.Grey25Percent);
  399. sheet1.GenerateCell(11 + index, 2).SetValue("1、The same Drawing No. are consider same Lot / Batch不同订单号但是相同零件图号的为一批;相同订单号,相同零件图号必须在同一行!", style4);
  400. sheet1.GenerateCell(12 + index, 2).SetValue("2、Only 5 Lots / Batch must be per page !. 一页最多只允许有5批或10行,否则拒收!", style5);
  401. sheet1.GenerateCell(13 + index, 2).SetValue("3、零件图号和版本号务必填写正确、完整;", style4);
  402. sheet1.GenerateCell(14 + index, 2).SetValue("4、供应商提供送检单须一式两份,一份给SAP操作员用于入录数据,一份给检验员用于检验记录;", style4);
  403. sheet1.GenerateCell(15 + index, 2).SetValue("5、检验完成后,一份交予仓库,一份质量部留档。", style4);
  404. var fileName = $"杭州西门子专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  405. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  406. if (!result.IsNullOrEmpty())
  407. {
  408. //CheckErrors(IwbIdentityResult.Failed(result));
  409. return null;
  410. }
  411. return $"/{savePath}/{fileName}";
  412. }
  413. /// <summary>
  414. /// 凯乐金霸
  415. /// </summary>
  416. /// <param name="bill"></param>
  417. /// <param name="orderSends"></param>
  418. /// <param name="customer"></param>
  419. /// <param name="templateInfo"></param>
  420. /// <returns></returns>
  421. public string ExportTempKlgb(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  422. TemplateInfo templateInfo)
  423. {
  424. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  425. //var savePath = "Download/Excel/OrderSendBill";
  426. var work = ExcelHelper.CreateWorkBook07(path);
  427. var sheet1 = work.GetSheet("Sheet1");
  428. //int sendCount = orderSends.Count;
  429. //List<IRow> rows = sheet1.GetRows(91, 101);
  430. //for (int i = 0; i < rows.Count; i++)
  431. //{
  432. // CopyRowEx(work, sheet1.GenerateRow(91+i), sheet1.GenerateRow(7+i+ sendCount), true);
  433. //}
  434. sheet1.GenerateCell(1, 10).SetValue(bill.Id);
  435. int index = 0;
  436. decimal totalCount = 0;
  437. ICellStyle style1 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Center, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black);
  438. foreach (var send in orderSends)
  439. {
  440. sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1, style1);
  441. sheet1.GenerateCell(7 + index, 2).SetValue(send.StockNo, style1);
  442. sheet1.GenerateCell(7 + index, 3).SetValue(send.PartNo??"", style1);
  443. sheet1.GenerateCell(7 + index, 4).SetValue(send.Model??"", style1);
  444. sheet1.GenerateCell(7 + index, 5).SetValue( (send.ProductName??"") + "," + (send.SurfaceColor??"") + "," + (send.Rigidity??"") , style1);
  445. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  446. var quantityPerPack = send.QuantityPerPack ?? 0;
  447. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  448. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  449. var sysl = sendQuantity - quantityPerPack * packageCount;
  450. sheet1.GenerateCell(7 + index, 6).SetValue<decimal>(sendQuantity * 1000, style1);
  451. totalCount += sendQuantity * 1000;
  452. sheet1.GenerateCell(7 + index, 7).SetValue("", style1);
  453. sheet1.GenerateCell(7 + index, 8).SetValue<decimal>(quantityPerPack*1000, style1);
  454. sheet1.GenerateCell(7 + index, 9).SetValue(packageCount+"箱"+"*"+ quantityPerPack+ (sysl>0?"+"+sysl:"")+"="+ sendQuantity, style1);
  455. sheet1.GenerateCell(7 + index, 10).SetValue("", style1);
  456. sheet1.GenerateCell(7 + index, 11).SetValue(send.Remark ?? "", style1);
  457. index++;
  458. }
  459. for (int i = 1; i <= 11; i++)
  460. {
  461. sheet1.GenerateCell(7 + index, i).SetValue("", style1);
  462. }
  463. ICellStyle style1_1 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black,wrapText:true);
  464. sheet1.GenerateCell(8 + index, 1).SetValue("收货验收确认Received Confirmation:", style1_1);
  465. sheet1.GenerateCell(8 + index, 2).SetValue("", style1);
  466. sheet1.GenerateCell(8 + index, 3).SetValue("", style1);
  467. sheet1.GenerateCell(8 + index, 4).SetValue("", style1);
  468. sheet1.GenerateCell(8 + index, 5).SetValue("", style1);
  469. sheet1.GenerateCell(8 + index, 6).SetValue<int>(totalCount, style1);
  470. sheet1.GenerateCell(8 + index, 7).SetValue("", style1);
  471. sheet1.GenerateCell(8 + index, 8).SetValue("", style1);
  472. sheet1.MergedRegion(8 + index, 8 + index, 9, 10);
  473. sheet1.GenerateCell(8 + index, 9).SetValue("合计_箱,附检测报告 ", style1);
  474. sheet1.GenerateCell(8 + index, 10).SetValue("", style1);
  475. sheet1.GenerateCell(8 + index, 11).SetValue("", style1);
  476. ICellStyle style1_2 = SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Center, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Black, wrapText: true,fillBackgroundColor:(short)ColorType.Grey25Percent);
  477. sheet1.GenerateCell(9 + index, 1).SetValue("日期及签字/Date & Signature:", style1_2);
  478. sheet1.GenerateCell(9 + index, 2).SetValue("", style1_2);
  479. sheet1.GenerateCell(9 + index, 3).SetValue("___日期____沈再红", style1_2);
  480. sheet1.GenerateCell(9 + index, 4).SetValue("", style1_2);
  481. sheet1.GenerateCell(9 + index, 5).SetValue("", style1_2);
  482. sheet1.GenerateCell(9 + index, 6).SetValue("送货人:", style1_2);
  483. sheet1.MergedRegion(9 + index, 9 + index, 7, 8);
  484. sheet1.GenerateCell(9 + index, 7).SetValue("", style1_2);
  485. sheet1.GenerateCell(9 + index, 8).SetValue("", style1_2);
  486. sheet1.GenerateCell(9 + index, 9).SetValue("收货人", style1_2);
  487. sheet1.MergedRegion(9 + index, 9 + index, 10, 11);
  488. sheet1.GenerateCell(9 + index, 10).SetValue("", style1_2);
  489. sheet1.GenerateCell(9 + index, 11).SetValue("", style1_2);
  490. ICellStyle style2= SetCellStyle(work, fontName: "Arial", fontHeightInPoints: 10, horizontalAlignment: HorizontalAlignment.Left, boldWeight: (short)FontBoldWeight.Normal, borderColor: (short)ColorType.Grey25Percent);
  491. for (int i = 0; i < 8; i++)
  492. {
  493. sheet1.GenerateCell(10+i + index, 1).SetValue("", style2);
  494. sheet1.MergedRegion(10 + i + index, 10 + i + index, 2, 7);
  495. sheet1.GenerateCell(10+i + index, 2).SetValue("", style2);
  496. sheet1.GenerateCell(10 + i + index, 3).SetValue("", style2);
  497. sheet1.GenerateCell(10 + i + index, 4).SetValue("", style2);
  498. sheet1.GenerateCell(10 + i + index, 5).SetValue("", style2);
  499. sheet1.GenerateCell(10 + i + index, 6).SetValue("", style2);
  500. sheet1.GenerateCell(10 + i + index, 7).SetValue("", style2);
  501. sheet1.GenerateCell(10+i + index, 8).SetValue("", style2);
  502. sheet1.GenerateCell(10+i + index, 9).SetValue("", style2);
  503. sheet1.GenerateCell(10 + i + index, 10).SetValue("", style2);
  504. sheet1.GenerateCell(10+i + index, 11).SetValue("", style2);
  505. }
  506. sheet1.GenerateCell(10 + index, 1).SetValue("送货及物品包装要求");
  507. sheet1.GenerateCell(10 + index, 2).SetValue("1: 物品包装箱子必须为纸箱,不允许麻布袋形式包装,含油性物料必须在包装箱内增加塑料袋");
  508. sheet1.GenerateCell(11 + index, 2).SetValue("2: 包装箱尺寸必须一致,推荐尺寸为320*220*120的包装箱");
  509. sheet1.GenerateCell(12 + index, 2).SetValue("3: 同一款物料每箱数量必须一致,只留一个尾箱,且必须在包装箱上标注尾数箱");
  510. sheet1.GenerateCell(13 + index, 2).SetValue("4: 每个物品独立包装箱,不可多个物料摆放在一个包装箱,避免造成混料");
  511. sheet1.GenerateCell(14 + index, 2).SetValue("5: 每箱物料重量必须控制在20KG以下");
  512. sheet1.GenerateCell(15 + index, 2).SetValue("6:物料箱上必须贴有物料标示,必须具备订单号/KK物料号/尺寸描述/装箱数量/最小包装量");
  513. sheet1.GenerateCell(16 + index, 2).SetValue("7: 严禁包装箱破损与无包装裸露送货,不满足的包装,仓库一律拒收");
  514. sheet1.GenerateCell(17 + index, 2).SetValue("8: 供应商送货数量必须与送货单数量一致");
  515. for (int i = 1; i <= 11; i++)
  516. {
  517. ICellStyle ss = work.CreateCellStyle();
  518. ss.BorderTop = BorderStyle.Thin;
  519. ss.TopBorderColor = (short)ColorType.Black;
  520. sheet1.GenerateCell(18 + index, i).CellStyle = ss;
  521. sheet1.GenerateCell(18 + index, i).SetValue("");
  522. }
  523. for (int i = 0; i < 8; i++)
  524. {
  525. ICellStyle ss = work.CreateCellStyle();
  526. ss.BorderLeft = BorderStyle.Thin;
  527. ss.LeftBorderColor = (short) ColorType.Black;
  528. sheet1.GenerateCell(10 + i + index, 12).CellStyle = ss;
  529. sheet1.GenerateCell(10 + i + index, 12).SetValue("");
  530. }
  531. var fileName = $"凯乐金霸专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  532. //var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  533. //if (!result.IsNullOrEmpty())
  534. //{
  535. // //CheckErrors(IwbIdentityResult.Failed(result));
  536. // return null;
  537. //}
  538. //return $"/{savePath}/{fileName}";
  539. return Save(sheet1, fileName);
  540. }
  541. /// <summary>
  542. /// 杭州德特
  543. /// </summary>
  544. /// <param name="bill"></param>
  545. /// <param name="orderSends"></param>
  546. /// <param name="customer"></param>
  547. /// <param name="templateInfo"></param>
  548. /// <returns></returns>
  549. public string ExportTempHzdt(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  550. TemplateInfo templateInfo)
  551. {
  552. var sheet1 = GetSheet1(templateInfo);
  553. int index = 0;
  554. sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.M.dd"));
  555. sheet1.InsertRows(6, orderSends.Count);
  556. var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  557. foreach (var send in viewOrderSends)
  558. {
  559. sheet1.GenerateCell(6 + index,1).SetValue<int>(index + 1);
  560. sheet1.GenerateCell(6 + index,2).SetValue(send.StockNo ?? "");
  561. sheet1.GenerateCell(6 + index,3).SetValue(send.PartNo ?? "");
  562. sheet1.GenerateCell(6 + index, 4).SetValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," +
  563. (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  564. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  565. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0)*1000)/1000;
  566. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  567. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  568. var sysl = sendQuantity - quantityPerPack * packageCount;
  569. sheet1.GenerateCell(6 + index, 5).SetValue<decimal>(sendQuantity);
  570. sheet1.GenerateCell(6 + index, 6).SetValue((packageCount + (sysl > 0 ? 1 : 0)) + "箱" );
  571. sheet1.GenerateCell(6 + index, 7).SetValue(send.ProductBatchNum);
  572. index++;
  573. }
  574. var fileName = $"杭州德特专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  575. return Save(sheet1, fileName);
  576. }
  577. //上海泛得五金配件厂
  578. public string ExportTempShFd(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  579. TemplateInfo templateInfo)
  580. {
  581. var sheet1 = GetSheet1(templateInfo);
  582. int index = 0;
  583. //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  584. var orderSendCount = orderSends.Count;
  585. if (orderSendCount < 20)
  586. {
  587. orderSendCount = 20;
  588. }
  589. sheet1.InsertRows(7, orderSendCount);
  590. var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  591. decimal allSendCount = 0;
  592. foreach (var send in viewOrderSends)
  593. {
  594. sheet1.GenerateCell(7 + index, 1).SetValue<int>(index + 1);
  595. sheet1.GenerateCell(7 + index, 2).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  596. sheet1.GenerateCell(7 + index, 3).SetValue(send.StockNo ?? "");
  597. sheet1.GenerateCell(7 + index, 4).SetValue(send.PartNo ?? "");
  598. sheet1.GenerateCell(7 + index, 5).SetValue((send.Model ?? "") + "," + (send.ProductName ?? "") + "," +
  599. (send.SurfaceColor ?? "") + "," + (send.Rigidity ?? ""));
  600. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  601. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  602. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  603. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  604. var sysl = sendQuantity - quantityPerPack * packageCount;
  605. sheet1.GenerateCell(7 + index, 6).SetValue<decimal>(sendQuantity*1000);
  606. sheet1.GenerateCell(7 + index, 7).SetValue((packageCount + (sysl > 0 ? 1 : 0))+"");
  607. sheet1.GenerateCell(7 + index, 8).SetValue(send.ProductBatchNum);
  608. allSendCount += sendQuantity * 1000;
  609. index++;
  610. }
  611. sheet1.MergedRegion(7 + orderSendCount+2, 7 + orderSendCount+2, 7, 9);
  612. sheet1.GenerateCell(7 + orderSendCount+2, 7).SetValue("合计:"+ allSendCount);
  613. //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  614. var fileName = $"上海泛得五金配件厂-{Clock.Now:yyMMddHHmmss}.xlsx";
  615. return Save(sheet1, fileName);
  616. }
  617. //太仓慧鱼
  618. public string ExportTempTCHY(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  619. TemplateInfo templateInfo)
  620. {
  621. var sheet1 = GetSheet1(templateInfo);
  622. int index = 0;
  623. //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  624. var orderSendCount = orderSends.Count;
  625. if (orderSendCount < 7)
  626. {
  627. orderSendCount = 7;
  628. }
  629. sheet1.InsertRows(14, orderSendCount);
  630. var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  631. //decimal allSendCount = 0;
  632. sheet1.GenerateCell(7, 3).SetValue(DateTime.Now.ToString("yyyy/MM/dd"));
  633. foreach (var send in viewOrderSends)
  634. {
  635. sheet1.GenerateCell(14 + index, 1).SetValue(send?.PartNo);
  636. sheet1.GenerateCell(14 + index, 2).SetValue(send.StockNo ?? "");
  637. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  638. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  639. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  640. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  641. var sysl = sendQuantity - quantityPerPack * packageCount;
  642. sheet1.GenerateCell(14 + index, 3).SetValue<decimal>(sendQuantity * 1000);
  643. sheet1.GenerateCell(14 + index, 5).SetValue(send.ProductBatchNum);
  644. sheet1.GenerateCell(14 + index, 6).SetValue((send.ProductName ?? "") + " " + (send.Model ?? "") + " " +
  645. (send.SurfaceColor ?? "") + " " + (send.Rigidity ?? ""));
  646. sheet1.GenerateCell(14 + index, 7).SetValue("太仓");
  647. sheet1.GenerateCell(14 + index, 8).SetValue(send.OrderDate.ToString("yyyy/MM/dd"));
  648. sheet1.GenerateCell(14 + index, 9).SetValue(packageCount + "箱*" + quantityPerPack + (sysl > 0 ? " + " + (sysl * 1000) : "") + "PCS");
  649. //allSendCount += sendQuantity * 1000;
  650. index++;
  651. }
  652. //sheet1.MergedRegion(7 + orderSendCount + 2, 7 + orderSendCount + 2, 7, 9);
  653. // sheet1.GenerateCell(7 + orderSendCount + 2, 7).SetValue("合计:" + allSendCount);
  654. //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  655. var fileName = $"太仓慧鱼送货单-{Clock.Now:yyMMddHHmmss}.xlsx";
  656. return Save(sheet1, fileName);
  657. }
  658. //上海特强汽车紧固件有限公司
  659. public string ExportTempTq(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  660. TemplateInfo templateInfo)
  661. {
  662. var sheet1 = GetSheet1(templateInfo);
  663. int index = 0;
  664. //sheet1.GenerateCell(3, 4).SetValue(DateTime.Now.ToString("yyyy.MM.dd"));
  665. var orderSendCount = orderSends.Count;
  666. //if (orderSendCount < 7)
  667. //{
  668. // orderSendCount = 7;
  669. //}
  670. sheet1.InsertRows(10, orderSendCount);
  671. var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  672. //decimal allSendCount = 0;
  673. sheet1.GenerateCell(2, 1).SetValue("单号:" + bill.Id);
  674. sheet1.GenerateCell(7, 1).SetValue("日期:"+DateTime.Now.ToString("yyyy年MM月dd日"));
  675. sheet1.GenerateCell(5, 2).SetValue("客户:"+ customer.CustomerName);
  676. sheet1.GenerateCell(5, 9).SetValue("地址:" + customer.Address);
  677. sheet1.GenerateCell(6, 2).SetValue("联系电话:" + customer.Telephone);
  678. sheet1.GenerateCell(6, 9).SetValue("联系人:" + customer.LinkMan);
  679. foreach (var send in viewOrderSends)
  680. {
  681. sheet1.GenerateCell(10 + index, 1).SetValue($"{index+1}");
  682. sheet1.GenerateCell(10 + index, 2).SetValue(send.StockNo ?? "");
  683. var sendQuantity = Math.Round(Math.Floor(send.SendQuantity * 1000) / 1000, 3);//发货数量
  684. var quantityPerPack = Math.Floor((send.QuantityPerPack ?? 0) * 1000) / 1000;
  685. quantityPerPack = quantityPerPack == 0 ? sendQuantity : quantityPerPack;//每包数量,如果为0则等于发货数量
  686. decimal packageCount = sendQuantity == 0 ? 0 : (sendQuantity <= quantityPerPack ? 1 : Math.Floor(send.SendQuantity / quantityPerPack));
  687. var sysl = sendQuantity - quantityPerPack * packageCount;
  688. //sheet1.GenerateCell(10 + index, 3).SetValue<decimal>(sendQuantity * 1000);
  689. sheet1.GenerateCell(10 + index, 3).SetValue(send.ProductName??"");
  690. sheet1.GenerateCell(10 + index, 4).SetValue(send.Model ?? "");
  691. sheet1.GenerateCell(10 + index, 5).SetValue(send.SurfaceColor??"");
  692. sheet1.GenerateCell(10 + index, 6).SetValue(send.Material??"");
  693. sheet1.GenerateCell(10 + index, 7).SetValue(send.Rigidity??"");
  694. sheet1.GenerateCell(10 + index, 8).SetValue("千件");
  695. sheet1.GenerateCell(10 + index, 9).SetValue<decimal>(sendQuantity);
  696. sheet1.GenerateCell(10 + index, 10).SetValue<decimal>(packageCount);
  697. sheet1.GenerateCell(10 + index, 11).SetValue<decimal>(quantityPerPack);
  698. sheet1.GenerateCell(10 + index, 12).SetValue<decimal>(sysl);
  699. sheet1.GenerateCell(10 + index, 13).SetValue<decimal>(sendQuantity);
  700. sheet1.GenerateCell(10 + index, 14).SetValue(send.ProductBatchNum??"");
  701. index++;
  702. }
  703. sheet1.GenerateCell(13 + index, 11).SetValue("送货日期:" + Clock.Now.ToString("yyyy-MM-dd"));
  704. //sheet1.MergedRegion(7 + orderSendCount + 2, 7 + orderSendCount + 2, 7, 9);
  705. // sheet1.GenerateCell(7 + orderSendCount + 2, 7).SetValue("合计:" + allSendCount);
  706. //sheet1.GenerateCell(7 + orderSendCount, 8).SetValue(send.ProductBatchNum);
  707. var fileName = $"上海特强送货单-{Clock.Now:yyMMddHHmmss}.xlsx";
  708. return Save(sheet1, fileName);
  709. }
  710. //上海巧耐森科技有限公司
  711. public string ExportTempQNS(OrderSendBill bill, List<ViewOrderSend> orderSends, Customer customer,
  712. TemplateInfo templateInfo)
  713. {
  714. var sheet1 = GetSheet1(templateInfo);
  715. int index = 0;
  716. sheet1.GenerateCell(2, 5).SetValue(bill.Id);
  717. var orderSendCount = orderSends.Count;
  718. //if (orderSendCount < 7)
  719. //{
  720. // orderSendCount = 7;
  721. //}
  722. sheet1.InsertRows(8, orderSendCount);
  723. //var viewOrderSends = orderSends.OrderBy(i => i.PartNo);
  724. //decimal allSendCount = 0;
  725. //sheet1.GenerateCell(2, 1).SetValue("单号:" + bill.Id);
  726. //sheet1.GenerateCell(7, 1).SetValue("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  727. //sheet1.GenerateCell(5, 2).SetValue("客户:" + customer.CustomerName);
  728. //sheet1.GenerateCell(5, 9).SetValue("地址:" + customer.Address);
  729. //sheet1.GenerateCell(6, 2).SetValue("联系电话:" + customer.Telephone);
  730. //sheet1.GenerateCell(6, 9).SetValue("联系人:" + customer.LinkMan);
  731. decimal allQuantity = 0;
  732. foreach (var send in orderSends)
  733. {
  734. sheet1.GenerateCell(8 + index, 1).SetValue($"{index + 1}");
  735. sheet1.GenerateCell(8 + index, 2).SetValue(send.SendDate?.ToString("yyyy.MM.dd"));
  736. sheet1.GenerateCell(8 + index, 3).SetValue(send.StockNo ?? "");
  737. var sendQuantity = Math.Round(send.SendQuantity * 1000);//发货数量
  738. sheet1.GenerateCell(8 + index, 4).SetValue(send.PartNo ?? "");
  739. sheet1.GenerateCell(8 + index, 5).SetValue((send.Model ?? "")+","+(send.ProductName??"") + "," + (send.SurfaceColor??"") + "," + (send.Rigidity??""));
  740. sheet1.GenerateCell(8 + index, 6).SetValue<decimal>(sendQuantity);
  741. sheet1.GenerateCell(8 + index, 7).SetValue<decimal>(1);
  742. sheet1.GenerateCell(8 + index, 8).SetValue(send.ProductBatchNum ?? "");
  743. allQuantity += sendQuantity;
  744. index++;
  745. }
  746. sheet1.GenerateCell(8 + index+1, 7).SetValue("合计:" + allQuantity);
  747. var fileName = $"上海巧耐森科技有限公司-{Clock.Now:yyMMddHHmmss}.xlsx";
  748. return Save(sheet1, fileName);
  749. }
  750. private ISheet GetSheet1(TemplateInfo templateInfo)
  751. {
  752. string path = AppDomain.CurrentDomain.BaseDirectory + templateInfo.FilePath;
  753. //var savePath = "Download/Excel/OrderSendBill";
  754. var work = ExcelHelper.CreateWorkBook07(path);
  755. var sheet1 = work.GetSheet("Sheet1");
  756. return sheet1;
  757. }
  758. private string Save(ISheet sheet,string fileName)
  759. {
  760. IWorkbook work = sheet.Workbook;
  761. var savePath = "Download/Excel/OrderSendBill";
  762. //var fileName = $"杭州德特专用-{Clock.Now:yyMMddHHmmss}.xlsx";
  763. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  764. if (!result.IsNullOrEmpty())
  765. {
  766. //CheckErrors(IwbIdentityResult.Failed(result));
  767. return null;
  768. }
  769. return $"/{savePath}/{fileName}";
  770. }
  771. #region ex
  772. private void RemoveMergedRegion(ISheet sheet, int rowIndex)
  773. {
  774. int mergedCount = sheet.NumMergedRegions;
  775. for (int i = mergedCount - 1; i >= 0; i--)
  776. {
  777. /**
  778. CellRangeAddress对象属性有:FirstColumn,FirstRow,LastColumn,LastRow 进行操作 取消合并单元格
  779. **/
  780. var temp = sheet.GetMergedRegion(i);
  781. if (temp.FirstRow == rowIndex)
  782. {
  783. sheet.RemoveMergedRegion(i);
  784. }
  785. }
  786. }
  787. public static ICellStyle SetCellStyle(IWorkbook work, BorderStyle borderStyle= BorderStyle.Thin, short borderColor = 0, short topBorderColor = 0, short rightBorderColor = 0, short leftBorderColor = 0, short bottomBorderColor = 0, short fillBackgroundColor = (short)ColorType.White,bool wrapText=false, VerticalAlignment verticalAlignment= VerticalAlignment.Center, HorizontalAlignment horizontalAlignment= HorizontalAlignment.Center,string fontName= "微软雅黑", short fontColor = (short)ColorType.Black, short boldWeight= (short)FontBoldWeight.Bold,int fontHeightInPoints=12,bool isItalic=false)
  788. {
  789. ExportTemplateFont fontStyle = new ExportTemplateFont()
  790. {
  791. FontName = fontName,
  792. BoldWeight = boldWeight,
  793. Color = fontColor,
  794. FontHeightInPoints = fontHeightInPoints,
  795. IsItalic = isItalic
  796. };
  797. ExportTemplateCss cssStyle = new ExportTemplateCss()
  798. {
  799. BorderStyle = borderStyle,
  800. FillBackgroundColor = fillBackgroundColor,
  801. HorizontalAlignment = horizontalAlignment,
  802. VerticalAlignment = verticalAlignment,
  803. WrapText = wrapText,
  804. FontStyle = fontStyle,
  805. BorderColor = borderColor,
  806. TopBorderColor = topBorderColor,
  807. BottomBorderColor = bottomBorderColor,
  808. LeftBorderColor = leftBorderColor,
  809. RightBorderColor = rightBorderColor
  810. };
  811. return SetCellStyle(work, cssStyle);
  812. }
  813. public static ICellStyle SetCellStyle(IWorkbook work, ExportTemplateCss cssStyle)
  814. {
  815. ICellStyle style = work.CreateCellStyle();
  816. style.BorderBottom = cssStyle.BorderStyle;
  817. style.BorderTop = cssStyle.BorderStyle;
  818. style.BorderLeft = cssStyle.BorderStyle;
  819. style.BorderRight = cssStyle.BorderStyle;
  820. if (cssStyle.BorderColor > 0)
  821. {
  822. style.BottomBorderColor = cssStyle.BorderColor;
  823. style.TopBorderColor = cssStyle.BorderColor;
  824. style.LeftBorderColor = cssStyle.BorderColor;
  825. style.RightBorderColor = cssStyle.BorderColor;
  826. }
  827. if (cssStyle.BottomBorderColor > 0)
  828. {
  829. style.BottomBorderColor = cssStyle.BottomBorderColor;
  830. }
  831. if (cssStyle.TopBorderColor > 0)
  832. {
  833. style.TopBorderColor = cssStyle.TopBorderColor;
  834. }
  835. if (cssStyle.RightBorderColor > 0)
  836. {
  837. style.RightBorderColor = cssStyle.RightBorderColor;
  838. }
  839. if (cssStyle.LeftBorderColor > 0)
  840. {
  841. style.LeftBorderColor = cssStyle.LeftBorderColor;
  842. }
  843. style.FillForegroundColor = cssStyle.FillBackgroundColor;
  844. style.FillPattern = FillPattern.Squares;
  845. style.FillBackgroundColor = cssStyle.FillBackgroundColor;
  846. style.WrapText = cssStyle.WrapText;
  847. style.VerticalAlignment = cssStyle.VerticalAlignment;
  848. style.Alignment = cssStyle.HorizontalAlignment;
  849. ExportTemplateFont fontStyle = cssStyle.FontStyle;
  850. IFont font = work.CreateFont();
  851. font.FontName = fontStyle.FontName;
  852. font.Color = fontStyle.Color;
  853. font.IsItalic = fontStyle.IsItalic;
  854. font.Boldweight = fontStyle.BoldWeight;
  855. font.FontHeightInPoints = fontStyle.FontHeightInPoints;
  856. style.SetFont(font);
  857. return style;
  858. }
  859. #region copy
  860. public static void CopyCellStyle(IWorkbook wb, ICellStyle fromStyle, ICellStyle toStyle)
  861. {
  862. toStyle.Alignment = fromStyle.Alignment;
  863. //边框和边框颜色
  864. toStyle.BorderBottom = fromStyle.BorderBottom;
  865. toStyle.BorderLeft = fromStyle.BorderLeft;
  866. toStyle.BorderRight = fromStyle.BorderRight;
  867. toStyle.BorderTop = fromStyle.BorderTop;
  868. toStyle.TopBorderColor = fromStyle.TopBorderColor;
  869. toStyle.BottomBorderColor = fromStyle.BottomBorderColor;
  870. toStyle.RightBorderColor = fromStyle.RightBorderColor;
  871. toStyle.LeftBorderColor = fromStyle.LeftBorderColor;
  872. //背景和前景
  873. toStyle.FillBackgroundColor = fromStyle.FillBackgroundColor;
  874. toStyle.FillForegroundColor = fromStyle.FillForegroundColor;
  875. toStyle.DataFormat = fromStyle.DataFormat;
  876. toStyle.FillPattern = fromStyle.FillPattern;
  877. //toStyle.Hidden=fromStyle.Hidden;
  878. toStyle.IsHidden = fromStyle.IsHidden;
  879. toStyle.Indention = fromStyle.Indention;//首行缩进
  880. toStyle.IsLocked = fromStyle.IsLocked;
  881. toStyle.Rotation = fromStyle.Rotation;//旋转
  882. toStyle.VerticalAlignment = fromStyle.VerticalAlignment;
  883. toStyle.WrapText = fromStyle.WrapText;
  884. toStyle.SetFont(fromStyle.GetFont(wb));
  885. }
  886. /// <summary>
  887. /// 复制行
  888. /// </summary>
  889. /// <param name="wb"></param>
  890. /// <param name="fromRow"></param>
  891. /// <param name="toRow"></param>
  892. /// <param name="copyValueFlag"></param>
  893. public static void CopyRowEx(IWorkbook wb, IRow fromRow, IRow toRow, bool copyValueFlag)
  894. {
  895. System.Collections.IEnumerator cells = fromRow.GetEnumerator();//.GetRowEnumerator();
  896. toRow.Height = fromRow.Height;
  897. while (cells.MoveNext())
  898. {
  899. ICell cell = null;
  900. //ICell cell = (wb is HSSFWorkbook) ? cells.Current as HSSFCell : cells.Current as NPOI.XSSF.UserModel.XSSFCell;
  901. if (wb is HSSFWorkbook)
  902. cell = cells.Current as HSSFCell;
  903. else
  904. cell = cells.Current as NPOI.XSSF.UserModel.XSSFCell;
  905. ICell newCell = toRow.CreateCell(cell.ColumnIndex);
  906. CopyCell(wb, cell, newCell, copyValueFlag);
  907. }
  908. }
  909. /// <summary>
  910. /// 复制原有sheet的合并单元格到新创建的sheet
  911. /// </summary>
  912. /// <param name="fromSheet"></param>
  913. /// <param name="toSheet"></param>
  914. public static void MergerRegion(ISheet fromSheet, ISheet toSheet)
  915. {
  916. int sheetMergerCount = fromSheet.NumMergedRegions;
  917. for (int i = 0; i < sheetMergerCount; i++)
  918. {
  919. //Region mergedRegionAt = fromSheet.GetMergedRegion(i); //.MergedRegionAt(i);
  920. //CellRangeAddress[] cra = new CellRangeAddress[1];
  921. //cra[0] = fromSheet.GetMergedRegion(i);
  922. //Region[] rg = Region.ConvertCellRangesToRegions(cra);
  923. toSheet.AddMergedRegion(fromSheet.GetMergedRegion(i));
  924. }
  925. }
  926. /// <summary>
  927. /// 复制单元格
  928. /// </summary>
  929. /// <param name="wb"></param>
  930. /// <param name="srcCell"></param>
  931. /// <param name="distCell"></param>
  932. /// <param name="copyValueFlag"></param>
  933. public static void CopyCell(IWorkbook wb, ICell srcCell, ICell distCell, bool copyValueFlag)
  934. {
  935. ICellStyle newstyle = wb.CreateCellStyle();
  936. CopyCellStyle(wb, srcCell.CellStyle, newstyle);
  937. //样式
  938. distCell.CellStyle = newstyle;
  939. //评论
  940. if (srcCell.CellComment != null)
  941. {
  942. distCell.CellComment = srcCell.CellComment;
  943. }
  944. // 不同数据类型处理
  945. CellType srcCellType = srcCell.CellType;
  946. distCell.SetCellType(srcCellType);
  947. if (copyValueFlag)
  948. {
  949. if (srcCellType == CellType.Numeric)
  950. {
  951. if (DateUtil.IsCellDateFormatted(srcCell))
  952. {
  953. distCell.SetCellValue(srcCell.DateCellValue);
  954. }
  955. else
  956. {
  957. distCell.SetCellValue(srcCell.NumericCellValue);
  958. }
  959. }
  960. else if (srcCellType == CellType.String)
  961. {
  962. distCell.SetCellValue(srcCell.RichStringCellValue);
  963. }
  964. else if (srcCellType == CellType.Blank)
  965. {
  966. // nothing21
  967. }
  968. else if (srcCellType == CellType.Boolean)
  969. {
  970. distCell.SetCellValue(srcCell.BooleanCellValue);
  971. }
  972. else if (srcCellType == CellType.Error)
  973. {
  974. distCell.SetCellErrorValue(srcCell.ErrorCellValue);
  975. }
  976. else if (srcCellType == CellType.Formula)
  977. {
  978. distCell.SetCellFormula(srcCell.CellFormula);
  979. }
  980. else
  981. {
  982. // nothing29
  983. }
  984. }
  985. }
  986. #endregion
  987. #endregion
  988. }
  989. public class ExportTemplateCss
  990. {
  991. /// <summary>
  992. /// 上下左右边框
  993. /// </summary>
  994. public BorderStyle BorderStyle { get; set; } = BorderStyle.Thin;
  995. public short TopBorderColor { get; set; }
  996. public short RightBorderColor { get; set; }
  997. public short LeftBorderColor { get; set; }
  998. public short BottomBorderColor { get; set; }
  999. public short BorderColor { get; set; }
  1000. /// <summary>
  1001. /// 背景色
  1002. /// </summary>
  1003. public short FillBackgroundColor { get; set; } = (short) ColorType.White;
  1004. /// <summary>
  1005. /// 文字换行
  1006. /// </summary>
  1007. public bool WrapText { get; set; } = false;
  1008. public VerticalAlignment VerticalAlignment { get; set; } = VerticalAlignment.Center;
  1009. public HorizontalAlignment HorizontalAlignment { get; set; } = HorizontalAlignment.Center;
  1010. public ExportTemplateFont FontStyle { get; set; }
  1011. }
  1012. public class ExportTemplateFont
  1013. {
  1014. public string FontName { get; set; } = "微软雅黑";
  1015. public bool IsItalic { get; set; } = false;
  1016. public short Color { get; set; } = (short) ColorType.Black;
  1017. public short BoldWeight { get; set; } = (short) FontBoldWeight.Bold;
  1018. public int FontHeightInPoints { get; set; } = 12;
  1019. //public bool IsBold { get; set; } = false;
  1020. }
  1021. }