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

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