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

234 lines
9.4 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 System.Configuration;
  13. namespace UFIDA.ISV.BFRCVApprove
  14. {
  15. public class CustBFRCVApprove
  16. {
  17. public static ReturnValue1 CustApproveRec(string DocCode, string OrgCode, string Status)
  18. {
  19. long DocID = 0;
  20. string EntityType = "";
  21. #region 服务调用框架结构
  22. //实例化代理类
  23. UFIDAU9PMRcvIRcvApprovedSVClient client = new UFIDAU9PMRcvIRcvApprovedSVClient();
  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 docHead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  33. try
  34. {
  35. string OrgID = "";
  36. string orgsql = @"select ID from Base_Organization
  37. where Code='{0}'";
  38. orgsql = string.Format(orgsql, OrgCode);
  39. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  40. if (orgdt.Rows.Count != 0)
  41. {
  42. OrgID = orgdt.Rows[0]["ID"].ToString();
  43. }
  44. else
  45. {
  46. throw new Exception("未获取到组织!");
  47. }
  48. DataTable dt = GetData(DocCode, OrgID);
  49. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()) || !string.IsNullOrEmpty(dt.Rows[0][1].ToString()))
  50. {
  51. DocID = long.Parse(dt.Rows[0][0].ToString());
  52. EntityType = dt.Rows[0][1].ToString();
  53. }
  54. else
  55. {
  56. throw new Exception("输入的单据号不正确!");
  57. }
  58. int acttype = int.Parse(ConfigurationManager.AppSettings["acttype"].ToString());
  59. //给上下文信息赋值
  60. context = CreateContextObj(OrgID);
  61. //给传入参数赋值
  62. docHead.EntityType = EntityType;
  63. docHead.ID = DocID;
  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. if (Status == "审核")
  69. {
  70. if (EntityType == "RCV01")
  71. {
  72. returnMsg = client.Do(context, 7, docHead);
  73. if (returnMsg != null)
  74. {
  75. ReturnValue1 value = new ReturnValue1();
  76. if (!string.IsNullOrWhiteSpace(returnMsg[0].localMessage))
  77. {
  78. value.IsSuccess = false;
  79. value.Mes = returnMsg[0].localMessage;
  80. return value;
  81. }
  82. }
  83. }
  84. returnMsg = client.Do(context, acttype, docHead);
  85. }
  86. else
  87. {
  88. returnMsg = client.Do(context, 9, docHead);
  89. }
  90. if (returnMsg != null)
  91. {
  92. ReturnValue1 value = new ReturnValue1();
  93. if (!string.IsNullOrWhiteSpace(returnMsg[0].localMessage))
  94. {
  95. value.IsSuccess = false;
  96. value.Mes = returnMsg[0].localMessage;
  97. return value;
  98. }
  99. else
  100. {
  101. value.poheadList = returnMsg;
  102. //value.Mes = returnMsg[0].localMessage;
  103. value.IsSuccess = true;
  104. return value;
  105. }
  106. }
  107. else
  108. {
  109. ReturnValue1 value = new ReturnValue1();
  110. //异常信息捕获
  111. value.poheadList = returnMsg;
  112. //value.Mes = "未返回任何数据";
  113. value.IsSuccess = true;
  114. StringBuilder str = new StringBuilder();
  115. str.AppendLine("审核入库单");
  116. str.AppendLine("单号:" + DocCode);
  117. str.AppendLine("结果:" + "True");
  118. Appconfig.WriteLogFile(str.ToString(), "审核入库单");
  119. return value;
  120. }
  121. }
  122. catch (Exception ex)
  123. {
  124. StringBuilder str = new StringBuilder();
  125. str.AppendLine("审核入库单");
  126. str.AppendLine("单号:" + DocCode);
  127. str.AppendLine("错误:" + GetExceptionMessage(ex));
  128. str.AppendLine("结果:" + "False");
  129. Appconfig.WriteLogFile(str.ToString(), "审核入库单");
  130. ReturnValue1 value = new ReturnValue1();
  131. //异常信息捕获
  132. value.Mes = "入库单号:" + DocCode + "," + GetExceptionMessage(ex);
  133. value.IsSuccess = false;
  134. return value;
  135. }
  136. #endregion
  137. }
  138. private static DataTable GetData(string DocCode, string OrgID)
  139. {
  140. string sql = @"select A.ID,A1.[Code] as [Receivement_RcvDocType_Code],A.Status
  141. from PM_Receivement as A
  142. left join [PM_RcvDocType] as A1 on (A.[RcvDocType] = A1.[ID])
  143. left join [PM_RcvDocType_Trl] as A2 on (A2.SysMlFlag = 'zh-CN') and (A1.[ID] = A2.[ID])
  144. where A.DocNo='" + DocCode + "' AND A.Org='" + OrgID + "'";
  145. return DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  146. }
  147. #region 提取异常信息
  148. /// <summary>
  149. /// 提取异常信息
  150. /// </summary>
  151. /// <param name="ex"></param>
  152. private static string GetExceptionMessage(Exception ex)
  153. {
  154. string faultMessage = "未知错误,请查看ERP日志!";
  155. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  156. if (timeoutEx != null)
  157. {
  158. faultMessage = "访问服务超时,请修改配置信息!";
  159. }
  160. else
  161. {
  162. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  163. if (faultEx == null)
  164. {
  165. faultMessage = ex.Message;
  166. }
  167. else
  168. {
  169. ServiceException serviceEx = faultEx.Detail;
  170. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  171. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  172. {
  173. // 错误信息在faultEx.Message中,请提取,
  174. // 格式为"Fault:料品不能为空,请录入\n 在....."
  175. int startIndex = serviceEx.Message.IndexOf(":");
  176. int endIndex = serviceEx.Message.IndexOf("\n");
  177. if (endIndex == -1)
  178. endIndex = serviceEx.Message.Length;
  179. if (endIndex > 0 && endIndex > startIndex + 1)
  180. {
  181. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  182. }
  183. else
  184. {
  185. faultMessage = serviceEx.Message;
  186. }
  187. }
  188. }
  189. }
  190. return faultMessage;
  191. }
  192. #endregion
  193. #region 给上下文信息赋值
  194. /// <summary>
  195. /// 给上下文信息赋值
  196. /// </summary>
  197. /// <returns></returns>
  198. private static ThreadContext CreateContextObj(string OrgID)
  199. {
  200. // 实例化应用上下文对象
  201. ThreadContext thContext = new ThreadContext();
  202. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  203. ns.Add("OrgID", OrgID);
  204. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  205. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  206. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  207. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  208. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  209. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  210. thContext.nameValueHas = ns;
  211. return thContext;
  212. }
  213. #endregion
  214. public class ReturnValue1//List<rtnPoinfo>
  215. {
  216. public bool IsSuccess;
  217. public string Mes;
  218. public MessageBase[] poheadList;
  219. }
  220. }
  221. }