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