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

801 lines
39 KiB

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