纽威
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.

159 lines
6.7 KiB

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