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

165 lines
7.1 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. namespace UFIDA.ISV.BFPMRecedeDelete
  13. {
  14. public class CustDeleteBFPMRecede
  15. {
  16. public static void CustBFPMRecedeDelete(List<string> DocCodeList, string OrgID)
  17. {
  18. long DocID = 0;
  19. string EntityType = "";
  20. #region 服务调用框架结构
  21. //实例化代理类
  22. UFIDAU9ISVPMIssueIDeletePMIssue4ExternalClient client = new UFIDAU9ISVPMIssueIDeletePMIssue4ExternalClient();
  23. //服务返回结果
  24. //UFIDAU9PMPOPurchaseOrderData[] returnItems;
  25. //返回异常信息,目前还没有使用此属性
  26. UFSoft.UBF.Exceptions.MessageBase[] outMessages;
  27. bool isSuccess = false;
  28. //上下文信息
  29. object context;
  30. //传入 参数
  31. //UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
  32. www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData[] docArray = new www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData[] { };
  33. List<www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData> docList = new List<www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData>();
  34. try
  35. {
  36. foreach (string DocCode in DocCodeList)
  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() == "2")
  45. {
  46. List<string> DocList = new List<string>();
  47. DocList.Add(DocCode);
  48. BFPMRecedeApprove.CustApproveBFPMRecede PMRecedeApprove = new BFPMRecedeApprove.CustApproveBFPMRecede();
  49. PMRecedeApprove.CustBFPMRecedeApprove(DocList, OrgID, "弃审");
  50. }
  51. }
  52. else
  53. {
  54. throw new Exception("需要删除的单据号不正确!");
  55. }
  56. www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData docinfo = new www.ufida.org.EntityData.UFIDAU9ISVPMIssuePMIssueKeyDTOData();
  57. //给传入参数赋值
  58. docinfo.m_iD = DocID;
  59. docList.Add(docinfo);
  60. }
  61. docArray = docList.ToArray();
  62. //给上下文信息赋值
  63. context = CreateContextObj(OrgID);
  64. //pOList = SetPoDtos(U9Info, poInfoList);
  65. //服务调用
  66. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  67. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  68. isSuccess = client.Do(out outMessages, context, docArray);
  69. }
  70. catch (Exception ex)
  71. {
  72. StringBuilder str = new StringBuilder();
  73. str.AppendLine("删除委外退料单");
  74. //str.AppendLine("单号:" + DocCode);
  75. str.AppendLine("错误:" + GetExceptionMessage(ex));
  76. str.AppendLine("结果:" + "False");
  77. Appconfig.WriteLogFile(str.ToString(), "删除委外退料单");
  78. }
  79. #endregion
  80. }
  81. private static DataTable GetData(string DocCode, string OrgID)
  82. {
  83. string sql = @"select ID,DocNO,DocState from PM_IssueDoc
  84. where DOCNO='" + DocCode + "' AND Org='" + OrgID + "'";
  85. return DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  86. }
  87. #region 提取异常信息
  88. /// <summary>
  89. /// 提取异常信息
  90. /// </summary>
  91. /// <param name="ex"></param>
  92. private static string GetExceptionMessage(Exception ex)
  93. {
  94. string faultMessage = "未知错误,请查看ERP日志!";
  95. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  96. if (timeoutEx != null)
  97. {
  98. faultMessage = "访问服务超时,请修改配置信息!";
  99. }
  100. else
  101. {
  102. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  103. if (faultEx == null)
  104. {
  105. faultMessage = ex.Message;
  106. }
  107. else
  108. {
  109. ServiceException serviceEx = faultEx.Detail;
  110. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  111. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  112. {
  113. // 错误信息在faultEx.Message中,请提取,
  114. // 格式为"Fault:料品不能为空,请录入\n 在....."
  115. int startIndex = serviceEx.Message.IndexOf(":");
  116. int endIndex = serviceEx.Message.IndexOf("\n");
  117. if (endIndex == -1)
  118. endIndex = serviceEx.Message.Length;
  119. if (endIndex > 0 && endIndex > startIndex + 1)
  120. {
  121. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  122. }
  123. else
  124. {
  125. faultMessage = serviceEx.Message;
  126. }
  127. }
  128. }
  129. }
  130. return faultMessage;
  131. }
  132. #endregion
  133. #region 给上下文信息赋值
  134. /// <summary>
  135. /// 给上下文信息赋值
  136. /// </summary>
  137. /// <returns></returns>
  138. private static ThreadContext CreateContextObj(string OrgID)
  139. {
  140. // 实例化应用上下文对象
  141. ThreadContext thContext = new ThreadContext();
  142. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  143. ns.Add("OrgID", OrgID);
  144. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  145. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  146. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  147. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  148. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  149. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  150. thContext.nameValueHas = ns;
  151. return thContext;
  152. }
  153. #endregion
  154. }
  155. }