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

232 lines
10 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  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. namespace ICSSoft.APIApproveRCV
  14. {
  15. public class ApproveRCV
  16. {
  17. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  18. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  19. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  20. public bool Approve(List<ICSPurchaseReceiveDoc> infos)
  21. {
  22. bool ResultFlag = false;
  23. if (infos.Count <= 0)
  24. {
  25. throw new Exception("传送数据为空!");
  26. }
  27. string res = string.Empty;
  28. string sql = string.Empty;
  29. foreach (ICSPurchaseReceiveDoc Info in infos)
  30. {
  31. try
  32. {
  33. long DocID = 0;
  34. string EntityType = "";
  35. Decimal RCVQty = 0;
  36. //实例化代理类
  37. UFIDAU9PMRcvIRcvApprovedSVClient client = new UFIDAU9PMRcvIRcvApprovedSVClient();
  38. //服务返回结果
  39. //UFIDAU9PMPOPurchaseOrderData[] returnItems;
  40. //返回异常信息,目前还没有使用此属性
  41. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  42. //上下文信息
  43. object context;
  44. //传入 参数
  45. //UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
  46. UFSoft.UBF.Business.BusinessEntity.EntityKey docHead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  47. string OrgID = "";
  48. string orgsql = @"select ID from Base_Organization
  49. where Code='{0}'";
  50. orgsql = string.Format(orgsql, Info.WorkPoint);
  51. DataTable orgdt = DBHelper.Query(orgsql, connString);
  52. if (orgdt.Rows.Count != 0)
  53. {
  54. OrgID = orgdt.Rows[0]["ID"].ToString();
  55. }
  56. else
  57. {
  58. throw new Exception("传入组织编码错误!");
  59. }
  60. DataTable dt = GetData(Info.DNCode, OrgID);
  61. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()) || !string.IsNullOrEmpty(dt.Rows[0][1].ToString()))
  62. {
  63. DocID = long.Parse(dt.Rows[0][0].ToString());
  64. EntityType = dt.Rows[0][1].ToString();
  65. RCVQty= Convert.ToDecimal(dt.Rows[0][3].ToString());
  66. decimal ACTQty = 0;
  67. foreach (ICSPurchaseReceiveDocs InfoLine in Info.details)
  68. {
  69. ACTQty += InfoLine.Quantity;
  70. }
  71. if (RCVQty != ACTQty)
  72. {
  73. throw new Exception("实际入库数量未满足收货单数量,请整单入库!");
  74. }
  75. }
  76. else
  77. {
  78. throw new Exception("传入的单据号不正确!");
  79. }
  80. int acttype = int.Parse(ConfigurationManager.AppSettings["acttype"].ToString());
  81. //给上下文信息赋值
  82. context = CreateContextObj(OrgID);
  83. //给传入参数赋值
  84. docHead.EntityType = EntityType;
  85. docHead.ID = DocID;
  86. //pOList = SetPoDtos(U9Info, poInfoList);
  87. //服务调用
  88. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  89. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  90. returnMsg = client.Do(context, acttype, docHead);
  91. if (returnMsg != null)
  92. {
  93. if (!string.IsNullOrWhiteSpace(returnMsg[0].localMessage))
  94. {
  95. throw new Exception(returnMsg[0].localMessage);
  96. }
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. log.Error(ex.Message);
  102. throw new Exception(ex.Message);
  103. }
  104. }
  105. ResultFlag = true;
  106. return ResultFlag;
  107. }
  108. public bool Approve(List<ICSSalesShipmentDocNegative> infos)
  109. {
  110. bool ResultFlag = false;
  111. if (infos.Count <= 0)
  112. {
  113. throw new Exception("传送数据为空!");
  114. }
  115. string res = string.Empty;
  116. string sql = string.Empty;
  117. foreach (ICSSalesShipmentDocNegative Info in infos)
  118. {
  119. try
  120. {
  121. long DocID = 0;
  122. string EntityType = "";
  123. //实例化代理类
  124. UFIDAU9PMRcvIRcvApprovedSVClient client = new UFIDAU9PMRcvIRcvApprovedSVClient();
  125. //服务返回结果
  126. //UFIDAU9PMPOPurchaseOrderData[] returnItems;
  127. //返回异常信息,目前还没有使用此属性
  128. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  129. //上下文信息
  130. object context;
  131. //传入 参数
  132. //UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
  133. UFSoft.UBF.Business.BusinessEntity.EntityKey docHead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  134. string OrgID = "";
  135. string orgsql = @"select ID from Base_Organization
  136. where Code='{0}'";
  137. orgsql = string.Format(orgsql, Info.WorkPoint);
  138. DataTable orgdt = DBHelper.Query(orgsql, connString);
  139. if (orgdt.Rows.Count != 0)
  140. {
  141. OrgID = orgdt.Rows[0]["ID"].ToString();
  142. }
  143. else
  144. {
  145. throw new Exception("传入组织编码错误!");
  146. }
  147. DataTable dt = GetData(Info.SDNNEGCode, OrgID);
  148. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()) || !string.IsNullOrEmpty(dt.Rows[0][1].ToString()))
  149. {
  150. DocID = long.Parse(dt.Rows[0][0].ToString());
  151. EntityType = dt.Rows[0][1].ToString();
  152. }
  153. else
  154. {
  155. throw new Exception("传入的单据号不正确!");
  156. }
  157. int acttype = int.Parse(ConfigurationManager.AppSettings["acttype"].ToString());
  158. //给上下文信息赋值
  159. context = CreateContextObj(OrgID);
  160. //给传入参数赋值
  161. docHead.EntityType = EntityType;
  162. docHead.ID = DocID;
  163. //pOList = SetPoDtos(U9Info, poInfoList);
  164. //服务调用
  165. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  166. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  167. returnMsg = client.Do(context, acttype, docHead);
  168. if (returnMsg != null)
  169. {
  170. if (!string.IsNullOrWhiteSpace(returnMsg[0].localMessage))
  171. {
  172. throw new Exception(returnMsg[0].localMessage);
  173. }
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. log.Error(ex.Message);
  179. throw new Exception(ex.Message);
  180. }
  181. }
  182. ResultFlag = true;
  183. return ResultFlag;
  184. }
  185. #region 给上下文信息赋值
  186. /// <summary>
  187. /// 给上下文信息赋值
  188. /// </summary>
  189. /// <returns></returns>
  190. private static ThreadContext CreateContextObj(string OrgID)
  191. {
  192. // 实例化应用上下文对象
  193. ThreadContext thContext = new ThreadContext();
  194. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  195. ns.Add("OrgID", OrgID);
  196. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  197. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  198. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  199. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  200. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  201. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  202. thContext.nameValueHas = ns;
  203. return thContext;
  204. }
  205. #endregion
  206. private static DataTable GetData(string DocCode, string OrgID)
  207. {
  208. string sql = @" select A.ID,A1.[Code] as [Receivement_RcvDocType_Code],A.Status,SUM(A3.RcvQtyCU) AS RcvQtyCU
  209. from PM_Receivement as A
  210. left join [PM_RcvDocType] as A1 on (A.[RcvDocType] = A1.[ID])
  211. left join [PM_RcvDocType_Trl] as A2 on (A2.SysMlFlag = 'zh-CN') and (A1.[ID] = A2.[ID])
  212. left join [PM_RcvLine] A3 ON A3.Receivement=A.ID
  213. where A.DocNo='" + DocCode + "' AND A.Org='" + OrgID + @"'
  214. GROUP BY A.ID,A1.[Code],A.Status";
  215. return DBHelper.Query(sql, connString);
  216. }
  217. }
  218. }