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

220 lines
9.2 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.Exceptions1;
  15. namespace ICSSoft.APIApproveCompRpt
  16. {
  17. public class ApproveCompRpt
  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<ICSManufactureReceiveDoc> infos)
  28. {
  29. bool ResultFlag = false;
  30. try
  31. {
  32. bool b = false;
  33. //实例化代理类
  34. UFIDAU9ISVMOIApproveCompleteRpt4ExternalSrvClient client = new UFIDAU9ISVMOIApproveCompleteRpt4ExternalSrvClient();
  35. //服务返回结果
  36. UFIDAU9ISVMOCompRptKeyDTOData[] returnValue;
  37. //返回异常信息,目前还没有使用此属性
  38. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  39. //上下文信息
  40. object context;
  41. //UFSoft.UBF.Business.BusinessEntity.EntityKey dochead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  42. //传入 参数
  43. UFIDAU9ISVMOCompRptKeyDTOData[] dOList;
  44. string OrgID = "";
  45. string orgsql = @"select ID from Base_Organization
  46. where Code='{0}'";
  47. orgsql = string.Format(orgsql, infos[0].WorkPoint);
  48. DataTable orgdt = DBHelper.Query(orgsql, connString);
  49. if (orgdt.Rows.Count != 0)
  50. {
  51. OrgID = orgdt.Rows[0]["ID"].ToString();
  52. }
  53. else
  54. {
  55. throw new Exception("传入组织编码错误!");
  56. }
  57. //给上下文信息赋值
  58. context = CreateContextObj(OrgID);
  59. //给传入参数赋值
  60. List<UFIDAU9ISVMOCompRptKeyDTOData> CodeList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  61. foreach (ICSManufactureReceiveDoc item in infos)
  62. {
  63. UFIDAU9ISVMOCompRptKeyDTOData dochead = new UFIDAU9ISVMOCompRptKeyDTOData();
  64. dochead.m_operateType = true;
  65. //dochead.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  66. dochead.m_docNo = item.MRCVCode;
  67. dochead.m_iD = GetTypeID(item.MRCVCode, OrgID);
  68. dochead.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  69. dochead.m_org.m_iD = long.Parse(OrgID);
  70. CodeList.Add(dochead);
  71. }
  72. dOList = CodeList.ToArray();
  73. //服务调用
  74. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  75. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  76. //bool m=SetBinCode(BinCode,DocCode);//赋值库位
  77. //b = m;
  78. returnValue = client.Do(out returnMsg, context, dOList, false);
  79. foreach (UFIDAU9ISVMOCompRptKeyDTOData returnInfo in returnValue)
  80. {
  81. if (returnInfo.m_operateResult == false)
  82. {
  83. throw new Exception(returnInfo.m_errorMsg);
  84. }
  85. ResultFlag = true;
  86. }
  87. }
  88. catch (Exception ex)
  89. {
  90. log.Error(ex.Message);
  91. throw new Exception(ex.Message);
  92. }
  93. return ResultFlag;
  94. }
  95. /// <summary>
  96. /// 审核完工报告(接口内部调用,如:创建退料单后调用审核单据)
  97. /// </summary>
  98. /// <param name="DocNOList"></param>
  99. /// <param name="OrgCode"></param>
  100. /// <returns></returns>
  101. public bool Approve(List<string> DocNOList, string OrgCode)
  102. {
  103. bool ResultFlag = false;
  104. try
  105. {
  106. bool b = false;
  107. //实例化代理类
  108. UFIDAU9ISVMOIApproveCompleteRpt4ExternalSrvClient client = new UFIDAU9ISVMOIApproveCompleteRpt4ExternalSrvClient();
  109. //服务返回结果
  110. UFIDAU9ISVMOCompRptKeyDTOData[] returnValue;
  111. //返回异常信息,目前还没有使用此属性
  112. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  113. //上下文信息
  114. object context;
  115. //UFSoft.UBF.Business.BusinessEntity.EntityKey dochead = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  116. //传入 参数
  117. UFIDAU9ISVMOCompRptKeyDTOData[] dOList;
  118. string OrgID = "";
  119. string orgsql = @"select ID from Base_Organization
  120. where Code='{0}'";
  121. orgsql = string.Format(orgsql, OrgCode);
  122. DataTable orgdt = DBHelper.Query(orgsql, connString);
  123. if (orgdt.Rows.Count != 0)
  124. {
  125. OrgID = orgdt.Rows[0]["ID"].ToString();
  126. }
  127. else
  128. {
  129. throw new Exception("传入组织编码错误!");
  130. }
  131. //给上下文信息赋值
  132. context = CreateContextObj(OrgID);
  133. //给传入参数赋值
  134. List<UFIDAU9ISVMOCompRptKeyDTOData> CodeList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  135. foreach (string DocNO in DocNOList)
  136. {
  137. UFIDAU9ISVMOCompRptKeyDTOData dochead = new UFIDAU9ISVMOCompRptKeyDTOData();
  138. dochead.m_operateType = true;
  139. //dochead.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  140. dochead.m_docNo = DocNO;
  141. dochead.m_iD = GetTypeID(DocNO, OrgID);
  142. dochead.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  143. dochead.m_org.m_iD = long.Parse(OrgID);
  144. CodeList.Add(dochead);
  145. }
  146. dOList = CodeList.ToArray();
  147. //服务调用
  148. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  149. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  150. //bool m=SetBinCode(BinCode,DocCode);//赋值库位
  151. //b = m;
  152. returnValue = client.Do(out returnMsg, context, dOList, false);
  153. foreach (UFIDAU9ISVMOCompRptKeyDTOData returnInfo in returnValue)
  154. {
  155. if (returnInfo.m_operateResult == false)
  156. {
  157. throw new Exception(returnInfo.m_errorMsg);
  158. }
  159. ResultFlag = true;
  160. }
  161. }
  162. catch (Exception ex)
  163. {
  164. log.Error(ex.Message);
  165. throw new Exception(ex.Message);
  166. }
  167. return ResultFlag;
  168. }
  169. private static long GetTypeID(string docTypeCode, string OrgID)
  170. {
  171. string sql = @"select ID from MO_CompleteRpt where DocNo='" + docTypeCode + "' AND Org='" + OrgID + "' ";
  172. DataTable dt = DBHelper.Query(sql, connString);
  173. if (dt.Rows.Count > 0)
  174. {
  175. return long.Parse(dt.Rows[0][0].ToString());
  176. }
  177. else
  178. {
  179. return 0;
  180. }
  181. }
  182. #region 给上下文信息赋值
  183. /// <summary>
  184. /// 给上下文信息赋值
  185. /// </summary>
  186. /// <returns></returns>
  187. private static ThreadContext CreateContextObj(string OrgID)
  188. {
  189. // 实例化应用上下文对象
  190. ThreadContext thContext = new ThreadContext();
  191. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  192. ns.Add("OrgID", OrgID);
  193. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  194. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  195. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  196. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  197. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  198. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  199. thContext.nameValueHas = ns;
  200. return thContext;
  201. }
  202. #endregion
  203. }
  204. }