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.

682 lines
44 KiB

2 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using SqlSugar;
  7. using SqlSugar.Base;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Linq;
  12. using System.Text.RegularExpressions;
  13. namespace EasyBL.WEBAPP.CRM
  14. {
  15. public class Customers_QryService : ServiceBase
  16. {
  17. #region 客戶管理(分頁查詢)
  18. /// <summary>
  19. /// 客戶管理(分頁查詢)
  20. /// </summary>
  21. /// <param name="i_crm"></param>
  22. /// <returns></returns>
  23. public ResponseMessage QueryPage(RequestMessage i_crm)
  24. {
  25. ResponseMessage rm = null;
  26. string sMsg = null;
  27. var db = SugarBase.GetIntance();
  28. try
  29. {
  30. do
  31. {
  32. var pml = new PageModel
  33. {
  34. PageIndex = _fetchInt(i_crm, @"pageIndex"),
  35. PageSize = _fetchInt(i_crm, @"pageSize")
  36. };
  37. var iPageCount = 0;
  38. var sSortField = _fetchString(i_crm, @"sortField");
  39. var sSortOrder = _fetchString(i_crm, @"sortOrder");
  40. var sCustomerNO = _fetchString(i_crm, @"CustomerNO");
  41. var sUniCode = _fetchString(i_crm, @"UniCode");
  42. var sCustomerName = _fetchString(i_crm, @"CustomerName");
  43. var sCreateUser = _fetchString(i_crm, @"CreateUser");
  44. var sTransactionType = _fetchString(i_crm, @"TransactionType");
  45. var sEffective = _fetchString(i_crm, @"Effective");
  46. var sState = _fetchString(i_crm, @"State");
  47. var sIsAudit = _fetchString(i_crm, @"IsAudit");
  48. var sCreateDateStart = _fetchString(i_crm, @"CreateDateStart");
  49. var sCreateDateEnd = _fetchString(i_crm, @"CreateDateEnd");
  50. var sModifyDateStart = _fetchString(i_crm, @"ModifyDateStart");
  51. var sModifyDateEnd = _fetchString(i_crm, @"ModifyDateEnd");
  52. var bExcel = _fetchBool(i_crm, @"Excel");
  53. var sExcelType = _fetchString(i_crm, @"ExcelType");
  54. string[] saEffective = null;
  55. string[] saIsAudit = null;
  56. string[] saTransactionType = null;
  57. if (!string.IsNullOrEmpty(sEffective))
  58. {
  59. saEffective = sEffective.Split(',');
  60. }
  61. if (!string.IsNullOrEmpty(sIsAudit))
  62. {
  63. saIsAudit = sIsAudit.Split(',');
  64. }
  65. if (!string.IsNullOrEmpty(sTransactionType))
  66. {
  67. saTransactionType = sTransactionType.Split(',');
  68. }
  69. var rCreateDateStart = new DateTime();
  70. var rCreateDateEnd = new DateTime();
  71. var rModifyDateStart = new DateTime();
  72. var rModifyDateEnd = new DateTime();
  73. if (!string.IsNullOrEmpty(sCreateDateStart))
  74. {
  75. rCreateDateStart = SqlFunc.ToDate(sCreateDateStart);
  76. }
  77. if (!string.IsNullOrEmpty(sCreateDateEnd))
  78. {
  79. rCreateDateEnd = SqlFunc.ToDate(sCreateDateEnd).AddDays(1);
  80. }
  81. if (!string.IsNullOrEmpty(sModifyDateStart))
  82. {
  83. rModifyDateStart = SqlFunc.ToDate(sModifyDateStart);
  84. }
  85. if (!string.IsNullOrEmpty(sModifyDateEnd))
  86. {
  87. rModifyDateEnd = SqlFunc.ToDate(sModifyDateEnd).AddDays(1);
  88. }
  89. pml.DataList = db.Queryable<OTB_CRM_Customers, OTB_SYS_Members, OTB_CRM_CustomersMST>
  90. ((t1, t2, t3) =>
  91. new object[] {
  92. JoinType.Inner, t1.OrgID == t2.OrgID && t1.CreateUser == t2.MemberID,
  93. JoinType.Inner, t3.customer_guid == t1.guid
  94. }
  95. )
  96. .Where((t1, t2) => t1.OrgID == i_crm.ORIGID && t1.UniCode.Contains(sUniCode) && SqlFunc.ContainsArray(saTransactionType, t1.TransactionType) && SqlFunc.ContainsArray(saEffective, t1.Effective) && SqlFunc.ContainsArray(saIsAudit, t1.IsAudit) && (t1.CustomerCName.Contains(sCustomerName) || t1.CustomerEName.Contains(sCustomerName) || t1.CustomerShotCName.Contains(sCustomerName)))
  97. .WhereIF(!string.IsNullOrEmpty(sCustomerNO), (t3) => t3.CustomerNO.Contains(sCustomerNO))
  98. .WhereIF(string.IsNullOrEmpty(sCustomerNO), (t3) => t3.Effective == "Y")
  99. .WhereIF(!string.IsNullOrEmpty(sCreateUser), (t1, t2) => t1.CreateUser == sCreateUser)
  100. .WhereIF(!string.IsNullOrEmpty(sCreateDateStart), (t1, t2) => t1.CreateDate >= rCreateDateStart.Date)
  101. .WhereIF(!string.IsNullOrEmpty(sCreateDateEnd), (t1, t2) => t1.CreateDate <= rCreateDateEnd.Date)
  102. .WhereIF(!string.IsNullOrEmpty(sModifyDateStart), (t1, t2) => t1.ModifyDate >= rModifyDateStart.Date)
  103. .WhereIF(!string.IsNullOrEmpty(sModifyDateEnd), (t1, t2) => t1.ModifyDate <= rModifyDateEnd.Date)
  104. .WhereIF(!string.IsNullOrEmpty(sState), (t1, t2) => t1.State == sState)
  105. .Select((t1, t2) => new OTB_CRM_Customers
  106. {
  107. guid = SqlFunc.GetSelfAndAutoFill(t1.guid),
  108. CreateUserName = t2.MemberName
  109. })
  110. .MergeTable()
  111. .OrderBy(sSortField, sSortOrder)
  112. .ToPageList(pml.PageIndex, bExcel ? 100000 : pml.PageSize, ref iPageCount);
  113. pml.Total = iPageCount;
  114. rm = new SuccessResponseMessage(null, i_crm);
  115. if (bExcel)
  116. {
  117. var sFileName = "";
  118. var oHeader = new Dictionary<string, string>();
  119. var listMerge = new List<Dictionary<string, int>>();
  120. var dicAlain = new Dictionary<string, string>();
  121. var dt_new = new DataTable();
  122. var saCustomers1 = pml.DataList;
  123. var saCustomers = pml.DataList as List<OTB_CRM_Customers>;
  124. switch (sExcelType)
  125. {
  126. case "Cus_BasicInformation":
  127. {
  128. sFileName = "客戶基本資料";
  129. oHeader = new Dictionary<string, string>
  130. {
  131. { "RowIndex", "項次" },
  132. { "CustomerNO", "客戶代號" },
  133. { "CustomerCName", "公司中文名稱" },
  134. { "CustomerEName", "公司英文名稱" },
  135. { "CustomerShotCName", "客戶簡稱" },
  136. { "UniCode", "統一編號" },
  137. { "Telephone", "公司電話" },
  138. { "FAX", "公司傳真" },
  139. { "Address", "地址" },
  140. { "CreateUser", "創建人代號" },
  141. { "CreateUserName", "創建人名稱" },
  142. { "CreateDate", "創建時間" },
  143. { "IsAudit", "審核狀態" }
  144. };
  145. dt_new.Columns.Add("RowIndex");
  146. dt_new.Columns.Add("CustomerNO");
  147. dt_new.Columns.Add("CustomerCName");
  148. dt_new.Columns.Add("CustomerEName");
  149. dt_new.Columns.Add("CustomerShotCName");
  150. dt_new.Columns.Add("UniCode");
  151. dt_new.Columns.Add("Telephone");
  152. dt_new.Columns.Add("FAX");
  153. dt_new.Columns.Add("Address");
  154. dt_new.Columns.Add("CreateUser");
  155. dt_new.Columns.Add("CreateUserName");
  156. dt_new.Columns.Add("CreateDate");
  157. dt_new.Columns.Add("IsAudit");
  158. foreach (var customer in saCustomers)
  159. {
  160. var row_new = dt_new.NewRow();
  161. row_new["RowIndex"] = customer.RowIndex;
  162. row_new["CustomerNO"] = customer.CustomerNO;
  163. row_new["CustomerCName"] = customer.CustomerCName;
  164. row_new["CustomerEName"] = customer.CustomerEName;
  165. row_new["CustomerShotCName"] = customer.CustomerShotCName;
  166. row_new["UniCode"] = customer.UniCode;
  167. row_new["Telephone"] = customer.Telephone;
  168. row_new["FAX"] = customer.FAX;
  169. row_new["Address"] = customer.Address;
  170. row_new["CreateUser"] = customer.CreateUser;
  171. row_new["CreateUserName"] = customer.CreateUserName;
  172. row_new["CreateDate"] = Convert.ToDateTime(customer.CreateDate).ToString("yyyy/MM/dd"); ;
  173. row_new["IsAudit"] = customer.IsAudit == "Y" ? "已審核" : customer.IsAudit == "N" ? "未審核" : "審核中";
  174. dt_new.Rows.Add(row_new);
  175. }
  176. dicAlain = ExcelService.GetExportAlain(oHeader, "CustomerNO,UniCode,Telephone,FAX,CreateUser,CreateUserName,CreateDate,IsAudit");
  177. }
  178. break;
  179. case "Cus_Email":
  180. {
  181. sFileName = "客戶資料(名稱^Email)";
  182. oHeader = new Dictionary<string, string>
  183. {
  184. { "RowIndex", "項次" },
  185. { "CustomerCName", "公司中文名稱" },
  186. { "CustomerEName", "公司英文名稱" },
  187. { "Email", "Email" },
  188. { "Contactor", "聯絡人" },
  189. { "ContactorEmail", "聯絡人Email" }
  190. };
  191. dicAlain = ExcelService.GetExportAlain(oHeader, new string[] { "Email", "Contactor", "ContactorEmail" });
  192. dt_new.Columns.Add("RowIndex");
  193. dt_new.Columns.Add("CustomerCName");
  194. dt_new.Columns.Add("CustomerEName");
  195. dt_new.Columns.Add("Email");
  196. dt_new.Columns.Add("Contactor");
  197. dt_new.Columns.Add("ContactorEmail");
  198. var iChildIndex = 0;
  199. foreach (var customer in saCustomers)
  200. {
  201. var iLastIndex = iChildIndex;
  202. var row_new = dt_new.NewRow();
  203. row_new["RowIndex"] = customer.RowIndex;
  204. row_new["CustomerCName"] = customer.CustomerCName;
  205. row_new["CustomerEName"] = customer.CustomerEName;
  206. row_new["Email"] = customer.Email;
  207. row_new["Contactor"] = "";
  208. row_new["ContactorEmail"] = "";
  209. var jaContactors = (JArray)JsonConvert.DeserializeObject(customer.Contactors);
  210. if (jaContactors != null && jaContactors.Count > 0)
  211. {
  212. var idx = 0;
  213. foreach (JObject jo in jaContactors)
  214. {
  215. if (idx != 0)
  216. {
  217. row_new = dt_new.NewRow();
  218. row_new["RowIndex"] = "";
  219. row_new["CustomerCName"] = "";
  220. row_new["CustomerEName"] = "";
  221. row_new["Email"] = "";
  222. row_new["Contactor"] = jo["FullName"];
  223. row_new["ContactorEmail"] = jo["Email"];
  224. dt_new.Rows.InsertAt(row_new, iChildIndex);
  225. }
  226. else
  227. {
  228. row_new["Contactor"] = jo["FullName"];
  229. row_new["ContactorEmail"] = jo["Email"];
  230. dt_new.Rows.Add(row_new);
  231. }
  232. idx++;
  233. iChildIndex++;
  234. }
  235. if (jaContactors.Count > 1)
  236. {
  237. var dicMerge = new Dictionary<string, int>
  238. {
  239. { "FirstRow", iLastIndex + 3 },
  240. { "FirstCol", 0 },
  241. { "RowCount", jaContactors.Count },
  242. { "ColCount", 1 }
  243. };
  244. listMerge.Add(dicMerge);
  245. dicMerge = new Dictionary<string, int>
  246. {
  247. { "FirstRow", iLastIndex + 3 },
  248. { "FirstCol", 1 },
  249. { "RowCount", jaContactors.Count },
  250. { "ColCount", 1 }
  251. };
  252. listMerge.Add(dicMerge);
  253. dicMerge = new Dictionary<string, int>
  254. {
  255. { "FirstRow", iLastIndex + 3 },
  256. { "FirstCol", 2 },
  257. { "RowCount", jaContactors.Count },
  258. { "ColCount", 1 }
  259. };
  260. listMerge.Add(dicMerge);
  261. dicMerge = new Dictionary<string, int>
  262. {
  263. { "FirstRow", iLastIndex + 3 },
  264. { "FirstCol", 3 },
  265. { "RowCount", jaContactors.Count },
  266. { "ColCount", 1 }
  267. };
  268. listMerge.Add(dicMerge);
  269. }
  270. }
  271. else
  272. {
  273. dt_new.Rows.Add(row_new);
  274. iChildIndex++;
  275. }
  276. }
  277. }
  278. break;
  279. case "Cus_WenzhongCusFile":
  280. {
  281. sFileName = "文中客供商檔";
  282. oHeader = new Dictionary<string, string>
  283. {
  284. { "RowIndex", "項次" },
  285. { "CustomerNO", "客戶供應商代號" },
  286. { "CusField1", "客戶供應商類別" },
  287. { "CustomerShotCName", "客戶供應商簡稱" },
  288. { "CustomerCName", "客戶供應商全稱" },
  289. { "CusField2", "行業別" },
  290. { "CusField3", "類別科目代號" },
  291. { "UniCode", "統一編號" },
  292. { "CusField4", "稅籍編號" },
  293. { "CusField5", "郵遞區號" },
  294. { "InvoiceAddress", "發票地址" },
  295. { "Address", " 聯絡地址" },
  296. { "CusField6", "送貨地址" },
  297. { "CusField7", "電話(發票地址)" },
  298. { "Telephone", "電話(公司地址)" },
  299. { "CusField8", "電話(送貨地址)" },
  300. { "FAX", "傳真" },
  301. { "CusField9", "數據機種類" },
  302. { "CusField10", "傳呼機號碼" },
  303. { "CusField11", "行動電話" },
  304. { "CusField12", "網址" },
  305. { "CusField13", "負責人" },
  306. { "CusField14", "聯絡人" },
  307. { "Memo", "備註(30C" },
  308. { "CusField15", "銷售折數" },
  309. { "CusField16", "等級" },
  310. { "CusField17", "區域" },
  311. { "CusField18", "進貨折數" },
  312. { "CusField19", "部門|工地編號" },
  313. { "CusField20", "業務員代號" },
  314. { "CusField21", "服務人員" },
  315. { "CusField22", "建立日期" },
  316. { "CusField23", "最近交易日" },
  317. { "CusField24", "信用額度" },
  318. { "CusField25", "保證額度" },
  319. { "CusField26", "抵押額度" },
  320. { "CusField27", "已用額度" },
  321. { "CusField28", "開立發票方式" },
  322. { "CusField29", "收款方式" },
  323. { "CusField30", "匯款銀行代號" },
  324. { "CusField31", "匯款帳號" },
  325. { "CusField32", "結帳方式(作廢不使用)" },
  326. { "CusField33", "銷貨後幾個月結帳" },
  327. { "CusField34", "銷貨後逢幾日結帳" },
  328. { "CusField35", "結帳後幾個月收款" },
  329. { "CusField36", "結帳後逢幾日收款" },
  330. { "CusField37", "收款後幾個月兌現" },
  331. { "CusField38", "收款後逢幾日兌現" },
  332. { "CusField39", "進貨後幾個月結帳" },
  333. { "CusField40", "進貨後逢幾日結帳" },
  334. { "CusField41", "結帳後幾個月付款" },
  335. { "CusField42", "結帳後逢幾日付款" },
  336. { "CusField43", "付款後幾個月兌現" },
  337. { "CusField44", "付款後逢幾日兌現" },
  338. { "CusField45", "郵遞區號(聯絡地址)" },
  339. { "CusField46", "郵遞區號(送貨地址)" },
  340. { "CusField47", "職稱" },
  341. { "CusField48", "專案|項目編號" },
  342. { "CusField49", "請款客戶" },
  343. { "CusField50", "EAMIL ADDRS" },
  344. { "CusField51", "收款/付款方式(描述)" },
  345. { "CusField52", "交貨/收貨方式" },
  346. { "CusField53", "進出口交易方式" },
  347. { "CusField54", "交易幣別" },
  348. { "CusField55", "英文負責人" },
  349. { "CusField56", "英文聯絡人" },
  350. { "CusField57", "電子發票通知方式" },
  351. { "CusField58", "發票預設捐贈" },
  352. { "CusField59", "預設發票捐贈對象" },
  353. { "CusField60", "自定義欄位一" },
  354. { "CusField61", "自定義欄位二" },
  355. { "CusField62", "自定義欄位三" },
  356. { "CusField63", "自定義欄位四" },
  357. { "CusField64", "自定義欄位五" },
  358. { "CusField65", "自定義欄位六" },
  359. { "CusField66", "自定義欄位七" },
  360. { "CusField67", "自定義欄位八" },
  361. { "CusField68", "自定義欄位九" },
  362. { "CusField69", "自定義欄位十" },
  363. { "CusField71", "自定義欄位十一" },
  364. { "CusField72", "自定義欄位十二" },
  365. { "CusField73", "會員卡號" },
  366. { "CusField74", "客供商英文名稱" },
  367. { "CusField75", "客戶英文地址" },
  368. { "CusField76", "銷貨結帳終止日" },
  369. { "CusField77", "進貨結帳終止日" },
  370. { "CusField78", "銷貨收款週期選項" },
  371. { "CusField79", "進貨付款週期選項" },
  372. { "CusField80", "進貨收付條件" },
  373. { "CusField81", "客供商英文聯絡電話" },
  374. { "CusField82", "匯款戶名" },
  375. { "CusField83", "使用電子發票" },
  376. { "CusField84", "單價含稅否" },
  377. { "CusField85", "批次結帳" },
  378. { "CusField86", "發票服務平台登入密碼" },
  379. { "CusField87", "絡地址經度" },
  380. { "CusField88", "聯絡地址緯度" }
  381. };
  382. dt_new.Columns.Add("RowIndex");
  383. dt_new.Columns.Add("CustomerNO");
  384. dt_new.Columns.Add("CusField1");
  385. dt_new.Columns.Add("CustomerShotCName");
  386. dt_new.Columns.Add("CustomerCName");
  387. dt_new.Columns.Add("CusField2");
  388. dt_new.Columns.Add("CusField3");
  389. dt_new.Columns.Add("UniCode");
  390. dt_new.Columns.Add("CusField4");
  391. dt_new.Columns.Add("CusField5");
  392. dt_new.Columns.Add("InvoiceAddress");
  393. dt_new.Columns.Add("Address");
  394. dt_new.Columns.Add("CusField6");
  395. dt_new.Columns.Add("CusField7");
  396. dt_new.Columns.Add("Telephone");
  397. dt_new.Columns.Add("CusField8");
  398. dt_new.Columns.Add("FAX");
  399. dt_new.Columns.Add("CusField9");
  400. dt_new.Columns.Add("CusField10");
  401. dt_new.Columns.Add("CusField11");
  402. dt_new.Columns.Add("CusField12");
  403. dt_new.Columns.Add("CusField13");
  404. dt_new.Columns.Add("CusField14");
  405. dt_new.Columns.Add("Memo");
  406. dt_new.Columns.Add("CusField15");
  407. dt_new.Columns.Add("CusField16");
  408. dt_new.Columns.Add("CusField17");
  409. dt_new.Columns.Add("CusField18");
  410. dt_new.Columns.Add("CusField19");
  411. dt_new.Columns.Add("CusField20");
  412. dt_new.Columns.Add("CusField21");
  413. dt_new.Columns.Add("CusField22");
  414. dt_new.Columns.Add("CusField23");
  415. dt_new.Columns.Add("CusField24");
  416. dt_new.Columns.Add("CusField25");
  417. dt_new.Columns.Add("CusField26");
  418. dt_new.Columns.Add("CusField27");
  419. dt_new.Columns.Add("CusField28");
  420. dt_new.Columns.Add("CusField29");
  421. dt_new.Columns.Add("CusField30");
  422. dt_new.Columns.Add("CusField31");
  423. dt_new.Columns.Add("CusField32");
  424. dt_new.Columns.Add("CusField33");
  425. dt_new.Columns.Add("CusField34");
  426. dt_new.Columns.Add("CusField35");
  427. dt_new.Columns.Add("CusField36");
  428. dt_new.Columns.Add("CusField37");
  429. dt_new.Columns.Add("CusField38");
  430. dt_new.Columns.Add("CusField39");
  431. dt_new.Columns.Add("CusField40");
  432. dt_new.Columns.Add("CusField41");
  433. dt_new.Columns.Add("CusField42");
  434. dt_new.Columns.Add("CusField43");
  435. dt_new.Columns.Add("CusField44");
  436. dt_new.Columns.Add("CusField45");
  437. dt_new.Columns.Add("CusField46");
  438. dt_new.Columns.Add("CusField47");
  439. dt_new.Columns.Add("CusField48");
  440. dt_new.Columns.Add("CusField49");
  441. dt_new.Columns.Add("CusField50");
  442. dt_new.Columns.Add("CusField51");
  443. dt_new.Columns.Add("CusField52");
  444. dt_new.Columns.Add("CusField53");
  445. dt_new.Columns.Add("CusField54");
  446. dt_new.Columns.Add("CusField55");
  447. dt_new.Columns.Add("CusField56");
  448. dt_new.Columns.Add("CusField57");
  449. dt_new.Columns.Add("CusField58");
  450. dt_new.Columns.Add("CusField59");
  451. dt_new.Columns.Add("CusField60");
  452. dt_new.Columns.Add("CusField61");
  453. dt_new.Columns.Add("CusField62");
  454. dt_new.Columns.Add("CusField63");
  455. dt_new.Columns.Add("CusField64");
  456. dt_new.Columns.Add("CusField65");
  457. dt_new.Columns.Add("CusField66");
  458. dt_new.Columns.Add("CusField67");
  459. dt_new.Columns.Add("CusField68");
  460. dt_new.Columns.Add("CusField69");
  461. dt_new.Columns.Add("CusField70");
  462. dt_new.Columns.Add("CusField71");
  463. dt_new.Columns.Add("CusField72");
  464. dt_new.Columns.Add("CusField73");
  465. dt_new.Columns.Add("CusField74");
  466. dt_new.Columns.Add("CusField75");
  467. dt_new.Columns.Add("CusField76");
  468. dt_new.Columns.Add("CusField77");
  469. dt_new.Columns.Add("CusField78");
  470. dt_new.Columns.Add("CusField79");
  471. dt_new.Columns.Add("CusField80");
  472. dt_new.Columns.Add("CusField81");
  473. dt_new.Columns.Add("CusField82");
  474. dt_new.Columns.Add("CusField83");
  475. dt_new.Columns.Add("CusField84");
  476. dt_new.Columns.Add("CusField85");
  477. dt_new.Columns.Add("CusField86");
  478. dt_new.Columns.Add("CusField87");
  479. dt_new.Columns.Add("CusField88");
  480. foreach (var customer in saCustomers)
  481. {
  482. var sName = string.IsNullOrEmpty(customer.CustomerCName) ? customer.CustomerEName : customer.CustomerCName;
  483. var sEName = customer.CustomerEName;
  484. if (sName.Trim() == "")
  485. {
  486. sName = sEName;
  487. }
  488. var sMemo = customer.Memo;
  489. var sInvoiceAddress = customer.InvoiceAddress;
  490. var sAddress = customer.Address;
  491. var sTelephone = customer.Telephone;
  492. var row_new = dt_new.NewRow();
  493. row_new["RowIndex"] = customer.RowIndex;
  494. row_new["CustomerCName"] = Common.CutByteString(sName, 60);
  495. row_new["InvoiceAddress"] = Common.CutByteString(sInvoiceAddress, 60);
  496. row_new["Address"] = Common.CutByteString(sAddress, 60);
  497. row_new["Telephone"] = Common.CutByteString(sTelephone, 60);
  498. row_new["Memo"] = Common.CutByteString(sMemo, 30);
  499. row_new["CusField1"] = "0";
  500. row_new["CusField2"] = "";
  501. row_new["CusField3"] = "";
  502. row_new["CusField4"] = "";
  503. row_new["CusField5"] = "";
  504. row_new["CusField6"] = "";
  505. row_new["CusField7"] = "";
  506. row_new["CusField8"] = "";
  507. row_new["CusField9"] = "";
  508. row_new["CusField10"] = "";
  509. row_new["CusField11"] = "";
  510. row_new["CusField12"] = "";
  511. row_new["CusField13"] = "";
  512. row_new["CusField14"] = "";
  513. row_new["CusField15"] = "";
  514. row_new["CusField16"] = "";
  515. row_new["CusField17"] = "";
  516. row_new["CusField18"] = "";
  517. row_new["CusField19"] = "";
  518. var _CreateUser = customer.CreateUser;
  519. sCreateUser = _CreateUser.Split('.')[0];
  520. row_new["CusField20"] = Common.CutByteString(_CreateUser, 30); ;
  521. row_new["CusField21"] = "";
  522. row_new["CusField22"] = "";
  523. row_new["CusField23"] = "";
  524. row_new["CusField24"] = "";
  525. row_new["CusField25"] = "";
  526. row_new["CusField26"] = "";
  527. row_new["CusField27"] = "";
  528. row_new["CusField28"] = "B,C".IndexOf(customer.TransactionType.Trim()) > -1 ? "6" : "5";
  529. row_new["CusField29"] = "";
  530. row_new["CusField30"] = "";
  531. row_new["CusField31"] = "";
  532. row_new["CusField32"] = "";
  533. row_new["CusField33"] = "";
  534. row_new["CusField34"] = "";
  535. row_new["CusField35"] = "";
  536. row_new["CusField36"] = "";
  537. row_new["CusField37"] = "";
  538. row_new["CusField38"] = "";
  539. row_new["CusField39"] = "";
  540. row_new["CusField40"] = "";
  541. row_new["CusField41"] = "";
  542. row_new["CusField42"] = "";
  543. row_new["CusField43"] = "";
  544. row_new["CusField44"] = "";
  545. row_new["CusField45"] = "";
  546. row_new["CusField46"] = "";
  547. row_new["CusField47"] = "";
  548. row_new["CusField48"] = "";
  549. row_new["CusField49"] = customer.CustomerNO;
  550. row_new["CusField50"] = "";
  551. row_new["CusField51"] = "";
  552. row_new["CusField52"] = "";
  553. row_new["CusField53"] = "";
  554. row_new["CusField54"] = "";
  555. row_new["CusField55"] = "";
  556. row_new["CusField56"] = "";
  557. row_new["CusField57"] = "";
  558. row_new["CusField58"] = "";
  559. row_new["CusField59"] = "";
  560. row_new["CusField60"] = "";
  561. row_new["CusField61"] = "";
  562. row_new["CusField62"] = "";
  563. row_new["CusField63"] = "";
  564. row_new["CusField64"] = "";
  565. row_new["CusField65"] = "";
  566. row_new["CusField66"] = "";
  567. row_new["CusField67"] = "";
  568. row_new["CusField68"] = "";
  569. row_new["CusField69"] = "";
  570. row_new["CusField70"] = "";
  571. row_new["CusField71"] = "";
  572. row_new["CusField72"] = "";
  573. row_new["CusField73"] = "";
  574. row_new["CusField74"] = Common.CutByteString(customer.CustomerEName, 120);
  575. if (Regex.IsMatch(sAddress, "[\u4e00-\u9fa5]+"))
  576. {
  577. sAddress = "";
  578. }
  579. row_new["CusField75"] = Common.CutByteString(sAddress, 240);
  580. row_new["CusField76"] = "";
  581. row_new["CusField77"] = "";
  582. row_new["CusField78"] = "";
  583. row_new["CusField79"] = "";
  584. row_new["CusField80"] = "";
  585. row_new["CusField81"] = "";
  586. row_new["CusField82"] = "";
  587. row_new["CusField83"] = "";
  588. row_new["CusField84"] = "";
  589. row_new["CusField85"] = "";
  590. row_new["CusField86"] = "";
  591. row_new["CusField87"] = "";
  592. row_new["CusField88"] = "";
  593. dt_new.Rows.Add(row_new);
  594. }
  595. dicAlain = ExcelService.GetExportAlain(oHeader, "CustomerNO,UniCode,Telephone,FAX,CusField1");
  596. }
  597. break;
  598. default:
  599. {
  600. break;
  601. }
  602. }
  603. var bOk = new ExcelService().CreateExcelByTb(dt_new, out string sPath, oHeader, dicAlain, listMerge, sFileName);
  604. rm.DATA.Add(BLWording.REL, sPath);
  605. }
  606. else
  607. {
  608. rm.DATA.Add(BLWording.REL, pml);
  609. }
  610. } while (false);
  611. }
  612. catch (Exception ex)
  613. {
  614. sMsg = Util.GetLastExceptionMsg(ex);
  615. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Customers_QryService), "", "QueryPage(客戶管理(分頁查詢))", "", "", "");
  616. }
  617. finally
  618. {
  619. if (null != sMsg)
  620. {
  621. rm = new ErrorResponseMessage(sMsg, i_crm);
  622. }
  623. }
  624. return rm;
  625. }
  626. #endregion 客戶管理(分頁查詢)
  627. #region 客戶管理(單筆查詢)
  628. /// <summary>
  629. /// 客戶管理(單筆查詢)
  630. /// </summary>
  631. /// <param name="i_crm"></param>
  632. /// <returns></returns>
  633. public ResponseMessage QueryOne(RequestMessage i_crm)
  634. {
  635. ResponseMessage rm = null;
  636. string sMsg = null;
  637. var db = SugarBase.GetIntance();
  638. try
  639. {
  640. do
  641. {
  642. var sId = _fetchString(i_crm, @"Guid");
  643. var oEntity = db.Queryable<OTB_CRM_Customers>().Single(x => x.OrgID == i_crm.ORIGID && x.guid == sId);
  644. rm = new SuccessResponseMessage(null, i_crm);
  645. rm.DATA.Add(BLWording.REL, oEntity);
  646. } while (false);
  647. }
  648. catch (Exception ex)
  649. {
  650. sMsg = Util.GetLastExceptionMsg(ex);
  651. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, nameof(Customers_QryService), "", "QueryOne(客戶管理(單筆查詢))", "", "", "");
  652. }
  653. finally
  654. {
  655. if (null != sMsg)
  656. {
  657. rm = new ErrorResponseMessage(sMsg, i_crm);
  658. }
  659. }
  660. return rm;
  661. }
  662. #endregion 客戶管理(單筆查詢)
  663. }
  664. }