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

409 lines
17 KiB

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. }
  181. else
  182. {
  183. result.IsSuccess = false;
  184. result.MESSAGE = "传入数据为空";
  185. return result;
  186. }
  187. }
  188. catch (Exception ex)
  189. {
  190. result.IsSuccess = false;
  191. result.MESSAGE = GetExceptionMessage(ex);
  192. }
  193. return result;
  194. }
  195. /// <summary>
  196. /// 创建上下文
  197. /// </summary>
  198. /// <returns></returns>
  199. private static ThreadContext CreateContextObj()
  200. {
  201. // 实例化应用上下文对象
  202. ThreadContext thContext = new ThreadContext();
  203. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  204. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  205. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  206. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  207. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  208. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  209. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  210. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  211. thContext.nameValueHas = ns;
  212. return thContext;
  213. }
  214. #region 提取异常信息
  215. /// <summary>
  216. /// 提取异常信息
  217. /// </summary>
  218. /// <param name="ex"></param>
  219. private static string GetExceptionMessage(Exception ex)
  220. {
  221. string faultMessage = "未知错误,请查看ERP日志!";
  222. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  223. if (timeoutEx != null)
  224. {
  225. faultMessage = "访问服务超时,请修改配置信息!";
  226. }
  227. else
  228. {
  229. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  230. if (faultEx == null)
  231. {
  232. faultMessage = ex.Message;
  233. }
  234. else
  235. {
  236. ServiceException serviceEx = faultEx.Detail;
  237. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  238. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  239. {
  240. // 错误信息在faultEx.Message中,请提取,
  241. // 格式为"Fault:料品不能为空,请录入\n 在....."
  242. int startIndex = serviceEx.Message.IndexOf(":");
  243. int endIndex = serviceEx.Message.IndexOf("\n");
  244. if (endIndex == -1)
  245. endIndex = serviceEx.Message.Length;
  246. if (endIndex > 0 && endIndex > startIndex + 1)
  247. {
  248. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  249. }
  250. else
  251. {
  252. faultMessage = serviceEx.Message;
  253. }
  254. }
  255. }
  256. }
  257. return faultMessage;
  258. }
  259. #endregion
  260. public class OperationResult
  261. {
  262. public bool IsSuccess { get; set; }
  263. public string MESSAGE { get; set; }
  264. public string SuppCode { get; set; }
  265. }
  266. public class Supplier
  267. {
  268. public string Code { get; set; }
  269. public string Name { get; set; }
  270. public string ShortName { get; set; }
  271. public string Category { get; set; }//分类
  272. public string Effective_EffectiveDate { get; set; }//生效日期
  273. public string APConfirmTerm { get; set; }//立账条件
  274. public string PaymentTerm { get; set; }//付款条件
  275. public string Org { get; set; }//组织
  276. public string desc1 { get; set; }//
  277. public string desc2 { get; set; }//
  278. public string StateTaxNo { get; set; }
  279. }
  280. public class CreateSupplierBankAccount
  281. {
  282. public string SupperBankCode { get; set; }
  283. public string SupperBankName { get; set; }
  284. public Bank BankAccount { get; set; }
  285. public string SupplierAccountCurrency { get; set; }
  286. //public string SupperCode { get; set; }
  287. public bool IsDefault { get; set; }
  288. public string BankAccountType { get; set; }
  289. }
  290. public class Bank
  291. {
  292. public string BankCode { get; set; }
  293. public string BankName { get; set; }
  294. public int BankStatement { get; set; } //Oppsite 日记账反向 1 否 是 否 是 Misc System.Int32
  295. //Same 日记账同向 0
  296. public string Country { get; set; } // 国家/地区
  297. public string BankCategory { get; set; }//银行类别
  298. public string UOpenAccount { get; set; }//开户行
  299. //public DateTime EffDatetime { get; set; }//
  300. //public DateTime DisDatetime { get; set; }//
  301. }
  302. public class Contact
  303. {
  304. //public string ContactCode { get; set; }
  305. public string ContactName { get; set; }
  306. public string ContactFixedPhone { get; set; }
  307. public string ContactMobilePhone { get; set; }
  308. public string ContactFax { get; set; }
  309. public string ContactMail { get; set; }
  310. public bool isDefault { get; set; }
  311. public string AddressCode { get; set; }
  312. }
  313. public class Address
  314. {
  315. public string AddressName { get; set; }
  316. public string AddressCode { get; set; }
  317. }
  318. }
  319. }