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

197 lines
8.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. using www.ufida.org.EntityData;
  14. using UFSoft.UBF.Exceptions1;
  15. namespace ICSSoft.APIApproveIssue
  16. {
  17. public class ApproveIssue
  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<ICSRdrecord11> infos)
  28. {
  29. bool ResultFlag = false;
  30. ThreadContext context;
  31. try
  32. {
  33. StringBuilder strHead = new StringBuilder();
  34. string _MOCode = string.Empty;
  35. UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
  36. MessageBase[] message = null;
  37. List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
  38. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  39. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
  40. string OrgID = "";
  41. string orgsql = @"select ID from Base_Organization
  42. where Code='{0}'";
  43. orgsql = string.Format(orgsql, infos[0].WorkPoint);
  44. DataTable orgdt = DBHelper.Query(orgsql, connString);
  45. if (orgdt.Rows.Count != 0)
  46. {
  47. OrgID = orgdt.Rows[0]["ID"].ToString();
  48. }
  49. else
  50. {
  51. throw new Exception("传入组织编码错误!");
  52. }
  53. foreach (ICSRdrecord11 info in infos)
  54. {
  55. string checksql = @"select * from MO_IssueDoc
  56. where DocNo='" + info.IssueCode + "' AND Org='" + OrgID + "'";
  57. checksql = string.Format(checksql);
  58. DataTable dtcheck = DBHelper.Query(checksql, connString);
  59. if (dtcheck.Rows.Count == 0)
  60. {
  61. throw new Exception("领料单号:'" + info.IssueCode + "'不存在!!");
  62. }
  63. else
  64. {
  65. LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  66. LL.m_docNo = info.IssueCode;
  67. LL.m_operateType = true;
  68. LLlist.Add(LL);
  69. }
  70. }
  71. context = CreateContextObj(OrgID);
  72. resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
  73. if (resultList != null && resultList.Count() > 0)
  74. {
  75. foreach (var item in resultList)
  76. {
  77. if (item.m_isSucceed == false)
  78. {
  79. throw new Exception(item.m_errorMsg);
  80. }
  81. }
  82. ResultFlag = true;
  83. }
  84. else
  85. {
  86. ResultFlag = true;
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. log.Error(ex.Message);
  92. throw new Exception(ex.Message);
  93. }
  94. return ResultFlag;
  95. }
  96. /// <summary>
  97. /// 审核领料单(接口内部调用,如:创建退料单后调用审核单据)
  98. /// </summary>
  99. /// <param name="DocNOList"></param>
  100. /// <param name="OrgCode"></param>
  101. /// <returns></returns>
  102. public bool Approve(List<string> DocNOList,string OrgCode)
  103. {
  104. bool ResultFlag = false;
  105. ThreadContext context;
  106. try
  107. {
  108. StringBuilder strHead = new StringBuilder();
  109. string _MOCode = string.Empty;
  110. UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
  111. MessageBase[] message = null;
  112. List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
  113. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  114. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
  115. string OrgID = "";
  116. string orgsql = @"select ID from Base_Organization
  117. where Code='{0}'";
  118. orgsql = string.Format(orgsql, OrgCode);
  119. DataTable orgdt = DBHelper.Query(orgsql, connString);
  120. if (orgdt.Rows.Count != 0)
  121. {
  122. OrgID = orgdt.Rows[0]["ID"].ToString();
  123. }
  124. else
  125. {
  126. throw new Exception("传入组织编码错误!");
  127. }
  128. foreach (string DocNO in DocNOList)
  129. {
  130. string checksql = @"select * from MO_IssueDoc
  131. where DocNo='" + DocNO + "' AND Org='" + OrgID + "'";
  132. checksql = string.Format(checksql);
  133. DataTable dtcheck = DBHelper.Query(checksql, connString);
  134. if (dtcheck.Rows.Count == 0)
  135. {
  136. throw new Exception("领料单号:'" + DocNO + "'不存在!!");
  137. }
  138. else
  139. {
  140. LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  141. LL.m_docNo = DocNO;
  142. LL.m_operateType = true;
  143. LLlist.Add(LL);
  144. }
  145. }
  146. context = CreateContextObj(OrgID);
  147. resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
  148. if (resultList != null && resultList.Count() > 0)
  149. {
  150. foreach (var item in resultList)
  151. {
  152. if (item.m_isSucceed == false)
  153. {
  154. throw new Exception(item.m_errorMsg);
  155. }
  156. }
  157. ResultFlag = true;
  158. }
  159. else
  160. {
  161. ResultFlag = true;
  162. }
  163. }
  164. catch (Exception ex)
  165. {
  166. log.Error(ex.Message);
  167. throw new Exception(ex.Message);
  168. }
  169. return ResultFlag;
  170. }
  171. #region 给上下文信息赋值
  172. /// <summary>
  173. /// 给上下文信息赋值
  174. /// </summary>
  175. /// <returns></returns>
  176. private static ThreadContext CreateContextObj(string OrgID)
  177. {
  178. // 实例化应用上下文对象
  179. ThreadContext thContext = new ThreadContext();
  180. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  181. ns.Add("OrgID", OrgID);
  182. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  183. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  184. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  185. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  186. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  187. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  188. thContext.nameValueHas = ns;
  189. return thContext;
  190. }
  191. #endregion
  192. }
  193. }