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

591 lines
30 KiB

2 years ago
  1. using ICS.WCF.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.ServiceModel;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using UFSoft.UBF.Service;
  11. using UFSoft.UBF.Util.Context;
  12. using www.ufida.org.EntityData;
  13. namespace ICS.ModifyU9Customer
  14. {
  15. public class ModifyCustomer
  16. {
  17. private string MessageLogName = "修改U9客户信息";
  18. private string ERPConStr = Appconfig.GetU9ConnStr();
  19. public ModifyCustomerResult CustModifyU9Customer(ModifyCustomerModel ModifyCustomer)
  20. {
  21. ModifyCustomerResult Return = new ModifyCustomerResult();//方法返回值
  22. Return.IsSuccess = false;
  23. Return.MESSAGE = "";
  24. try
  25. {
  26. if (ModifyCustomer != null)
  27. {
  28. StringBuilder strHead = new StringBuilder();
  29. strHead.AppendLine("-------------接口传入参数:");
  30. if (string.IsNullOrEmpty(ModifyCustomer.Code))
  31. {
  32. ModifyCustomer.Code = "";
  33. }
  34. if (string.IsNullOrEmpty(ModifyCustomer.Name))
  35. {
  36. ModifyCustomer.Name = "";
  37. }
  38. if (string.IsNullOrEmpty(ModifyCustomer.ORGCode))
  39. {
  40. ModifyCustomer.ORGCode = "";
  41. }
  42. if (string.IsNullOrEmpty(ModifyCustomer.PrivateDescSeg2))
  43. {
  44. ModifyCustomer.PrivateDescSeg2 = "";
  45. }
  46. if (string.IsNullOrEmpty(ModifyCustomer.Department))
  47. {
  48. ModifyCustomer.Department = "";
  49. }
  50. if (string.IsNullOrEmpty(ModifyCustomer.Saleser))
  51. {
  52. ModifyCustomer.Saleser = "";
  53. }
  54. strHead.AppendLine("CustomerCode:" + ModifyCustomer.Code);
  55. strHead.AppendLine("Name:" + ModifyCustomer.Name);
  56. strHead.AppendLine("ORGCode:" + ModifyCustomer.ORGCode);
  57. strHead.AppendLine("PrivateDescSeg1:" + ModifyCustomer.PrivateDescSeg2);
  58. strHead.AppendLine("Department:" + ModifyCustomer.Department);
  59. strHead.AppendLine("Saleser:" + ModifyCustomer.Saleser);
  60. //strHead.AppendLine("IsEffective:" + ModifyCustomer.IsEffective );
  61. strHead.AppendLine("***************接口传入参数End");
  62. Appconfig.WriteLogFile(strHead.ToString(), MessageLogName);
  63. Return.CustomerCode = ModifyCustomer.Code;
  64. string QueryMessage = "";//修改前的错误信息
  65. if (string.IsNullOrEmpty(ModifyCustomer.ORGCode))
  66. {
  67. ModifyCustomer.ORGCode = ConfigurationManager.AppSettings["orgCode"].ToString();
  68. }
  69. #region check
  70. if (string.IsNullOrEmpty(ModifyCustomer.Code))
  71. {
  72. QueryMessage += "客户编码为空";
  73. }
  74. #endregion
  75. if (string.IsNullOrEmpty(QueryMessage))
  76. {
  77. //上下文信息
  78. object context;
  79. context = CreateContextObj();
  80. UFIDAU9CBOPubControllerContextDTOData contextDTO = new UFIDAU9CBOPubControllerContextDTOData();
  81. contextDTO = CreateContextDto();
  82. #region 修改服务调用框架结构
  83. //修改SV
  84. UFIDAU9ISVCustomerIBatchModifyCustomerByDTOSVClient client = new UFIDAU9ISVCustomerIBatchModifyCustomerByDTOSVClient();
  85. //服务返回结果
  86. UFIDAU9CBOSCMCustomerCustomerData[] returnCustomers;
  87. UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;//修改返回的报错
  88. #endregion
  89. #region 查询服务调用框架结构
  90. //查询SV
  91. UFIDAU9ISVCustomerIBatchQueryCustomerByDTOSRVClient Qclient = new global::UFIDAU9ISVCustomerIBatchQueryCustomerByDTOSRVClient();
  92. //服务返回结果
  93. UFIDAU9ISVCustomerCustomerDTOData[] QreturnCustomers;//查询返回的客户类
  94. UFSoft.UBF.Exceptions1.MessageBase[] QreturnMsg;//查询返回的报错
  95. #endregion
  96. //先查询
  97. List<UFIDAU9ISVCustomerQueryCustomerDTOData> QDTOS = new List<UFIDAU9ISVCustomerQueryCustomerDTOData>();
  98. UFIDAU9ISVCustomerQueryCustomerDTOData CC = new UFIDAU9ISVCustomerQueryCustomerDTOData();
  99. CC.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  100. CC.m_org.m_code = ModifyCustomer.ORGCode;
  101. CC.m_customer = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  102. CC.m_customer.m_code = ModifyCustomer.Code;
  103. QDTOS.Add(CC);
  104. QreturnCustomers = Qclient.Do(out QreturnMsg, context, QDTOS.ToArray(), contextDTO);
  105. if (QreturnCustomers == null || QreturnCustomers.Count() == 0)
  106. {
  107. throw new Exception("组织:" + ModifyCustomer.ORGCode + ",未找到客户编码:" + ModifyCustomer.Code);
  108. }
  109. //后修改
  110. if (QreturnMsg != null && QreturnMsg.Length > 0)
  111. {
  112. foreach (UFSoft.UBF.Exceptions1.MessageBase MESS in QreturnMsg)
  113. {
  114. QueryMessage += MESS.innerMessages + ";";
  115. }
  116. }
  117. if (string.IsNullOrEmpty(QueryMessage))
  118. {
  119. List<UFIDAU9ISVCustomerCustomerDTOData> OLDList = QreturnCustomers.ToList();
  120. UFIDAU9ISVCustomerCustomerDTOData OldCus = OLDList.Find(a => a.m_code == ModifyCustomer.Code && a.m_org.m_code == ModifyCustomer.ORGCode);
  121. if (OldCus != null)
  122. {
  123. Return.CustomerID = OldCus.m_iD;
  124. Return.CustomerCode = OldCus.m_code;
  125. UFIDAU9ISVCustomerCustomerDTOData cus = OldCus;
  126. cus.Name = ModifyCustomer.Name;
  127. cus.m_shortName = ModifyCustomer.Name;
  128. if (cus.m_descFlexField != null)
  129. {
  130. cus.m_descFlexField.m_privateDescSeg2 = ModifyCustomer.PrivateDescSeg2;
  131. }
  132. else
  133. {
  134. UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData deflex = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  135. deflex.m_privateDescSeg2 = ModifyCustomer.PrivateDescSeg2;
  136. cus.m_descFlexField = deflex;
  137. }
  138. if (cus.m_descFlexField != null)
  139. {
  140. cus.m_descFlexField.m_privateDescSeg7 = ModifyCustomer.PrivateDescSeg7;
  141. }
  142. else
  143. {
  144. UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData deflex = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  145. deflex.m_privateDescSeg7 = ModifyCustomer.PrivateDescSeg7;
  146. cus.m_descFlexField = deflex;
  147. }
  148. if (cus.m_descFlexField != null)
  149. {
  150. cus.m_descFlexField.m_privateDescSeg8 = ModifyCustomer.PrivateDescSeg8;
  151. }
  152. else
  153. {
  154. UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData deflex = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  155. deflex.m_privateDescSeg8 = ModifyCustomer.PrivateDescSeg8;
  156. cus.m_descFlexField = deflex;
  157. }
  158. if (cus.m_descFlexField != null)
  159. {
  160. cus.m_descFlexField.m_privateDescSeg11 = ModifyCustomer.PrivateDescSeg11;
  161. }
  162. else
  163. {
  164. UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData deflex = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  165. deflex.m_privateDescSeg11 = ModifyCustomer.PrivateDescSeg11;
  166. cus.m_descFlexField = deflex;
  167. }
  168. if (!string.IsNullOrEmpty(ModifyCustomer.Department))
  169. {
  170. string DepID = GetDepartmentID(ModifyCustomer.Department, ModifyCustomer.ORGCode);
  171. if (string.IsNullOrEmpty(DepID))
  172. {
  173. throw new Exception("部门编码:" + ModifyCustomer.Department + "在组织:" + ModifyCustomer.ORGCode + "中不存在");
  174. }
  175. else
  176. {
  177. UFIDAU9CBOPubControllerCommonArchiveDataDTOData dep = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  178. dep.m_code = ModifyCustomer.Department;
  179. dep.m_iD = Convert.ToInt64(DepID);
  180. cus.m_department = dep;
  181. }
  182. }
  183. if (!string.IsNullOrEmpty(ModifyCustomer.Saleser))
  184. {
  185. string SalerID = GetOperatorsID(ModifyCustomer.Saleser, ModifyCustomer.ORGCode);
  186. if (string.IsNullOrEmpty(SalerID))
  187. {
  188. throw new Exception("业务员编码:" + ModifyCustomer.Department + "在组织:" + ModifyCustomer.ORGCode + "中不存在");
  189. }
  190. else
  191. {
  192. UFIDAU9CBOPubControllerCommonArchiveDataDTOData saleser = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  193. saleser.m_code = ModifyCustomer.Saleser;
  194. saleser.m_iD = Convert.ToInt64(SalerID);
  195. cus.m_saleser = saleser;
  196. }
  197. }
  198. if (cus.m_effective != null)
  199. {
  200. //cus.m_effective.m_isEffective = ModifyCustomer.IsEffective;
  201. cus.m_effective.m_isEffective = true;
  202. }
  203. else
  204. {
  205. UFIDAU9BasePropertyTypesEffectiveData ee = new UFIDAU9BasePropertyTypesEffectiveData();
  206. //cus.m_effective.m_isEffective = ModifyCustomer.IsEffective;
  207. cus.m_effective.m_isEffective = true;
  208. ee.m_effectiveDate = DateTime.Now;
  209. cus.m_effective = ee;
  210. }
  211. if (cus.m_effective.m_isEffective)
  212. {
  213. cus.m_effective.m_disableDate = Convert.ToDateTime("9999.12.31");
  214. }
  215. else
  216. {
  217. cus.m_effective.m_disableDate = DateTime.Now;
  218. }
  219. #region 获取立账条件名称
  220. string ARConfirmTermName = "";
  221. string ARConfirmTermID = "";
  222. string ctermrsql = @"select a.ID,a.Code,b.Name from CBO_ARConfirmTerm a
  223. left join CBO_ARConfirmTerm_Trl b on a.id=b.id
  224. left join Base_Organization j on a.Org=j.ID
  225. where a.Code='{0}' AND j.Code='{1}'";
  226. ctermrsql = string.Format(ctermrsql, ModifyCustomer.ARConfirmTerm, ModifyCustomer.ORGCode);
  227. DataTable ctermdt2 = DBhlper.Query(ctermrsql, Appconfig.GetU9ConnStr());
  228. if (ctermdt2.Rows.Count != 0)
  229. {
  230. ARConfirmTermName = ctermdt2.Rows[0]["Name"].ToString();
  231. ARConfirmTermID = ctermdt2.Rows[0]["ID"].ToString();
  232. }
  233. else
  234. {
  235. throw new Exception("未获取到立账条件名称:" + ModifyCustomer.ARConfirmTerm + "对应ID");
  236. }
  237. #endregion
  238. cus.m_aRConfirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();//立账条件
  239. cus.m_aRConfirmTerm.m_iD = long.Parse(ARConfirmTermID);
  240. cus.m_aRConfirmTerm.m_code = ModifyCustomer.ARConfirmTerm;
  241. cus.m_descFlexField.m_privateDescSeg1 = "0";//欠回单数
  242. cus.m_descFlexField.m_privateDescSeg3 = "02";//是否逾期
  243. cus.m_descFlexField.m_privateDescSeg4 = "01";//是否拆分
  244. if (ARConfirmTermName == "月结30天")
  245. {
  246. cus.m_descFlexField.m_privateDescSeg6 = "30";//信用期限
  247. }
  248. else if (ARConfirmTermName == "月结60天")
  249. {
  250. cus.m_descFlexField.m_privateDescSeg6 = "60";
  251. }
  252. else if (ARConfirmTermName == "月结90天")
  253. {
  254. cus.m_descFlexField.m_privateDescSeg6 = "90";
  255. }
  256. else if (ARConfirmTermName == "月结360天")
  257. {
  258. cus.m_descFlexField.m_privateDescSeg6 = "360";
  259. }
  260. else
  261. {
  262. cus.m_descFlexField.m_privateDescSeg6 = "0";
  263. }
  264. cus.m_isCreditCheck = false;//信用检查
  265. #region 客户位置
  266. //UFIDAU9ISVCustomerCustomerSiteDTOData custSiteInfo = new UFIDAU9ISVCustomerCustomerSiteDTOData();
  267. //List<UFIDAU9ISVCustomerCustomerSiteDTOData> custSiteList = new List<UFIDAU9ISVCustomerCustomerSiteDTOData>();
  268. //UFIDAU9ISVCustomerCustomerSiteDTOData[] custSites;
  269. //custSiteInfo.m_code = ModifyCustomer.SiteCode;
  270. //custSiteInfo.Name = ModifyCustomer.SiteName;
  271. //custSiteInfo.m_isDefaultBillTo = true;//默认开票位置
  272. //custSiteInfo.m_customerState = 1;//目标客户
  273. //custSiteInfo.m_isPriceListModify = true; // 价表可改
  274. //custSiteInfo.m_isShippmentRuleEditable = true; // 出货原则可改
  275. //custSiteInfo.m_isPaymentTermEditable = true; // 收款条件可改
  276. //custSiteInfo.m_isSalesDiscount = true;
  277. //custSiteInfo.m_shipmentMode = 1;
  278. //custSiteInfo.m_isPostBankCheckList = true;
  279. //custSiteInfo.m_bankCheckPeriod = 3;
  280. //custSiteInfo.m_isPrePayment = false;
  281. //custSiteInfo.m_holdDate = DateTime.Now;
  282. //custSiteInfo.m_releaseDate = DateTime.Now;
  283. //custSiteInfo.m_isHoldRelease = false;
  284. //custSiteInfo.m_priceListID = -1;
  285. //custSiteInfo.m_invoiceVerificationOrder = 1;
  286. //custSiteInfo.m_supplySource = 3;
  287. //custSiteInfo.m_demandTransType = 3;
  288. //custSiteInfo.m_effective = new UFIDAU9BasePropertyTypesEffectiveData();
  289. //custSiteInfo.m_effective.m_isEffective = true;
  290. //custSiteInfo.m_effective.m_effectiveDate = DateTime.Parse("2021-11-01");
  291. //custSiteInfo.m_effective.m_disableDate = DateTime.Parse("2099-01-01");
  292. //custSiteInfo.m_supplyOrg = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  293. //custSiteInfo.m_supplyOrg.m_iD = long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
  294. //custSiteInfo.m_supplier = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  295. //custSiteInfo.m_aRConfirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();//立账条件
  296. //custSiteInfo.m_aRConfirmTerm.m_iD = long.Parse(ARConfirmTermID);
  297. //custSiteInfo.m_aRConfirmTerm.m_code = ModifyCustomer.ARConfirmTerm;
  298. //custSiteList.Add(custSiteInfo);
  299. //custSites = custSiteList.ToArray();
  300. //cus.m_customerSiteDTOs = custSites;
  301. #endregion
  302. List<UFIDAU9ISVCustomerCustomerDTOData> NewList = new List<UFIDAU9ISVCustomerCustomerDTOData>();
  303. NewList.Add(cus);
  304. returnCustomers = client.Do(out returnMsg, context, NewList.ToArray(), contextDTO);
  305. string errmessage = "";
  306. if (returnMsg != null && returnMsg.Count() > 0)
  307. {
  308. foreach (UFSoft.UBF.Exceptions1.MessageBase ee in returnMsg)
  309. {
  310. errmessage += ee.innerMessages + ";";
  311. }
  312. Return.IsSuccess = false;
  313. Return.MESSAGE = errmessage;
  314. }
  315. else
  316. {
  317. Return.IsSuccess = true;
  318. Return.MESSAGE = "组织:" + ModifyCustomer.ORGCode + ",客户:" + ModifyCustomer.Code + "修改成功";
  319. if (!string.IsNullOrWhiteSpace(ARConfirmTermID))
  320. {
  321. string SiteID = "";
  322. long CusID = 0;
  323. #region 获取组织ID
  324. string OrgID = "";
  325. string orgsql = @"select ID from Base_Organization
  326. where Code='{0}'";
  327. orgsql = string.Format(orgsql, ModifyCustomer.ORGCode);
  328. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  329. if (orgdt.Rows.Count != 0)
  330. {
  331. OrgID = orgdt.Rows[0]["ID"].ToString();
  332. }
  333. #endregion
  334. string cussql = @"select ID,State from CBO_Customer
  335. where Code='{0}' AND Org='{1}'";
  336. cussql = string.Format(cussql, ModifyCustomer.Code, OrgID);
  337. DataTable cusdt = DBhlper.Query(cussql, Appconfig.GetU9ConnStr());
  338. if (cusdt.Rows.Count > 0)
  339. {
  340. CusID = long.Parse(cusdt.Rows[0]["ID"].ToString());
  341. #region 获取位置ID
  342. string sitesql = @"select ID from CBO_CustomerSite
  343. where Customer='{0}'";
  344. sitesql = string.Format(sitesql, CusID);
  345. DataTable sitedt = DBhlper.Query(sitesql, Appconfig.GetU9ConnStr());
  346. if (sitedt.Rows.Count != 0)
  347. {
  348. SiteID = sitedt.Rows[0]["ID"].ToString();
  349. }
  350. #endregion
  351. if (!string.IsNullOrWhiteSpace(SiteID))
  352. {
  353. string updatesql = @" update CBO_CustomerSite set ARConfirmTerm='{0}',Customer='{2}' where ID='{1}'
  354. update CBO_CustomerSite_trl set name='{3}' where ID='{1}' ";
  355. updatesql = string.Format(updatesql, ARConfirmTermID, SiteID, CusID, ModifyCustomer.Name);
  356. DBhlper.Query(updatesql, Appconfig.GetU9ConnStr());
  357. }
  358. }
  359. }
  360. }
  361. }
  362. else
  363. {
  364. Return.IsSuccess = false;
  365. Return.MESSAGE = "组织:" + ModifyCustomer.ORGCode + "下未找到客户:" + ModifyCustomer.Code;
  366. }
  367. }
  368. else
  369. {
  370. Return.IsSuccess = false;
  371. Return.MESSAGE = QueryMessage;
  372. }
  373. }
  374. else
  375. {
  376. Return.IsSuccess = false;
  377. Return.MESSAGE = QueryMessage;
  378. }
  379. }
  380. else
  381. {
  382. Return.IsSuccess = false;
  383. Return.MESSAGE = "传入的客户信息为空";
  384. }
  385. }
  386. catch (Exception ex)
  387. {
  388. Return.IsSuccess = false;
  389. Return.MESSAGE = GetExceptionMessage(ex);
  390. }
  391. StringBuilder strHeadr = new StringBuilder();
  392. strHeadr.AppendLine("-------------接口传出参数:");
  393. strHeadr.AppendLine("IsSuccess:" + Return.IsSuccess);
  394. strHeadr.AppendLine("MESSAGE:" + Return.MESSAGE);
  395. strHeadr.AppendLine("Code:" + Return.CustomerCode);
  396. strHeadr.AppendLine("***************接口传出参数End");
  397. Appconfig.WriteLogFile(strHeadr.ToString(), MessageLogName);
  398. return Return;
  399. }
  400. #region 给上下文信息赋值1
  401. /// <summary>
  402. /// 给上下文信息赋值
  403. /// </summary>
  404. /// <returns></returns>
  405. private ThreadContext CreateContextObj()
  406. {
  407. // 实例化应用上下文对象
  408. ThreadContext thContext = new ThreadContext();
  409. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  410. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  411. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  412. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  413. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  414. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  415. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  416. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  417. thContext.nameValueHas = ns;
  418. return thContext;
  419. }
  420. #endregion
  421. #region 给上下文信息赋值
  422. /// <summary>
  423. /// 给上下文信息赋值
  424. /// </summary>
  425. /// <returns></returns>
  426. private UFIDAU9CBOPubControllerContextDTOData CreateContextDto()
  427. {
  428. // 实例化应用上下文对象
  429. UFIDAU9CBOPubControllerContextDTOData thContext = new UFIDAU9CBOPubControllerContextDTOData();
  430. thContext.m_orgID = long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
  431. thContext.m_cultureName = ConfigurationManager.AppSettings["cultureName"].ToString();
  432. thContext.m_entCode = ConfigurationManager.AppSettings["enterpriseID"].ToString();
  433. thContext.m_orgCode = ConfigurationManager.AppSettings["orgCode"].ToString();
  434. thContext.m_userCode = ConfigurationManager.AppSettings["userCode"].ToString();
  435. thContext.m_userID = long.Parse(ConfigurationManager.AppSettings["userID"].ToString());
  436. return thContext;
  437. }
  438. #endregion
  439. private string GetDepartmentID(string Code, string ORGCode)
  440. {
  441. string sql = @"
  442. select oo.ID from CBO_Department oo
  443. inner join CBO_Department_Trl oot on oo.id=oot.id and oot.SysMLFlag='zh-CN'
  444. inner join Base_Organization org on org.id=oo.org
  445. where org.code='" + ORGCode + @"' and oo.Code='" + Code + @"'";
  446. DataTable dt = DBhlper.Query(sql, ERPConStr);
  447. if (dt != null && dt.Rows.Count > 0)
  448. {
  449. return dt.Rows[0][0].ToString();
  450. }
  451. return "";
  452. }
  453. private string GetOperatorsID(string Code, string ORGCode)
  454. {
  455. string sql = @"
  456. select oo.ID from CBO_Operators oo
  457. inner join CBO_Operators_Trl oot on oo.id=oot.id and oot.SysMLFlag='zh-CN'
  458. inner join Base_Organization org on org.id=oo.org
  459. where org.code='" + ORGCode + @"' and oo.Code='" + Code + @"'";
  460. DataTable dt = DBhlper.Query(sql, ERPConStr);
  461. if (dt != null && dt.Rows.Count > 0)
  462. {
  463. return dt.Rows[0][0].ToString();
  464. }
  465. return "";
  466. }
  467. #region 提取异常信息
  468. /// <summary>
  469. /// 提取异常信息
  470. /// </summary>
  471. /// <param name="ex"></param>
  472. private string GetExceptionMessage(Exception ex)
  473. {
  474. string faultMessage = "未知错误,请查看ERP日志!";
  475. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  476. if (timeoutEx != null)
  477. {
  478. faultMessage = "访问服务超时,请修改配置信息!";
  479. }
  480. else
  481. {
  482. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  483. if (faultEx == null)
  484. {
  485. faultMessage = ex.Message;
  486. }
  487. else
  488. {
  489. ServiceException serviceEx = faultEx.Detail;
  490. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  491. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  492. {
  493. // 错误信息在faultEx.Message中,请提取,
  494. // 格式为"Fault:料品不能为空,请录入\n 在....."
  495. int startIndex = serviceEx.Message.IndexOf(":");
  496. int endIndex = serviceEx.Message.IndexOf("\n");
  497. if (endIndex == -1)
  498. endIndex = serviceEx.Message.Length;
  499. if (endIndex > 0 && endIndex > startIndex + 1)
  500. {
  501. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  502. }
  503. else
  504. {
  505. faultMessage = serviceEx.Message;
  506. }
  507. }
  508. }
  509. }
  510. return faultMessage;
  511. }
  512. #endregion
  513. }
  514. }