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

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