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

219 lines
9.4 KiB

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