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

195 lines
7.6 KiB

2 years ago
  1. using ICS.WCF.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Linq;
  6. using System.ServiceModel;
  7. using System.Text;
  8. using System.Threading.Tasks;
  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.SubmitMisRcv
  14. {
  15. public class CustCallSubmitMisRcv
  16. {
  17. public static OperationResult CustSubmitMisRcv(string MisRcvCode,string orgID)
  18. {
  19. OperationResult result = new OperationResult();
  20. bool IsSuccess = false;
  21. string MESSAGE = "";
  22. bool flag = false;
  23. string returnCode = "";
  24. try
  25. {
  26. UFIDAU9ISVMiscRcvISVICommonCommitMiscRcvClient client = new UFIDAU9ISVMiscRcvISVICommonCommitMiscRcvClient();
  27. UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData[] resultList = new UFIDAU9ISVMiscRcvISVIC_MiscRcvDTOData[] { };
  28. List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData> modelList = new List<UFIDAU9CBOPubControllerCommonArchiveDataDTOData>();
  29. UFIDAU9CBOPubControllerCommonArchiveDataDTOData model = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  30. MessageBase[] messageBase = null;
  31. object _context;
  32. _context = GetLLStateContext(orgID);
  33. bool isNotNewTransaction = true;
  34. model.m_code = MisRcvCode;
  35. modelList.Add(model);
  36. resultList = client.Do(out messageBase, _context, modelList.ToArray());
  37. bool issuccess = true;
  38. if (resultList != null && resultList.Count() > 0)
  39. {
  40. StringBuilder str = new StringBuilder();
  41. foreach (var item in resultList)
  42. {
  43. if (item.m_docNo == "" || item.m_docNo == null)
  44. {
  45. issuccess = false;
  46. break;
  47. }
  48. else
  49. {
  50. returnCode = item.m_docNo;
  51. }
  52. }
  53. }
  54. else
  55. {
  56. StringBuilder str = new StringBuilder();
  57. str.AppendLine("提交杂收单");
  58. str.AppendLine("错误:提交失败");
  59. str.AppendLine("单号:" + returnCode);
  60. str.AppendLine("结果:" + "False");
  61. Appconfig.WriteLogFile(str.ToString(), "提交杂收单");
  62. result.Message = "提交失败";
  63. result.IsSuccess = false;
  64. return result;
  65. }
  66. if (issuccess == false)
  67. {
  68. StringBuilder str = new StringBuilder();
  69. str.AppendLine("提交杂收单");
  70. str.AppendLine("错误:提交失败");
  71. str.AppendLine("单号:" + returnCode);
  72. str.AppendLine("结果:" + "False");
  73. Appconfig.WriteLogFile(str.ToString(), "提交杂收单");
  74. result.Message = "提交失败";
  75. result.IsSuccess = false;
  76. return result;
  77. }
  78. else
  79. {
  80. StringBuilder str = new StringBuilder();
  81. str.AppendLine("提交杂收单");
  82. str.AppendLine("单号:" + returnCode);
  83. str.AppendLine("结果:" + "True");
  84. Appconfig.WriteLogFile(str.ToString(), "提交杂收单");
  85. result.Message = "提交成功";
  86. result.IsSuccess = true;
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. result.IsSuccess = false;
  92. result.Message = MESSAGE = GetExceptionMessage(ex);
  93. result.DocNo = returnCode;
  94. StringBuilder str = new StringBuilder();
  95. str.AppendLine("提交杂收单");
  96. str.AppendLine("错误:" + MESSAGE);
  97. str.AppendLine("单号:" + returnCode);
  98. str.AppendLine("结果:" + "False");
  99. Appconfig.WriteLogFile(str.ToString(), "提交杂收单");
  100. }
  101. return result;
  102. }
  103. #region 给上下文信息赋值
  104. /// <summary>
  105. /// 给上下文信息赋值
  106. /// </summary>
  107. /// <returns></returns>
  108. private static ThreadContext GetLLStateContext(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. thContext.nameValueHas = ns;
  121. return thContext;
  122. }
  123. #endregion
  124. #region 提取异常信息
  125. /// <summary>
  126. /// 提取异常信息
  127. /// </summary>
  128. /// <param name="ex"></param>
  129. private static string GetExceptionMessage(Exception ex)
  130. {
  131. string faultMessage = "未知错误,请查看ERP日志!";
  132. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  133. if (timeoutEx != null)
  134. {
  135. faultMessage = "访问服务超时,请修改配置信息!";
  136. }
  137. else
  138. {
  139. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  140. if (faultEx == null)
  141. {
  142. faultMessage = ex.Message;
  143. }
  144. else
  145. {
  146. ServiceException serviceEx = faultEx.Detail;
  147. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  148. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  149. {
  150. // 错误信息在faultEx.Message中,请提取,
  151. // 格式为"Fault:料品不能为空,请录入\n 在....."
  152. int startIndex = serviceEx.Message.IndexOf(":");
  153. int endIndex = serviceEx.Message.IndexOf("\n");
  154. if (endIndex == -1)
  155. endIndex = serviceEx.Message.Length;
  156. if (endIndex > 0 && endIndex > startIndex + 1)
  157. {
  158. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  159. }
  160. else
  161. {
  162. faultMessage = serviceEx.Message;
  163. }
  164. }
  165. }
  166. }
  167. return faultMessage;
  168. }
  169. #endregion
  170. }
  171. public class OperationResult
  172. {
  173. public string DocNo { get; set; }
  174. public bool IsSuccess { get; set; }
  175. public string Message { get; set; }
  176. }
  177. }