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

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