You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
10 KiB

2 years ago
  1. using DocumentFormat.OpenXml.Wordprocessing;
  2. using Entity.Sugar;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Globalization;
  6. using System.Linq;
  7. namespace EasyBL.WEBAPP.OPM
  8. {
  9. public class ExhibitionHelper
  10. {
  11. #region RenderFeeItemsTW
  12. /// <summary>
  13. /// 組裝費用表格
  14. /// </summary>
  15. /// <param name="row"></param>
  16. /// <param name="jo"></param>
  17. /// <param name="iCellCount"></param>
  18. /// <param name="iIdex"></param>
  19. public static void RenderFeeItemsTW(TableRow row, JObject jo, int iCellCount, int iIdex)
  20. {
  21. for (int i = 0; i < iCellCount; i++)
  22. {
  23. var tcell = row.Elements<TableCell>().ElementAt(i);
  24. var tmpPa = tcell.Elements<Paragraph>().FirstOrDefault();
  25. var tmpRun = tmpPa.Elements<Run>().FirstOrDefault();
  26. var tmpText = tmpRun.Elements<Text>().FirstOrDefault();
  27. switch (i)
  28. {
  29. case 0:
  30. tmpText.Text = iIdex.ToString();
  31. break;
  32. case 1:
  33. var sRemark = jo[@"Memo"] == null ? @"" : jo[@"Memo"].ToString();
  34. var sCostStatement = jo[@"FinancialCostStatement"].ToString();
  35. tmpText.Text = sCostStatement == @"" ? sRemark : jo[@"FinancialCostStatement"] + (sRemark == @"" ? @"" : @"(" + sRemark + @")");
  36. break;
  37. case 2:
  38. tmpText.Text = jo[@"FinancialCurrency"].ToString();
  39. break;
  40. case 3:
  41. var sFinancialUnitPrice = jo[@"FinancialUnitPrice"].ToString();
  42. tmpText.Text = $@"{Convert.ToDecimal(sFinancialUnitPrice.Trim() == @"" ? @"0" : sFinancialUnitPrice):N}";
  43. break;
  44. case 4:
  45. tmpText.Text = jo[@"FinancialNumber"].ToString();
  46. break;
  47. case 5:
  48. tmpText.Text = jo[@"FinancialUnit"].ToString();
  49. break;
  50. case 6:
  51. var sFinancialAmount = jo[@"FinancialAmount"].ToString();
  52. tmpText.Text = $@"{Convert.ToDecimal(sFinancialAmount.Trim() == @"" ? @"0" : sFinancialAmount):N}";
  53. break;
  54. case 7:
  55. tmpText.Text = jo[@"FinancialExchangeRate"].ToString();
  56. break;
  57. case 8:
  58. var sFinancialTWAmount = jo[@"FinancialTWAmount"].ToString();
  59. tmpText.Text = $@"{Convert.ToDecimal(sFinancialTWAmount.Trim() == @"" ? @"0" : sFinancialTWAmount):N}";
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. }
  66. #endregion RenderFeeItemsTW
  67. #region RenderFeeItemsTW
  68. /// <summary>
  69. /// 組裝費用表格
  70. /// </summary>
  71. /// <param name="row"></param>
  72. /// <param name="jo"></param>
  73. /// <param name="iCellCount"></param>
  74. /// <param name="iIdex"></param>
  75. public static void RenderFeeItemsFR(TableRow row, JObject jo, int iCellCount, int iIdex)
  76. {
  77. for (int i = 0; i < iCellCount; i++)
  78. {
  79. var tcell = row.Elements<TableCell>().ElementAt(i);
  80. var tmpPa = tcell.Elements<Paragraph>().FirstOrDefault();
  81. var tmpRun = tmpPa.Elements<Run>().FirstOrDefault();
  82. var tmpText = tmpRun.Elements<Text>().FirstOrDefault();
  83. switch (i)
  84. {
  85. case 0:
  86. tmpText.Text = iIdex.ToString();
  87. break;
  88. case 1:
  89. var sRemark = jo[@"Memo"] == null ? @"" : jo[@"Memo"].ToString();
  90. var sCostStatement = jo[@"FinancialCostStatement"].ToString();
  91. tmpText.Text = sCostStatement == @"" ? sRemark : jo[@"FinancialCostStatement"] + (sRemark == @"" ? @"" : @"(" + sRemark + @")");
  92. break;
  93. case 2:
  94. tmpText.Text = jo[@"FinancialCurrency"].ToString();
  95. break;
  96. case 3:
  97. var sFinancialUnitPrice = jo[@"FinancialUnitPrice"].ToString();
  98. tmpText.Text = $@"{Convert.ToDecimal(sFinancialUnitPrice.Trim() == @"" ? @"0" : sFinancialUnitPrice):N}";
  99. break;
  100. case 4:
  101. tmpText.Text = jo[@"FinancialNumber"].ToString();
  102. break;
  103. case 5:
  104. tmpText.Text = jo[@"FinancialUnit"].ToString();
  105. break;
  106. case 6:
  107. var sFinancialTWAmount = jo[@"FinancialTWAmount"].ToString();
  108. tmpText.Text = $@"{Convert.ToDecimal(sFinancialTWAmount.Trim() == @"" ? @"0" : sFinancialTWAmount):N}";//保留兩位小數
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. }
  115. #endregion RenderFeeItemsTW
  116. #region RenderMemo
  117. /// <summary>
  118. /// 組裝費用表格
  119. /// </summary>
  120. /// <param name="body">todo: describe body parameter on RenderMemo</param>
  121. /// <param name="memo">todo: describe memo parameter on RenderMemo</param>
  122. public static void RenderMemo(Body body, string memo)
  123. {
  124. Paragraph pMemo = null;
  125. foreach (DocumentFormat.OpenXml.OpenXmlElement el in body.ChildElements)
  126. {
  127. if (el.GetType() == typeof(Paragraph) && el.InnerText.IndexOf(@"[PARM27]") > -1)
  128. {
  129. pMemo = (Paragraph)el;
  130. break;
  131. }
  132. }
  133. var saMemo = memo.Split(new string[] { @"\n" }, StringSplitOptions.RemoveEmptyEntries);
  134. foreach (string str in saMemo)
  135. {
  136. var pCopy = pMemo.Clone() as Paragraph;
  137. var sPart = pMemo.InnerXml.Replace(@"[PARM27]", str);
  138. if (sPart.Contains(@"&") || sPart.Contains(@"<") || sPart.Contains(@">") || sPart.Contains(@"""") || sPart.Contains(@"'"))
  139. {
  140. sPart = Common.EncodeEscapeChar(sPart);
  141. //sPart = sPart.Replace(@"&", @"+");
  142. ////sPart = sPart.Replace("<", "&gt;");
  143. ////sPart = sPart.Replace(">", "&lt;");
  144. ////sPart = sPart.Replace("\"", "&quot;");
  145. ////sPart = sPart.Replace("\'", "&apos;");
  146. }
  147. pCopy.InnerXml = sPart;
  148. pMemo.InsertBeforeSelf(pCopy);
  149. }
  150. pMemo.Remove();
  151. }
  152. #endregion RenderMemo
  153. /// <summary> 实现数据的四舍五入法
  154.    /// </summary>
  155. /// <param name="v">要进行处理的数据</param>
  156. /// <param name="x">保留的小数位数</param>
  157. /// <returns>四舍五入后的结果</returns>
  158. public static double Round(double v, int x)
  159. {
  160. return Math.Round(v, x, MidpointRounding.AwayFromZero);
  161. }
  162. /// <summary>
  163. /// 優先取得發票地址(InvoiceAddress),再來是地址(Address)
  164. /// </summary>
  165. /// <param name="customer"></param>
  166. /// <returns></returns>
  167. public static string GetBillAddress(OTB_CRM_Customers customer)
  168. {
  169. if (customer == null)
  170. return "";
  171. string InvoiceAddress = string.IsNullOrWhiteSpace(customer.InvoiceAddress) ? "": customer.InvoiceAddress;
  172. string Address = string.IsNullOrWhiteSpace(customer.Address) ? "" : customer.Address;
  173. return InvoiceAddress.Length > 0 ? InvoiceAddress : Address;
  174. }
  175. /// <summary>
  176. /// 首字大寫
  177. /// </summary>
  178. /// <param name="memberID"></param>
  179. /// <returns></returns>
  180. public static string GetEnglishName(string memberID)
  181. {
  182. if (string.IsNullOrEmpty(memberID))
  183. return "";
  184. TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
  185. memberID = memberID.Replace(".", " ");
  186. return textInfo.ToTitleCase(memberID);
  187. }
  188. /// <summary>
  189. /// 進口加註文字:
  190. /// 報價/預估成本:進口/Inbound
  191. /// 退運報價/預估成本: 回運/ Return
  192. /// </summary>
  193. /// <param name="GetExhibitioImport"></param>
  194. /// <param name="IsEnglish"></param>
  195. /// <param name="IsReturn"></param>
  196. /// <returns></returns>
  197. public static string GetExhibitioImportComment(bool English = false, bool Return = false)
  198. {
  199. //英文:Inbound/Return
  200. if (English)
  201. {
  202. if (Return)
  203. return "(Return)";
  204. else
  205. return "(Inbound)";
  206. }
  207. //中文:進口/回運
  208. else
  209. {
  210. if (Return)
  211. return "(回運)";
  212. else
  213. return "(進口)";
  214. }
  215. }
  216. /// <summary>
  217. /// 出口加註文字:
  218. /// 報價/預估成本:出口/ Outbound
  219. /// 退運報價/預估成本: 回運/ Return
  220. /// </summary>
  221. /// <param name="ExhibitioExportName"></param>
  222. /// <param name="IsEnglish"></param>
  223. /// <param name="IsReturn"></param>
  224. /// <returns></returns>
  225. public static string GetExhibitioExportComment( bool English = false, bool Return = false)
  226. {
  227. //英文:Outbound/Return
  228. if (English)
  229. {
  230. if (Return)
  231. return "(Return)";
  232. else
  233. return "(Outbound)";
  234. }
  235. //中文:出口/回運
  236. else
  237. {
  238. if (Return)
  239. return "(回運)";
  240. else
  241. return "(出口)";
  242. }
  243. }
  244. }
  245. }