圣珀
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.

384 lines
17 KiB

2 years ago
  1. using ICS.WCF.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.ServiceModel;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using UFSoft.UBF.Exceptions1;
  11. using UFSoft.UBF.Service;
  12. using UFSoft.UBF.Util.Context;
  13. using www.ufida.org.EntityData;
  14. namespace UFIDA.ISV.BFIssueApprove
  15. {
  16. public class CustApproveIssue
  17. {
  18. /// <summary>
  19. /// 审核领料单
  20. /// </summary>
  21. /// <returns></returns>
  22. ///
  23. public OperationResult CustBFApproveIssue(List<string> LLCodeList, string OrgCode)
  24. {
  25. OperationResult result = new OperationResult();
  26. ThreadContext context;
  27. try
  28. {
  29. StringBuilder strHead = new StringBuilder();
  30. string _MOCode = string.Empty;
  31. UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
  32. MessageBase[] message = null;
  33. List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
  34. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  35. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
  36. string OrgID = "";
  37. if (LLCodeList != null && LLCodeList.Count != 0)
  38. {
  39. strHead.AppendLine("***************审核领料单开始****************:");
  40. strHead.AppendLine("组织编码:" + OrgCode);
  41. string orgsql = @"select ID from Base_Organization
  42. where Code='{0}'";
  43. orgsql = string.Format(orgsql, OrgCode);
  44. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  45. if (orgdt.Rows.Count != 0)
  46. {
  47. OrgID = orgdt.Rows[0]["ID"].ToString();
  48. }
  49. else
  50. {
  51. result.MESSAGE = "组织编码:" + OrgCode + "不存在!";
  52. result.IsSuccess = false;
  53. return result;
  54. }
  55. foreach (string Code in LLCodeList)
  56. {
  57. strHead.AppendLine("单号:" + Code);
  58. string checksql = @"select * from MO_IssueDoc
  59. where DocNo='" + Code + "' AND Org='" + OrgID + "'";
  60. checksql = string.Format(checksql);
  61. DataTable dtcheck = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
  62. if (dtcheck.Rows.Count == 0)
  63. {
  64. result.MESSAGE = "领料单号:'" + Code + "'不存在!";
  65. result.IsSuccess = false;
  66. return result;
  67. }
  68. else
  69. {
  70. LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  71. LL.m_docNo = Code;
  72. LL.m_operateType = true;
  73. LLlist.Add(LL);
  74. }
  75. }
  76. }
  77. else
  78. {
  79. result.MESSAGE = "传入数据不能为空!";
  80. result.IsSuccess = false;
  81. return result;
  82. }
  83. strHead.AppendLine("***************审核领料单结束****************:");
  84. Appconfig.WriteLogFile(strHead.ToString(), "审核生产领料单");
  85. context = CreateContextObj(OrgID);
  86. resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
  87. if (resultList != null && resultList.Count() > 0)
  88. {
  89. StringBuilder str = new StringBuilder();
  90. foreach (var item in resultList)
  91. {
  92. if (item.m_isSucceed == true)
  93. {
  94. #region 审核成功后修改单据的修改人和审核人为WMS
  95. foreach (string Code in LLCodeList)
  96. {
  97. Appconfig.UpdateDocApproveMan(Code, OrgID, "WMS", "MO_IssueDoc", "MO_IssueDocLine");
  98. }
  99. #endregion
  100. }
  101. result.LLCode = item.m_docNo;
  102. result.MESSAGE = item.m_errorMsg;
  103. result.IsSuccess = item.m_isSucceed;
  104. str.AppendLine("审核生产领料单:");
  105. str.AppendLine("单号:" + item.m_docNo);
  106. str.AppendLine("返回信息:" + item.m_errorMsg);
  107. }
  108. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  109. }
  110. else
  111. {
  112. #region 审核成功后修改单据的修改人和审核人为WMS
  113. foreach (string Code in LLCodeList)
  114. {
  115. Appconfig.UpdateDocApproveMan(Code, OrgID, "WMS", "MO_IssueDoc", "MO_IssueDocLine");
  116. }
  117. #endregion
  118. StringBuilder str = new StringBuilder();
  119. foreach (string docNo in LLCodeList)
  120. {
  121. str.AppendLine("审核生产领料单:");
  122. str.AppendLine("单号:" + docNo);
  123. str.AppendLine("审核成功");
  124. }
  125. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  126. result.MESSAGE = "审核成功";
  127. result.IsSuccess = true;
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. string Message = GetExceptionMessage(ex);
  133. result.IsSuccess = false;
  134. result.MESSAGE += Message;
  135. StringBuilder str = new StringBuilder();
  136. str.AppendLine("审核生产领料单:");
  137. for (int i = 0; i < LLCodeList.Count(); i++)
  138. {
  139. str.AppendLine("单号:" + LLCodeList[i]);
  140. }
  141. str.AppendLine("返回错误信息:" + Message);
  142. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  143. }
  144. return result;
  145. }
  146. /// <summary>
  147. /// 审核领料单
  148. /// </summary>
  149. /// <param name="LLCodeList"></param>
  150. /// <param name="OrgCode"></param>
  151. /// <param name="UserCode"></param>
  152. /// <returns></returns>
  153. public OperationResult CustBFApproveIssue(string LLCode, string OrgCode, string UserCode)
  154. {
  155. OperationResult result = new OperationResult();
  156. ThreadContext context;
  157. try
  158. {
  159. StringBuilder strHead = new StringBuilder();
  160. string _MOCode = string.Empty;
  161. UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient client = new UFIDAU9ISVMOIApproveIssueDoc4ExternalSrvClient();
  162. MessageBase[] message = null;
  163. List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData> LLlist = new List<UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData>();
  164. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  165. UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] resultList = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData[] { };
  166. string OrgID = "";
  167. string CreateBy = string.Empty;
  168. if (LLCode != null && LLCode != "")
  169. {
  170. strHead.AppendLine("***************审核领料单开始****************:");
  171. strHead.AppendLine("组织编码:" + OrgCode);
  172. string orgsql = @"select ID from Base_Organization
  173. where Code='{0}'";
  174. orgsql = string.Format(orgsql, OrgCode);
  175. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  176. if (orgdt.Rows.Count != 0)
  177. {
  178. OrgID = orgdt.Rows[0]["ID"].ToString();
  179. }
  180. else
  181. {
  182. result.MESSAGE = "组织编码:" + OrgCode + "不存在!";
  183. result.IsSuccess = false;
  184. return result;
  185. }
  186. #region 获取业务员名称
  187. string usersql = @"select B.Name from CBO_Operators A
  188. LEFT JOIN CBO_Operators_Trl B
  189. ON B.ID=A.ID
  190. where A.Code='{0}' and A.Org='{1}'";
  191. usersql = string.Format(usersql, UserCode, OrgID);
  192. DataTable userdt = DBhlper.Query(usersql, Appconfig.GetU9ConnStr());
  193. #endregion
  194. if (userdt.Rows.Count != 0)
  195. {
  196. CreateBy = userdt.Rows[0]["Name"].ToString();
  197. }
  198. else
  199. {
  200. CreateBy = "U9ERP";
  201. }
  202. strHead.AppendLine("单号:" + LLCode);
  203. string checksql = @"select * from MO_IssueDoc
  204. where DocNo='" + LLCode + "' AND Org='" + OrgID + "'";
  205. checksql = string.Format(checksql);
  206. DataTable dtcheck = DBhlper.Query(checksql, Appconfig.GetU9ConnStr());
  207. if (dtcheck.Rows.Count == 0)
  208. {
  209. result.MESSAGE = "领料单号:'" + LLCode + "'不存在!";
  210. result.IsSuccess = false;
  211. return result;
  212. }
  213. else
  214. {
  215. LL = new UFIDAU9ISVMOApproveIssueDoc4ExternalDTOData();
  216. LL.m_docNo = LLCode;
  217. LL.m_operateType = true;
  218. LLlist.Add(LL);
  219. }
  220. }
  221. else
  222. {
  223. result.MESSAGE = "传入领料单号不能为空!";
  224. result.IsSuccess = false;
  225. return result;
  226. }
  227. strHead.AppendLine("***************审核领料单结束****************:");
  228. Appconfig.WriteLogFile(strHead.ToString(), "审核生产领料单");
  229. context = CreateContextObj(OrgID);
  230. resultList = client.Do(out message, context, LLlist.ToArray(), false, false);
  231. if (resultList != null && resultList.Count() > 0)
  232. {
  233. StringBuilder str = new StringBuilder();
  234. foreach (var item in resultList)
  235. {
  236. result.LLCode = item.m_docNo;
  237. result.MESSAGE = item.m_errorMsg;
  238. result.IsSuccess = item.m_isSucceed;
  239. str.AppendLine("审核生产领料单:");
  240. str.AppendLine("单号:" + item.m_docNo);
  241. str.AppendLine("返回信息:" + item.m_errorMsg);
  242. }
  243. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  244. }
  245. else
  246. {
  247. StringBuilder str = new StringBuilder();
  248. str.AppendLine("审核生产领料单:");
  249. str.AppendLine("单号:" + LLCode);
  250. str.AppendLine("审核成功");
  251. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  252. result.MESSAGE = "审核成功";
  253. result.IsSuccess = true;
  254. }
  255. if (result.IsSuccess == true)
  256. {
  257. string updatesql = @"select ID from MO_IssueDoc
  258. where DOCNO='{0}' AND Org='{1}'";
  259. updatesql = string.Format(updatesql, LLCode, OrgID);
  260. DataTable updatedt = DBhlper.Query(updatesql, Appconfig.GetU9ConnStr());
  261. if (updatedt.Rows.Count != 0)
  262. {
  263. string LLID = updatedt.Rows[0]["ID"].ToString();
  264. updatesql = @"update MO_IssueDoc set ApproveBy='{1}'
  265. where ID='{0}'";
  266. updatesql = string.Format(updatesql, LLID, CreateBy);
  267. DBhlper.EXecute(updatesql, Appconfig.GetU9ConnStr());
  268. }
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. string Message = GetExceptionMessage(ex);
  274. result.IsSuccess = false;
  275. result.MESSAGE += Message;
  276. StringBuilder str = new StringBuilder();
  277. str.AppendLine("审核生产领料单:");
  278. str.AppendLine("单号:" + LLCode);
  279. str.AppendLine("返回错误信息:" + Message);
  280. Appconfig.WriteLogFile(str.ToString(), "审核生产领料单");
  281. }
  282. return result;
  283. }
  284. /// <summary>
  285. /// 创建上下文
  286. /// </summary>
  287. /// <returns></returns>
  288. private static ThreadContext CreateContextObj(string OrgID)
  289. {
  290. // 实例化应用上下文对象
  291. ThreadContext thContext = new ThreadContext();
  292. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  293. ns.Add("OrgID", OrgID);
  294. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  295. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  296. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  297. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  298. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  299. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  300. ns.Add("acttype", ConfigurationManager.AppSettings["acttype"].ToString());
  301. thContext.nameValueHas = ns;
  302. return thContext;
  303. return thContext;
  304. }
  305. #region 提取异常信息
  306. /// <summary>
  307. /// 提取异常信息
  308. /// </summary>
  309. /// <param name="ex"></param>
  310. private static string GetExceptionMessage(Exception ex)
  311. {
  312. string faultMessage = "未知错误,请查看ERP日志!";
  313. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  314. if (timeoutEx != null)
  315. {
  316. faultMessage = "访问服务超时,请修改配置信息!";
  317. }
  318. else
  319. {
  320. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  321. if (faultEx == null)
  322. {
  323. faultMessage = ex.Message;
  324. }
  325. else
  326. {
  327. ServiceException serviceEx = faultEx.Detail;
  328. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  329. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  330. {
  331. // 错误信息在faultEx.Message中,请提取,
  332. // 格式为"Fault:料品不能为空,请录入\n 在....."
  333. int startIndex = serviceEx.Message.IndexOf(":");
  334. int endIndex = serviceEx.Message.IndexOf("\n");
  335. if (endIndex == -1)
  336. endIndex = serviceEx.Message.Length;
  337. if (endIndex > 0 && endIndex > startIndex + 1)
  338. {
  339. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  340. }
  341. else
  342. {
  343. faultMessage = serviceEx.Message;
  344. }
  345. }
  346. }
  347. }
  348. return faultMessage;
  349. }
  350. #endregion
  351. public class OperationResult
  352. {
  353. /// <summary>
  354. /// 结果状态,默认值false
  355. /// </summary>
  356. public bool IsSuccess { get; set; }
  357. /// <summary>
  358. ///处理消息
  359. /// </summary>
  360. public string MESSAGE { get; set; }
  361. /// <summary>
  362. /// 输出领料订单
  363. /// </summary>
  364. public string LLCode { get; set; }
  365. }
  366. }
  367. }