圣珀
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.

794 lines
38 KiB

2 years ago
2 years ago
2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.Serialization;
  7. using System.Data;
  8. using ICS.WCF.Base;
  9. using ICSSoft.Entity;
  10. using www.ufida.org.EntityData;
  11. using UFSoft.UBF.Util.Context;
  12. using System.Configuration;
  13. using System.ServiceModel;
  14. using UFSoft.UBF.Service;
  15. namespace ICS.CreateU9Customer
  16. {
  17. public class CreateU9Customer
  18. {
  19. public OperationResult CustCreateU9Customer(CustomerInsertDataClass CusList)
  20. {
  21. OperationResult result = new OperationResult();
  22. //U9.PM.PO.POShipLine.CreatePOShipLineDefault();
  23. #region 服务调用框架结构
  24. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  25. UFIDAU9ISVCustomerIBatchCreateCustomerByDTOSVClient client = new UFIDAU9ISVCustomerIBatchCreateCustomerByDTOSVClient();
  26. //服务返回结果
  27. UFIDAU9CBOSCMCustomerCustomerData[] returnCustomers;
  28. //返回异常信息,目前还没有使用此属性
  29. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  30. //上下文信息
  31. object context;
  32. //传入 参数
  33. string[] splitBy = new string[] { };
  34. try
  35. {
  36. context = CreateContextObj();
  37. StringBuilder beginstr = new StringBuilder();
  38. beginstr.AppendLine("-----------------------传入数据验证开始-----------------------------");
  39. beginstr.AppendLine("创建U9客户信息");
  40. beginstr.AppendLine("组织:" + CusList.OrgCode);
  41. //beginstr.AppendLine("客户区号:" + CusList.CustomerCode);
  42. beginstr.AppendLine("客户名称:" + CusList.CustomerName);
  43. beginstr.AppendLine("客户简称:" + CusList.ShrotName);
  44. beginstr.AppendLine("客户分类:" + CusList.CustomerType);
  45. beginstr.AppendLine("业务员:" + CusList.CustomerUser);
  46. beginstr.AppendLine("行业:" + CusList.TradeCategory);
  47. beginstr.AppendLine("工商注册码:" + CusList.CorpUnifyCode);
  48. beginstr.AppendLine("-----------------------传入数据验证结束-----------------------------");
  49. Appconfig.WriteLogFile(beginstr.ToString(), "创建U9客户信息");
  50. //if (CusList.OrgCode != "01")
  51. //{
  52. // result.MESSAGE = "组织不为苏州伟创时不能新建客户,只能下发!";
  53. // result.IsSuccess = false;
  54. // return result;
  55. //}
  56. #region 获取组织ID
  57. string OrgID = "";
  58. string orgsql = @"select ID from Base_Organization
  59. where Code='{0}'";
  60. orgsql = string.Format(orgsql, CusList.OrgCode);
  61. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  62. if (orgdt.Rows.Count != 0)
  63. {
  64. OrgID = orgdt.Rows[0]["ID"].ToString();
  65. }
  66. else
  67. {
  68. result.MESSAGE = "组织编码:'" + CusList.OrgCode + "'不存在!";
  69. result.IsSuccess = false;
  70. return result;
  71. }
  72. #endregion
  73. //验证客户是否已经存在(如果组织为苏州伟创则查询流水号,否则直接查询苏州伟创相同的客户,没有则报错)
  74. string checksql = "";
  75. string CusCode = "";
  76. checksql = @"select * from CBO_Customer A
  77. LEFT JOIN CBO_Customer_Trl B
  78. ON B.ID=A.ID
  79. WHERE B.Name='{0}'
  80. AND A.Org='{1}'";
  81. checksql = string.Format(checksql, CusList.CustomerName, OrgID);
  82. DataTable checkdt = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
  83. if (checkdt.Rows.Count == 0)
  84. {
  85. string SerialNo = "";
  86. //if (CusList.OrgCode == "01")
  87. //{
  88. #region 查询客户编码流水号
  89. // string areasql = @"select Code from Base_DefineValue
  90. // where ValueSetDef='1001912240122432'
  91. // AND Code='{0}'";
  92. // areasql = string.Format(areasql, CusList.CustomerCode);
  93. // DataTable areadt = DBhlper.Query(areasql, Appconfig.GetU9ConnStr());
  94. // if (areadt.Rows.Count == 0)
  95. // {
  96. // result.MESSAGE = "区号:'" + CusList.CustomerCode + "'不存在!";
  97. // result.IsSuccess = false;
  98. // return result;
  99. // }
  100. // string serialsql = @"select TOP 1 Code from CBO_Customer
  101. // where Org='" + OrgID + "' and code < '999999' and code not like'%[a-z]%' order by Code DESC";
  102. // serialsql = string.Format(serialsql, OrgID);
  103. // //serialsql = string.Format(serialsql, CusList.CustomerCode, OrgID);
  104. // DataTable serialdt = DBhlper.Query(serialsql, Appconfig.GetU9ConnStr());
  105. // if (serialdt.Rows.Count == 0)
  106. // {
  107. // SerialNo = "0001";
  108. // }
  109. // else
  110. // {
  111. // //string BaseNo = serialdt.Rows[0]["Code"].ToString().Split('-')[1];
  112. // string BaseNo = serialdt.Rows[0]["Code"].ToString();
  113. // SerialNo = (Convert.ToInt32(BaseNo) + 1).ToString().PadLeft(4, '0');
  114. // }
  115. SerialNo = CusList.CustomerNo;
  116. #endregion
  117. //}
  118. //给传入参数赋值
  119. UFIDAU9ISVCustomerCustomerDTOData[] customerDatas = setDataForCustomer(CusList, SerialNo, OrgID, CusCode);
  120. UFIDAU9CBOPubControllerContextDTOData custContext = CreateContextDto();
  121. //服务调用
  122. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  123. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  124. returnCustomers = client.Do(out returnMsg, context, customerDatas.ToArray(), custContext);
  125. StringBuilder str = new StringBuilder();
  126. str.AppendLine("创建U9客户信息");
  127. str.AppendLine("组织:" + CusList.OrgCode);
  128. //str.AppendLine("客户区号:" + CusList.CustomerCode);
  129. str.AppendLine("客户名称:" + CusList.CustomerName);
  130. str.AppendLine("客户简称:" + CusList.ShrotName);
  131. str.AppendLine("客户分类:" + CusList.CustomerType);
  132. str.AppendLine("业务员:" + CusList.CustomerUser);
  133. str.AppendLine("行业:" + CusList.TradeCategory);
  134. str.AppendLine("工商注册码:" + CusList.CorpUnifyCode);
  135. str.AppendLine("结果:" + "True");
  136. Appconfig.WriteLogFile(str.ToString(), "创建U9客户信息");
  137. result.MESSAGE = "客户" + SerialNo + "创建成功";
  138. result.IsSuccess = true;
  139. result.CustomerCode = returnCustomers[0].m_code;
  140. result.CustomerID = returnCustomers[0].m_iD;
  141. return result;
  142. }
  143. else
  144. {
  145. StringBuilder str = new StringBuilder();
  146. str.AppendLine("创建U9客户信息");
  147. str.AppendLine("组织:" + CusList.OrgCode);
  148. //str.AppendLine("客户区号:" + CusList.CustomerCode);
  149. str.AppendLine("客户名称:" + CusList.CustomerName);
  150. str.AppendLine("客户简称:" + CusList.ShrotName);
  151. str.AppendLine("客户分类:" + CusList.CustomerType);
  152. str.AppendLine("业务员:" + CusList.CustomerUser);
  153. str.AppendLine("行业:" + CusList.TradeCategory);
  154. str.AppendLine("工商注册码:" + CusList.CorpUnifyCode);
  155. str.AppendLine("结果:" + "客户已存在");
  156. Appconfig.WriteLogFile(str.ToString(), "创建U9客户信息");
  157. result.CustomerCode = checkdt.Rows[0]["Code"].ToString();
  158. result.CustomerID = long.Parse(checkdt.Rows[0]["ID"].ToString());
  159. result.MESSAGE = "客户" + CusList.CustomerName + "已存在";
  160. result.IsSuccess = true;
  161. return result;
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. //异常信息捕获
  167. string Message = GetExceptionMessage(ex);
  168. StringBuilder str = new StringBuilder();
  169. str.AppendLine("创建U9客户信息");
  170. str.AppendLine("组织:" + CusList.OrgCode);
  171. //str.AppendLine("客户区号:" + CusList.CustomerCode);
  172. str.AppendLine("客户名称:" + CusList.CustomerName);
  173. str.AppendLine("客户简称:" + CusList.ShrotName);
  174. str.AppendLine("客户分类:" + CusList.CustomerType);
  175. str.AppendLine("业务员:" + CusList.CustomerUser);
  176. str.AppendLine("行业:" + CusList.TradeCategory);
  177. str.AppendLine("工商注册码:" + CusList.CorpUnifyCode);
  178. str.AppendLine("结果:" + "False");
  179. str.AppendLine("错误:" + GetExceptionMessage(ex));
  180. Appconfig.WriteLogFile(str.ToString(), "创建U9客户信息");
  181. result.MESSAGE = Message;
  182. result.IsSuccess = false;
  183. return result;
  184. }
  185. }
  186. #endregion
  187. #region 提取异常信息
  188. /// <summary>
  189. /// 提取异常信息
  190. /// </summary>
  191. /// <param name="ex"></param>
  192. private string GetExceptionMessage(Exception ex)
  193. {
  194. string faultMessage = "未知错误,请查看ERP日志!";
  195. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  196. if (timeoutEx != null)
  197. {
  198. faultMessage = "访问服务超时,请修改配置信息!";
  199. }
  200. else
  201. {
  202. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  203. if (faultEx == null)
  204. {
  205. faultMessage = ex.Message;
  206. }
  207. else
  208. {
  209. ServiceException serviceEx = faultEx.Detail;
  210. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  211. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  212. {
  213. // 错误信息在faultEx.Message中,请提取,
  214. // 格式为"Fault:料品不能为空,请录入\n 在....."
  215. int startIndex = serviceEx.Message.IndexOf(":");
  216. int endIndex = serviceEx.Message.IndexOf("\n");
  217. if (endIndex == -1)
  218. endIndex = serviceEx.Message.Length;
  219. if (endIndex > 0 && endIndex > startIndex + 1)
  220. {
  221. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  222. }
  223. else
  224. {
  225. faultMessage = serviceEx.Message;
  226. }
  227. }
  228. }
  229. }
  230. return faultMessage;
  231. }
  232. #endregion
  233. #region 给上下文信息赋值
  234. /// <summary>
  235. /// 给上下文信息赋值
  236. /// </summary>
  237. /// <returns></returns>
  238. private UFIDAU9CBOPubControllerContextDTOData CreateContextDto()
  239. {
  240. // 实例化应用上下文对象
  241. UFIDAU9CBOPubControllerContextDTOData thContext = new UFIDAU9CBOPubControllerContextDTOData();
  242. thContext.m_orgID = long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
  243. thContext.m_cultureName = ConfigurationManager.AppSettings["cultureName"].ToString();
  244. thContext.m_entCode = ConfigurationManager.AppSettings["enterpriseID"].ToString();
  245. thContext.m_orgCode = ConfigurationManager.AppSettings["orgCode"].ToString();
  246. thContext.m_userCode = ConfigurationManager.AppSettings["userCode"].ToString();
  247. thContext.m_userID = long.Parse(ConfigurationManager.AppSettings["userID"].ToString());
  248. return thContext;
  249. }
  250. #endregion
  251. #region 给上下文信息赋值1
  252. /// <summary>
  253. /// 给上下文信息赋值
  254. /// </summary>
  255. /// <returns></returns>
  256. private ThreadContext CreateContextObj()
  257. {
  258. // 实例化应用上下文对象
  259. ThreadContext thContext = new ThreadContext();
  260. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  261. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  262. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  263. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  264. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  265. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  266. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  267. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  268. thContext.nameValueHas = ns;
  269. return thContext;
  270. }
  271. #endregion
  272. private UFIDAU9ISVCustomerCustomerDTOData[] setDataForCustomer(CustomerInsertDataClass datas, string SerialNo, string OrgID, string CusCode)
  273. {
  274. try
  275. {
  276. List<UFIDAU9ISVCustomerCustomerDTOData> customers = new List<UFIDAU9ISVCustomerCustomerDTOData>();
  277. UFIDAU9ISVCustomerCustomerDTOData customer = new UFIDAU9ISVCustomerCustomerDTOData();
  278. if (CusCode == "")
  279. {
  280. //customer.m_code = datas.CustomerCode + "-" + SerialNo;
  281. customer.m_code = SerialNo;
  282. }
  283. else
  284. {
  285. customer.m_code = CusCode;
  286. }
  287. customer.Name = datas.CustomerName;
  288. customer.m_shortName = datas.CustomerName;
  289. //customer.m_shortName = datas.ShrotName;
  290. #region 获取客户分类ID
  291. string infosql = @"select B.ID,B.Code from CBO_CustomerCategory_Trl A
  292. LEFT JOIN CBO_CustomerCategory B
  293. ON B.ID=A.ID
  294. where B.Code='{0}' AND B.Org='{1}' ";
  295. infosql = string.Format(infosql, datas.CustomerType, OrgID);
  296. DataTable infodt = DBhlper.Query(infosql, Appconfig.GetU9ConnStr());
  297. if (infodt.Rows.Count != 0)
  298. {
  299. customer.m_customerCategory = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  300. customer.m_customerCategory.m_code = infodt.Rows[0]["Code"].ToString();
  301. customer.m_customerCategory.m_iD = long.Parse(infodt.Rows[0]["ID"].ToString());
  302. }
  303. else
  304. {
  305. throw new Exception("未获取到客户分类:" + datas.CustomerType + "对应编码");
  306. }
  307. #endregion
  308. #region 获取交易币种ID
  309. string tcurrencysql = @"select A.ID from Base_Currency_Trl a
  310. left join Base_Currency b on a.id=b.id
  311. where SysMLFlag='zh-CN' AND b.code='{0}'";
  312. tcurrencysql = string.Format(tcurrencysql, datas.TradeCurrencyName);
  313. DataTable tcurrencydt = DBhlper.Query(tcurrencysql, Appconfig.GetU9ConnStr());
  314. if (tcurrencydt.Rows.Count == 0)
  315. {
  316. throw new Exception("未获取到交易币种编码:" + datas.TradeCurrencyName + "对应ID");
  317. }
  318. else
  319. {
  320. customer.m_tradeCurrency = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  321. customer.m_tradeCurrency.m_iD = long.Parse(tcurrencydt.Rows[0]["ID"].ToString());
  322. }
  323. #endregion
  324. #region 获取收款币种ID
  325. datas.ReceiveCurrencyName = datas.TradeCurrencyName;//收款币种选择和交易币种一致
  326. string rcurrencysql = @"select A.ID from Base_Currency_Trl a
  327. left join Base_Currency b on a.id=b.id
  328. where SysMLFlag='zh-CN' AND b.code='{0}'";
  329. rcurrencysql = string.Format(rcurrencysql, datas.ReceiveCurrencyName);
  330. DataTable rcurrencydt = DBhlper.Query(rcurrencysql, Appconfig.GetU9ConnStr());
  331. if (rcurrencydt.Rows.Count == 0)
  332. {
  333. throw new Exception("未获取到收款币种编码:" + datas.ReceiveCurrencyName + "对应ID");
  334. }
  335. else
  336. {
  337. customer.m_payCurrency = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  338. customer.m_payCurrency.m_iD = long.Parse(rcurrencydt.Rows[0]["ID"].ToString());
  339. }
  340. #endregion
  341. #region 获取供应组织
  342. string SupplyOrgID = "";
  343. string orgsql = @"select ID from Base_Organization
  344. where Code='{0}'";
  345. orgsql = string.Format(orgsql, datas.OrgCode);
  346. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  347. if (orgdt.Rows.Count != 0)
  348. {
  349. SupplyOrgID = orgdt.Rows[0]["ID"].ToString();
  350. }
  351. else
  352. {
  353. throw new Exception("未获取到供应组织:" + datas.OrgCode + "对应ID");
  354. }
  355. #endregion
  356. #region 获取税组合ID
  357. string TaxRuleID = "";
  358. string taxsql = @"select ID from CBO_TaxSchedule
  359. where Code='{0}'";
  360. taxsql = string.Format(taxsql, datas.TaxScheduleCode);
  361. DataTable taxdt = DBhlper.Query(taxsql, Appconfig.GetU9ConnStr());
  362. if (taxdt.Rows.Count != 0)
  363. {
  364. TaxRuleID = taxdt.Rows[0]["ID"].ToString();
  365. }
  366. else
  367. {
  368. throw new Exception("未获取到税组合编码:" + datas.TaxScheduleCode + "对应ID");
  369. }
  370. #endregion
  371. #region 获取收款条件ID
  372. string RecervalTermID = "";
  373. datas.RecervalTermCode = "YZ01";
  374. if (datas.RecervalTermCode != "" && datas.RecervalTermCode != null)
  375. {
  376. string rtermsql = @"select ID from CBO_ReceivalTerm
  377. where Code='{0}' and Org='{1}'";
  378. rtermsql = string.Format(rtermsql, datas.RecervalTermCode, OrgID);
  379. DataTable rtermdt = DBhlper.Query(rtermsql, Appconfig.GetU9ConnStr());
  380. if (rtermdt.Rows.Count != 0)
  381. {
  382. RecervalTermID = rtermdt.Rows[0]["ID"].ToString();
  383. }
  384. else
  385. {
  386. throw new Exception("未获取到收款条件编码:" + datas.RecervalTermCode + "对应ID");
  387. }
  388. }
  389. #endregion
  390. #region 获取立账条件ID
  391. string ARConfirmTermID = "";
  392. string ctermsql = @"select ID from CBO_ARConfirmTerm
  393. where Code='{0}' AND Org='{1}'";
  394. ctermsql = string.Format(ctermsql, datas.ARConfirmTerm, OrgID);
  395. DataTable ctermdt = DBhlper.Query(ctermsql, Appconfig.GetU9ConnStr());
  396. if (ctermdt.Rows.Count != 0)
  397. {
  398. ARConfirmTermID = ctermdt.Rows[0]["ID"].ToString();
  399. }
  400. else
  401. {
  402. throw new Exception("未获取到立账条件编码:" + datas.ARConfirmTerm + "对应ID");
  403. }
  404. #endregion
  405. #region 获取立账条件名称
  406. string ARConfirmTermName = "";
  407. string ctermrsql = @"select a.Code,b.Name from CBO_ARConfirmTerm a
  408. left join CBO_ARConfirmTerm_Trl b on a.id=b.id
  409. where a.Code='{0}' AND a.Org='{1}'";
  410. ctermrsql = string.Format(ctermrsql, datas.ARConfirmTerm, OrgID);
  411. DataTable ctermdt2 = DBhlper.Query(ctermrsql, Appconfig.GetU9ConnStr());
  412. if (ctermdt2.Rows.Count != 0)
  413. {
  414. ARConfirmTermName = ctermdt2.Rows[0]["Name"].ToString();
  415. }
  416. else
  417. {
  418. throw new Exception("未获取到立账条件名称:" + datas.ARConfirmTerm + "对应ID");
  419. }
  420. #endregion
  421. #region 获取收货地址ID
  422. // string OfficialLocationID = "";
  423. // if (datas.OfficialLocation != "" && datas.OfficialLocation != null)
  424. // {
  425. // string Officialsql = @"select ID from Base_Location_trl
  426. // where Name='{0}'";
  427. // Officialsql = string.Format(Officialsql, datas.OfficialLocation);
  428. // DataTable Officialdt = DBhlper.Query(Officialsql, Appconfig.GetU9ConnStr());
  429. // if (Officialdt.Rows.Count != 0)
  430. // {
  431. // OfficialLocationID = Officialdt.Rows[0]["ID"].ToString();
  432. // }
  433. // else
  434. // {
  435. // throw new Exception("未获取到收货地址编码:" + datas.OfficialLocation + "对应ID");
  436. // }
  437. // }
  438. #endregion
  439. #region 获取价目表ID
  440. string PriceListID = "";
  441. //if (datas.CustomerType == "01")
  442. //{
  443. // datas.PriceListCode = "SPL2021100002";
  444. // //datas.PriceListCode = "SPL2021110001";
  445. //}
  446. //else if (datas.CustomerType == "02")
  447. //{
  448. // datas.PriceListCode = "SPL2021100003";
  449. //}
  450. //if (datas.TradeCurrencyName == "C001")
  451. //{
  452. // datas.PriceListCode = "SPL2021100002";
  453. //}
  454. //else if (datas.TradeCurrencyName == "C009")
  455. //{
  456. // datas.PriceListCode = "SPL2021100003";
  457. //}
  458. //else if (datas.TradeCurrencyName == "C005")
  459. //{
  460. // datas.PriceListCode = "SPL2021110001";
  461. //}
  462. #region MyRegion
  463. // string pricesql = @"select ID from SPR_SalePriceList
  464. // where Code='{0}' AND Org='{1}'";
  465. // pricesql = string.Format(pricesql, datas.PriceListCode, OrgID);
  466. // DataTable pricedt = DBhlper.Query(pricesql, Appconfig.GetU9ConnStr());
  467. // if (pricedt.Rows.Count != 0)
  468. // {
  469. // PriceListID = pricedt.Rows[0]["ID"].ToString();
  470. // }
  471. // else
  472. // {
  473. // throw new Exception("未获取到价目表编码:" + datas.PriceListCode + "对应ID");
  474. // }
  475. #endregion
  476. // else
  477. // {
  478. // string pricesql = @"select ID from SPR_SalePriceList
  479. // where Code='{0}' AND Org='{1}'";
  480. // pricesql = string.Format(pricesql, datas.PriceListCode, OrgID);
  481. // DataTable pricedt = DBhlper.Query(pricesql, Appconfig.GetU9ConnStr());
  482. // if (pricedt.Rows.Count != 0)
  483. // {
  484. // PriceListID = pricedt.Rows[0]["ID"].ToString();
  485. // }
  486. // else
  487. // {
  488. // PriceListID = "0";
  489. // }
  490. // }
  491. #endregion
  492. #region 获取存储地点ID
  493. string WHID = "";
  494. if (datas.WHCode != "" && datas.WHCode != null)
  495. {
  496. string whsql = @"select ID from CBO_WH
  497. where Code='{0}' AND Org='{1}'";
  498. whsql = string.Format(whsql, datas.WHCode, OrgID);
  499. DataTable whdt = DBhlper.Query(whsql, Appconfig.GetU9ConnStr());
  500. if (whdt.Rows.Count != 0)
  501. {
  502. WHID = whdt.Rows[0]["ID"].ToString();
  503. }
  504. else
  505. {
  506. WHID = "0";
  507. throw new Exception("未获取到仓库编码:" + datas.WHCode + "对应ID");
  508. }
  509. }
  510. #endregion
  511. #region 获取注册地址ID
  512. // string LocationID = "";
  513. // if (datas.WHCode != "" && datas.WHCode != null)
  514. // {
  515. // string whsql = @"select ID from CBO_WH
  516. // where Code='{0}' AND Org='{1}'";
  517. // whsql = string.Format(whsql, datas.WHCode, OrgID);
  518. // DataTable whdt = DBhlper.Query(whsql, Appconfig.GetU9ConnStr());
  519. // if (whdt.Rows.Count != 0)
  520. // {
  521. // LocationID = whdt.Rows[0]["ID"].ToString();
  522. // }
  523. // else
  524. // {
  525. // LocationID = "0";
  526. // throw new Exception("未获取到注册地址:" + datas.WHCode + "对应ID");
  527. // }
  528. // }
  529. #endregion
  530. customer.m_saleser = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  531. customer.m_saleser.m_code = datas.CustomerUser;
  532. customer.CorpUnifyCode = datas.CorpUnifyCode;
  533. customer.m_stateTaxNo = datas.StateTaxNo;
  534. #region 默认值
  535. customer.m_saleType = 0;
  536. customer.m_priceListCode = datas.PriceListCode;
  537. //customer.m_priceListID = long.Parse(PriceListID);
  538. customer.m_isPriceListModify = true;
  539. customer.m_isFromCRM = true;
  540. if (datas.SupplySource == "供应商")
  541. {
  542. customer.m_supplySource = 0;
  543. }
  544. else if (datas.SupplySource == "内部组织")
  545. {
  546. customer.m_supplySource = 1;
  547. }
  548. else if (datas.SupplySource == "转生产制造")
  549. {
  550. customer.m_supplySource = 2;
  551. }
  552. else if (datas.SupplySource == "当前组织")
  553. {
  554. customer.m_supplySource = 3;
  555. }
  556. customer.m_supplySource = 3;//供应来源(默认 3)
  557. if (datas.DemandTransType == "转当前组织采购")
  558. {
  559. customer.m_demandTransType = 0;
  560. }
  561. else if (datas.DemandTransType == "跨组织出货")
  562. {
  563. customer.m_demandTransType = 1;
  564. }
  565. else if (datas.DemandTransType == "转制令")
  566. {
  567. customer.m_demandTransType = 2;
  568. }
  569. else if (datas.DemandTransType == "当前组织出货")
  570. {
  571. customer.m_demandTransType = 3;
  572. }
  573. else if (datas.DemandTransType == "转外协")
  574. {
  575. customer.m_demandTransType = 4;
  576. }
  577. customer.m_demandTransType = 3;//供应类型 (默认 3)
  578. if (WHID != "0" && WHID != "")
  579. {
  580. customer.m_wH = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  581. //if (datas.OrgCode == "02" || datas.OrgCode == "01")
  582. //{
  583. // customer.m_wH.m_code = "CP01";
  584. // customer.m_wH.m_iD = 1001912020027545;
  585. //}
  586. customer.m_wH.m_code = datas.WHCode;
  587. customer.m_wH.m_iD = long.Parse(WHID);
  588. }
  589. customer.m_supplyOrg = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  590. customer.m_supplyOrg.m_iD = 1002303100000860;
  591. customer.m_supplyOrg.m_code = datas.SupplyOrgCode;
  592. customer.m_shippmentRule = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  593. customer.m_shippmentRule.m_iD = 1002303100150515;
  594. customer.m_isShipmentModify = true;
  595. customer.m_taxSchedule = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  596. customer.m_taxSchedule.m_iD = long.Parse(TaxRuleID);
  597. customer.m_taxSchedule.m_code = datas.TaxScheduleCode;
  598. customer.m_bargain = -1;
  599. if (datas.RecervalTermCode != "" && datas.RecervalTermCode != null)
  600. {
  601. customer.m_recervalTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  602. customer.m_recervalTerm.m_iD = long.Parse(RecervalTermID);
  603. customer.m_recervalTerm.m_code = datas.RecervalTermCode;
  604. }
  605. customer.m_isRecTermModify = true;
  606. customer.m_qualityPledge = 0;
  607. customer.m_aRConfirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  608. customer.m_aRConfirmTerm.m_iD = long.Parse(ARConfirmTermID);
  609. customer.m_aRConfirmTerm.m_code = datas.ARConfirmTerm;
  610. customer.m_isARCfmModify = true;
  611. //customer.m_registerLocation = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  612. //customer.m_registerLocation.m_name=datas.CusAddress;//注册地址
  613. //if (datas.OfficialLocation != "" && datas.OfficialLocation !=null)
  614. //{
  615. // customer.m_OfficialLocation = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  616. // customer.m_OfficialLocation.m_iD = long.Parse(OfficialLocationID);
  617. // customer.m_OfficialLocation.m_code = datas.OfficialLocation;
  618. //}
  619. if (datas.InvoiceVerificationOrder == "后进先出")
  620. {
  621. customer.m_invoiceVerificationOrder = 0;
  622. }
  623. else if (datas.InvoiceVerificationOrder == "先进先出")
  624. {
  625. customer.m_invoiceVerificationOrder = 1;
  626. }
  627. else if (datas.InvoiceVerificationOrder == "从大到小")
  628. {
  629. customer.m_invoiceVerificationOrder = 2;
  630. }
  631. else if (datas.InvoiceVerificationOrder == "从小到大")
  632. {
  633. customer.m_invoiceVerificationOrder = 3;
  634. }
  635. else if (datas.InvoiceVerificationOrder == "优先等级")
  636. {
  637. customer.m_invoiceVerificationOrder = 4;
  638. }
  639. customer.m_invoiceVerificationOrder = 1;//核销顺序(默认 1)
  640. if (datas.VerificationMode == "按客户")
  641. {
  642. customer.m_verificationMode = 0;
  643. }
  644. else if (datas.VerificationMode == "按单")
  645. {
  646. customer.m_verificationMode = 1;
  647. }
  648. else if (datas.VerificationMode == "按行")
  649. {
  650. customer.m_verificationMode = 2;
  651. }
  652. else if (datas.VerificationMode == "按分期收款行")
  653. {
  654. customer.m_verificationMode = 3;
  655. }
  656. customer.m_verificationMode = 0;
  657. customer.m_isByAccountAge = true;//按账龄催款(默认为True)
  658. customer.m_checkAccountPeriod = 3;//对账期间(默认为3)
  659. customer.m_commissionType = 0;
  660. customer.m_commissionCurrency = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  661. customer.m_commissionCurrency.m_iD = 1;
  662. customer.m_commission = 1000;
  663. customer.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  664. customer.m_descFlexField.m_privateDescSeg1 = "0";//欠回单数
  665. customer.m_descFlexField.m_privateDescSeg3 = "02";//是否逾期
  666. customer.m_descFlexField.m_privateDescSeg4 = "01";//是否拆分
  667. customer.m_descFlexField.m_privateDescSeg2 = datas.OfficialLocation;//默认发货地址
  668. customer.m_descFlexField.m_privateDescSeg7 = datas.customertype;//客户类型
  669. customer.m_descFlexField.m_privateDescSeg8 = datas.areaDivision;//地区划分
  670. customer.m_descFlexField.m_privateDescSeg11 = datas.emterritory;//所属大区
  671. if (ARConfirmTermName == "月结30天")
  672. {
  673. customer.m_descFlexField.m_privateDescSeg6 = "30";//信用期限
  674. }
  675. else if (ARConfirmTermName == "月结60天")
  676. {
  677. customer.m_descFlexField.m_privateDescSeg6 = "60";
  678. }
  679. else if (ARConfirmTermName == "月结90天")
  680. {
  681. customer.m_descFlexField.m_privateDescSeg6 = "90";
  682. }
  683. else if (ARConfirmTermName == "月结360天")
  684. {
  685. customer.m_descFlexField.m_privateDescSeg6 = "360";
  686. }
  687. else
  688. {
  689. customer.m_descFlexField.m_privateDescSeg6 = "0";
  690. }
  691. customer.m_effective = new UFIDAU9BasePropertyTypesEffectiveData();
  692. customer.m_effective.m_effectiveDate = datas.EfftiveDate;
  693. //customer.m_effective.m_effectiveDate = DateTime.Now.AddDays(-1);
  694. customer.m_effective.m_disableDate = Convert.ToDateTime("9999.12.31");
  695. customer.m_effective.m_isEffective = true;
  696. #endregion
  697. customer.m_tradeCategory = datas.TradeCategory;
  698. customers.Add(customer);
  699. return customers.ToArray();
  700. }
  701. catch (Exception ex)
  702. {
  703. throw new Exception(ex.Message);
  704. }
  705. }
  706. #region 时间戳方法
  707. private DateTime TimestampToDateTime(long timestamp)
  708. {
  709. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  710. long lTime = timestamp * 10000000;
  711. TimeSpan nowTimeSpan = new TimeSpan(lTime);
  712. DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
  713. return resultDateTime;
  714. }
  715. #endregion
  716. /// <summary>
  717. /// 返回值
  718. /// </summary>
  719. public class FormICSCreatedArrivalNoticeModel
  720. {
  721. //0 :正常数据,-1:失败。
  722. public int Code { get; set; }
  723. public string ResMsg { get; set; }
  724. public object ResData { get; set; }
  725. public bool IsCompress { get; set; }
  726. public bool IsSuccess { get; set; }
  727. }
  728. public class OperationResult
  729. {
  730. /// <summary>
  731. /// 结果状态,默认值false
  732. /// </summary>
  733. public bool IsSuccess { get; set; }
  734. /// <summary>
  735. ///处理消息
  736. /// </summary>
  737. public string MESSAGE { get; set; }
  738. /// <summary>
  739. /// 输出客户编码
  740. /// </summary>
  741. public string CustomerCode { get; set; }
  742. /// <summary>
  743. /// 客户ID
  744. /// </summary>
  745. public long CustomerID { get; set; }
  746. }
  747. }
  748. }