纽威
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.

200 lines
8.1 KiB

  1. using ICSSoft.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using ICSSoft.Entity;
  11. using UFSoft.UBF.Util.Context;
  12. using System.ServiceModel;
  13. using www.ufida.org.EntityData;
  14. using UFSoft.UBF.Exceptions;
  15. namespace ICSSoft.APIApproveShipment
  16. {
  17. public class ApproveShipment
  18. {
  19. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  20. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  21. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  22. /// <summary>
  23. /// 审核出货单(外部通过API调用)
  24. /// </summary>
  25. /// <param name="infos"></param>
  26. /// <returns></returns>
  27. public bool Approve(List<ICSSalesShipmentDoc> infos)
  28. {
  29. bool ResultFlag = false;
  30. UFIDAU9ISVSMIAuditShipSVClient client = new UFIDAU9ISVSMIAuditShipSVClient();
  31. //返回异常信息,目前还没有使用此属性
  32. MessageBase[] returnMsg;
  33. //上下文信息
  34. object context;
  35. try
  36. {
  37. if (infos == null || infos.Count == 0)
  38. {
  39. throw new Exception("传入数据不能为空!");
  40. }
  41. string OrgID = "";
  42. string orgsql = @"select ID from Base_Organization
  43. where Code='{0}'";
  44. orgsql = string.Format(orgsql, infos[0].WorkPoint);
  45. DataTable orgdt = DBHelper.Query(orgsql, connString);
  46. if (orgdt.Rows.Count != 0)
  47. {
  48. OrgID = orgdt.Rows[0]["ID"].ToString();
  49. }
  50. else
  51. {
  52. throw new Exception("传入组织编码错误!");
  53. }
  54. //给上下文信息赋值
  55. context = CreateContextObj(OrgID);
  56. //服务调用
  57. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  58. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  59. UFIDAU9ISVSMDocKeyDTOData[] shipKeys = new UFIDAU9ISVSMDocKeyDTOData[] { };
  60. List<UFIDAU9ISVSMDocKeyDTOData> _shipKeys = new List<UFIDAU9ISVSMDocKeyDTOData>();
  61. UFIDAU9ISVSMDocKeyDTOData shipkey = new UFIDAU9ISVSMDocKeyDTOData();
  62. bool isSubmit = false;
  63. bool isUnApprove = false;
  64. bool isSubmitAndApprove = false;
  65. UFIDAU9BCCalcDataCreateBarCodeUsedInDTOData[] itemBarCodes = new UFIDAU9BCCalcDataCreateBarCodeUsedInDTOData[] { };
  66. foreach (ICSSalesShipmentDoc Info in infos)
  67. {
  68. shipkey = new UFIDAU9ISVSMDocKeyDTOData();
  69. shipkey.m_docNO = Info.SDNCode;
  70. _shipKeys.Add(shipkey);
  71. }
  72. shipKeys = _shipKeys.ToArray();
  73. returnMsg = client.Do(context, shipKeys, isSubmit, isSubmitAndApprove, isUnApprove, itemBarCodes);
  74. if (returnMsg != null && returnMsg.Length > 0)
  75. {
  76. foreach (var item in returnMsg)
  77. {
  78. throw new Exception(item.localMessage);
  79. }
  80. }
  81. else
  82. {
  83. ResultFlag = true;
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. log.Error(ex.Message);
  89. throw new Exception(ex.Message);
  90. }
  91. return ResultFlag;
  92. }
  93. /// <summary>
  94. /// 审核出货单(接口内部调用,如:创建退料单后调用审核单据)
  95. /// </summary>
  96. /// <param name="DocNOList"></param>
  97. /// <param name="OrgCode"></param>
  98. /// <returns></returns>
  99. public bool Approve(List<string> DocNOList, string OrgCode)
  100. {
  101. bool ResultFlag = false;
  102. UFIDAU9ISVSMIAuditShipSVClient client = new UFIDAU9ISVSMIAuditShipSVClient();
  103. //返回异常信息,目前还没有使用此属性
  104. MessageBase[] returnMsg;
  105. //上下文信息
  106. object context;
  107. try
  108. {
  109. if (DocNOList == null || DocNOList.Count == 0)
  110. {
  111. throw new Exception("传入数据不能为空!");
  112. }
  113. string OrgID = "";
  114. string orgsql = @"select ID from Base_Organization
  115. where Code='{0}'";
  116. orgsql = string.Format(orgsql, OrgCode);
  117. DataTable orgdt = DBHelper.Query(orgsql, connString);
  118. if (orgdt.Rows.Count != 0)
  119. {
  120. OrgID = orgdt.Rows[0]["ID"].ToString();
  121. }
  122. else
  123. {
  124. throw new Exception("传入组织编码错误!");
  125. }
  126. //给上下文信息赋值
  127. context = CreateContextObj(OrgID);
  128. //服务调用
  129. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  130. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  131. UFIDAU9ISVSMDocKeyDTOData[] shipKeys = new UFIDAU9ISVSMDocKeyDTOData[] { };
  132. List<UFIDAU9ISVSMDocKeyDTOData> _shipKeys = new List<UFIDAU9ISVSMDocKeyDTOData>();
  133. UFIDAU9ISVSMDocKeyDTOData shipkey = new UFIDAU9ISVSMDocKeyDTOData();
  134. bool isSubmit = false;
  135. bool isUnApprove = false;
  136. bool isSubmitAndApprove = false;
  137. UFIDAU9BCCalcDataCreateBarCodeUsedInDTOData[] itemBarCodes = new UFIDAU9BCCalcDataCreateBarCodeUsedInDTOData[] { };
  138. foreach (string DocNO in DocNOList)
  139. {
  140. shipkey = new UFIDAU9ISVSMDocKeyDTOData();
  141. shipkey.m_docNO = DocNO;
  142. _shipKeys.Add(shipkey);
  143. }
  144. shipKeys = _shipKeys.ToArray();
  145. returnMsg = client.Do(context, shipKeys, isSubmit, isSubmitAndApprove, isUnApprove, itemBarCodes);
  146. if (returnMsg != null && returnMsg.Length > 0)
  147. {
  148. foreach (var item in returnMsg)
  149. {
  150. throw new Exception(item.localMessage);
  151. }
  152. }
  153. else
  154. {
  155. ResultFlag = true;
  156. }
  157. }
  158. catch (Exception ex)
  159. {
  160. log.Error(ex.Message);
  161. throw new Exception(ex.Message);
  162. }
  163. return ResultFlag;
  164. }
  165. #region 给上下文信息赋值
  166. /// <summary>
  167. /// 给上下文信息赋值
  168. /// </summary>
  169. /// <returns></returns>
  170. private static ThreadContext CreateContextObj(string OrgID)
  171. {
  172. // 实例化应用上下文对象
  173. ThreadContext thContext = new ThreadContext();
  174. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  175. ns.Add("OrgID", OrgID);
  176. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  177. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  178. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  179. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  180. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  181. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  182. thContext.nameValueHas = ns;
  183. return thContext;
  184. }
  185. #endregion
  186. }
  187. }