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

175 lines
7.3 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.ServiceModel;
  6. using System.Text;
  7. using ICS.WCF.Base;
  8. using UFSoft.UBF.Exceptions1;
  9. using UFSoft.UBF.Service;
  10. using UFSoft.UBF.Util.Context;
  11. using UFSoft.UBF.Exceptions;
  12. using UFIDA.ISV.BFRCVApprove;
  13. namespace UFIDA.ISV.BFRCVDelete
  14. {
  15. public class CustBFRCVDelete
  16. {
  17. public static void CustDeleteRCV(List<string> DocList, string OrgID)
  18. {
  19. long DocID = 0;
  20. string EntityType = "";
  21. #region 服务调用框架结构
  22. //实例化代理类
  23. UFIDAU9PMRcvIDeleteRCVSRVClient client = new UFIDAU9PMRcvIDeleteRCVSRVClient();
  24. //服务返回结果
  25. //UFIDAU9PMPOPurchaseOrderData[] returnItems;
  26. //返回异常信息,目前还没有使用此属性
  27. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  28. //上下文信息
  29. object context;
  30. //传入 参数
  31. //UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
  32. UFSoft.UBF.Business.BusinessEntity.EntityKey[] docArray = new UFSoft.UBF.Business.BusinessEntity.EntityKey[] { };
  33. List<UFSoft.UBF.Business.BusinessEntity.EntityKey> docList = new List<UFSoft.UBF.Business.BusinessEntity.EntityKey>();
  34. try
  35. {
  36. foreach (string DocCode in DocList)
  37. {
  38. DataTable dt = GetData(DocCode, OrgID);
  39. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()) || !string.IsNullOrEmpty(dt.Rows[0][1].ToString()))
  40. {
  41. DocID = long.Parse(dt.Rows[0][0].ToString());
  42. EntityType = dt.Rows[0][1].ToString();
  43. //审核完成的单据需要先弃审,后删除
  44. if (dt.Rows[0][2].ToString() == "5")
  45. {
  46. CustBFRCVApprove.CustApproveRec(DocCode, OrgID, "弃审");
  47. }
  48. }
  49. else
  50. {
  51. throw new Exception("需要删除的单据号不正确!");
  52. }
  53. UFSoft.UBF.Business.BusinessEntity.EntityKey docinfo = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  54. //给传入参数赋值
  55. docinfo.ID = DocID;
  56. docList.Add(docinfo);
  57. docArray = docList.ToArray();
  58. }
  59. //给上下文信息赋值
  60. context = CreateContextObj(OrgID);
  61. //pOList = SetPoDtos(U9Info, poInfoList);
  62. //服务调用
  63. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  64. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  65. returnMsg = client.Do(context, docArray);
  66. }
  67. catch (Exception ex)
  68. {
  69. StringBuilder str = new StringBuilder();
  70. str.AppendLine("删除入库单");
  71. //str.AppendLine("单号:" + DocCode);
  72. str.AppendLine("错误:" + GetExceptionMessage(ex));
  73. str.AppendLine("结果:" + "False");
  74. Appconfig.WriteLogFile(str.ToString(), "删除入库单");
  75. ReturnValue1 value = new ReturnValue1();
  76. //异常信息捕获
  77. value.Mes = GetExceptionMessage(ex);
  78. value.IsSuccess = false;
  79. }
  80. #endregion
  81. }
  82. private static DataTable GetData(string DocCode, string OrgID)
  83. {
  84. string sql = @"select A.ID,A1.[Code] as [Receivement_RcvDocType_Code],A.Status
  85. from PM_Receivement as A
  86. left join [PM_RcvDocType] as A1 on (A.[RcvDocType] = A1.[ID])
  87. left join [PM_RcvDocType_Trl] as A2 on (A2.SysMlFlag = 'zh-CN') and (A1.[ID] = A2.[ID])
  88. where A.DocNo='" + DocCode + "' AND A.Org='" + OrgID + "'";
  89. return DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  90. }
  91. #region 提取异常信息
  92. /// <summary>
  93. /// 提取异常信息
  94. /// </summary>
  95. /// <param name="ex"></param>
  96. private static string GetExceptionMessage(Exception ex)
  97. {
  98. string faultMessage = "未知错误,请查看ERP日志!";
  99. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  100. if (timeoutEx != null)
  101. {
  102. faultMessage = "访问服务超时,请修改配置信息!";
  103. }
  104. else
  105. {
  106. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  107. if (faultEx == null)
  108. {
  109. faultMessage = ex.Message;
  110. }
  111. else
  112. {
  113. ServiceException serviceEx = faultEx.Detail;
  114. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  115. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  116. {
  117. // 错误信息在faultEx.Message中,请提取,
  118. // 格式为"Fault:料品不能为空,请录入\n 在....."
  119. int startIndex = serviceEx.Message.IndexOf(":");
  120. int endIndex = serviceEx.Message.IndexOf("\n");
  121. if (endIndex == -1)
  122. endIndex = serviceEx.Message.Length;
  123. if (endIndex > 0 && endIndex > startIndex + 1)
  124. {
  125. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  126. }
  127. else
  128. {
  129. faultMessage = serviceEx.Message;
  130. }
  131. }
  132. }
  133. }
  134. return faultMessage;
  135. }
  136. #endregion
  137. #region 给上下文信息赋值
  138. /// <summary>
  139. /// 给上下文信息赋值
  140. /// </summary>
  141. /// <returns></returns>
  142. private static ThreadContext CreateContextObj(string OrgID)
  143. {
  144. // 实例化应用上下文对象
  145. ThreadContext thContext = new ThreadContext();
  146. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  147. ns.Add("OrgID", OrgID);
  148. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  149. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  150. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  151. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  152. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  153. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  154. thContext.nameValueHas = ns;
  155. return thContext;
  156. }
  157. #endregion
  158. public class ReturnValue1//List<rtnPoinfo>
  159. {
  160. public bool IsSuccess;
  161. public string Mes;
  162. public MessageBase[] poheadList;
  163. }
  164. }
  165. }