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

203 lines
8.0 KiB

2 years ago
  1. using ICS.WCF.Base;
  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.Exceptions1;
  11. using UFSoft.UBF.Service;
  12. using UFSoft.UBF.Util.Context;
  13. using www.ufida.org.EntityData;
  14. namespace UFIDA.ISV.BFPMRecedeApprove
  15. {
  16. public class CustApproveBFPMRecede
  17. {
  18. /// <summary>
  19. /// 审核领料单
  20. /// </summary>
  21. /// <returns></returns>
  22. ///
  23. public OperationResult CustBFPMRecedeApprove(List<string> DocCodeList, string OrgID, string Status)
  24. {
  25. OperationResult result = new OperationResult();
  26. ThreadContext context;
  27. www.ufida.org.EntityData.UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData[] returnMsg;
  28. UFSoft.UBF.Exceptions.MessageBase1[] outMessages;
  29. try
  30. {
  31. string _MOCode = string.Empty;
  32. UFIDAU9ISVPMIssueIApprovePMIssueDoc4ExternalSrvClient client = new UFIDAU9ISVPMIssueIApprovePMIssueDoc4ExternalSrvClient();
  33. //MessageBase[] message = null;
  34. List<UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData> Doclist = new List<UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData>();
  35. UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData DocNo = new UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData();
  36. UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData[] DocArray = new UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData[] { };
  37. if (DocCodeList != null && DocCodeList.Count != 0)
  38. {
  39. foreach (string Code in DocCodeList)
  40. {
  41. string checksql = @"select * from PM_IssueDoc
  42. where DocNo='" + Code + "' AND Org='" + OrgID + "'";
  43. checksql = string.Format(checksql);
  44. DataTable dtcheck = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
  45. if (dtcheck.Rows.Count == 0)
  46. {
  47. result.MESSAGE = "领料单号:'" + Code + "'不存在!";
  48. result.IsSuccess = false;
  49. return result;
  50. }
  51. else
  52. {
  53. DocNo = new UFIDAU9ISVPMIssueApprovePMIssueDoc4ExternalDTOData();
  54. DocNo.m_docNo = Code;
  55. if (Status == "审核")
  56. {
  57. DocNo.m_operateType = true;
  58. }
  59. else
  60. {
  61. DocNo.m_operateType = false;
  62. }
  63. Doclist.Add(DocNo);
  64. }
  65. }
  66. DocArray = Doclist.ToArray();
  67. }
  68. else
  69. {
  70. result.MESSAGE = "传入数据不能为空!";
  71. result.IsSuccess = false;
  72. return result;
  73. }
  74. context = CreateContextObj(OrgID);
  75. returnMsg = client.Do(out outMessages, context, DocArray.ToArray());
  76. if (returnMsg != null && returnMsg.Count() > 0)
  77. {
  78. StringBuilder str = new StringBuilder();
  79. foreach (var item in returnMsg)
  80. {
  81. result.LLCode = item.m_docNo;
  82. result.MESSAGE = item.m_errorMsg;
  83. result.IsSuccess = item.m_isSucceed;
  84. str.AppendLine("审核委外退料单:");
  85. str.AppendLine("单号:" + item.m_docNo);
  86. str.AppendLine("返回错误信息:" + item.m_errorMsg);
  87. }
  88. Appconfig.WriteLogFile(str.ToString(), "审核委外退料单");
  89. }
  90. else
  91. {
  92. result.MESSAGE = "审核成功";
  93. result.IsSuccess = true;
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. string Message = GetExceptionMessage(ex);
  99. result.IsSuccess = false;
  100. result.MESSAGE += Message;
  101. }
  102. return result;
  103. }
  104. /// <summary>
  105. /// 创建上下文
  106. /// </summary>
  107. /// <returns></returns>
  108. private static ThreadContext CreateContextObj(string OrgID)
  109. {
  110. // 实例化应用上下文对象
  111. ThreadContext thContext = new ThreadContext();
  112. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  113. ns.Add("OrgID", OrgID);
  114. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  115. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  116. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  117. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  118. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  119. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  120. ns.Add("acttype", ConfigurationManager.AppSettings["acttype"].ToString());
  121. thContext.nameValueHas = ns;
  122. return thContext;
  123. return thContext;
  124. }
  125. #region 提取异常信息
  126. /// <summary>
  127. /// 提取异常信息
  128. /// </summary>
  129. /// <param name="ex"></param>
  130. private static string GetExceptionMessage(Exception ex)
  131. {
  132. string faultMessage = "未知错误,请查看ERP日志!";
  133. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  134. if (timeoutEx != null)
  135. {
  136. faultMessage = "访问服务超时,请修改配置信息!";
  137. }
  138. else
  139. {
  140. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  141. if (faultEx == null)
  142. {
  143. faultMessage = ex.Message;
  144. }
  145. else
  146. {
  147. ServiceException serviceEx = faultEx.Detail;
  148. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  149. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  150. {
  151. // 错误信息在faultEx.Message中,请提取,
  152. // 格式为"Fault:料品不能为空,请录入\n 在....."
  153. int startIndex = serviceEx.Message.IndexOf(":");
  154. int endIndex = serviceEx.Message.IndexOf("\n");
  155. if (endIndex == -1)
  156. endIndex = serviceEx.Message.Length;
  157. if (endIndex > 0 && endIndex > startIndex + 1)
  158. {
  159. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  160. }
  161. else
  162. {
  163. faultMessage = serviceEx.Message;
  164. }
  165. }
  166. }
  167. }
  168. return faultMessage;
  169. }
  170. #endregion
  171. public class OperationResult
  172. {
  173. /// <summary>
  174. /// 结果状态,默认值false
  175. /// </summary>
  176. public bool IsSuccess { get; set; }
  177. /// <summary>
  178. ///处理消息
  179. /// </summary>
  180. public string MESSAGE { get; set; }
  181. /// <summary>
  182. /// 输出领料订单
  183. /// </summary>
  184. public string LLCode { get; set; }
  185. }
  186. }
  187. }