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

237 lines
9.3 KiB

  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 UFSoft.UBF.Exceptions1;
  10. using UFSoft.UBF.Service;
  11. using UFSoft.UBF.Util.Context;
  12. using www.ufida.org.EntityData;
  13. namespace UFIDA.ISV.ApproveMiscRcv
  14. {
  15. public class CustApproveMiscRcv
  16. {
  17. /// <summary>
  18. /// 审核杂收单
  19. /// </summary>
  20. /// <returns></returns>
  21. public OperationResult_ApproveMiscRcv CustApproveMis(string docNo, string OrgCode)
  22. {
  23. //List<OperationResult_ApproveMiscRcv> result = new List<OperationResult_ApproveMiscRcv>();
  24. OperationResult_ApproveMiscRcv result = new OperationResult_ApproveMiscRcv();
  25. #region 服务调用框架结构
  26. UFIDAU9ISVMiscRcvISVICommonApproveMiscRcvClient client = new UFIDAU9ISVMiscRcvISVICommonApproveMiscRcvClient();
  27. //返回异常信息,目前还没有使用此属性
  28. MessageBase[] returnMsg;
  29. //上下文信息
  30. object context;
  31. //传入 参数
  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. result.IsSuccess = false;
  46. result.Message = "传入组织编码:" + OrgCode + "不存在!";
  47. result.DocNo = docNo;
  48. return result;
  49. }
  50. long ID = 0L;
  51. string sql = @"SELECT ID FROM InvDoc_MiscRcvTrans a WHERE a.DocNo='" + docNo + "' AND Org='" + OrgID + "'";
  52. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  53. if (dt != null && dt.Rows.Count > 0)
  54. {
  55. string a = dt.Rows[0][0].ToString();
  56. if (string.IsNullOrWhiteSpace(a))
  57. {
  58. result.IsSuccess = false;
  59. result.Message = "请传入单号有误,请重新输入";
  60. result.DocNo = docNo;
  61. return result;
  62. }
  63. else
  64. {
  65. ID = long.Parse(a);
  66. }
  67. }
  68. else
  69. {
  70. result.IsSuccess = false;
  71. result.Message = "请传入单号有误,请重新输入";
  72. result.DocNo = docNo;
  73. return result;
  74. }
  75. UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData[] returnItems;
  76. //给上下文信息赋值
  77. context = CreateContextObj(OrgID);
  78. //给传入参数赋值
  79. //服务调用
  80. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  81. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  82. UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] queryList = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData[] { };
  83. List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> query = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
  84. UFIDAU9CBOPubControllerCommonArchiveDataDTOData q = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  85. //q.m_code = "Mis2019110031";
  86. q.m_iD = ID;
  87. q.m_code = docNo;
  88. query.Add(q);
  89. queryList = query.ToArray();
  90. returnItems = client.Do(out returnMsg, context, queryList);
  91. if (returnItems != null && returnItems.Length > 0)
  92. {
  93. //获取返回信息得到创建的收货单信息
  94. foreach (var item in returnItems)
  95. {
  96. //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv();
  97. result.IsSuccess = true;
  98. result.Message = "审核杂收单成功";
  99. result.DocNo = docNo;
  100. //result.Add(model);
  101. }
  102. }
  103. else
  104. {
  105. //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv();
  106. result.IsSuccess = true;
  107. result.Message = "审核杂收单成功";
  108. result.DocNo = docNo;
  109. //result.Add(model);
  110. }
  111. StringBuilder str = new StringBuilder();
  112. str.AppendLine("审核杂收");
  113. str.AppendLine("单号:" + docNo);
  114. str.AppendLine("消息:" + result.Message);
  115. str.AppendLine("结果:" + result.IsSuccess);
  116. Appconfig.WriteLogFile(str.ToString(), "审核杂收单");
  117. return result;
  118. }
  119. catch (Exception ex)
  120. {
  121. //异常信息捕获
  122. //OperationResult_ApproveMiscRcv model = new OperationResult_ApproveMiscRcv();
  123. result.IsSuccess = false;
  124. result.Message = GetExceptionMessage(ex);
  125. result.DocNo = docNo;
  126. //result.Add(model);
  127. StringBuilder str = new StringBuilder();
  128. str.AppendLine("审核杂收单异常");
  129. str.AppendLine("单号:" + docNo);
  130. str.AppendLine("错误消息:" + result.Message);
  131. str.AppendLine("结果:" + "false");
  132. Appconfig.WriteLogFile(str.ToString(), "审核杂收单异常");
  133. return result;
  134. }
  135. #endregion
  136. }
  137. #region 给上下文信息赋值
  138. /// <summary>
  139. /// 给上下文信息赋值
  140. /// </summary>
  141. /// <returns></returns>
  142. private ThreadContext CreateContextObj(string OrgID)
  143. {
  144. // 实例化应用上下文对象
  145. ThreadContext thContext = new ThreadContext();
  146. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  147. ns.Add("OrgID", OrgID);
  148. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  149. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  150. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  151. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  152. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  153. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  154. thContext.nameValueHas = ns;
  155. return thContext;
  156. }
  157. #endregion
  158. #region 提取异常信息
  159. /// <summary>
  160. /// 提取异常信息
  161. /// </summary>
  162. /// <param name="ex"></param>
  163. private string GetExceptionMessage(Exception ex)
  164. {
  165. string faultMessage = "未知错误,请查看ERP日志!";
  166. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  167. if (timeoutEx != null)
  168. {
  169. faultMessage = "访问服务超时,请修改配置信息!";
  170. }
  171. else
  172. {
  173. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  174. if (faultEx == null)
  175. {
  176. faultMessage = ex.Message;
  177. }
  178. else
  179. {
  180. ServiceException serviceEx = faultEx.Detail;
  181. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  182. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  183. {
  184. // 错误信息在faultEx.Message中,请提取,
  185. // 格式为"Fault:料品不能为空,请录入\n 在....."
  186. int startIndex = serviceEx.Message.IndexOf(":");
  187. int endIndex = serviceEx.Message.IndexOf("\n");
  188. if (endIndex == -1)
  189. endIndex = serviceEx.Message.Length;
  190. if (endIndex > 0 && endIndex > startIndex + 1)
  191. {
  192. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  193. }
  194. else
  195. {
  196. faultMessage = serviceEx.Message;
  197. }
  198. }
  199. }
  200. }
  201. return faultMessage;
  202. }
  203. #endregion
  204. public class OperationResult_ApproveMiscRcv
  205. {
  206. public string DocNo { get; set; }
  207. public bool IsSuccess { get; set; }
  208. public string Message { get; set; }
  209. }
  210. }
  211. }