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

1096 lines
59 KiB

  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 UFIDA.ISV.BFIssueApprove;
  11. using UFIDA.ISV.BFIssueDelete;
  12. using UFSoft.UBF.Exceptions1;
  13. using UFSoft.UBF.Service;
  14. using UFSoft.UBF.Util.Context;
  15. using www.ufida.org.EntityData;
  16. namespace UFIDA.ISV.CreateAboveIssue
  17. {
  18. public class CustCreateAboveIssue
  19. {
  20. /// <summary>
  21. /// 创建领料单
  22. /// </summary>
  23. /// <returns></returns>
  24. ///
  25. public OperationResult CreateAboveIssue(List<IssueAboveData> modellist)
  26. {
  27. #region 入口日志
  28. StringBuilder beginstrlog = new StringBuilder();
  29. beginstrlog.AppendLine("日志记录开始");
  30. beginstrlog.AppendLine("*****************************************************");
  31. foreach (IssueAboveData model in modellist)
  32. {
  33. beginstrlog.AppendLine("领料部门:" + model.DeptNo);
  34. beginstrlog.AppendLine("生产订单:" + model.MoCode);
  35. beginstrlog.AppendLine("组织编码:" + model.OrgCode);
  36. beginstrlog.AppendLine("备注:" + model.Memo);
  37. foreach (IssueLineData lineinfo in model.linelist)
  38. {
  39. bool isLotCheck = Appconfig.WHLotCheckState(lineinfo.WHCode, model.OrgCode);
  40. if (isLotCheck == false)
  41. {
  42. lineinfo.Batch = "";
  43. }
  44. beginstrlog.AppendLine("领料料号:" + lineinfo.ItemCode);
  45. beginstrlog.AppendLine("领料数量:" + lineinfo.ItemQty);
  46. beginstrlog.AppendLine("存储地点:" + lineinfo.WHCode);
  47. beginstrlog.AppendLine("领料批号:" + lineinfo.Batch);
  48. beginstrlog.AppendLine("领料供应商:" + lineinfo.Vender);
  49. }
  50. }
  51. beginstrlog.AppendLine("*****************************************************");
  52. Appconfig.WriteLogFile(beginstrlog.ToString(), "创建U9领料单");
  53. #endregion
  54. OperationResult result = new OperationResult();
  55. ThreadContext context = CreateContextObj();
  56. string OrgID = "";
  57. try
  58. {
  59. string _MOCode = string.Empty;
  60. UFIDAU9ISVMOICreateIssue4ExternalClient client = new UFIDAU9ISVMOICreateIssue4ExternalClient();
  61. MessageBase[] message = null;
  62. List<UFIDAU9ISVMOIssueDTOData> molist = new List<UFIDAU9ISVMOIssueDTOData>();
  63. UFIDAU9ISVMOIssueDTOData mo = new UFIDAU9ISVMOIssueDTOData();
  64. List<UFIDAU9ISVMOPickListDTOData> PL = new List<UFIDAU9ISVMOPickListDTOData>();
  65. foreach (IssueAboveData model in modellist)
  66. {
  67. mo = new UFIDAU9ISVMOIssueDTOData();
  68. PL = new List<UFIDAU9ISVMOPickListDTOData>();
  69. if (!string.IsNullOrWhiteSpace(model.MoCode))
  70. {
  71. string orgsql = @"select ID from Base_Organization
  72. where Code='{0}'";
  73. orgsql = string.Format(orgsql, model.OrgCode);
  74. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  75. if (orgdt.Rows.Count != 0)
  76. {
  77. OrgID = orgdt.Rows[0]["ID"].ToString();
  78. }
  79. else
  80. {
  81. throw new Exception("未获取到组织!");
  82. }
  83. //验证该工单的备料表中是否存在数据
  84. int p = Appconfig.IsExistcPickList(model.MoCode);
  85. if (p > 0)
  86. {
  87. #region 遍历入参LL单行
  88. foreach (var item in model.linelist)
  89. {
  90. bool IsVMI = false;
  91. string strCcode = item.ItemCode; //子料
  92. decimal _useQty = item.ItemQty; //子件使用量
  93. string _strWhID = string.Empty;//仓库ID
  94. string WHID = "";
  95. if (!string.IsNullOrWhiteSpace(strCcode))
  96. {
  97. //虚拟库位 ZP1-01 20190912新增过滤虚拟库位
  98. string _SqlDbType = @" select Distinct ID,Code from CBO_WH
  99. where Code='" + item.WHCode + "' AND Org='" + OrgID + "'";
  100. _SqlDbType = string.Format(_SqlDbType);
  101. DataTable _SqlDbTypedt = DBhlper.Query(_SqlDbType, Appconfig.GetU9ConnStr());
  102. if (_SqlDbTypedt != null && _SqlDbTypedt.Rows.Count > 0)
  103. {
  104. WHID = _SqlDbTypedt.Rows[0]["ID"].ToString();
  105. }
  106. else
  107. {
  108. result.MESSAGE = "传入仓库不存在!";
  109. result.IsSuccess = false;
  110. return result;
  111. }
  112. }
  113. UFIDAU9ISVMOPickListDTOData PLS = new UFIDAU9ISVMOPickListDTOData();
  114. int i = Appconfig.IsExistItem(strCcode);
  115. if (i < 1)
  116. {
  117. result.MESSAGE = "料品编码不存在!";
  118. result.IsSuccess = false;
  119. return result;
  120. }
  121. Decimal MOQty = 0;
  122. long MOID = 0;
  123. _MOCode = model.MoCode;
  124. DataTable _dt = Appconfig.GetMOQtyAndID(model.MoCode);
  125. if (_dt != null && _dt.Rows.Count > 0)
  126. {
  127. foreach (DataRow _item in _dt.Rows)
  128. {
  129. string _strMOQty = string.Empty;
  130. string _strMOID = string.Empty;
  131. _strMOQty = _item["ProductQty"].ToString();
  132. if (!string.IsNullOrWhiteSpace(_strMOQty))
  133. {
  134. MOQty = Decimal.Parse(_strMOQty);//生产订单数量
  135. }
  136. _strMOID = _item["ID"].ToString();
  137. if (!string.IsNullOrWhiteSpace(_strMOID))
  138. {
  139. MOID = long.Parse(_strMOID);
  140. }
  141. }
  142. }
  143. string mOPickList = string.Empty;
  144. mOPickList = Appconfig.GetMoPickListID(model.MoCode, strCcode);// 1001903220007058;// iPickid;
  145. Decimal IssuedQty = 0; //已发放数量
  146. Decimal ActualReqQty = 0; //实际需求数量
  147. if (!string.IsNullOrWhiteSpace(mOPickList))
  148. {
  149. //已发放数量-领料未发数量
  150. DataTable dtQty = Appconfig.GetQtyBymOPickList(model.MoCode, strCcode);
  151. if (dtQty != null && dtQty.Rows.Count > 0)
  152. {
  153. ActualReqQty = Decimal.Parse(dtQty.Rows[0]["ActualReqQty"].ToString());
  154. }
  155. PLS.m_mOPickList = long.Parse(mOPickList);
  156. }
  157. else
  158. {
  159. result.MESSAGE = "备料表单ID不存在!工单:'" + model.MoCode + "',料号:'" + strCcode + "' ";
  160. result.IsSuccess = false;
  161. return result;
  162. }
  163. //PLS.m_issueQty = useQty * MOQty - SendQty;// item.issueQty* useQty;//1; //应发数量
  164. if (ActualReqQty < _useQty)
  165. {
  166. result.MESSAGE += "该料品" + strCcode + "需要领用的数量大于未领数量不能创建改料品的领用;";
  167. }
  168. else
  169. {
  170. //if (useQty * MOQty - SendQty - IssueNotDeliverQty > 0)
  171. //{
  172. //20190920修改ZM
  173. //PLS.m_issuedQty = useQty * MOQty - SendQty - IssueNotDeliverQty;// item.issuedQty* useQty;// 1; //实发数量
  174. PLS.m_issueQty = _useQty;
  175. PLS.m_issuedQty = _useQty;// item.issuedQty* useQty;// 1; //实发数量
  176. //仓库
  177. if (!string.IsNullOrWhiteSpace(WHID))
  178. {
  179. PLS.m_issueWh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  180. //PLS.m_issueWh.m_code = strWhCode;// "004";//cWh;
  181. PLS.m_issueWh.m_iD = long.Parse(WHID);// "004";//cWh;
  182. }
  183. //发货单位
  184. PLS.m_issueUOM = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  185. string uom = Appconfig.GetMaterialUOM(strCcode);
  186. if (!string.IsNullOrWhiteSpace(uom))
  187. {
  188. PLS.m_issueUOM.m_iD = long.Parse(uom);// Appconfig.GetMaterialUOM(item.ItemCode);// 1001607080022602;// iMaterialOutUOM;
  189. }
  190. PLS.m_aCDType = 0;
  191. PLS.m_storageType = 4;//存储类型
  192. //SourceDoc_SrcDocNo
  193. PLS.SourceIssueDocLine = MOID;
  194. #region 获取批号ID
  195. long LotID = 0;
  196. if (item.Batch != "")
  197. {
  198. string lotsql = @"SELECT ID FROM Lot_LotMaster
  199. WHERE LotCode='{0}' AND ItemCode='{1}'
  200. AND ItemOwnerOrg='{2}'";
  201. lotsql = string.Format(lotsql, item.Batch, item.ItemCode, OrgID);
  202. DataTable lotdt = DBhlper.Query(lotsql, Appconfig.GetU9ConnStr());
  203. if (lotdt.Rows.Count == 0)
  204. {
  205. result.MESSAGE += "传入批号对应料号无关联,获取批号ID失败!";
  206. result.IsSuccess = false;
  207. return result;
  208. }
  209. else
  210. {
  211. LotID = long.Parse(lotdt.Rows[0]["ID"].ToString());
  212. }
  213. }
  214. #endregion
  215. if (LotID != 0)
  216. {
  217. PLS.m_lot = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  218. PLS.m_lot.m_code = item.Batch;
  219. PLS.m_lot.m_iD = LotID;
  220. }
  221. if (IsVMI == true)
  222. {
  223. PLS.m_supplier = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  224. PLS.m_supplier.m_code = item.Vender;
  225. }
  226. PL.Add(PLS);
  227. }
  228. }
  229. #endregion
  230. }
  231. else
  232. {
  233. result.MESSAGE += "该工单没有备料表信息 ";
  234. result.IsSuccess = false;
  235. return result;
  236. }
  237. if (PL != null && PL.Count() > 0)
  238. {
  239. mo.m_issueType = 0;
  240. //部门
  241. mo.m_dept = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  242. mo.m_dept.m_code = model.DeptNo;// "MY0601";
  243. mo.m_docType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  244. #region 获取生产订单单据类型(作为生产领料单的业务类型)
  245. string IssueDocType = "";
  246. int IssueBusinessType = 0;
  247. string doctypesql = @"select B.Code AS DocTypeCode,B.BusinessType from MO_MO A
  248. LEFT JOIN MO_MODocType B
  249. ON B.ID=A.MODocType AND B.Org=A.Org";
  250. doctypesql = string.Format(doctypesql, model.MoCode, OrgID);
  251. DataTable doctypedt = DBhlper.Query(doctypesql, Appconfig.GetU9ConnStr());
  252. if (doctypedt.Rows.Count != 0)
  253. {
  254. IssueDocType = doctypedt.Rows[0]["DocTypeCode"].ToString();
  255. IssueBusinessType = int.Parse(doctypedt.Rows[0]["BusinessType"].ToString());
  256. }
  257. #endregion
  258. mo.m_docType.m_code = IssueDocType;
  259. mo.m_businessType = IssueBusinessType;
  260. string BusinessType = Appconfig.GetBusinessType(model.DocTypeCode);
  261. mo.m_srcDoc = new UFIDAU9MOPropertyTypesMOSourceDocData();// _MOCode;
  262. mo.m_srcDoc.m_srcDocNo = _MOCode;
  263. mo.m_memo = model.Memo; //备注
  264. mo.m_pickListDTOs = PL.ToArray();
  265. molist.Add(mo);
  266. }
  267. else
  268. {
  269. result.MESSAGE += "传入的数据未获取到创建领料的信息 ";
  270. result.IsSuccess = false;
  271. return result;
  272. }
  273. }
  274. else
  275. {
  276. result.MESSAGE += "该工单号不能为空 ";
  277. result.IsSuccess = false;
  278. return result;
  279. }
  280. }
  281. UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
  282. _result = client.Do(out message, context, molist.ToArray());
  283. List<string> LLCodeList = new List<string>();
  284. if (_result != null && _result.Count() > 0)
  285. {
  286. foreach (var item in _result)
  287. {
  288. if (!string.IsNullOrWhiteSpace(item.m_docNo))
  289. {
  290. LLCodeList.Add(item.m_docNo);
  291. }
  292. }
  293. }
  294. #region 审核生产领料单
  295. CustApproveIssue approveIssue = new CustApproveIssue();
  296. CustApproveIssue.OperationResult approveresult = new CustApproveIssue.OperationResult();
  297. approveresult = approveIssue.CustBFApproveIssue(LLCodeList, modellist[0].OrgCode);
  298. #endregion
  299. if (approveresult.IsSuccess == true)
  300. {
  301. foreach (string docno in LLCodeList)
  302. {
  303. result.LLCode += docno + ";";
  304. }
  305. result.IsSuccess = true;
  306. result.MESSAGE = "成功创建领料单!";
  307. }
  308. else
  309. {
  310. #region 审核失败日志
  311. StringBuilder strlog = new StringBuilder();
  312. strlog.AppendLine("审核失败日志记录开始");
  313. strlog.AppendLine("*****************************************************");
  314. foreach (string code in LLCodeList)
  315. {
  316. strlog.AppendLine("领料单号:" + code);
  317. }
  318. strlog.AppendLine("失败原因:" + approveresult.MESSAGE);
  319. strlog.AppendLine("*****************************************************");
  320. Appconfig.WriteLogFile(strlog.ToString(), "创建U9领料单");
  321. #endregion
  322. #region 审核失败时删除所有生成的领料单
  323. CustBFIssueDelete issueDelete = new CustBFIssueDelete();
  324. issueDelete.CustDeleteIssue(LLCodeList, OrgID);
  325. #endregion
  326. result.IsSuccess = false;
  327. result.MESSAGE = "领料单审核失败,生成的领料单已经删除,失败原因:" + approveresult.MESSAGE;
  328. }
  329. }
  330. catch (Exception ex)
  331. {
  332. #region 错误日志
  333. StringBuilder strlog = new StringBuilder();
  334. strlog.AppendLine("错误日志记录开始");
  335. strlog.AppendLine("*****************************************************");
  336. foreach (IssueAboveData model in modellist)
  337. {
  338. strlog.AppendLine("领料部门:" + model.DeptNo);
  339. strlog.AppendLine("生产订单:" + model.MoCode);
  340. strlog.AppendLine("组织编码:" + model.OrgCode);
  341. strlog.AppendLine("备注:" + model.Memo);
  342. foreach (IssueLineData lineinfo in model.linelist)
  343. {
  344. strlog.AppendLine("领料料号:" + lineinfo.ItemCode);
  345. strlog.AppendLine("领料数量:" + lineinfo.ItemQty);
  346. strlog.AppendLine("存储地点:" + lineinfo.WHCode);
  347. }
  348. }
  349. strlog.AppendLine("失败原因:" + GetExceptionMessage(ex));
  350. strlog.AppendLine("*****************************************************");
  351. Appconfig.WriteLogFile(strlog.ToString(), "创建U9领料单");
  352. #endregion
  353. string Message = GetExceptionMessage(ex);
  354. result.IsSuccess = false;
  355. result.MESSAGE += Message;
  356. }
  357. //"必需设置请指定IssueDTO.BusinessType属性,生产线日计划:51,标准生产:47,返工生产:48,报废生产:49"
  358. return result;
  359. }
  360. # region 辅助方法
  361. /// <summary>
  362. /// 创建上下文
  363. /// </summary>
  364. /// <returns></returns>
  365. private static ThreadContext CreateContextObj()
  366. {
  367. // 实例化应用上下文对象
  368. ThreadContext thContext = new ThreadContext();
  369. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  370. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  371. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  372. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  373. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  374. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  375. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  376. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  377. thContext.nameValueHas = ns;
  378. return thContext;
  379. }
  380. # endregion
  381. #region 提取异常信息
  382. /// <summary>
  383. /// 提取异常信息
  384. /// </summary>
  385. /// <param name="ex"></param>
  386. private static string GetExceptionMessage(Exception ex)
  387. {
  388. string faultMessage = "未知错误,请查看ERP日志!";
  389. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  390. if (timeoutEx != null)
  391. {
  392. faultMessage = "访问服务超时,请修改配置信息!";
  393. }
  394. else
  395. {
  396. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  397. if (faultEx == null)
  398. {
  399. faultMessage = ex.Message;
  400. }
  401. else
  402. {
  403. ServiceException serviceEx = faultEx.Detail;
  404. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  405. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  406. {
  407. // 错误信息在faultEx.Message中,请提取,
  408. // 格式为"Fault:料品不能为空,请录入\n 在....."
  409. int startIndex = serviceEx.Message.IndexOf(":");
  410. int endIndex = serviceEx.Message.IndexOf("\n");
  411. if (endIndex == -1)
  412. endIndex = serviceEx.Message.Length;
  413. if (endIndex > 0 && endIndex > startIndex + 1)
  414. {
  415. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  416. }
  417. else
  418. {
  419. faultMessage = serviceEx.Message;
  420. }
  421. }
  422. }
  423. }
  424. return faultMessage;
  425. }
  426. #endregion
  427. public class OperationResult
  428. {
  429. /// <summary>
  430. /// 结果状态,默认值false
  431. /// </summary>
  432. public bool IsSuccess { get; set; }
  433. /// <summary>
  434. ///处理消息
  435. /// </summary>
  436. public string MESSAGE { get; set; }
  437. /// <summary>
  438. /// 输出领料订单
  439. /// </summary>
  440. public string LLCode { get; set; }
  441. }
  442. #region 20190705
  443. //public OperationResult CreateIssue_20190701bak(IssueData model)
  444. //{
  445. // OperationResult result = new OperationResult();
  446. // ThreadContext context = CreateContextObj();
  447. // //MO-19050007 11020007
  448. // try
  449. // {
  450. // string _MOCode = string.Empty;
  451. // UFIDAU9ISVMOICreateIssue4ExternalClient client = new UFIDAU9ISVMOICreateIssue4ExternalClient();
  452. // MessageBase[] message = null;
  453. // List<UFIDAU9ISVMOIssueDTOData> molist = new List<UFIDAU9ISVMOIssueDTOData>();
  454. // UFIDAU9ISVMOIssueDTOData mo = new UFIDAU9ISVMOIssueDTOData();
  455. // List<UFIDAU9ISVMOPickListDTOData> PL = new List<UFIDAU9ISVMOPickListDTOData>();
  456. // if (model != null && model.lines.Count > 0)
  457. // {
  458. // foreach (var item in model.lines)
  459. // {
  460. // if (!string.IsNullOrWhiteSpace(item.ItemCode))
  461. // {
  462. // DataTable dt = Appconfig.GetCcodeListByMcode(item.ItemCode);
  463. // if (dt != null && dt.Rows.Count > 0)
  464. // {
  465. // foreach (DataRow row in dt.Rows)
  466. // {
  467. // string strCcode = row["ccode"].ToString(); //子料
  468. // decimal useQty = Decimal.Parse(row["useQty"].ToString()); //子件使用量
  469. // string strUnitCode = row["UnitCode"].ToString(); //单位
  470. // //string strWhCode = row["WhCode"].ToString(); //仓库
  471. // //string strBinCode = row["BinCode"].ToString(); //库位
  472. // string strWhCode = item.WhCode; //row["WhCode"].ToString(); //仓库
  473. // string strBinCode = item.BinCode;//row["BinCode"].ToString(); //库位
  474. // UFIDAU9ISVMOPickListDTOData PLS = new UFIDAU9ISVMOPickListDTOData();
  475. // int i = Appconfig.IsExistItem(strCcode);
  476. // if (i < 1)
  477. // {
  478. // result.MESSAGE = "料品编码不存在!";
  479. // result.IsSuccess = false;
  480. // return result;
  481. // }
  482. // #region 注释
  483. // //if (!string.IsNullOrWhiteSpace(item.BinCode))
  484. // //{
  485. // // int j = Appconfig.IsExistcPos(item.BinCode);
  486. // // if (i < 1)
  487. // // {
  488. // // result.MESSAGE = "库位编码不存在!";
  489. // // result.IsSuccess = false;
  490. // // return result;
  491. // // }
  492. // // else
  493. // // {
  494. // // PLS.m_issueBin = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  495. // // PLS.m_issueBin.m_code = item.BinCode;
  496. // // }
  497. // //}
  498. // //string WhCode = string.Empty;
  499. // //if (!string.IsNullOrWhiteSpace(item.BinCode))
  500. // //{
  501. // // WhCode = Appconfig.GetWhCodeByBin(item.BinCode);
  502. // //}
  503. // #endregion
  504. // Decimal MOQty = 0;
  505. // long MOID = 0;
  506. // _MOCode = item.MoCode;
  507. // DataTable _dt = Appconfig.GetMOQtyAndID(item.MoCode);
  508. // if (_dt != null && _dt.Rows.Count > 0)
  509. // {
  510. // foreach (DataRow _item in _dt.Rows)
  511. // {
  512. // string _strMOQty = string.Empty;
  513. // string _strMOID = string.Empty;
  514. // _strMOQty = _item["ProductQty"].ToString();
  515. // if (!string.IsNullOrWhiteSpace(_strMOQty))
  516. // {
  517. // MOQty = Decimal.Parse(_strMOQty);
  518. // }
  519. // _strMOID = _item["ID"].ToString();
  520. // if (!string.IsNullOrWhiteSpace(_strMOID))
  521. // {
  522. // MOID = long.Parse(_strMOID);
  523. // }
  524. // }
  525. // }
  526. // string mOPickList = string.Empty;
  527. // mOPickList = Appconfig.GetMoPickListID(item.MoCode, strCcode);// 1001903220007058;// iPickid;
  528. // Decimal IssuedQty = 0; //已发放数量
  529. // Decimal IssueNotDeliverQty = 0; //领料未发数量
  530. // Decimal SendQty = 0; //已发放数量
  531. // if (!string.IsNullOrWhiteSpace(mOPickList))
  532. // {
  533. // //已发放数量-领料未发数量
  534. // DataTable dtQty = Appconfig.GetQtyBymOPickList(item.MoCode);
  535. // if (dtQty != null && dtQty.Rows.Count > 0)
  536. // {
  537. // //IssuedQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  538. // IssueNotDeliverQty = Decimal.Parse(dtQty.Rows[0]["TotalIssueNotDeliverQty"].ToString());
  539. // SendQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  540. // }
  541. // PLS.m_mOPickList = long.Parse(mOPickList);
  542. // }
  543. // else
  544. // {
  545. // result.MESSAGE = "备料表单ID不存在!工单:'" + item.MoCode + "',料号:'" + strCcode + "' ";
  546. // result.IsSuccess = false;
  547. // return result;
  548. // }
  549. // //根据工单获取已发掉的料数量
  550. // //Decimal SendQty = Appconfig.GetMOSendQty(item.MoCode);
  551. // //PLS.m_issueQty = useQty * MOQty - SendQty;// item.issueQty* useQty;//1; //应发数量
  552. // PLS.m_issueQty = useQty * MOQty;// item.issueQty* useQty;//1; //应发数量
  553. // //产生领料单的数量为:实际需求数量-已发放数量-领料未发数量
  554. // //PLS.m_issuedQty = useQty * MOQty - SendQty;// item.issuedQty* useQty;// 1; //实发数量
  555. // if (useQty * MOQty - SendQty - IssueNotDeliverQty > 0)
  556. // {
  557. // PLS.m_issuedQty = useQty * MOQty - SendQty - IssueNotDeliverQty;// item.issuedQty* useQty;// 1; //实发数量
  558. // if (!string.IsNullOrWhiteSpace(strBinCode))
  559. // {
  560. // PLS.m_issueBin = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  561. // PLS.m_issueBin.m_code = strBinCode;
  562. // }
  563. // //仓库
  564. // if (!string.IsNullOrWhiteSpace(strWhCode))
  565. // {
  566. // PLS.m_issueWh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  567. // PLS.m_issueWh.m_code = strWhCode;// "004";//cWh;
  568. // }
  569. // //发货单位
  570. // PLS.m_issueUOM = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  571. // string uom = Appconfig.GetMaterialUOM(strCcode);
  572. // if (!string.IsNullOrWhiteSpace(uom))
  573. // {
  574. // PLS.m_issueUOM.m_iD = long.Parse(uom);// Appconfig.GetMaterialUOM(item.ItemCode);// 1001607080022602;// iMaterialOutUOM;
  575. // }
  576. // PLS.m_aCDType = 0;
  577. // //Decimal MOQty = Decimal.Parse(Appconfig.GetMOQty(item.MoCode));
  578. // PLS.m_storageType = 4;//存储类型
  579. // //SourceDoc_SrcDocNo
  580. // PLS.SourceIssueDocLine = MOID;
  581. // PL.Add(PLS);
  582. // }
  583. // else
  584. // {
  585. // result.MESSAGE = "该工单料品数量已经领料完成,不能继续领料" + item.MoCode + "',料号:'" + strCcode + "' ";
  586. // result.IsSuccess = false;
  587. // return result;
  588. // }
  589. // }
  590. // }
  591. // }
  592. // }
  593. // }
  594. // //部门
  595. // mo.m_dept = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  596. // mo.m_dept.m_code = model.DeptNo;// "MY0601";
  597. // mo.m_docType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  598. // mo.m_docType.m_code = model.DocTypeCode;//"1"; 单据类型
  599. // //mo.m_businessType = model.BusinessType;// 47;//标准生产
  600. // string BusinessType = Appconfig.GetBusinessType(model.DocTypeCode);
  601. // if (!string.IsNullOrWhiteSpace(BusinessType))
  602. // {
  603. // mo.m_businessType = Int32.Parse(BusinessType);// 47;//标准生产
  604. // }
  605. // mo.m_srcDoc = new UFIDAU9MOPropertyTypesMOSourceDocData();// _MOCode;
  606. // mo.m_srcDoc.m_srcDocNo = _MOCode;
  607. // mo.m_memo = model.Memo; //备注
  608. // mo.m_pickListDTOs = PL.ToArray();
  609. // molist.Add(mo);
  610. // UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
  611. // _result = client.Do(out message, context, molist.ToArray());
  612. // if (_result != null && _result.Count() > 0)
  613. // {
  614. // foreach (var item in _result)
  615. // {
  616. // result.LLCode = item.m_docNo;
  617. // if (!string.IsNullOrWhiteSpace(item.m_docNo))
  618. // {
  619. // result.IsSuccess = true;
  620. // result.MESSAGE = "成功创建领料单!";
  621. // }
  622. // }
  623. // }
  624. // #region 错误
  625. // // //class UFIDA.U9.MO.MO.MO has no such field: Code in AttributeMap when Compiling OQL: Code=@Code and Org=@Org
  626. // // //领料单1001906120110350不存在单行信息
  627. // // //未将对象引用设置到对象的实例。
  628. // // //领料单1001906140000062不存在单行信息
  629. // // //领料单1001906140000083不存在单行信息
  630. // // //领料单1001906140000105不存在单行信息
  631. // // //领料单1001906140000106不存在单行信息
  632. // // //必需设置单据类型
  633. // // //领料单1001906170000093不存在单行信息
  634. // // //领料单1001906170000104不存在单行信息
  635. // #endregion
  636. // }
  637. // catch (Exception ex)
  638. // {
  639. // string Message = GetExceptionMessage(ex);
  640. // result.IsSuccess = false;
  641. // result.MESSAGE = Message;
  642. // }
  643. // return result;
  644. //}
  645. //public OperationResult CreateIssue(IssueData model)
  646. //{
  647. // OperationResult result = new OperationResult();
  648. // ThreadContext context = CreateContextObj();
  649. // //MO-19050007 11020007
  650. // try
  651. // {
  652. // string _MOCode = string.Empty;
  653. // UFIDAU9ISVMOICreateIssue4ExternalClient client = new UFIDAU9ISVMOICreateIssue4ExternalClient();
  654. // MessageBase[] message = null;
  655. // List<UFIDAU9ISVMOIssueDTOData> molist = new List<UFIDAU9ISVMOIssueDTOData>();
  656. // UFIDAU9ISVMOIssueDTOData mo = new UFIDAU9ISVMOIssueDTOData();
  657. // List<UFIDAU9ISVMOPickListDTOData> PL = new List<UFIDAU9ISVMOPickListDTOData>();
  658. // if (model != null && model.lines.Count > 0)
  659. // {
  660. // foreach (var item in model.lines)
  661. // {
  662. // //if (!string.IsNullOrWhiteSpace(item.ItemCode))
  663. // //{
  664. // //验证该工单的备料表中是否存在数据
  665. // int p = Appconfig.IsExistcPickList(item.MoCode);
  666. // if (p > 0)
  667. // {
  668. // #region 根据备料表获取数据
  669. // DataTable dt = Appconfig.GetPickList(item.MoCode);
  670. // if (dt != null && dt.Rows.Count > 0)
  671. // {
  672. // foreach (DataRow row in dt.Rows)
  673. // {
  674. // string strCcode = row["ccode"].ToString(); //子料
  675. // decimal useQty = Decimal.Parse(row["useQty"].ToString()); //子件使用量
  676. // string strUnitCode = row["UnitCode"].ToString(); //单位
  677. // //string strWhCode = row["WhCode"].ToString(); //仓库
  678. // //string strBinCode = row["BinCode"].ToString(); //库位
  679. // string strWhCode = item.WhCode; //row["WhCode"].ToString(); //仓库
  680. // string strBinCode = item.BinCode;//row["BinCode"].ToString(); //库位
  681. // UFIDAU9ISVMOPickListDTOData PLS = new UFIDAU9ISVMOPickListDTOData();
  682. // int i = Appconfig.IsExistItem(strCcode);
  683. // if (i < 1)
  684. // {
  685. // result.MESSAGE = "料品编码不存在!";
  686. // result.IsSuccess = false;
  687. // return result;
  688. // }
  689. // Decimal MOQty = 0;
  690. // long MOID = 0;
  691. // _MOCode = item.MoCode;
  692. // DataTable _dt = Appconfig.GetMOQtyAndID(item.MoCode);
  693. // if (_dt != null && _dt.Rows.Count > 0)
  694. // {
  695. // foreach (DataRow _item in _dt.Rows)
  696. // {
  697. // string _strMOQty = string.Empty;
  698. // string _strMOID = string.Empty;
  699. // _strMOQty = _item["ProductQty"].ToString();
  700. // if (!string.IsNullOrWhiteSpace(_strMOQty))
  701. // {
  702. // MOQty = Decimal.Parse(_strMOQty);//生产订单数量
  703. // }
  704. // _strMOID = _item["ID"].ToString();
  705. // if (!string.IsNullOrWhiteSpace(_strMOID))
  706. // {
  707. // MOID = long.Parse(_strMOID);
  708. // }
  709. // }
  710. // }
  711. // string mOPickList = string.Empty;
  712. // mOPickList = Appconfig.GetMoPickListID(item.MoCode, strCcode);// 1001903220007058;// iPickid;
  713. // Decimal IssuedQty = 0; //已发放数量
  714. // Decimal IssueNotDeliverQty = 0; //领料未发数量
  715. // Decimal SendQty = 0; //已发放数量
  716. // if (!string.IsNullOrWhiteSpace(mOPickList))
  717. // {
  718. // //已发放数量-领料未发数量
  719. // DataTable dtQty = Appconfig.GetQtyBymOPickList(item.MoCode);
  720. // if (dtQty != null && dtQty.Rows.Count > 0)
  721. // {
  722. // //IssuedQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  723. // IssueNotDeliverQty = Decimal.Parse(dtQty.Rows[0]["TotalIssueNotDeliverQty"].ToString());
  724. // SendQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  725. // }
  726. // PLS.m_mOPickList = long.Parse(mOPickList);
  727. // }
  728. // else
  729. // {
  730. // result.MESSAGE = "备料表单ID不存在!工单:'" + item.MoCode + "',料号:'" + strCcode + "' ";
  731. // result.IsSuccess = false;
  732. // return result;
  733. // }
  734. // //根据工单获取已发掉的料数量
  735. // //Decimal SendQty = Appconfig.GetMOSendQty(item.MoCode);
  736. // //PLS.m_issueQty = useQty * MOQty - SendQty;// item.issueQty* useQty;//1; //应发数量
  737. // PLS.m_issueQty = useQty * MOQty;// item.issueQty* useQty;//1; //应发数量
  738. // //产生领料单的数量为:实际需求数量-已发放数量-领料未发数量
  739. // //PLS.m_issuedQty = useQty * MOQty - SendQty;// item.issuedQty* useQty;// 1; //实发数量
  740. // if (useQty * MOQty - SendQty - IssueNotDeliverQty > 0)
  741. // {
  742. // PLS.m_issuedQty = useQty * MOQty - SendQty - IssueNotDeliverQty;// item.issuedQty* useQty;// 1; //实发数量
  743. // if (!string.IsNullOrWhiteSpace(strBinCode))
  744. // {
  745. // PLS.m_issueBin = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  746. // PLS.m_issueBin.m_code = strBinCode;
  747. // }
  748. // //仓库
  749. // if (!string.IsNullOrWhiteSpace(strWhCode))
  750. // {
  751. // PLS.m_issueWh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  752. // PLS.m_issueWh.m_code = strWhCode;// "004";//cWh;
  753. // }
  754. // //发货单位
  755. // PLS.m_issueUOM = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  756. // string uom = Appconfig.GetMaterialUOM(strCcode);
  757. // if (!string.IsNullOrWhiteSpace(uom))
  758. // {
  759. // PLS.m_issueUOM.m_iD = long.Parse(uom);// Appconfig.GetMaterialUOM(item.ItemCode);// 1001607080022602;// iMaterialOutUOM;
  760. // }
  761. // PLS.m_aCDType = 0;
  762. // //Decimal MOQty = Decimal.Parse(Appconfig.GetMOQty(item.MoCode));
  763. // PLS.m_storageType = 4;//存储类型
  764. // //SourceDoc_SrcDocNo
  765. // PLS.SourceIssueDocLine = MOID;
  766. // PL.Add(PLS);
  767. // }
  768. // else
  769. // {
  770. // result.MESSAGE = "该工单料品数量已经领料完成,不能继续领料" + item.MoCode + "',料号:'" + strCcode + "' ";
  771. // result.IsSuccess = false;
  772. // return result;
  773. // }
  774. // }
  775. // }
  776. // #endregion
  777. // }
  778. // else
  779. // {
  780. // result.MESSAGE = "该工单没有备料表信息 ";
  781. // result.IsSuccess = false;
  782. // return result;
  783. // }
  784. // #region 20190705注释ZM
  785. // //else
  786. // //{
  787. // // #region 根据BOM展开获取数据
  788. // // DataTable dt = Appconfig.GetCcodeListByMcode(item.ItemCode);
  789. // // if (dt != null && dt.Rows.Count > 0)
  790. // // {
  791. // // foreach (DataRow row in dt.Rows)
  792. // // {
  793. // // string strCcode = row["ccode"].ToString(); //子料
  794. // // decimal useQty = Decimal.Parse(row["useQty"].ToString()); //子件使用量
  795. // // string strUnitCode = row["UnitCode"].ToString(); //单位
  796. // // //string strWhCode = row["WhCode"].ToString(); //仓库
  797. // // //string strBinCode = row["BinCode"].ToString(); //库位
  798. // // string strWhCode = item.WhCode; //row["WhCode"].ToString(); //仓库
  799. // // string strBinCode = item.BinCode;//row["BinCode"].ToString(); //库位
  800. // // UFIDAU9ISVMOPickListDTOData PLS = new UFIDAU9ISVMOPickListDTOData();
  801. // // int i = Appconfig.IsExistItem(strCcode);
  802. // // if (i < 1)
  803. // // {
  804. // // result.MESSAGE = "料品编码不存在!";
  805. // // result.IsSuccess = false;
  806. // // return result;
  807. // // }
  808. // // #region 注释
  809. // // //if (!string.IsNullOrWhiteSpace(item.BinCode))
  810. // // //{
  811. // // // int j = Appconfig.IsExistcPos(item.BinCode);
  812. // // // if (i < 1)
  813. // // // {
  814. // // // result.MESSAGE = "库位编码不存在!";
  815. // // // result.IsSuccess = false;
  816. // // // return result;
  817. // // // }
  818. // // // else
  819. // // // {
  820. // // // PLS.m_issueBin = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  821. // // // PLS.m_issueBin.m_code = item.BinCode;
  822. // // // }
  823. // // //}
  824. // // //string WhCode = string.Empty;
  825. // // //if (!string.IsNullOrWhiteSpace(item.BinCode))
  826. // // //{
  827. // // // WhCode = Appconfig.GetWhCodeByBin(item.BinCode);
  828. // // //}
  829. // // #endregion
  830. // // Decimal MOQty = 0;
  831. // // long MOID = 0;
  832. // // _MOCode = item.MoCode;
  833. // // DataTable _dt = Appconfig.GetMOQtyAndID(item.MoCode);
  834. // // if (_dt != null && _dt.Rows.Count > 0)
  835. // // {
  836. // // foreach (DataRow _item in _dt.Rows)
  837. // // {
  838. // // string _strMOQty = string.Empty;
  839. // // string _strMOID = string.Empty;
  840. // // _strMOQty = _item["ProductQty"].ToString();
  841. // // if (!string.IsNullOrWhiteSpace(_strMOQty))
  842. // // {
  843. // // MOQty = Decimal.Parse(_strMOQty);
  844. // // }
  845. // // _strMOID = _item["ID"].ToString();
  846. // // if (!string.IsNullOrWhiteSpace(_strMOID))
  847. // // {
  848. // // MOID = long.Parse(_strMOID);
  849. // // }
  850. // // }
  851. // // }
  852. // // string mOPickList = string.Empty;
  853. // // mOPickList = Appconfig.GetMoPickListID(item.MoCode, strCcode);// 1001903220007058;// iPickid;
  854. // // Decimal IssuedQty = 0; //已发放数量
  855. // // Decimal IssueNotDeliverQty = 0; //领料未发数量
  856. // // Decimal SendQty = 0; //已发放数量
  857. // // if (!string.IsNullOrWhiteSpace(mOPickList))
  858. // // {
  859. // // //已发放数量-领料未发数量
  860. // // DataTable dtQty = Appconfig.GetQtyBymOPickList(item.MoCode);
  861. // // if (dtQty != null && dtQty.Rows.Count > 0)
  862. // // {
  863. // // //IssuedQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  864. // // IssueNotDeliverQty = Decimal.Parse(dtQty.Rows[0]["TotalIssueNotDeliverQty"].ToString());
  865. // // SendQty = Decimal.Parse(dtQty.Rows[0]["IssuedQty"].ToString());
  866. // // }
  867. // // PLS.m_mOPickList = long.Parse(mOPickList);
  868. // // }
  869. // // else
  870. // // {
  871. // // result.MESSAGE = "备料表单ID不存在!工单:'" + item.MoCode + "',料号:'" + strCcode + "' ";
  872. // // result.IsSuccess = false;
  873. // // return result;
  874. // // }
  875. // // //根据工单获取已发掉的料数量
  876. // // //Decimal SendQty = Appconfig.GetMOSendQty(item.MoCode);
  877. // // //PLS.m_issueQty = useQty * MOQty - SendQty;// item.issueQty* useQty;//1; //应发数量
  878. // // PLS.m_issueQty = useQty * MOQty;// item.issueQty* useQty;//1; //应发数量
  879. // // //产生领料单的数量为:实际需求数量-已发放数量-领料未发数量
  880. // // //PLS.m_issuedQty = useQty * MOQty - SendQty;// item.issuedQty* useQty;// 1; //实发数量
  881. // // if (useQty * MOQty - SendQty - IssueNotDeliverQty > 0)
  882. // // {
  883. // // PLS.m_issuedQty = useQty * MOQty - SendQty - IssueNotDeliverQty;// item.issuedQty* useQty;// 1; //实发数量
  884. // // if (!string.IsNullOrWhiteSpace(strBinCode))
  885. // // {
  886. // // PLS.m_issueBin = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  887. // // PLS.m_issueBin.m_code = strBinCode;
  888. // // }
  889. // // //仓库
  890. // // if (!string.IsNullOrWhiteSpace(strWhCode))
  891. // // {
  892. // // PLS.m_issueWh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  893. // // PLS.m_issueWh.m_code = strWhCode;// "004";//cWh;
  894. // // }
  895. // // //发货单位
  896. // // PLS.m_issueUOM = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  897. // // string uom = Appconfig.GetMaterialUOM(strCcode);
  898. // // if (!string.IsNullOrWhiteSpace(uom))
  899. // // {
  900. // // PLS.m_issueUOM.m_iD = long.Parse(uom);// Appconfig.GetMaterialUOM(item.ItemCode);// 1001607080022602;// iMaterialOutUOM;
  901. // // }
  902. // // PLS.m_aCDType = 0;
  903. // // //Decimal MOQty = Decimal.Parse(Appconfig.GetMOQty(item.MoCode));
  904. // // PLS.m_storageType = 4;//存储类型
  905. // // //SourceDoc_SrcDocNo
  906. // // PLS.SourceIssueDocLine = MOID;
  907. // // PL.Add(PLS);
  908. // // }
  909. // // else
  910. // // {
  911. // // result.MESSAGE = "该工单料品数量已经领料完成,不能继续领料" + item.MoCode + "',料号:'" + strCcode + "' ";
  912. // // result.IsSuccess = false;
  913. // // return result;
  914. // // }
  915. // // }
  916. // // }
  917. // // #endregion
  918. // //}
  919. // #endregion
  920. // //}
  921. // }
  922. // }
  923. // //部门
  924. // mo.m_dept = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  925. // mo.m_dept.m_code = model.DeptNo;// "MY0601";
  926. // mo.m_docType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  927. // mo.m_docType.m_code = model.DocTypeCode;//"1"; 单据类型
  928. // //mo.m_businessType = model.BusinessType;// 47;//标准生产
  929. // string BusinessType = Appconfig.GetBusinessType(model.DocTypeCode);
  930. // if (!string.IsNullOrWhiteSpace(BusinessType))
  931. // {
  932. // mo.m_businessType = Int32.Parse(BusinessType);// 47;//标准生产
  933. // }
  934. // mo.m_srcDoc = new UFIDAU9MOPropertyTypesMOSourceDocData();// _MOCode;
  935. // mo.m_srcDoc.m_srcDocNo = _MOCode;
  936. // mo.m_memo = model.Memo; //备注
  937. // mo.m_pickListDTOs = PL.ToArray();
  938. // molist.Add(mo);
  939. // UFIDAU9ISVMOIssueKeyDTOData[] _result = null;
  940. // _result = client.Do(out message, context, molist.ToArray());
  941. // if (_result != null && _result.Count() > 0)
  942. // {
  943. // foreach (var item in _result)
  944. // {
  945. // result.LLCode = item.m_docNo;
  946. // if (!string.IsNullOrWhiteSpace(item.m_docNo))
  947. // {
  948. // result.IsSuccess = true;
  949. // result.MESSAGE = "成功创建领料单!";
  950. // }
  951. // }
  952. // }
  953. // #region 错误
  954. // // //class UFIDA.U9.MO.MO.MO has no such field: Code in AttributeMap when Compiling OQL: Code=@Code and Org=@Org
  955. // // //领料单1001906120110350不存在单行信息
  956. // // //未将对象引用设置到对象的实例。
  957. // // //领料单1001906140000062不存在单行信息
  958. // // //领料单1001906140000083不存在单行信息
  959. // // //领料单1001906140000105不存在单行信息
  960. // // //领料单1001906140000106不存在单行信息
  961. // // //必需设置单据类型
  962. // // //领料单1001906170000093不存在单行信息
  963. // // //领料单1001906170000104不存在单行信息
  964. // #endregion
  965. // }
  966. // catch (Exception ex)
  967. // {
  968. // string Message = GetExceptionMessage(ex);
  969. // result.IsSuccess = false;
  970. // result.MESSAGE = Message;
  971. // }
  972. // return result;
  973. //}
  974. #endregion
  975. }
  976. }