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

360 lines
16 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. using ICSSoft.APIDeleteCompRpt;
  17. namespace ICSSoft.APICloseCompRpt
  18. {
  19. public class CloseCompRpt
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"];
  23. private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"];
  24. /// <summary>
  25. /// 关闭完工报告(外部通过API调用)
  26. /// </summary>
  27. /// <param name="infos"></param>
  28. /// <returns></returns>
  29. public bool Close(List<ICSManufactureReceiveDoc> infos)
  30. {
  31. bool ResultFlag = false;
  32. object context;
  33. string OrgID = "";
  34. UFIDAU9ISVMOIRcvCompleteRpt4ExternalSrvClient client = new UFIDAU9ISVMOIRcvCompleteRpt4ExternalSrvClient();
  35. UFIDAU9ISVMOCompRptKeyDTOData[] _result = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  36. MessageBase[] returnMsg;
  37. try
  38. {
  39. if (infos == null || infos.Count == 0)
  40. {
  41. throw new Exception("传入数据不能为空!");
  42. }
  43. string orgsql = @"select ID from Base_Organization
  44. where Code='{0}'";
  45. orgsql = string.Format(orgsql, infos[0].WorkPoint);
  46. DataTable orgdt = DBHelper.Query(orgsql, connString);
  47. if (orgdt.Rows.Count != 0)
  48. {
  49. OrgID = orgdt.Rows[0]["ID"].ToString();
  50. }
  51. else
  52. {
  53. throw new Exception("传入组织编码错误!");
  54. }
  55. UFIDAU9ISVMOCompRptKeyDTOData[] compRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  56. List<UFIDAU9ISVMOCompRptKeyDTOData> compRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  57. foreach (ICSManufactureReceiveDoc Info in infos)
  58. {
  59. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  60. model.m_docNo = Info.MRCVCode;
  61. model.m_iD = GetTypeID(Info.MRCVCode, OrgID);
  62. model.m_operateResult = true;
  63. model.m_operateType = true;
  64. compRptKeyList.Add(model);
  65. }
  66. compRptKeyDTOs = compRptKeyList.ToArray();
  67. context = CreateContextObj(OrgID);
  68. //服务调用
  69. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  70. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  71. _result = client.Do(out returnMsg, context, compRptKeyDTOs, true);
  72. bool ISSuccess = true;
  73. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  74. {
  75. if (info.m_operateResult == false)
  76. {
  77. ISSuccess = false;
  78. }
  79. }
  80. if (ISSuccess == true)
  81. {
  82. ResultFlag = true;
  83. }
  84. else
  85. {
  86. #region 存在完工报告关闭失败时先取消入库已入库的完工报告
  87. UFIDAU9ISVMOCompRptKeyDTOData[] opencompRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  88. List<UFIDAU9ISVMOCompRptKeyDTOData> opencompRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  89. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  90. {
  91. if (info.m_operateResult == true)
  92. {
  93. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  94. model.m_docNo = info.m_docNo;
  95. model.m_iD = GetTypeID(info.m_docNo, OrgID);
  96. model.m_operateResult = true;
  97. model.m_operateType = false;//true:完工报告入库 false:完工报告取消入库
  98. opencompRptKeyList.Add(model);
  99. }
  100. }
  101. opencompRptKeyDTOs = opencompRptKeyList.ToArray();
  102. client.Do(out returnMsg, context, opencompRptKeyDTOs, true);
  103. #endregion
  104. #region 弃审完工报告
  105. List<string> DocIDList = new List<string>();
  106. foreach (ICSManufactureReceiveDoc Info in infos)
  107. {
  108. long docid = GetTypeID(Info.MRCVCode, OrgID);
  109. DocIDList.Add(docid.ToString());
  110. }
  111. UnApproveCompRpt unapprove = new UnApproveCompRpt();
  112. unapprove.UnApprove(DocIDList, OrgID);
  113. #endregion
  114. #region 删除完工报告
  115. List<string> docNoList = new List<string>();
  116. foreach (ICSManufactureReceiveDoc Info in infos)
  117. {
  118. docNoList.Add(Info.MRCVCode);
  119. }
  120. DeleteCompRpt del = new DeleteCompRpt();
  121. del.Delete(docNoList, OrgID);
  122. #endregion
  123. }
  124. }
  125. catch (Exception ex)
  126. {
  127. #region 存在完工报告关闭失败时先取消入库已入库的完工报告
  128. context = CreateContextObj(OrgID);
  129. UFIDAU9ISVMOCompRptKeyDTOData[] opencompRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  130. List<UFIDAU9ISVMOCompRptKeyDTOData> opencompRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  131. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  132. {
  133. if (info.m_operateResult == true)
  134. {
  135. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  136. model.m_docNo = info.m_docNo;
  137. model.m_iD = GetTypeID(info.m_docNo, OrgID);
  138. model.m_operateResult = true;
  139. model.m_operateType = false;//true:完工报告入库 false:完工报告取消入库
  140. opencompRptKeyList.Add(model);
  141. }
  142. }
  143. opencompRptKeyDTOs = opencompRptKeyList.ToArray();
  144. client.Do(out returnMsg, context, opencompRptKeyDTOs, true);
  145. #endregion
  146. #region 弃审完工报告
  147. List<string> DocIDList = new List<string>();
  148. foreach (ICSManufactureReceiveDoc Info in infos)
  149. {
  150. long docid = GetTypeID(Info.MRCVCode, OrgID);
  151. DocIDList.Add(docid.ToString());
  152. }
  153. UnApproveCompRpt unapprove = new UnApproveCompRpt();
  154. unapprove.UnApprove(DocIDList, OrgID);
  155. #endregion
  156. #region 删除完工报告
  157. List<string> docNoList = new List<string>();
  158. foreach (ICSManufactureReceiveDoc Info in infos)
  159. {
  160. docNoList.Add(Info.MRCVCode);
  161. }
  162. DeleteCompRpt del = new DeleteCompRpt();
  163. del.Delete(docNoList, OrgID);
  164. #endregion
  165. log.Error(ex.Message);
  166. throw new Exception(ex.Message);
  167. }
  168. return ResultFlag;
  169. }
  170. /// <summary>
  171. /// 关闭完工报告(接口内部调用,如:创建退料单后调用审核单据)
  172. /// </summary>
  173. /// <param name="DocNOList"></param>
  174. /// <param name="OrgCode"></param>
  175. /// <returns></returns>
  176. public bool Close(List<string> DocNOList, string OrgCode)
  177. {
  178. bool ResultFlag = false;
  179. object context;
  180. string OrgID = "";
  181. UFIDAU9ISVMOIRcvCompleteRpt4ExternalSrvClient client = new UFIDAU9ISVMOIRcvCompleteRpt4ExternalSrvClient();
  182. UFIDAU9ISVMOCompRptKeyDTOData[] _result = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  183. MessageBase[] returnMsg;
  184. try
  185. {
  186. if (DocNOList == null || DocNOList.Count == 0)
  187. {
  188. throw new Exception("传入数据不能为空!");
  189. }
  190. string orgsql = @"select ID from Base_Organization
  191. where Code='{0}'";
  192. orgsql = string.Format(orgsql, OrgCode);
  193. DataTable orgdt = DBHelper.Query(orgsql, connString);
  194. if (orgdt.Rows.Count != 0)
  195. {
  196. OrgID = orgdt.Rows[0]["ID"].ToString();
  197. }
  198. else
  199. {
  200. throw new Exception("传入组织编码错误!");
  201. }
  202. UFIDAU9ISVMOCompRptKeyDTOData[] compRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  203. List<UFIDAU9ISVMOCompRptKeyDTOData> compRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  204. foreach (string DocNO in DocNOList)
  205. {
  206. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  207. model.m_docNo = DocNO;
  208. model.m_iD = GetTypeID(DocNO, OrgID);
  209. model.m_operateResult = true;
  210. model.m_operateType = true;
  211. compRptKeyList.Add(model);
  212. }
  213. compRptKeyDTOs = compRptKeyList.ToArray();
  214. context = CreateContextObj(OrgID);
  215. //服务调用
  216. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  217. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  218. _result = client.Do(out returnMsg, context, compRptKeyDTOs, true);
  219. bool ISSuccess = true;
  220. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  221. {
  222. if (info.m_operateResult == false)
  223. {
  224. ISSuccess = false;
  225. }
  226. }
  227. if (ISSuccess == true)
  228. {
  229. ResultFlag = true;
  230. }
  231. else
  232. {
  233. #region 存在完工报告关闭失败时先取消入库已入库的完工报告
  234. UFIDAU9ISVMOCompRptKeyDTOData[] opencompRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  235. List<UFIDAU9ISVMOCompRptKeyDTOData> opencompRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  236. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  237. {
  238. if (info.m_operateResult == true)
  239. {
  240. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  241. model.m_docNo = info.m_docNo;
  242. model.m_iD = GetTypeID(info.m_docNo, OrgID);
  243. model.m_operateResult = true;
  244. model.m_operateType = false;//true:完工报告入库 false:完工报告取消入库
  245. opencompRptKeyList.Add(model);
  246. }
  247. }
  248. opencompRptKeyDTOs = opencompRptKeyList.ToArray();
  249. client.Do(out returnMsg, context, opencompRptKeyDTOs, true);
  250. #endregion
  251. #region 弃审完工报告
  252. List<string> DocIDList = new List<string>();
  253. foreach (string DocNO in DocNOList)
  254. {
  255. long docid = GetTypeID(DocNO, OrgID);
  256. DocIDList.Add(docid.ToString());
  257. }
  258. UnApproveCompRpt unapprove = new UnApproveCompRpt();
  259. unapprove.UnApprove(DocIDList, OrgID);
  260. #endregion
  261. #region 删除完工报告
  262. DeleteCompRpt del = new DeleteCompRpt();
  263. del.Delete(DocNOList, OrgID);
  264. #endregion
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. #region 存在完工报告关闭失败时先取消入库已入库的完工报告
  270. context = CreateContextObj(OrgID);
  271. UFIDAU9ISVMOCompRptKeyDTOData[] opencompRptKeyDTOs = new UFIDAU9ISVMOCompRptKeyDTOData[] { };
  272. List<UFIDAU9ISVMOCompRptKeyDTOData> opencompRptKeyList = new List<UFIDAU9ISVMOCompRptKeyDTOData>();
  273. foreach (UFIDAU9ISVMOCompRptKeyDTOData info in _result)
  274. {
  275. if (info.m_operateResult == true)
  276. {
  277. UFIDAU9ISVMOCompRptKeyDTOData model = new UFIDAU9ISVMOCompRptKeyDTOData();
  278. model.m_docNo = info.m_docNo;
  279. model.m_iD = GetTypeID(info.m_docNo, OrgID);
  280. model.m_operateResult = true;
  281. model.m_operateType = false;//true:完工报告入库 false:完工报告取消入库
  282. opencompRptKeyList.Add(model);
  283. }
  284. }
  285. opencompRptKeyDTOs = opencompRptKeyList.ToArray();
  286. client.Do(out returnMsg, context, opencompRptKeyDTOs, true);
  287. #endregion
  288. #region 弃审完工报告
  289. List<string> DocIDList = new List<string>();
  290. foreach (string DocNO in DocNOList)
  291. {
  292. long docid = GetTypeID(DocNO, OrgID);
  293. DocIDList.Add(docid.ToString());
  294. }
  295. UnApproveCompRpt unapprove = new UnApproveCompRpt();
  296. unapprove.UnApprove(DocIDList, OrgID);
  297. #endregion
  298. #region 删除完工报告
  299. DeleteCompRpt del = new DeleteCompRpt();
  300. del.Delete(DocNOList, OrgID);
  301. #endregion
  302. log.Error(ex.Message);
  303. throw new Exception(ex.Message);
  304. }
  305. return ResultFlag;
  306. }
  307. private static long GetTypeID(string docTypeCode, string OrgID)
  308. {
  309. string sql = @"select ID from MO_CompleteRpt where DocNo='" + docTypeCode + "' AND Org='" + OrgID + "' ";
  310. DataTable dt = DBHelper.Query(sql, connString);
  311. if (dt.Rows.Count > 0)
  312. {
  313. return long.Parse(dt.Rows[0][0].ToString());
  314. }
  315. else
  316. {
  317. return 0;
  318. }
  319. }
  320. #region 给上下文信息赋值
  321. /// <summary>
  322. /// 给上下文信息赋值
  323. /// </summary>
  324. /// <returns></returns>
  325. private static ThreadContext CreateContextObj(string OrgID)
  326. {
  327. // 实例化应用上下文对象
  328. ThreadContext thContext = new ThreadContext();
  329. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  330. ns.Add("OrgID", OrgID);
  331. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  332. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  333. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  334. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  335. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  336. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  337. thContext.nameValueHas = ns;
  338. return thContext;
  339. }
  340. #endregion
  341. }
  342. }