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

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