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

256 lines
10 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. using ICSSoft.APIUnApproveCompRpt;
  16. namespace ICSSoft.APIDeleteCompRpt
  17. {
  18. public class DeleteCompRpt
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  22. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  23. /// <summary>
  24. /// 删除完工报告(外部通过API调用)
  25. /// </summary>
  26. /// <param name="infos"></param>
  27. /// <returns></returns>
  28. public bool Delete(List<ICSManufactureReceiveDoc> infos)
  29. {
  30. bool ResultFlag = false;
  31. try
  32. {
  33. UFIDAU9ISVMOIDeleteCompRptSrvClient client = new UFIDAU9ISVMOIDeleteCompRptSrvClient();
  34. MessageBase[] returnMsg;
  35. object context;
  36. if (infos == null || infos.Count == 0)
  37. {
  38. throw new Exception("传入参数不能为空!");
  39. }
  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. #region 已审核的单据先弃审
  54. List<string> DocList = new List<string>();
  55. foreach (ICSManufactureReceiveDoc Info in infos)
  56. {
  57. long DocID = 0;
  58. string DocType = "";
  59. DataTable dt = GetData(Info.MRCVCode, 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. //审核完成的单据需要先弃审,后删除
  64. if (dt.Rows[0][1].ToString() == "1")
  65. {
  66. DocList.Add(DocID.ToString());
  67. }
  68. }
  69. else
  70. {
  71. throw new Exception("需要删除的单据号不正确!");
  72. }
  73. }
  74. UnApproveCompRpt UnApprove = new UnApproveCompRpt();
  75. UnApprove.UnApprove(DocList, OrgID);
  76. #endregion
  77. UFIDAU9ISVMOCompRptKeyDTOData[] compRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  78. List<UFIDAU9ISVMOCompRptKeyDTOData> compRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  79. foreach (ICSManufactureReceiveDoc Info in infos)
  80. {
  81. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  82. model.m_docNo = Info.MRCVCode;
  83. model.m_iD = GetTypeID(Info.MRCVCode, OrgID);
  84. compRptKeyList.Add(model);
  85. }
  86. compRptKeyDTOs = compRptKeyList.ToArray();
  87. context = CreateContextObj(OrgID);
  88. //服务调用
  89. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  90. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  91. bool isfalse = false;
  92. isfalse = client.Do(out returnMsg, context, compRptKeyDTOs);
  93. if (isfalse)
  94. {
  95. ResultFlag = true;
  96. }
  97. else
  98. {
  99. throw new Exception("完工报告删除失败,请查看日志!");
  100. }
  101. }
  102. catch (Exception ex)
  103. {
  104. log.Error(ex.Message);
  105. throw new Exception(ex.Message);
  106. }
  107. return ResultFlag;
  108. }
  109. /// <summary>
  110. /// 删除完工报告(接口内部调用,如:创建退料单后调用审核单据)
  111. /// </summary>
  112. /// <param name="DocNOList"></param>
  113. /// <param name="OrgCode"></param>
  114. /// <returns></returns>
  115. public bool Delete(List<string> DocNOList, string OrgCode)
  116. {
  117. bool ResultFlag = false;
  118. try
  119. {
  120. UFIDAU9ISVMOIDeleteCompRptSrvClient client = new UFIDAU9ISVMOIDeleteCompRptSrvClient();
  121. MessageBase[] returnMsg;
  122. object context;
  123. if (DocNOList == null || DocNOList.Count == 0)
  124. {
  125. throw new Exception("传入参数不能为空!");
  126. }
  127. string OrgID = "";
  128. string orgsql = @"select ID from Base_Organization
  129. where Code='{0}'";
  130. orgsql = string.Format(orgsql, OrgCode);
  131. DataTable orgdt = DBHelper.Query(orgsql, connString);
  132. if (orgdt.Rows.Count != 0)
  133. {
  134. OrgID = orgdt.Rows[0]["ID"].ToString();
  135. }
  136. else
  137. {
  138. throw new Exception("传入组织编码错误!");
  139. }
  140. #region 已审核的单据先弃审
  141. List<string> DocList = new List<string>();
  142. foreach (string DocNo in DocNOList)
  143. {
  144. long DocID = 0;
  145. string DocType = "";
  146. DataTable dt = GetData(DocNo, OrgID);
  147. if (!string.IsNullOrEmpty(dt.Rows[0][0].ToString()) || !string.IsNullOrEmpty(dt.Rows[0][1].ToString()))
  148. {
  149. DocID = long.Parse(dt.Rows[0][0].ToString());
  150. //审核完成的单据需要先弃审,后删除
  151. if (dt.Rows[0][1].ToString() == "1")
  152. {
  153. DocList.Add(DocID.ToString());
  154. }
  155. }
  156. else
  157. {
  158. throw new Exception("需要删除的单据号不正确!");
  159. }
  160. }
  161. UnApproveCompRpt UnApprove = new UnApproveCompRpt();
  162. UnApprove.UnApprove(DocList, OrgID);
  163. #endregion
  164. UFIDAU9ISVMOCompRptKeyDTOData[] compRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  165. List<UFIDAU9ISVMOCompRptKeyDTOData> compRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  166. foreach (string DocNo in DocNOList)
  167. {
  168. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  169. model.m_docNo = DocNo;
  170. model.m_iD = GetTypeID(DocNo, OrgID);
  171. compRptKeyList.Add(model);
  172. }
  173. compRptKeyDTOs = compRptKeyList.ToArray();
  174. context = CreateContextObj(OrgID);
  175. //服务调用
  176. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  177. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  178. bool isfalse = false;
  179. isfalse = client.Do(out returnMsg, context, compRptKeyDTOs);
  180. if (isfalse)
  181. {
  182. ResultFlag = true;
  183. }
  184. else
  185. {
  186. throw new Exception("完工报告删除失败,请查看日志!");
  187. }
  188. }
  189. catch (Exception ex)
  190. {
  191. log.Error(ex.Message);
  192. throw new Exception(ex.Message);
  193. }
  194. return ResultFlag;
  195. }
  196. private static long GetTypeID(string docTypeCode, string OrgID)
  197. {
  198. string sql = @"select ID from MO_CompleteRpt where DocNo='" + docTypeCode + "' AND Org='" + OrgID + "' ";
  199. DataTable dt = DBHelper.Query(sql, connString);
  200. if (dt.Rows.Count > 0)
  201. {
  202. return long.Parse(dt.Rows[0][0].ToString());
  203. }
  204. else
  205. {
  206. return 0;
  207. }
  208. }
  209. #region 给上下文信息赋值
  210. /// <summary>
  211. /// 给上下文信息赋值
  212. /// </summary>
  213. /// <returns></returns>
  214. private static ThreadContext CreateContextObj(string OrgID)
  215. {
  216. // 实例化应用上下文对象
  217. ThreadContext thContext = new ThreadContext();
  218. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  219. ns.Add("OrgID", OrgID);
  220. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  221. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  222. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  223. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  224. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  225. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  226. thContext.nameValueHas = ns;
  227. return thContext;
  228. }
  229. #endregion
  230. private static DataTable GetData(string DocCode, string OrgID)
  231. {
  232. string sql = @" select ID,DocState from MO_CompleteRpt
  233. where DocNo='"+ DocCode + "' AND Org='" + OrgID + "'";
  234. return DBHelper.Query(sql, connString);
  235. }
  236. }
  237. }