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

414 lines
18 KiB

2 years ago
2 years ago
2 years ago
  1. 
  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.Exceptions;
  11. using UFSoft.UBF.Service;
  12. using UFSoft.UBF.Util.Context;
  13. using www.ufida.org.EntityData;
  14. using CustCreateSupplierBankAccountSV;
  15. using CustCreateBank;
  16. using CustCreateAddress;
  17. using ICS.WCF.Base;
  18. namespace UFIDA.U9.CreateSupplier
  19. {
  20. public class CustCreateSupplier
  21. {
  22. public OperationResult CustCreateSupp(Supplier Supp)
  23. {
  24. OperationResult result = new OperationResult();
  25. try
  26. {
  27. StringBuilder beginstr = new StringBuilder();
  28. beginstr.AppendLine("-----------------------传入数据验证开始-----------------------------");
  29. beginstr.AppendLine("创建U9供应商信息");
  30. beginstr.AppendLine("供应商编码:" + Supp.Code);
  31. beginstr.AppendLine("供应商名称:" + Supp.Name);
  32. beginstr.AppendLine("供应商简称:" + Supp.ShortName);
  33. beginstr.AppendLine("分类:" + Supp.Category);
  34. beginstr.AppendLine("税号:" + Supp.StateTaxNo);
  35. beginstr.AppendLine("生效日期:" + Supp.Effective_EffectiveDate);
  36. beginstr.AppendLine("立账条件:" + Supp.APConfirmTerm);
  37. beginstr.AppendLine("付款条件:" + Supp.PaymentTerm);
  38. beginstr.AppendLine("联系人:" + Supp.desc1);
  39. beginstr.AppendLine("联系电话:" + Supp.desc2);
  40. beginstr.AppendLine("-----------------------传入数据验证结束-----------------------------");
  41. Appconfig.WriteLogFile(beginstr.ToString(), "创建U9供应商信息");
  42. //上下文信息
  43. object context;
  44. context = CreateContextObj();
  45. MessageBase[] outMessages;
  46. string SuppCode = string.Empty;
  47. if (Supp != null)
  48. {
  49. UFIDAU9CBOSCMSupplierIBatchCreateSupplierByDTOSVClient client = new UFIDAU9CBOSCMSupplierIBatchCreateSupplierByDTOSVClient();
  50. UFIDAU9CBOSCMSupplierSupplierDTOData[] suppliers = new UFIDAU9CBOSCMSupplierSupplierDTOData[] { };
  51. List<UFIDAU9CBOSCMSupplierSupplierDTOData> supplierList = new List<UFIDAU9CBOSCMSupplierSupplierDTOData>();
  52. UFIDAU9CBOSCMSupplierSupplierDTOData supplierInfo = new UFIDAU9CBOSCMSupplierSupplierDTOData();
  53. if (!string.IsNullOrWhiteSpace(Supp.Category))
  54. {
  55. supplierInfo.m_category = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  56. supplierInfo.m_category.m_code = Supp.Category;
  57. }
  58. else
  59. {
  60. result.IsSuccess = false;
  61. result.MESSAGE = "供应商分类不允许为空";
  62. return result;
  63. }
  64. if (string.IsNullOrWhiteSpace(Supp.Code))
  65. {
  66. result.IsSuccess = false;
  67. result.MESSAGE = "供应商编码不允许为空";
  68. return result;
  69. }
  70. if (string.IsNullOrWhiteSpace(Supp.StateTaxNo))
  71. {
  72. result.IsSuccess = false;
  73. result.MESSAGE = "税号不允许为空";
  74. return result;
  75. }
  76. SuppCode = Supp.Code;
  77. supplierInfo.m_code = SuppCode;
  78. supplierInfo.Name = Supp.Name;
  79. supplierInfo.m_shortName = Supp.ShortName;
  80. supplierInfo.m_isPriceListModify = true;//价目表可改
  81. supplierInfo.m_isReceiptRuleEditable = true; // 收货原则可改
  82. supplierInfo.m_isPaymentTermModify = true; // 付款条件可改
  83. supplierInfo.m_isAPConfirmTermEditable = true; //立账条件可改
  84. string StateTaxNo = "";
  85. string sqlWH = @"select StateTaxNo from CBO_Supplier where StateTaxNo <>'' and StateTaxNo='"+Supp.StateTaxNo+"' ";
  86. sqlWH = string.Format(sqlWH);
  87. DataTable _dtWH = DBhlper.Query(sqlWH, Appconfig.GetU9ConnStr());
  88. string WHCode = string.Empty;
  89. if (_dtWH != null && _dtWH.Rows.Count > 0)
  90. {
  91. StateTaxNo = _dtWH.Rows[0][0].ToString();
  92. }
  93. if (string.IsNullOrWhiteSpace(WHCode))
  94. supplierInfo.m_stateTaxNo = Supp.StateTaxNo;
  95. else
  96. throw new Exception("税号已被使用请重新输入!");
  97. //SupplierBankAccount
  98. //supplierInfo.m_supplierSiteDTOs
  99. UFIDAU9CBOPubControllerCommonArchiveDataDTOData m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  100. m_org.m_code = ConfigurationManager.AppSettings["orgCode"].ToString();//"01";// Supp.Org;
  101. supplierInfo.m_org = m_org;
  102. supplierInfo.m_receiptRule = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  103. supplierInfo.m_receiptRule.m_code = "01";// Supp.ReceiptRule;//收货原则
  104. UFIDAU9BasePropertyTypesEffectiveData m_effective = new UFIDAU9BasePropertyTypesEffectiveData();
  105. //m_effective.m_effectiveDate = new DateTime(2022, 9, 1);
  106. m_effective.m_effectiveDate = Convert.ToDateTime(Supp.Effective_EffectiveDate);// DateTime.Now.AddDays(-1);
  107. m_effective.m_disableDate = new DateTime(9999, 12, 31);
  108. m_effective.m_isEffective = true;
  109. supplierInfo.m_effective = m_effective;
  110. #region 供应商1
  111. supplierInfo.m_paymentTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  112. supplierInfo.m_paymentTerm.m_code = Supp.PaymentTerm; ;//付款条件
  113. List<UFIDAU9CBOSCMSupplierSupplierSiteDTOData> supplierSiteList = new List<UFIDAU9CBOSCMSupplierSupplierSiteDTOData>();
  114. supplierInfo.m_supplierSiteDTOs = new UFIDAU9CBOSCMSupplierSupplierSiteDTOData[] { };
  115. UFIDAU9CBOSCMSupplierSupplierSiteDTOData supplierSiteInfo = new UFIDAU9CBOSCMSupplierSupplierSiteDTOData();
  116. supplierSiteInfo.m_code = SuppCode;
  117. supplierSiteInfo.Name = Supp.Name;
  118. supplierSiteInfo.m_isDefaultBillTo = true;
  119. supplierSiteInfo.m_isPriceListModify = true;//价目表可改
  120. supplierSiteInfo.m_isReceiptRuleModify = true; // 收货原则可改
  121. supplierSiteInfo.m_isPayItemEditable = true; // 付款条件可改
  122. #region 201912114
  123. supplierSiteInfo.m_isShipTo = true;
  124. supplierSiteInfo.m_isBillTo = true;
  125. supplierSiteInfo.m_isClaim = true;
  126. supplierSiteInfo.m_isContrast = true;
  127. supplierSiteInfo.m_isRemit = true;
  128. supplierSiteInfo.m_isInquire = true;
  129. supplierSiteInfo.m_isDefaultShipTo = true;
  130. supplierSiteInfo.m_isDefaultBillTo = true;
  131. supplierSiteInfo.m_isDefaultClaim = true;
  132. supplierSiteInfo.m_isDefaultContrast = true;
  133. supplierSiteInfo.m_isDefaultRemit = true;
  134. supplierSiteInfo.m_isDefaultInquire = true;
  135. supplierSiteInfo.m_receiptRule = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  136. supplierSiteInfo.m_receiptRule.m_code = "01";// Supp.ReceiptRule;//收货原则
  137. supplierSiteInfo.m_paymentTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  138. supplierSiteInfo.m_paymentTerm.m_code = "YZ01"; //Supp.Payment; ;//付款条件
  139. supplierSiteInfo.m_aPConfirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  140. supplierSiteInfo.m_aPConfirmTerm.m_code = Supp.APConfirmTerm; //立账条件
  141. supplierSiteInfo.m_invoiceVerificationDetail = 0;// Supp.InvoiceVerificationDetai;//核销明细
  142. supplierSiteInfo.m_invoiceVerificationOrder = 1;
  143. supplierSiteInfo.m_docVerificationOrder = 1;
  144. supplierSiteInfo.m_effective = new UFIDAU9BasePropertyTypesEffectiveData();
  145. supplierSiteInfo.m_effective.m_isEffective = true;
  146. supplierSiteInfo.m_effective.m_effectiveDate = Convert.ToDateTime(Supp.Effective_EffectiveDate); //DateTime.Now.AddDays(-1);
  147. supplierSiteInfo.m_effective.m_disableDate = new DateTime(9999, 12, 31);
  148. //supplierSiteInfo.m_createdOn = DateTime.Now.AddDays(-1);
  149. //SupplierBankAccount
  150. supplierSiteInfo.m_defaultBankAccount = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  151. #endregion
  152. supplierSiteList.Add(supplierSiteInfo);
  153. supplierInfo.m_supplierSiteDTOs = supplierSiteList.ToArray();
  154. #endregion
  155. supplierInfo.m_invoiceVerificationDetai = 1;
  156. supplierInfo.m_invoiceVerificationOrder = 1;
  157. supplierInfo.m_docVerificationOrder = 1;
  158. supplierInfo.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  159. if (!string.IsNullOrWhiteSpace(Supp.desc1))
  160. {
  161. supplierInfo.m_descFlexField.m_privateDescSeg1 = Supp.desc1;
  162. }
  163. if (!string.IsNullOrWhiteSpace(Supp.desc2))
  164. {
  165. supplierInfo.m_descFlexField.m_privateDescSeg2 = Supp.desc2;
  166. }
  167. //supplierInfo.m_contactObject = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  168. //supplierInfo.m_contactObject.m_code = SuppCode;
  169. supplierInfo.m_ourSideSupplyRecRefStd = 1;// Supp.OutSide;
  170. supplierInfo.m_paymentTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  171. supplierInfo.m_paymentTerm.m_code = "YZ01";//Supp.Payment;
  172. supplierInfo.m_aPConfirmTerm = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  173. supplierInfo.m_aPConfirmTerm.m_code = Supp.APConfirmTerm;
  174. supplierList.Add(supplierInfo);
  175. suppliers = supplierList.ToArray();
  176. UFIDAU9CBOSCMSupplierSupplierData[] returnMsg = client.Do(out outMessages, context, suppliers);
  177. result.IsSuccess = true;
  178. result.MESSAGE = "创建供应商成功";
  179. result.SuppCode = SuppCode;
  180. if (result.IsSuccess)
  181. {
  182. string Updatesql = @"UPDATE CBO_Supplier SET IsTaxPrice=1 WHERE Code='" + SuppCode + "' ";
  183. Updatesql = string.Format(Updatesql);
  184. DBhlper.Query(Updatesql, Appconfig.GetU9ConnStr());
  185. }
  186. }
  187. else
  188. {
  189. result.IsSuccess = false;
  190. result.MESSAGE = "传入数据为空";
  191. return result;
  192. }
  193. }
  194. catch (Exception ex)
  195. {
  196. result.IsSuccess = false;
  197. result.MESSAGE = GetExceptionMessage(ex);
  198. }
  199. return result;
  200. }
  201. /// <summary>
  202. /// 创建上下文
  203. /// </summary>
  204. /// <returns></returns>
  205. private static ThreadContext CreateContextObj()
  206. {
  207. // 实例化应用上下文对象
  208. ThreadContext thContext = new ThreadContext();
  209. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  210. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  211. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  212. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  213. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  214. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  215. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  216. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  217. thContext.nameValueHas = ns;
  218. return thContext;
  219. }
  220. #region 提取异常信息
  221. /// <summary>
  222. /// 提取异常信息
  223. /// </summary>
  224. /// <param name="ex"></param>
  225. private static string GetExceptionMessage(Exception ex)
  226. {
  227. string faultMessage = "未知错误,请查看ERP日志!";
  228. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  229. if (timeoutEx != null)
  230. {
  231. faultMessage = "访问服务超时,请修改配置信息!";
  232. }
  233. else
  234. {
  235. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  236. if (faultEx == null)
  237. {
  238. faultMessage = ex.Message;
  239. }
  240. else
  241. {
  242. ServiceException serviceEx = faultEx.Detail;
  243. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  244. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  245. {
  246. // 错误信息在faultEx.Message中,请提取,
  247. // 格式为"Fault:料品不能为空,请录入\n 在....."
  248. int startIndex = serviceEx.Message.IndexOf(":");
  249. int endIndex = serviceEx.Message.IndexOf("\n");
  250. if (endIndex == -1)
  251. endIndex = serviceEx.Message.Length;
  252. if (endIndex > 0 && endIndex > startIndex + 1)
  253. {
  254. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  255. }
  256. else
  257. {
  258. faultMessage = serviceEx.Message;
  259. }
  260. }
  261. }
  262. }
  263. return faultMessage;
  264. }
  265. #endregion
  266. public class OperationResult
  267. {
  268. public bool IsSuccess { get; set; }
  269. public string MESSAGE { get; set; }
  270. public string SuppCode { get; set; }
  271. }
  272. public class Supplier
  273. {
  274. public string Code { get; set; }
  275. public string Name { get; set; }
  276. public string ShortName { get; set; }
  277. public string Category { get; set; }//分类
  278. public string Effective_EffectiveDate { get; set; }//生效日期
  279. public string APConfirmTerm { get; set; }//立账条件
  280. public string PaymentTerm { get; set; }//付款条件
  281. public string Org { get; set; }//组织
  282. public string desc1 { get; set; }//
  283. public string desc2 { get; set; }//
  284. public string StateTaxNo { get; set; }
  285. }
  286. public class CreateSupplierBankAccount
  287. {
  288. public string SupperBankCode { get; set; }
  289. public string SupperBankName { get; set; }
  290. public Bank BankAccount { get; set; }
  291. public string SupplierAccountCurrency { get; set; }
  292. //public string SupperCode { get; set; }
  293. public bool IsDefault { get; set; }
  294. public string BankAccountType { get; set; }
  295. }
  296. public class Bank
  297. {
  298. public string BankCode { get; set; }
  299. public string BankName { get; set; }
  300. public int BankStatement { get; set; } //Oppsite 日记账反向 1 否 是 否 是 Misc System.Int32
  301. //Same 日记账同向 0
  302. public string Country { get; set; } // 国家/地区
  303. public string BankCategory { get; set; }//银行类别
  304. public string UOpenAccount { get; set; }//开户行
  305. //public DateTime EffDatetime { get; set; }//
  306. //public DateTime DisDatetime { get; set; }//
  307. }
  308. public class Contact
  309. {
  310. //public string ContactCode { get; set; }
  311. public string ContactName { get; set; }
  312. public string ContactFixedPhone { get; set; }
  313. public string ContactMobilePhone { get; set; }
  314. public string ContactFax { get; set; }
  315. public string ContactMail { get; set; }
  316. public bool isDefault { get; set; }
  317. public string AddressCode { get; set; }
  318. }
  319. public class Address
  320. {
  321. public string AddressName { get; set; }
  322. public string AddressCode { get; set; }
  323. }
  324. }
  325. }