锐腾搅拌上料功能
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.

2544 lines
124 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. using ICSSoft.Base.Config.AppConfig;
  7. using System.Configuration;
  8. using ICSSoft.Entity.PU_AppVouch;
  9. using Newtonsoft.Json;
  10. using System.Net;
  11. using System.IO;
  12. using ICSSoft.YT.Entity.Vouch;
  13. using ICSSoft.YT.Entity.OM_PO;
  14. using System.Data;
  15. using ICSSoft.Frame.Data.Entity.NcApiEntity;
  16. namespace ICSSoft.Frame.Data.DAL
  17. {
  18. public class ICSCollectDAL
  19. {
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. private static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  22. private static string DataCollectWW = APIURL + "APICreateInventory_PU_AppVouch";
  23. private static string urlCreatPO = APIURL + "sendPO";//生成采购入库单
  24. private static string urlCreat4D = APIURL + "send4D";//生成材料出库单
  25. private static string urlClosePOLine = APIURL + "sendM21Rowclose";//关闭工单行
  26. public static string CheckRoute(FramDataContext db, ICSLOTONWIP onwip)
  27. {
  28. var lotcount = db.ICSMO2User.Count(a => a.LOTNO == onwip.LOTNO);
  29. var routecount = db.ICSITEMROUTE2OPLot.Count(a => a.LotNo == onwip.LOTNO);
  30. if (lotcount != routecount)
  31. {
  32. return "跟踪单:" + onwip.LOTNO + ",存在新增工序尚未派工,请重新派工后再进行报工操作!\n\r";
  33. }
  34. else
  35. {
  36. return "";
  37. }
  38. }
  39. public static void CheckInfo(FramDataContext db, ICSLOTSIMULATION simulation)
  40. {
  41. //try
  42. //{
  43. // var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  44. // if (user == null)
  45. // throw new Exception("用户不存在!");
  46. // var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  47. // if (mouser == null)
  48. // throw new Exception("批次工序派工信息不存在!");
  49. // var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
  50. // if (mo == null)
  51. // throw new Exception("工单信息不存在!");
  52. // var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
  53. // if (moroute == null)
  54. // throw new Exception("工单未关联途程!");
  55. // if (moroute.ROUTECODE != mouser.RouteCode)
  56. // throw new Exception("工单途程与派工途程不同!");
  57. // var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
  58. // if (itemop == null)
  59. // throw new Exception("产品途程工序不存在!");
  60. // var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  61. // var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
  62. // if (sim == null && itemops != null && itemops.Count() > 0)
  63. // throw new Exception("请从第一道工序开始报工!");
  64. // //判断
  65. // if (sim != null)
  66. // {
  67. // if (sim.ISCOM == "1")
  68. // {
  69. // throw new Exception("该批次已完工!");
  70. // }
  71. // //如果是完工判断是否是当前工序、设备
  72. // else if (sim.CollectStatus == "COLLECT_BEGIN")
  73. // {
  74. // if (sim.OPCODE != simulation.OPCODE)
  75. // throw new Exception(string.Format("应采集工序:{0}!", sim.OPCODE));
  76. // if (sim.EQPCODE != simulation.EQPCODE)
  77. // throw new Exception(string.Format("应采集设备:{0}!", sim.EQPCODE));
  78. // }
  79. // //开始下道工序时判断下一道工序是否正确
  80. // else if (sim.CollectStatus == "COLLECT_END")
  81. // {
  82. // var simitemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == sim.ITEMCODE && a.ROUTECODE == sim.ROUTECODE && a.OPCODE == sim.OPCODE);
  83. // var ops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == simitemop.ITEMCODE && a.ROUTECODE == simitemop.ROUTECODE && a.OPSEQ > simitemop.OPSEQ).OrderBy(a => a.OPSEQ).FirstOrDefault();
  84. // if (ops == null)
  85. // throw new Exception("已是最后一道工序,无需再采集!");
  86. // else if (ops.OPCODE != simulation.OPCODE)
  87. // throw new Exception(string.Format("应采集工序:{0}!", ops.OPCODE));
  88. // //完工状态判断是否检验
  89. // var wipCheck = (from a in db.ICSLOTONWIP
  90. // join b in db.ICSLOTONWIPCheck on a.ID equals b.ONWIPID
  91. // where a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ
  92. // select b).FirstOrDefault();
  93. // if (wipCheck != null)
  94. // {
  95. // if (wipCheck.Result == "不合格" && (wipCheck.TResult == null || wipCheck.TResult == "报废"))
  96. // throw new Exception("上道工序不合格且不是让步或返工状态,不能开始该工序!");
  97. // }
  98. // else
  99. // {
  100. // throw new Exception("上道工序未做检验,不能开始该工序!");
  101. // }
  102. // }
  103. // if (sim.LOTStatus.Equals("暂停"))
  104. // {
  105. // throw new Exception("该批次工序处于暂停状态!");
  106. // }
  107. // if (sim.CollectStatus.Equals(simulation.EATTRIBUTE1))
  108. // {
  109. // throw new Exception("状态不正确,请重新扫描!");
  110. // }
  111. // }
  112. // //var onwipNow = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ);
  113. // var onwipNow = db.ICSLOTONWIP.Where(a => a.LOTNO == mouser.LOTNO && a.ROUTECODE == mouser.RouteCode && a.OPCODE == mouser.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
  114. // //var onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.EQPCODE == simulation.EQPCODE && a.ACTIONRESULT == "COLLECT_BEGIN");
  115. // //if (onwip != null && onwipNow == null)
  116. // // throw new Exception("设备正在使用,不能采集!");
  117. // //else if (onwip != null && onwipNow != null && onwip.ID != onwipNow.ID)
  118. // // throw new Exception("设备正在使用,不能采集!");
  119. // if (onwipNow != null && !onwipNow.UserCodeBegin.Equals(simulation.MUSER))
  120. // {
  121. // var UserCodeBegin = db.Sys_User.SingleOrDefault(a => a.UserCode == onwipNow.UserCodeBegin);
  122. // throw new Exception("与开工人员:" + onwipNow.UserCodeBegin + ";" + UserCodeBegin.UserName + "不同,不能采集!");
  123. // }
  124. //}
  125. //catch (Exception ex)
  126. //{
  127. // throw ex;
  128. //}
  129. }
  130. public static string CheckInfoWW(FramDataContext db, ICSLOTONWIP onwip)
  131. {
  132. try
  133. {
  134. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == onwip.MUSER);
  135. if (user == null)
  136. throw new Exception("跟踪单:" + onwip.LOTNO + ",用户不存在!\n\r");
  137. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == onwip.LOTNO && a.OPCODE == onwip.OPCODE);
  138. if (mouser == null)
  139. throw new Exception("跟踪单:" + onwip.LOTNO + ",批次工序派工信息不存在!\n\r");
  140. var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
  141. if (mo == null)
  142. throw new Exception("跟踪单:" + onwip.LOTNO + ",工单信息不存在!\n\r");
  143. var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
  144. if (moroute == null)
  145. throw new Exception("跟踪单:" + onwip.LOTNO + ",工单未关联途程!\n\r");
  146. if (moroute.ROUTECODE != mouser.RouteCode)
  147. throw new Exception("跟踪单:" + onwip.LOTNO + ",工单途程与派工途程不同!\n\r");
  148. var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
  149. if (itemop == null)
  150. throw new Exception("跟踪单:" + onwip.LOTNO + ",产品途程工序不存在!\n\r");
  151. //var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  152. //var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
  153. //if (sim == null && itemops != null && itemops.Count() > 0)
  154. // throw new Exception("跟踪单:" + simulation.LOTNO + ",请从第一道工序开始报工!\n\r");
  155. ////判断
  156. //if (sim != null)
  157. //{
  158. // if (sim.ISCOM == "1")
  159. // {
  160. // throw new Exception("跟踪单:" + simulation.LOTNO + ",该批次已完工!\n\r");
  161. // }
  162. // //如果是完工判断是否是当前工序、设备
  163. // else if (sim.CollectStatus == "COLLECT_BEGIN")
  164. // {
  165. // if (sim.OPCODE != simulation.OPCODE)
  166. // throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集工序:{0}!\n\r", sim.OPCODE));
  167. // if (sim.EQPCODE != simulation.EQPCODE)
  168. // throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集设备:{0}!\n\r", sim.EQPCODE));
  169. // }
  170. // //开始下道工序时判断下一道工序是否正确
  171. // else if (sim.CollectStatus == "COLLECT_END")
  172. // {
  173. // var simitemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == sim.ITEMCODE && a.ROUTECODE == sim.ROUTECODE && a.OPCODE == sim.OPCODE);
  174. // var ops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == simitemop.ITEMCODE && a.ROUTECODE == simitemop.ROUTECODE && a.OPSEQ > simitemop.OPSEQ).OrderBy(a => a.OPSEQ).FirstOrDefault();
  175. // if (ops == null)
  176. // throw new Exception("跟踪单:" + simulation.LOTNO + ",已是最后一道工序,无需再采集!\n\r");
  177. // else if (ops.OPCODE != simulation.OPCODE)
  178. // throw new Exception(string.Format("跟踪单:" + simulation.LOTNO + ",应采集工序:{0}!\n\r", ops.OPCODE));
  179. // //完工状态判断是否检验
  180. // var wipCheck = (from a in db.ICSLOTONWIP
  181. // join b in db.ICSLOTONWIPCheck on a.ID equals b.FORTRANID
  182. // where a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ
  183. // select b).FirstOrDefault();
  184. // if (wipCheck != null)
  185. // {
  186. // if (wipCheck.Status != "正常" && wipCheck.Status != "放行")
  187. // throw new Exception("跟踪单:" + simulation.LOTNO + ",上道工序不合格且不是放行状态,不能开始该工序!\n\r");
  188. // }
  189. // else
  190. // {
  191. // throw new Exception("跟踪单:" + simulation.LOTNO + ",上道工序未做检验,不能开始该工序!\n\r");
  192. // }
  193. // }
  194. // if (sim.LOTStatus.Equals("暂停"))
  195. // {
  196. // throw new Exception("跟踪单:" + simulation.LOTNO + ",该批次工序处于暂停状态!\n\r");
  197. // }
  198. // if (sim.CollectStatus.Equals(simulation.EATTRIBUTE1))
  199. // {
  200. // throw new Exception("跟踪单:" + simulation.LOTNO + ",状态不正确,请重新扫描!\n\r");
  201. // }
  202. //}
  203. ////var onwipNow = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.SEQ == sim.SEQ);
  204. //var onwipNow = db.ICSLOTONWIP.Where(a => a.LOTNO == mouser.LOTNO && a.ROUTECODE == mouser.RouteCode && a.OPCODE == mouser.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
  205. ////var onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.EQPCODE == simulation.EQPCODE && a.ACTIONRESULT == "COLLECT_BEGIN");
  206. ////if (onwip != null && onwipNow == null)
  207. //// throw new Exception("跟踪单:" + simulation.LOTNO + ",设备正在使用,不能采集!\n\r");
  208. ////else if (onwip != null && onwipNow != null && onwip.ID != onwipNow.ID)
  209. //// throw new Exception("跟踪单:" + simulation.LOTNO + ",设备正在使用,不能采集!\n\r");
  210. //if (onwipNow != null && !onwipNow.UserCodeBegin.Equals(simulation.MUSER))
  211. //{
  212. // throw new Exception("跟踪单:" + simulation.LOTNO + ",与开工人员不同,不能采集!\n\r");
  213. //}
  214. return "";
  215. }
  216. catch (Exception ex)
  217. {
  218. return ex.Message;
  219. }
  220. }
  221. public static void Save(FramDataContext db, ICSLOTSIMULATION simulation)
  222. {
  223. try
  224. {
  225. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  226. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  227. var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.LOTNO);
  228. var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
  229. bool simNew = false;
  230. var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  231. #region simulation
  232. //ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
  233. if (simulationNew == null)
  234. {
  235. simNew = true;
  236. simulationNew = new ICSLOTSIMULATION();
  237. simulationNew.ID = AppConfig.GetGuid();
  238. simulationNew.LOTNO = simulation.LOTNO;
  239. simulationNew.MOCODE = mouser.MOCODE;
  240. simulationNew.LOTSEQ = 0;
  241. simulationNew.LOTQTY = Convert.ToInt32(lot.LOTQTY);
  242. simulationNew.GOODQTY = simulationNew.LOTQTY;
  243. simulationNew.NGQTY = 0;
  244. simulationNew.LOTStatus = "新增";
  245. simulationNew.MODELCODE = "";
  246. simulationNew.ITEMCODE = lot.ItemCode;
  247. simulationNew.FROMROUTE = "";
  248. simulationNew.FROMOP = "";
  249. simulationNew.ROUTECODE = mouser.RouteCode;
  250. simulationNew.RESCODE = "";
  251. simulationNew.CHECKLOTNO = "";
  252. simulationNew.CARTONCODE = "";
  253. simulationNew.PALLETCODE = "";
  254. simulationNew.PRODUCTSTATUS = "GOOD";
  255. simulationNew.LACTION = "GOOD";
  256. simulationNew.ACTIONLIST = "GOOD";
  257. simulationNew.NGTIMES = 0;
  258. simulationNew.ISCOM = "0";
  259. simulationNew.ISHOLD = 0;
  260. simulationNew.SHELFNO = "";
  261. simulationNew.MOSEQ = mouser.MOSEQ;
  262. simulationNew.CollectStatus = "COLLECT_BEGIN";
  263. //simulationNew.SEQ = 1;
  264. simulationNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  265. }
  266. else
  267. {
  268. if (simulationNew.OPCODE == simulation.OPCODE)
  269. {
  270. simulationNew.CollectStatus = "COLLECT_END";
  271. }
  272. else
  273. {
  274. simulationNew.CollectStatus = "COLLECT_BEGIN";
  275. simulationNew.LOTSEQ = simulationNew.LOTSEQ + 1;
  276. }
  277. if (itemop.OPCODE == simulation.OPCODE && simulationNew.CollectStatus == "COLLECT_END")
  278. {
  279. simulationNew.ISCOM = "1";
  280. }
  281. }
  282. simulationNew.OPCODE = simulation.OPCODE;
  283. simulationNew.EQPCODE = simulation.EQPCODE;
  284. simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  285. simulationNew.MUSER = AppConfig.UserCode;
  286. simulationNew.MUSERName = AppConfig.UserName;
  287. simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  288. simulationNew.WorkPoint = AppConfig.WorkPointCode;
  289. if (simNew)
  290. db.ICSLOTSIMULATION.InsertOnSubmit(simulationNew);
  291. #endregion
  292. bool wipNew = false;
  293. ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
  294. #region onwip
  295. //ICSLOTONWIP onwipNew = new ICSLOTONWIP();
  296. if (onwipNew == null)
  297. {
  298. wipNew = true;
  299. onwipNew = new ICSLOTONWIP();
  300. onwipNew.ID = AppConfig.GetGuid();
  301. onwipNew.LOTNO = simulationNew.LOTNO;
  302. onwipNew.LOTSEQ = simulationNew.LOTSEQ;
  303. onwipNew.SEGCODE = "";
  304. onwipNew.SSCODE = "";
  305. onwipNew.SHIFTTYPECODE = "";
  306. onwipNew.MOCODE = simulationNew.MOCODE;
  307. //onwipNew.LOTSEQ = 0;
  308. onwipNew.MODELCODE = simulationNew.MODELCODE;
  309. onwipNew.ITEMCODE = simulationNew.ITEMCODE;
  310. onwipNew.ROUTECODE = simulationNew.ROUTECODE;
  311. onwipNew.RESCODE = simulationNew.RESCODE;
  312. onwipNew.ACTION = "GOOD";
  313. onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
  314. onwipNew.NGTIMES = simulationNew.NGTIMES;
  315. onwipNew.SHELFNO = simulationNew.SHELFNO;
  316. onwipNew.MOSEQ = simulationNew.MOSEQ;
  317. onwipNew.Processed = 0;
  318. onwipNew.LOTQTY = (int)simulationNew.LOTQTY;
  319. onwipNew.GOODQTY = (int)simulationNew.GOODQTY;
  320. onwipNew.NGQTY = (int)simulationNew.NGQTY;
  321. onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  322. onwipNew.UserCodeBegin = simulation.MUSER;
  323. }
  324. else
  325. {
  326. onwipNew.ACTIONRESULT = "COLLECT_END";
  327. //调用接口生成四个单据
  328. if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
  329. {
  330. var eqp = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == simulation.EQPCODE);
  331. //泛微设备回写109账套
  332. if (eqp != null && eqp.MTStatus.Equals("是"))
  333. {
  334. var op = db.ICSOP.SingleOrDefault(a => a.OPCODE == simulationNew.OPCODE);
  335. List<VouchHead> headList = new List<VouchHead>();
  336. VouchHead head = new VouchHead();
  337. head.cMemo = simulationNew.OPCODE + op.OPDESC;
  338. head.UserCode = AppConfig.UserCode;
  339. head.TargetAccount = ConfigurationManager.AppSettings["TargetAccount"];
  340. head.list = new List<VouchBody>();
  341. VouchBody body = new VouchBody();
  342. body.cInvCode = simulationNew.ITEMCODE;
  343. body.iQuantity = simulationNew.LOTQTY;
  344. body.iNum = simulationNew.LOTQTY * lot.EATTRIBUTE3;
  345. body.cBatch = lot.VenderLotNO;
  346. body.MOCode = simulationNew.MOCODE;
  347. body.MOSeq = simulationNew.MOSEQ.ToString();
  348. body.OPCode = simulationNew.OPCODE;
  349. var price = db.ICSItemOPPrice.Where(a => a.ITEMCODE == simulationNew.ITEMCODE && a.OPCODE == simulationNew.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
  350. body.iCost = price == null ? 0.1M : (price.Price ?? 0.1M);
  351. head.list.Add(body);
  352. headList.Add(head);
  353. string Istr = JsonConvert.SerializeObject(headList);
  354. string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APICreateVouch", Istr);
  355. Result INVOUTResult = new Result();
  356. INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  357. if (INVOUTResult.code != "200")
  358. {
  359. throw new Exception(INVOUTResult.msg);
  360. }
  361. }
  362. }
  363. }
  364. onwipNew.OPCODE = simulationNew.OPCODE;
  365. onwipNew.EQPCODE = simulationNew.EQPCODE;
  366. onwipNew.RESCODE = simulation.RESCODE;
  367. onwipNew.SHIFTTYPECODE = simulation.CHECKLOTNO;
  368. onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  369. onwipNew.UserCodeEnd = simulation.MUSER;
  370. onwipNew.MUSER = AppConfig.UserCode;
  371. onwipNew.MUSERName = AppConfig.UserName;
  372. onwipNew.MTIME = DateTime.Now;
  373. onwipNew.WorkPoint = AppConfig.WorkPointCode;
  374. if (wipNew)
  375. {
  376. db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
  377. }
  378. #endregion
  379. }
  380. catch (Exception ex)
  381. {
  382. throw ex;
  383. }
  384. }
  385. public static void Save(FramDataContext db, ICSLOTONWIP onwip)
  386. {
  387. try
  388. {
  389. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == onwip.MUSER);
  390. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == onwip.LOTNO && a.OPCODE == onwip.OPCODE);
  391. var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == onwip.LOTNO);
  392. var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
  393. bool simNew = false;
  394. var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == onwip.LOTNO);
  395. #region simulation
  396. //ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
  397. if (simulationNew == null)
  398. {
  399. simNew = true;
  400. simulationNew = new ICSLOTSIMULATION();
  401. simulationNew.ID = AppConfig.GetGuid();
  402. simulationNew.LOTNO = onwip.LOTNO;
  403. simulationNew.MOCODE = mouser.MOCODE;
  404. simulationNew.LOTSEQ = 0;
  405. simulationNew.LOTQTY = Convert.ToInt32(lot.LOTQTY);
  406. simulationNew.GOODQTY = simulationNew.LOTQTY;
  407. simulationNew.NGQTY = 0;
  408. simulationNew.LOTStatus = "新增";
  409. simulationNew.MODELCODE = "";
  410. simulationNew.ITEMCODE = lot.ItemCode;
  411. simulationNew.FROMROUTE = "";
  412. simulationNew.FROMOP = "";
  413. simulationNew.ROUTECODE = mouser.RouteCode;
  414. simulationNew.RESCODE = "";
  415. simulationNew.CHECKLOTNO = "";
  416. simulationNew.CARTONCODE = "";
  417. simulationNew.PALLETCODE = "";
  418. simulationNew.PRODUCTSTATUS = "GOOD";
  419. simulationNew.LACTION = "GOOD";
  420. simulationNew.ACTIONLIST = "GOOD";
  421. simulationNew.NGTIMES = 0;
  422. simulationNew.ISCOM = "0";
  423. simulationNew.ISHOLD = 0;
  424. simulationNew.SHELFNO = "";
  425. simulationNew.MOSEQ = mouser.MOSEQ;
  426. simulationNew.CollectStatus = "COLLECT_BEGIN";
  427. //simulationNew.SEQ = 1;
  428. simulationNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  429. }
  430. else
  431. {
  432. //if (simulationNew.OPCODE == onwip.OPCODE)
  433. //{
  434. // simulationNew.CollectStatus = "COLLECT_END";
  435. //}
  436. //else
  437. //{
  438. // simulationNew.CollectStatus = "COLLECT_BEGIN";
  439. // simulationNew.SEQ = simulationNew.SEQ + 1;
  440. //}
  441. if (itemop.OPCODE == onwip.OPCODE && simulationNew.CollectStatus == "COLLECT_END")
  442. {
  443. simulationNew.ISCOM = "1";
  444. }
  445. }
  446. simulationNew.OPCODE = onwip.OPCODE;
  447. simulationNew.EQPCODE = onwip.EQPCODE;
  448. //simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  449. simulationNew.MUSER = AppConfig.UserCode;
  450. simulationNew.MUSERName = AppConfig.UserName;
  451. simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  452. simulationNew.WorkPoint = AppConfig.WorkPointCode;
  453. if (simNew)
  454. db.ICSLOTSIMULATION.InsertOnSubmit(simulationNew);
  455. #endregion
  456. bool wipNew = false;
  457. ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.OPCODE == simulationNew.OPCODE);
  458. #region onwip
  459. //ICSLOTONWIP onwipNew = new ICSLOTONWIP();
  460. if (onwipNew == null)
  461. {
  462. wipNew = true;
  463. onwipNew = new ICSLOTONWIP();
  464. onwipNew.ID = AppConfig.GetGuid();
  465. onwipNew.LOTNO = simulationNew.LOTNO;
  466. onwipNew.LOTSEQ = simulationNew.LOTSEQ;
  467. onwipNew.SEGCODE = "";
  468. onwipNew.SSCODE = "";
  469. onwipNew.SHIFTTYPECODE = "";
  470. onwipNew.MOCODE = simulationNew.MOCODE;
  471. onwipNew.LOTSEQ = 0;
  472. onwipNew.MODELCODE = simulationNew.MODELCODE;
  473. onwipNew.ITEMCODE = simulationNew.ITEMCODE;
  474. onwipNew.ROUTECODE = simulationNew.ROUTECODE;
  475. onwipNew.RESCODE = simulationNew.RESCODE;
  476. onwipNew.ACTION = "GOOD";
  477. onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
  478. onwipNew.NGTIMES = simulationNew.NGTIMES;
  479. onwipNew.SHELFNO = simulationNew.SHELFNO;
  480. onwipNew.MOSEQ = simulationNew.MOSEQ;
  481. onwipNew.Processed = 0;
  482. onwipNew.LOTQTY = (int)simulationNew.LOTQTY;
  483. onwipNew.GOODQTY = (int)simulationNew.GOODQTY;
  484. onwipNew.NGQTY = (int)simulationNew.NGQTY;
  485. onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  486. onwipNew.UserCodeBegin = onwip.MUSER;
  487. }
  488. else
  489. {
  490. onwipNew.ACTIONRESULT = "COLLECT_END";
  491. ////调用接口生成四个单据
  492. //if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
  493. //{
  494. // var eqp = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == simulation.EQPCODE);
  495. // //泛微设备回写109账套
  496. // if (eqp != null && eqp.MTStatus.Equals("是"))
  497. // {
  498. // var op = db.ICSOP.SingleOrDefault(a => a.OPCODE == simulationNew.OPCODE);
  499. // List<VouchHead> headList = new List<VouchHead>();
  500. // VouchHead head = new VouchHead();
  501. // head.cMemo = simulationNew.OPCODE + op.OPDESC;
  502. // head.UserCode = AppConfig.UserCode;
  503. // head.TargetAccount = ConfigurationManager.AppSettings["TargetAccount"];
  504. // head.list = new List<VouchBody>();
  505. // VouchBody body = new VouchBody();
  506. // body.cInvCode = simulationNew.ITEMCODE;
  507. // body.iQuantity = simulationNew.LOTQTY;
  508. // body.iNum = simulationNew.LOTQTY * lot.EATTRIBUTE3;
  509. // body.cBatch = lot.VenderLotNO;
  510. // body.MOCode = simulationNew.MOCODE;
  511. // body.MOSeq = simulationNew.MOSEQ.ToString();
  512. // body.OPCode = simulationNew.OPCODE;
  513. // var price = db.ICSItemOPPrice.Where(a => a.ITEMCODE == simulationNew.ITEMCODE && a.OPCODE == simulationNew.OPCODE).OrderByDescending(a => a.MTIME).FirstOrDefault();
  514. // body.iCost = price == null ? 0.1M : (price.Price ?? 0.1M);
  515. // head.list.Add(body);
  516. // headList.Add(head);
  517. // string Istr = JsonConvert.SerializeObject(headList);
  518. // string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APICreateVouch", Istr);
  519. // Result INVOUTResult = new Result();
  520. // INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  521. // if (INVOUTResult.code != "200")
  522. // {
  523. // throw new Exception(INVOUTResult.msg);
  524. // }
  525. // }
  526. //}
  527. }
  528. onwipNew.OPCODE = simulationNew.OPCODE;
  529. onwipNew.EQPCODE = simulationNew.EQPCODE;
  530. onwipNew.RESCODE = onwip.RESCODE;
  531. //onwipNew.SHIFTTYPECODE = onwip.CHECKLOTNO;
  532. onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  533. onwipNew.UserCodeEnd = onwip.MUSER;
  534. onwipNew.MUSER = AppConfig.UserCode;
  535. onwipNew.MUSERName = AppConfig.UserName;
  536. onwipNew.MTIME = DateTime.Now;
  537. onwipNew.WorkPoint = AppConfig.WorkPointCode;
  538. if (wipNew)
  539. {
  540. db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
  541. }
  542. #endregion
  543. }
  544. catch (Exception ex)
  545. {
  546. throw ex;
  547. }
  548. }
  549. public static void SaveLogInfo(FramDataContext db, ICSLOTSIMULATION simulation, bool IsSend)
  550. {
  551. var lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO).FirstOrDefault();
  552. if (IsSend == true)
  553. {
  554. lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO && a.Memo == simulation.OPCODE && a.BusinessCode == "委外发料" && a.TransType == "发").FirstOrDefault();
  555. }
  556. else
  557. {
  558. lotinfolog = db.ICSWareHouseLotInfoLog.Where(a => a.LotNO == simulation.LOTNO && a.BusinessCode == "委外发料" && a.TransType == "发" && a.Memo == simulation.OPCODE).FirstOrDefault();
  559. }
  560. var poinfo = db.ICSPO_PoMain.Where(a => a.POCode == lotinfolog.TransNO && a.InvCode == lotinfolog.ITEMCODE.Split('_')[0] + "_" + simulation.OPCODE).FirstOrDefault();
  561. #region ICSWareHouseLotInfolog
  562. var log = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.LotNO == simulation.LOTNO && a.Memo == simulation.OPCODE && a.TransType == "收" && a.BusinessCode == "委外发料");
  563. if (log == null)
  564. {
  565. ICSWareHouseLotInfoLog infolog = new ICSWareHouseLotInfoLog();
  566. infolog.ID = AppConfig.GetGuid();
  567. infolog.TransNO = lotinfolog.TransNO;
  568. infolog.TransLine = lotinfolog.TransLine;
  569. infolog.ITEMCODE = lotinfolog.ITEMCODE;
  570. infolog.LotNO = lotinfolog.LotNO;
  571. infolog.Memo = simulation.OPCODE;
  572. infolog.TransQTY = lotinfolog.TransQTY;
  573. infolog.TransType = "收";
  574. infolog.BusinessCode = "委外发料";
  575. infolog.MUSER = AppConfig.UserCode;
  576. infolog.MUSERName = AppConfig.UserName;
  577. infolog.WorkPoint = lotinfolog.WorkPoint;
  578. infolog.MTIME = DateTime.Now;
  579. db.ICSWareHouseLotInfoLog.InsertOnSubmit(infolog);
  580. }
  581. #endregion
  582. }
  583. public static void CheckListEnd(FramDataContext db, List<ICSLOTSIMULATION> InfoList)
  584. {
  585. foreach (ICSLOTSIMULATION info in InfoList)
  586. {
  587. var lotinfo = from A in db.ICSWareHouseLotInfoLog
  588. where A.LotNO == info.LOTNO && A.BusinessCode == "委外发料" && A.TransType == "发"
  589. select A;
  590. foreach (var lotno in lotinfo)
  591. {
  592. var endlot = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.LotNO == lotno.LotNO && a.Memo == lotno.Memo && a.BusinessCode == "委外发料" && a.TransType == "收");
  593. if (endlot == null)
  594. {
  595. ICSWareHouseLotInfoLog infolog = new ICSWareHouseLotInfoLog();
  596. infolog.ID = AppConfig.GetGuid();
  597. infolog.TransNO = lotno.TransNO;
  598. infolog.TransLine = lotno.TransLine;
  599. infolog.ITEMCODE = lotno.ITEMCODE;
  600. infolog.LotNO = lotno.LotNO;
  601. infolog.Memo = lotno.Memo;
  602. infolog.TransQTY = lotno.TransQTY;
  603. infolog.TransType = "收";
  604. infolog.BusinessCode = "委外发料";
  605. infolog.MUSER = AppConfig.UserCode;
  606. infolog.MUSERName = AppConfig.UserName;
  607. infolog.WorkPoint = lotno.WorkPoint;
  608. infolog.MTIME = DateTime.Now;
  609. db.ICSWareHouseLotInfoLog.InsertOnSubmit(infolog);
  610. db.SubmitChanges();
  611. }
  612. }
  613. db.SubmitChanges();
  614. }
  615. }
  616. public static void CheckAutoOP(FramDataContext db, List<ICSLOTSIMULATION> InfoList)
  617. {
  618. throw new Exception("表变更,注释掉此方法内容");
  619. //foreach (ICSLOTSIMULATION info in InfoList)
  620. //{
  621. // int OPSEQ = 0;
  622. // var opinfo = from A in db.ICSMO2User
  623. // join B in db.ICSITEMROUTE2OPLot
  624. // on A.LOTNO equals B.LotNo
  625. // where A.OPCODE == B.OPCODE && A.OPCODE == info.OPCODE && A.LOTNO == info.LOTNO
  626. // select B;
  627. // foreach (var OP in opinfo)
  628. // {
  629. // OPSEQ = OP.OPSEQ;
  630. // }
  631. // var Status = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == info.LOTNO && a.OPCODE == info.OPCODE && a.CollectStatus == "COLLECT_BEGIN" && a.WorkPoint == AppConfig.WorkPointCode);
  632. // if (Status != null)
  633. // {
  634. // Save(db, info);
  635. // SaveLogInfo(db, Status, true);
  636. // }
  637. // else
  638. // {
  639. // var lotinfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == info.LOTNO && a.WorkPoint == AppConfig.WorkPointCode);
  640. // if (lotinfo.CollectStatus == "COLLECT_END")
  641. // {
  642. // throw new Exception("跟踪单:" + lotinfo.LOTNO + "没有对应工序不是已发料的状态,不能进行委外收料!");
  643. // }
  644. // else
  645. // {
  646. // var opseqmin = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == lotinfo.LOTNO && a.OPCODE == lotinfo.OPCODE);
  647. // //var opseq = from A in db.ICSMO2User
  648. // // join B in db.ICSITEMROUTE2OPLot
  649. // // on A.LOTNO equals B.LotNo
  650. // // where B.OPSEQ > lotinfo.SEQ && B.OPSEQ <= OPSEQ && A.OPCODE == B.OPCODE && A.LOTNO == lotinfo.LOTNO
  651. // // && A.EATTRIBUTE1 == "1"
  652. // // select A;
  653. // var opseq = from A in db.ICSITEMROUTE2OPLot
  654. // join B in db.ICSMO2User
  655. // on A.LotNo equals B.LOTNO
  656. // where A.OPSEQ >= opseqmin.OPSEQ && A.OPSEQ <= OPSEQ && A.OPCODE == B.OPCODE && B.LOTNO == lotinfo.LOTNO
  657. // && B.EATTRIBUTE1 == "1"
  658. // orderby A.OPSEQ
  659. // select B;
  660. // if (opseq == null)
  661. // {
  662. // throw new Exception("上级委外工序尚未发料,不能进行委外收料!");
  663. // }
  664. // else
  665. // {
  666. // foreach (var lot in opseq)
  667. // {
  668. // ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
  669. // simulation.MUSER = AppConfig.UserCode;
  670. // simulation.LOTNO = lot.LOTNO;
  671. // simulation.OPCODE = lot.OPCODE;
  672. // simulation.EQPCODE = lot.EQPCode;
  673. // var simulationinfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
  674. // if (simulationinfo == null)
  675. // {
  676. // simulation.ID = AppConfig.GetGuid();
  677. // for (int i = 0; i < 2; i++)
  678. // {
  679. // Save(db, simulation);
  680. // SaveLogInfo(db, simulation, false);
  681. // db.SubmitChanges();
  682. // }
  683. // if (lot.OPCODE != info.OPCODE)
  684. // {
  685. // var onwipcheck = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
  686. // var check = new ICSLOTONWIPCheck();
  687. // check.ID = AppConfig.GetGuid();
  688. // check.ONWIPID = onwipcheck.ID;
  689. // check.Result = "待检";
  690. // check.USER = null;
  691. // check.TIME = null;
  692. // //check.RUSER = AppConfig.UserCode;
  693. // //check.RTIME = DateTime.Now;
  694. // check.MUSER = AppConfig.UserCode;
  695. // check.MUSERName = AppConfig.UserName;
  696. // check.MTIME = DateTime.Now;
  697. // check.WorkPoint = AppConfig.WorkPointCode;
  698. // db.ICSLOTONWIPCheck.InsertOnSubmit(check);
  699. // }
  700. // }
  701. // else
  702. // {
  703. // simulationinfo.CollectStatus = "COLLECT_END";
  704. // Save(db, simulationinfo);
  705. // db.SubmitChanges();
  706. // if (lot.OPCODE != info.OPCODE)
  707. // {
  708. // var onwipcheck = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == lot.LOTNO && a.OPCODE == lot.OPCODE);
  709. // var check = new ICSLOTONWIPCheck();
  710. // check.ID = AppConfig.GetGuid();
  711. // check.ONWIPID = onwipcheck.ID;
  712. // check.Result = "待检";
  713. // check.USER = null;
  714. // check.TIME = null;
  715. // //check.RUSER = AppConfig.UserCode;
  716. // //check.RTIME = DateTime.Now;
  717. // check.MUSER = AppConfig.UserCode;
  718. // check.MUSERName = AppConfig.UserName;
  719. // check.MTIME = DateTime.Now;
  720. // check.WorkPoint = AppConfig.WorkPointCode;
  721. // db.ICSLOTONWIPCheck.InsertOnSubmit(check);
  722. // }
  723. // }
  724. // }
  725. // }
  726. // }
  727. // }
  728. //}
  729. }
  730. public static void CheckTransferInfo(FramDataContext db, ICSLOTSIMULATION simulation)
  731. {
  732. try
  733. {
  734. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  735. if (user == null)
  736. throw new Exception("用户不存在!");
  737. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  738. if (mouser == null)
  739. throw new Exception("批次工序派工信息不存在!");
  740. var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
  741. if (mo == null)
  742. throw new Exception("工单信息不存在!");
  743. var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
  744. if (moroute == null)
  745. throw new Exception("工单未关联途程!");
  746. if (moroute.ROUTECODE != mouser.RouteCode)
  747. throw new Exception("工单途程与派工途程不同!");
  748. var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
  749. if (itemop == null)
  750. throw new Exception("产品途程工序不存在!");
  751. var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  752. var itemops = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
  753. if (sim == null && itemops != null && itemops.Count() > 0)
  754. throw new Exception("请从第一道工序开始报工!");
  755. ICSLOTONWIP onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == sim.LOTNO && a.LOTSEQ == sim.LOTSEQ);
  756. //判断
  757. if (sim == null)
  758. {
  759. throw new Exception("该批次不是在制品,任务不能转移!");
  760. }
  761. else if (onwip == null)
  762. {
  763. throw new Exception("该批次工序不是在制品,任务不能转移!");
  764. }
  765. else
  766. {
  767. if (sim.ISCOM == "1")
  768. {
  769. throw new Exception("该批次已完工!");
  770. }
  771. if (sim.LOTStatus.Equals("暂停"))
  772. {
  773. throw new Exception("该批次工序处于暂停状态,任务不能转移!");
  774. }
  775. if (sim.CollectStatus == "COLLECT_END")
  776. {
  777. throw new Exception("该工序已经完工,任务不能转移!");
  778. }
  779. if (onwip.UserCodeBegin.Equals(simulation.MUSER) && onwip.EQPCODE.Equals(simulation.EQPCODE))
  780. {
  781. throw new Exception("同一员工同一设备,任务不需要转移!");
  782. }
  783. if (sim.OPCODE != simulation.OPCODE)
  784. {
  785. throw new Exception("采集工序与输入工序不对应!");
  786. }
  787. }
  788. }
  789. catch (Exception ex)
  790. {
  791. throw ex;
  792. }
  793. }
  794. public static void Transfer(FramDataContext db, ICSLOTSIMULATION simulation)
  795. {
  796. try
  797. {
  798. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  799. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  800. var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.LOTNO);
  801. var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
  802. var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  803. ICSLOTONWIP onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
  804. #region simulation
  805. //ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
  806. if (simulationNew == null)
  807. {
  808. throw new Exception("该批次不是在制品,任务不能转移!");
  809. }
  810. else
  811. {
  812. simulationNew.LOTSEQ = simulationNew.LOTSEQ + 1;
  813. }
  814. simulationNew.EQPCODE = simulation.EQPCODE;
  815. simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  816. simulationNew.MUSER = AppConfig.UserCode;
  817. simulationNew.MUSERName = AppConfig.UserName;
  818. simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  819. simulationNew.WorkPoint = AppConfig.WorkPointCode;
  820. #endregion
  821. #region onwip
  822. //ICSLOTONWIP onwipNew = new ICSLOTONWIP();
  823. if (onwip == null)
  824. {
  825. throw new Exception("该批次工序未开工,任务不能转移!");
  826. }
  827. else
  828. onwip.ACTIONRESULT = "COLLECT_END";
  829. onwip.EATTRIBUTE1 = "转移";
  830. onwip.OPCODE = simulationNew.OPCODE;
  831. //onwip.EQPCODE = simulationNew.EQPCODE;
  832. onwip.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  833. //onwip.UserCodeEnd = simulation.MUSER;
  834. onwip.MUSER = AppConfig.UserCode;
  835. onwip.MUSERName = AppConfig.UserName;
  836. onwip.MTIME = DateTime.Now;
  837. onwip.WorkPoint = AppConfig.WorkPointCode;
  838. #endregion
  839. #region onwip
  840. ICSLOTONWIP onwipNew = new ICSLOTONWIP();
  841. onwipNew.ID = AppConfig.GetGuid();
  842. onwipNew.LOTNO = onwip.LOTNO;
  843. onwipNew.MOCODE = onwip.MOCODE;
  844. onwipNew.LOTSEQ = onwip.LOTSEQ;
  845. onwipNew.MODELCODE = onwip.MODELCODE;
  846. onwipNew.ITEMCODE = onwip.ITEMCODE;
  847. onwipNew.ROUTECODE = onwip.ROUTECODE;
  848. onwipNew.OPCODE = onwip.OPCODE;
  849. onwipNew.SEGCODE = onwip.SEGCODE;
  850. onwipNew.SSCODE = onwip.SSCODE;
  851. onwipNew.RESCODE = onwip.RESCODE;
  852. onwipNew.EQPCODE = simulationNew.EQPCODE;
  853. onwipNew.SHIFTTYPECODE = onwip.SHIFTTYPECODE;
  854. onwipNew.ACTION = onwip.ACTION;
  855. onwipNew.ACTIONRESULT = "COLLECT_BEGIN";
  856. onwipNew.NGTIMES = onwip.NGTIMES;
  857. onwipNew.SHELFNO = onwip.SHELFNO;
  858. onwipNew.MOSEQ = onwip.MOSEQ;
  859. onwipNew.Processed = onwip.Processed;
  860. onwipNew.LOTQTY = onwip.LOTQTY;
  861. onwipNew.GOODQTY = onwip.GOODQTY;
  862. onwipNew.NGQTY = onwip.NGQTY;
  863. onwipNew.UserCodeBegin = simulation.MUSER;
  864. onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  865. onwipNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  866. onwipNew.UserCodeEnd = simulation.MUSER;
  867. onwipNew.RESCODE = simulation.RESCODE;
  868. onwipNew.SHIFTTYPECODE = simulation.CHECKLOTNO;
  869. onwipNew.MUSER = AppConfig.UserCode;
  870. onwipNew.MUSERName = AppConfig.UserName;
  871. onwipNew.MTIME = DateTime.Now;
  872. onwipNew.WorkPoint = AppConfig.WorkPointCode;
  873. db.ICSLOTONWIP.InsertOnSubmit(onwipNew);
  874. #endregion
  875. }
  876. catch (Exception ex)
  877. {
  878. throw ex;
  879. }
  880. }
  881. public static void CheckItemInfo(FramDataContext db, ICSLOTONWIPITEM simulation)
  882. {
  883. try
  884. {
  885. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  886. if (user == null)
  887. throw new Exception("用户不存在!");
  888. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  889. if (mouser == null)
  890. throw new Exception("批次工序派工信息不存在!");
  891. var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE == mouser.MOCODE && a.MOSEQ == mouser.MOSEQ.ToString());
  892. if (mo == null)
  893. throw new Exception("工单信息不存在!");
  894. var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
  895. if (moroute == null)
  896. throw new Exception("工单未关联途程!");
  897. if (moroute.ROUTECODE != mouser.RouteCode)
  898. throw new Exception("工单途程与派工途程不同!");
  899. var itemop = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == mo.ITEMCODE && a.ROUTECODE == moroute.ROUTECODE && a.OPCODE == mouser.OPCODE);
  900. if (itemop == null)
  901. throw new Exception("产品途程工序不存在!");
  902. //获取上料历史记录信息
  903. var LotOnWipItem = db.ICSLOTONWIPITEM.SingleOrDefault(a => a.LOTNO == simulation.LOTNO &&
  904. a.INVLOTNO == simulation.INVLOTNO && a.OPCODE == simulation.OPCODE && a.WorkPoint == AppConfig.WorkPointCode);
  905. if (LotOnWipItem != null)
  906. {
  907. //上料信息已存在,不用上料
  908. throw new Exception("上料信息已存在!");
  909. }
  910. //检验在制品批次信息
  911. var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  912. if (sim == null)
  913. {
  914. throw new Exception("该批次不是在制品,不能上料!");
  915. }
  916. else if (sim.OPCODE != simulation.OPCODE)
  917. {
  918. throw new Exception("不应该在工序:" + simulation.OPCODE + " 上料,请更换工序条码:" + sim.OPCODE);
  919. }
  920. else if (sim.ISCOM == "1")
  921. {
  922. throw new Exception("该批次已完工!");
  923. }
  924. if (sim.LOTStatus.Equals("暂停"))
  925. {
  926. throw new Exception("该批次工序处于暂停状态,不能上料!");
  927. }
  928. if (sim.CollectStatus == "COLLECT_END")
  929. {
  930. throw new Exception("该批次工序已经完工,不能上料!");
  931. }
  932. }
  933. catch (Exception ex)
  934. {
  935. throw ex;
  936. }
  937. }
  938. public static void SaveItem(FramDataContext db, ICSLOTONWIPITEM simulation)
  939. {
  940. try
  941. {
  942. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  943. //var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  944. //var itemop = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == mouser.LOTNO && a.ITEMCODE == lot.ItemCode && a.ROUTECODE == mouser.RouteCode).OrderByDescending(a => a.OPSEQ).FirstOrDefault();
  945. var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.INVLOTNO);
  946. var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  947. ICSLOTONWIP onwipNew = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulationNew.LOTNO && a.LOTSEQ == simulationNew.LOTSEQ);
  948. ICSLOTONWIPITEM wipItem = new ICSLOTONWIPITEM();
  949. wipItem.ID = AppConfig.GetGuid();
  950. wipItem.LOTNO = onwipNew.LOTNO;
  951. wipItem.INVCODE = lot.ItemCode;
  952. wipItem.MCARDTYPE = onwipNew.EATTRIBUTE1;
  953. wipItem.ITEMCODE = onwipNew.ITEMCODE;
  954. wipItem.RESCODE = onwipNew.RESCODE;
  955. wipItem.ROUTECODE = onwipNew.ROUTECODE;
  956. wipItem.SEGCODE = onwipNew.SEGCODE;
  957. wipItem.SHIFTTYPECODE = "";
  958. wipItem.SSCODE = onwipNew.SSCODE;
  959. wipItem.MOCODE = onwipNew.MOCODE;
  960. wipItem.MODELCODE = onwipNew.MODELCODE;
  961. wipItem.OPCODE = onwipNew.OPCODE;
  962. wipItem.BeginSHIFTCODE = onwipNew.SHIFTTYPECODE;
  963. wipItem.EndSHIFTCODE = onwipNew.SHIFTTYPECODE;
  964. wipItem.BeginTPCODE = "";
  965. wipItem.ENDTPCODE = "";
  966. wipItem.INVLOTNO = simulation.INVLOTNO;
  967. wipItem.MUSER = user.UserCode;
  968. wipItem.MUSERName = user.UserName;
  969. wipItem.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  970. wipItem.WorkPoint = AppConfig.WorkPointCode;
  971. wipItem.QTY = (decimal)onwipNew.LOTQTY;
  972. wipItem.TRANSSTATUS = "否";
  973. wipItem.MCARDTYPE = "1";
  974. wipItem.LOTSEQ = (int)onwipNew.LOTSEQ;
  975. //新增 采集类型
  976. wipItem.ACTIONTYPE = 0;
  977. wipItem.MOSEQ = onwipNew.MOSEQ;
  978. db.ICSLOTONWIPITEM.InsertOnSubmit(wipItem);
  979. }
  980. catch (Exception ex)
  981. {
  982. throw ex;
  983. }
  984. }
  985. public static void Pause(FramDataContext db, ICSLOTSIMULATION simulation)
  986. {
  987. try
  988. {
  989. //var line = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  990. //if (line != null && line.LOTStatus.Equals("暂停"))
  991. //{
  992. // throw new Exception("该批次工序已经暂停!");
  993. //}
  994. #region LOTPAUSE
  995. ICSLOTPAUSE lotpause = new ICSLOTPAUSE();
  996. lotpause.ID = AppConfig.GetGuid();
  997. lotpause.LOTNO = simulation.LOTNO;
  998. lotpause.MOCODE = simulation.MOCODE;
  999. lotpause.LOTSEQ = int.Parse(simulation.LOTSEQ.ToString());
  1000. //lotpause.SEQ = ;
  1001. lotpause.MODELCODE = simulation.MODELCODE;
  1002. lotpause.ITEMCODE = simulation.ITEMCODE;
  1003. lotpause.ROUTECODE = simulation.ROUTECODE;
  1004. lotpause.OPCODE = simulation.OPCODE;
  1005. lotpause.RESCODE = simulation.RESCODE;
  1006. lotpause.EQPCODE = simulation.EQPCODE;
  1007. lotpause.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1008. lotpause.SEQ = simulation.LOTSEQ;
  1009. lotpause.MUSER = AppConfig.UserCode;
  1010. lotpause.MUSERName = AppConfig.UserName;
  1011. lotpause.MTIME = DateTime.Now;
  1012. lotpause.WorkPoint = AppConfig.WorkPointCode;
  1013. lotpause.EATTRIBUTE1 = simulation.EATTRIBUTE1;
  1014. #endregion
  1015. db.ICSLOTPAUSE.InsertOnSubmit(lotpause);
  1016. //更新采集表状态
  1017. simulation.LOTStatus = "暂停";
  1018. }
  1019. catch (Exception ex)
  1020. {
  1021. throw ex;
  1022. }
  1023. }
  1024. //public static ICSLOTONWIPCheck GetModel(string id, string dsconn)
  1025. //{
  1026. // //FramDataContext db = new FramDataContext(dsconn);
  1027. // //db.Connection.Open();
  1028. // //db.Transaction = db.Connection.BeginTransaction();
  1029. // //try
  1030. // //{
  1031. // // var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == id);
  1032. // // if (line != null)
  1033. // // {
  1034. // // return line;
  1035. // // }
  1036. // // return null;
  1037. // //}
  1038. // //catch (Exception ex)
  1039. // //{
  1040. // // db.Transaction.Rollback();
  1041. // // throw new Exception(ex.Message);
  1042. // //}
  1043. //}
  1044. #region 保存PDF
  1045. public static void AddPDF(string id, string fname, string dsconn)
  1046. {
  1047. //FramDataContext db = new FramDataContext(dsconn);
  1048. //db.Connection.Open();
  1049. //db.Transaction = db.Connection.BeginTransaction();
  1050. //try
  1051. //{
  1052. // var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == id);
  1053. // if (line != null)
  1054. // {
  1055. // line.EATTRIBUTE1 = fname;
  1056. // }
  1057. // db.SubmitChanges();
  1058. // db.Transaction.Commit();
  1059. //}
  1060. //catch (Exception ex)
  1061. //{
  1062. // db.Transaction.Rollback();
  1063. // throw new Exception(ex.Message);
  1064. //}
  1065. }
  1066. #endregion
  1067. public static void CancelPause(FramDataContext db, ICSLOTSIMULATION simulation)
  1068. {
  1069. try
  1070. {
  1071. ICSLOTPAUSE line = db.ICSLOTPAUSE.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE && a.EndTime == null);
  1072. if (line != null)
  1073. {
  1074. line.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1075. line.MUSER = AppConfig.UserCode;
  1076. line.MUSERName = AppConfig.UserName;
  1077. line.MTIME = DateTime.Now;
  1078. line.WorkPoint = AppConfig.WorkPointCode;
  1079. //更新采集表状态
  1080. var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == line.LOTNO);
  1081. sim.LOTStatus = "取消暂停";
  1082. }
  1083. else
  1084. {
  1085. throw new Exception("已取消暂停,无需再次操作!");
  1086. }
  1087. }
  1088. catch (Exception ex)
  1089. {
  1090. throw ex;
  1091. }
  1092. }
  1093. //结算料费
  1094. public static void Calculate(FramDataContext db, List<string> list, string Result)
  1095. {
  1096. throw new Exception("表变更,注释掉此方法内容");
  1097. //try
  1098. //{
  1099. // //调用接口生成三个单据
  1100. // if (Convert.ToBoolean(ConfigurationManager.AppSettings["IsOpen"]))
  1101. // {
  1102. // var data = from a in db.ICSLOTONWIPCheck
  1103. // join b in db.ICSLOTONWIP on a.ONWIPID equals b.ID
  1104. // join c in db.ICSITEMLot on b.LOTNO equals c.LotNO
  1105. // join d in db.ICSMO on c.TransNO + c.TransLine equals d.MOCODE + d.MOSEQ
  1106. // join e in db.ICSWareHouseLotInfoLog on b.LOTNO + b.OPCODE equals e.LotNO + e.Memo
  1107. // join f in db.ICSPO_PoMain on e.TransNO + e.TransLine equals f.POCode + f.PORow
  1108. // where list.Contains(a.ID) && e.BusinessCode == "委外发料" && e.TransType == "收" && a.Result == Result
  1109. // orderby f.WBS, d.EATTRIBUTE1
  1110. // select new
  1111. // {
  1112. // CheckID = a.ID,
  1113. // UserCode = AppConfig.UserCode,
  1114. // POID = f.WBS,
  1115. // cIWhCode = ConfigurationManager.AppSettings["WHCode"].ToString(),
  1116. // cOWhCode = ConfigurationManager.AppSettings["WHCode"].ToString(),
  1117. // MODId = d.EATTRIBUTE1,
  1118. // ID = f.Free5,
  1119. // cInvCode = b.ITEMCODE + "_" + b.OPCODE,
  1120. // iQuantity = b.LOTQTY ?? 0,
  1121. // iNum = (Convert.ToDecimal(b.LOTQTY ?? 0) * Convert.ToDecimal(c.EATTRIBUTE1 ?? "0")),
  1122. // cBatch = c.VenderLotNO,
  1123. // };
  1124. // if (data != null && data.Count() > 0)
  1125. // {
  1126. // List<OM_POmain> headList = new List<OM_POmain>();
  1127. // OM_POmain head = new OM_POmain();
  1128. // string key = "";
  1129. // foreach (var info in data)
  1130. // {
  1131. // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == info.CheckID);
  1132. // if (line == null)
  1133. // {
  1134. // throw new Exception("检验信息不存在!");
  1135. // }
  1136. // line.IsInput = true;
  1137. // line.MUSER = AppConfig.UserCode;
  1138. // line.MUSERName = AppConfig.UserName;
  1139. // line.MTIME = DateTime.Now;
  1140. // line.WorkPoint = AppConfig.WorkPointCode;
  1141. // if (!key.Equals(info.UserCode + info.POID + info.cIWhCode + info.cOWhCode + info.MODId))
  1142. // {
  1143. // if (key != "")
  1144. // headList.Add(head);
  1145. // key = info.UserCode + info.POID + info.cIWhCode + info.cOWhCode + info.MODId;
  1146. // head = new OM_POmain();
  1147. // head.UserCode = info.UserCode;
  1148. // head.POID = info.POID;
  1149. // head.cIWhCode = info.cIWhCode;
  1150. // head.cOWhCode = info.cOWhCode;
  1151. // head.MODId = info.MODId;
  1152. // head.list = new List<OM_PODetails>();
  1153. // }
  1154. // OM_PODetails body = new OM_PODetails();
  1155. // body.ID = info.ID;
  1156. // body.cInvCode = info.cInvCode;
  1157. // body.iQuantity = Convert.ToDecimal(info.iQuantity);
  1158. // body.iNum = info.iNum;
  1159. // body.cBatch = info.cBatch;
  1160. // head.list.Add(body);
  1161. // }
  1162. // headList.Add(head);
  1163. // string Istr = JsonConvert.SerializeObject(headList);
  1164. // string iresult = HttpPost(System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString() + "APIOM_POMain", Istr);
  1165. // Result INVOUTResult = new Result();
  1166. // INVOUTResult = JsonConvert.DeserializeObject<Result>(iresult);
  1167. // if (INVOUTResult.code != "200")
  1168. // {
  1169. // throw new Exception(INVOUTResult.msg);
  1170. // }
  1171. // }
  1172. // }
  1173. //}
  1174. //catch (Exception ex)
  1175. //{
  1176. // throw ex;
  1177. //}
  1178. }
  1179. //第一次判定
  1180. //public static void FirstResult(FramDataContext db, List<ICSLOTONWIPCheck> list, List<string> idList)
  1181. //{
  1182. // throw new Exception("表变更,注释掉此方法内容");
  1183. // //try
  1184. // //{
  1185. // // foreach (ICSLOTONWIPCheck check in list)
  1186. // // {
  1187. // // bool isNew = false;
  1188. // // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
  1189. // // if (line == null)
  1190. // // {
  1191. // // isNew = true;
  1192. // // line = new ICSLOTONWIPCheck();
  1193. // // line.ID = check.ID;
  1194. // // line.ONWIPID = check.ONWIPID;
  1195. // // }
  1196. // // line.Result = check.Result;
  1197. // // line.USER = AppConfig.UserCode;
  1198. // // line.TIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1199. // // line.MUSER = AppConfig.UserCode;
  1200. // // line.MUSERName = AppConfig.UserName;
  1201. // // line.MTIME = DateTime.Now;
  1202. // // line.WorkPoint = AppConfig.WorkPointCode;
  1203. // // if (isNew)
  1204. // // db.ICSLOTONWIPCheck.InsertOnSubmit(line);
  1205. // // }
  1206. // // if (idList != null && idList.Count > 0)
  1207. // // {
  1208. // // db.SubmitChanges();
  1209. // // Calculate(db, idList, "合格");
  1210. // // }
  1211. // //}
  1212. // //catch (Exception ex)
  1213. // //{
  1214. // // throw ex;
  1215. // //}
  1216. //}
  1217. //第二次判定
  1218. //public static void SecondResult(FramDataContext db, List<ICSLOTONWIPCheck> list, List<string> idList)
  1219. //{
  1220. // throw new Exception("表变更,注释掉此方法内容");
  1221. // //try
  1222. // //{
  1223. // // foreach (ICSLOTONWIPCheck check in list)
  1224. // // {
  1225. // // bool isNew = false;
  1226. // // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
  1227. // // if (line == null)
  1228. // // {
  1229. // // isNew = true;
  1230. // // line = new ICSLOTONWIPCheck();
  1231. // // line.ID = check.ID;
  1232. // // line.ONWIPID = check.ONWIPID;
  1233. // // }
  1234. // // line.Result = check.Result;
  1235. // // line.RUSER = AppConfig.UserCode;
  1236. // // line.RTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1237. // // line.MUSER = AppConfig.UserCode;
  1238. // // line.MUSERName = AppConfig.UserName;
  1239. // // line.MTIME = DateTime.Now;
  1240. // // line.WorkPoint = AppConfig.WorkPointCode;
  1241. // // if (isNew)
  1242. // // db.ICSLOTONWIPCheck.InsertOnSubmit(line);
  1243. // // }
  1244. // // if (idList != null && idList.Count > 0)
  1245. // // {
  1246. // // db.SubmitChanges();
  1247. // // Calculate(db, idList, "合格");
  1248. // // }
  1249. // //}
  1250. // //catch (Exception ex)
  1251. // //{
  1252. // // throw ex;
  1253. // //}
  1254. //}
  1255. #region 根据条码获取条码采集信息
  1256. public static ICSLOTSIMULATION GetSimInfoByLotNo(string LotNo, string dsconn)
  1257. {
  1258. FramDataContext db = new FramDataContext(dsconn);
  1259. db.Connection.Open();
  1260. db.Transaction = db.Connection.BeginTransaction();
  1261. try
  1262. {
  1263. var line = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LotNo && a.WorkPoint == AppConfig.WorkPointCode);
  1264. return line;
  1265. }
  1266. catch (Exception ex)
  1267. {
  1268. throw new Exception(ex.Message);
  1269. }
  1270. }
  1271. #endregion
  1272. #region 检查当前检验的工序是否是委外工(True:委外,Flase:非委外)
  1273. public static bool GetLotOPInfoByCode(string LotNo, string OPCode, string dsconn)
  1274. {
  1275. FramDataContext db = new FramDataContext(dsconn);
  1276. db.Connection.Open();
  1277. db.Transaction = db.Connection.BeginTransaction();
  1278. try
  1279. {
  1280. var line = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == LotNo && a.OPCODE == OPCode && a.WorkPoint == AppConfig.WorkPointCode);
  1281. if (line.EATTRIBUTE1 == "1")
  1282. {
  1283. return true;
  1284. }
  1285. else
  1286. {
  1287. return false;
  1288. }
  1289. }
  1290. catch (Exception ex)
  1291. {
  1292. throw new Exception(ex.Message);
  1293. }
  1294. }
  1295. #endregion
  1296. //public static void TResult(FramDataContext db, List<ICSLOTONWIPCheck> list)
  1297. //{
  1298. // throw new Exception("表变更,注释掉此方法内容");
  1299. // //try
  1300. // //{
  1301. // // foreach (ICSLOTONWIPCheck check in list)
  1302. // // {
  1303. // // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
  1304. // // if (line != null)
  1305. // // {
  1306. // // line.TResult = check.TResult;
  1307. // // line.TUSER = AppConfig.UserCode;
  1308. // // line.TTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1309. // // line.MUSER = AppConfig.UserCode;
  1310. // // line.MUSERName = AppConfig.UserName;
  1311. // // line.MTIME = DateTime.Now;
  1312. // // line.WorkPoint = AppConfig.WorkPointCode;
  1313. // // }
  1314. // // }
  1315. // //}
  1316. // //catch (Exception ex)
  1317. // //{
  1318. // // throw ex;
  1319. // //}
  1320. //}
  1321. //public static void RResult(FramDataContext db, List<ICSLOTONWIPCheck> list)
  1322. //{
  1323. // throw new Exception("表变更,注释掉此方法内容");
  1324. // //try
  1325. // //{
  1326. // // foreach (ICSLOTONWIPCheck check in list)
  1327. // // {
  1328. // // ICSLOTONWIPCheck line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == check.ID);
  1329. // // if (line != null)
  1330. // // {
  1331. // // line.RResult = check.RResult;
  1332. // // line.RUSER = AppConfig.UserCode;
  1333. // // line.RTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  1334. // // line.MUSER = AppConfig.UserCode;
  1335. // // line.MUSERName = AppConfig.UserName;
  1336. // // line.MTIME = DateTime.Now;
  1337. // // line.WorkPoint = AppConfig.WorkPointCode;
  1338. // // }
  1339. // // }
  1340. // //}
  1341. // //catch (Exception ex)
  1342. // //{
  1343. // // throw ex;
  1344. // //}
  1345. //}
  1346. //采购订单已发数量更新
  1347. public static void UpdatePOInfo(FramDataContext db, ICSPO_PoMain info)
  1348. {
  1349. var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == info.POCode && a.PORow == info.PORow);
  1350. line.INQty = Convert.ToDecimal(line.INQty) + Convert.ToDecimal(info.INQty);
  1351. line.MTIME = DateTime.Now;
  1352. }
  1353. //日志表条码对应采购订单信息记录
  1354. public static void AddLogInfo(FramDataContext db, ICSWareHouseLotInfoLog info)
  1355. {
  1356. var line = new ICSWareHouseLotInfoLog();
  1357. line.ID = info.ID;
  1358. line.TransNO = info.TransNO;
  1359. line.TransLine = info.TransLine;
  1360. line.ITEMCODE = info.ITEMCODE;
  1361. line.LotNO = info.LotNO;
  1362. line.TransQTY = info.TransQTY;
  1363. line.TransType = "发";
  1364. line.BusinessCode = "委外发料";
  1365. line.Memo = info.Memo;
  1366. line.MUSER = info.MUSER;
  1367. line.MUSERName = info.MUSERName;
  1368. line.MTIME = info.MTIME;
  1369. line.WorkPoint = info.WorkPoint;
  1370. db.ICSWareHouseLotInfoLog.InsertOnSubmit(line);
  1371. }
  1372. public static string HttpPost(string url, string body)
  1373. {
  1374. try
  1375. {
  1376. Encoding encoding = Encoding.UTF8;
  1377. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  1378. request.Method = "POST";
  1379. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  1380. request.ContentType = "application/json; charset=utf-8";
  1381. byte[] buffer = encoding.GetBytes(body);
  1382. request.ContentLength = buffer.Length;
  1383. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  1384. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  1385. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  1386. {
  1387. return reader.ReadToEnd();
  1388. }
  1389. }
  1390. catch (WebException ex)
  1391. {
  1392. var res = (HttpWebResponse)ex.Response;
  1393. StringBuilder sb = new StringBuilder();
  1394. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  1395. sb.Append(sr.ReadToEnd());
  1396. //string ssb = sb.ToString();
  1397. throw new Exception(sb.ToString());
  1398. }
  1399. }
  1400. public static void DataDelete(FramDataContext db, List<FormICSCollectDataDeleteUIModel> infolist)
  1401. {
  1402. try
  1403. {
  1404. foreach (FormICSCollectDataDeleteUIModel info in infolist)
  1405. {
  1406. //删除ICSLOTONWIP数据
  1407. var lines1 = db.ICSLOTONWIP.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
  1408. db.ICSLOTONWIP.DeleteAllOnSubmit(lines1);
  1409. db.SubmitChanges();
  1410. var lastInfo = db.ICSLOTONWIP.Where(a => a.LOTNO == info.LotNO && a.ACTIONRESULT == "COLLECT_END").OrderByDescending(a => a.MTIME).FirstOrDefault();
  1411. if (lastInfo == null)
  1412. {
  1413. //删除ICSLOTSIMULATION数据
  1414. var lines2 = db.ICSLOTSIMULATION.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
  1415. db.ICSLOTSIMULATION.DeleteAllOnSubmit(lines2);
  1416. db.SubmitChanges();
  1417. }
  1418. else
  1419. {
  1420. //更新ICSLOTSIMULATION数据
  1421. var lines2 = db.ICSLOTSIMULATION.SingleOrDefault(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
  1422. lines2.MOSEQ = lastInfo.MOSEQ;
  1423. lines2.GOODQTY = lastInfo.GOODQTY;
  1424. lines2.NGQTY = lastInfo.NGQTY;
  1425. lines2.OPCODE = lastInfo.OPCODE;
  1426. lines2.LOTSEQ = lastInfo.LOTSEQ;
  1427. lines2.CollectStatus = lastInfo.ACTIONRESULT;
  1428. db.SubmitChanges();
  1429. }
  1430. }
  1431. }
  1432. catch (Exception ex)
  1433. {
  1434. throw ex;
  1435. }
  1436. }
  1437. public static void DataDeleteForWW(FramDataContext db, List<FormICSCollectWWDataDeleteUIModel> infolist)
  1438. {
  1439. try
  1440. {
  1441. foreach (FormICSCollectWWDataDeleteUIModel info in infolist)
  1442. {
  1443. var lines1 = db.ICSLOTONWIP.Where(a => a.MOCODE == info.MOCode && a.LOTNO == info.LotNO && a.OPCODE == info.OPCode);
  1444. if (lines1 != null)
  1445. {
  1446. db.ICSLOTONWIP.DeleteAllOnSubmit(lines1);
  1447. }
  1448. var lines3 = db.ICSWareHouseLotInfoLog.Where(a => a.TransNO == info.POCode && a.TransLine == info.PORow && a.LotNO == info.LotNO
  1449. && a.ITEMCODE == info.ItemCode + "_" + info.OPCode && a.BusinessCode == "委外发料");
  1450. if (lines3 != null)
  1451. {
  1452. #region 删除前先存入删除日志表(ICSWWDataDeleteLog)
  1453. var loginfo = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.TransNO == info.POCode && a.TransLine == info.PORow && a.LotNO == info.LotNO
  1454. && a.ITEMCODE == info.ItemCode + "_" + info.OPCode && a.BusinessCode == "委外发料");
  1455. if (loginfo != null)
  1456. {
  1457. ICSWWDataDeleteLog dlog = new ICSWWDataDeleteLog();
  1458. dlog.ID = AppConfig.GetGuid();
  1459. dlog.TransNO = loginfo.TransNO;
  1460. dlog.TransLine = loginfo.TransLine;
  1461. dlog.ITEMCODE = loginfo.ITEMCODE;
  1462. dlog.LotNO = loginfo.LotNO;
  1463. dlog.TransQTY = loginfo.TransQTY;
  1464. dlog.Memo = loginfo.Memo;
  1465. dlog.TransType = loginfo.TransType;
  1466. dlog.BusinessCode = loginfo.BusinessCode;
  1467. dlog.MUSER = AppConfig.UserCode;
  1468. dlog.MUSERName = AppConfig.UserName;
  1469. dlog.MTIME = DateTime.Now;
  1470. dlog.WorkPoint = loginfo.WorkPoint;
  1471. dlog.EATTRIBUTE3 = info.PRCode;
  1472. db.ICSWWDataDeleteLog.InsertOnSubmit(dlog);
  1473. }
  1474. #endregion
  1475. db.ICSWareHouseLotInfoLog.DeleteAllOnSubmit(lines3);
  1476. }
  1477. else
  1478. {
  1479. throw new Exception("没有匹配到采购订单信息,无法删除委外开工记录,请联系开发人员!");
  1480. }
  1481. var lines4 = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == info.POCode && a.PORow == info.PORow);
  1482. if (lines4 != null)
  1483. {
  1484. lines4.INQty = lines4.INQty - info.LotQTY;
  1485. }
  1486. }
  1487. foreach (FormICSCollectWWDataDeleteUIModel wwinfo in infolist)
  1488. {
  1489. var lastInfo = db.ICSLOTONWIP.Where(a => a.LOTNO == wwinfo.LotNO && a.ACTIONRESULT == "COLLECT_END").OrderByDescending(a => a.MTIME).FirstOrDefault();
  1490. if (lastInfo == null)
  1491. {
  1492. //删除ICSLOTSIMULATION数据
  1493. var lines2 = db.ICSLOTSIMULATION.Where(a => a.MOCODE == wwinfo.MOCode && a.LOTNO == wwinfo.LotNO);
  1494. db.ICSLOTSIMULATION.DeleteAllOnSubmit(lines2);
  1495. db.SubmitChanges();
  1496. }
  1497. else
  1498. {
  1499. //更新ICSLOTSIMULATION数据
  1500. var lines2 = db.ICSLOTSIMULATION.SingleOrDefault(a => a.MOCODE == wwinfo.MOCode && a.LOTNO == wwinfo.LotNO);
  1501. lines2.MOSEQ = lastInfo.MOSEQ;
  1502. lines2.GOODQTY = lastInfo.GOODQTY;
  1503. lines2.NGQTY = lastInfo.NGQTY;
  1504. lines2.OPCODE = lastInfo.OPCODE;
  1505. lines2.LOTSEQ = lastInfo.LOTSEQ;
  1506. lines2.CollectStatus = lastInfo.ACTIONRESULT;
  1507. db.SubmitChanges();
  1508. }
  1509. }
  1510. }
  1511. catch (Exception ex)
  1512. {
  1513. throw ex;
  1514. }
  1515. }
  1516. #region 判断第二次检验是否与第一次检验相同(True:相同;False:不同)
  1517. //public static string CheckFSDifferent(FramDataContext db, List<ICSLOTONWIPCheck> infolist, List<string> LotNO, List<string> OPCode)
  1518. //{
  1519. // throw new Exception("表变更,注释掉此方法内容");
  1520. // //try
  1521. // //{
  1522. // // string Result = "";
  1523. // // for (int i = 0; i < infolist.Count(); i++)
  1524. // // {
  1525. // // var line = db.ICSLOTONWIPCheck.SingleOrDefault(a => a.ID == infolist[i].ID && a.Result == infolist[i].RResult);
  1526. // // if (line != null)
  1527. // // {
  1528. // // if (Result == "")
  1529. // // {
  1530. // // Result += "跟踪单:" + LotNO[0] + ",工序:" + OPCode[0] + ";\n";
  1531. // // }
  1532. // // else
  1533. // // {
  1534. // // Result += ",跟踪单:" + LotNO[0] + ",工序:" + OPCode[0] + ";\n";
  1535. // // }
  1536. // // }
  1537. // // }
  1538. // // if (Result != "")
  1539. // // {
  1540. // // Result += "以上跟踪单对应工序的第一次检验结果与第二次检验结果相同,\n不能进行第二次检验";
  1541. // // }
  1542. // // return Result;
  1543. // //}
  1544. // //catch (Exception ex)
  1545. // //{
  1546. // // throw new Exception(ex.Message);
  1547. // //}
  1548. //}
  1549. #endregion
  1550. /// <summary>
  1551. /// 发料
  1552. /// </summary>
  1553. /// <param name="send"></param>
  1554. /// <param name="ds"></param>
  1555. /// <param name="conn"></param>
  1556. public static void OutsourceSubmit(bool send, DataSet ds, string conn)
  1557. {
  1558. string TransType = "";
  1559. string BusinessCode = "";
  1560. string CollectStatus = "";
  1561. decimal GOODQTY = 0;
  1562. DateTime? EndTime = null;
  1563. string EndUser = "";
  1564. FramDataContext db = new FramDataContext(conn);
  1565. db.Connection.Open();
  1566. db.Transaction = db.Connection.BeginTransaction();
  1567. try
  1568. {
  1569. foreach (DataTable dt in ds.Tables)
  1570. {
  1571. #region 主数据
  1572. //发料时dt排序为正序,收料是倒序,因此此处取首行,即发料第一道工序,收料最后一道工序
  1573. string MOCODE = dt.Rows[0]["MOCODE"].ToString();
  1574. int MOSEQ = Convert.ToInt32(dt.Rows[0]["MOSEQ"].ToString());
  1575. string LOTNO = dt.Rows[0]["LotNo"].ToString();
  1576. string ITEMCODE = dt.Rows[0]["ITEMCODE"].ToString();
  1577. decimal LOTQTY = Convert.ToDecimal(dt.Rows[0]["PRQTY"].ToString());
  1578. decimal RcvNGQTY = Convert.ToDecimal(dt.Rows[0]["RcvNGQTY"].ToString());//收料:供应商欠料数量
  1579. string ROUTECODE = dt.Rows[0]["ROUTECODE"].ToString();
  1580. string OPCODE = dt.Rows[0]["OPCODE"].ToString();
  1581. int OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
  1582. string EQPCODE = dt.Rows[0]["EQPCode"].ToString();
  1583. //string EQPName = dt.Rows[0]["EQPName"].ToString();
  1584. string CtrlType = dt.Rows[0]["控制方式"].ToString();
  1585. string VenCode = dt.Rows[0]["VenCode"].ToString();
  1586. //string VenName = dt.Rows[0]["VenName"].ToString();
  1587. if (send)
  1588. {
  1589. TransType = "发";
  1590. BusinessCode = "委外发料";
  1591. CollectStatus = "COLLECT_BEGIN";
  1592. GOODQTY = 0;
  1593. EndTime = null;
  1594. EndUser = null;
  1595. }
  1596. else
  1597. {
  1598. TransType = "收";
  1599. BusinessCode = "委外收料";
  1600. CollectStatus = "COLLECT_END";
  1601. GOODQTY = LOTQTY;
  1602. EndTime = DateTime.Now;
  1603. EndUser = VenCode;
  1604. }
  1605. #endregion
  1606. #region ICSLOTSIMULATION
  1607. bool isNew_Sim = false;
  1608. var simInfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LOTNO);
  1609. if (simInfo == null)
  1610. {
  1611. if (send == false)
  1612. {
  1613. throw new Exception("跟踪单开工表无记录,不能收料");
  1614. }
  1615. isNew_Sim = true;
  1616. simInfo = new ICSLOTSIMULATION();
  1617. simInfo.ID = AppConfig.GetGuid();
  1618. simInfo.MOCODE = MOCODE;
  1619. simInfo.MOSEQ = MOSEQ;
  1620. simInfo.LOTNO = LOTNO;
  1621. simInfo.LOTSEQ = 1;
  1622. simInfo.LOTStatus = "新增";
  1623. simInfo.MODELCODE = "";
  1624. simInfo.ITEMCODE = ITEMCODE;
  1625. simInfo.ROUTECODE = ROUTECODE;
  1626. simInfo.NGTIMES = 0;
  1627. simInfo.ISCOM = "0";
  1628. simInfo.ISHOLD = 0;
  1629. simInfo.BeginTime = DateTime.Now;
  1630. simInfo.EndTime = null;
  1631. simInfo.WorkPoint = AppConfig.WorkPointCode;
  1632. }
  1633. else
  1634. {
  1635. simInfo.EATTRIBUTE1 = send ? simInfo.OPList : null;//发料:保存发料前的OPList,用于开工未完工删除时,回写. 收料:置null.
  1636. }
  1637. if (send == false)
  1638. {
  1639. //收料,是否结束跟踪单
  1640. int maxOpSeq = db.ICSITEMROUTE2OPLot.AsEnumerable().Max(a => a.OPSEQ);
  1641. if (OPSEQ > maxOpSeq)
  1642. {
  1643. throw new Exception("跟踪单" + LOTNO + "工艺路线变更,工序" + OPCODE + "(" + OPSEQ.ToString() + ")可能已被删除");
  1644. }
  1645. if (OPSEQ == maxOpSeq)
  1646. {
  1647. simInfo.EndTime = DateTime.Now;
  1648. simInfo.ISCOM = "1";
  1649. }
  1650. }
  1651. simInfo.CollectStatus = CollectStatus;
  1652. simInfo.LOTQTY = LOTQTY;
  1653. simInfo.GOODQTY = GOODQTY;
  1654. simInfo.NGQTY = 0;
  1655. simInfo.OPSEQ = OPSEQ;
  1656. simInfo.OPCODE = OPCODE;
  1657. simInfo.EQPCODE = EQPCODE;
  1658. simInfo.PRODUCTSTATUS = "GOOD";
  1659. simInfo.LACTION = "GOOD";
  1660. simInfo.ACTIONLIST = "GOOD";
  1661. simInfo.MUSER = AppConfig.UserCode;
  1662. simInfo.MUSERName = AppConfig.UserName;
  1663. simInfo.MTIME = DateTime.Now;
  1664. simInfo.OPList = OPSEQ.ToString();
  1665. simInfo.OPListAttr = CtrlType;
  1666. if (isNew_Sim)
  1667. {
  1668. db.ICSLOTSIMULATION.InsertOnSubmit(simInfo);
  1669. }
  1670. db.SubmitChanges();
  1671. #endregion
  1672. for (int i = 0; i < dt.Rows.Count; i++)
  1673. {
  1674. #region 行数据
  1675. OPCODE = dt.Rows[0]["OPCODE"].ToString();
  1676. OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
  1677. string POCode = dt.Rows[0]["POCode"].ToString();
  1678. string PORow = dt.Rows[0]["PORow"].ToString();
  1679. string PRLineID = dt.Rows[0]["PRLine"].ToString();
  1680. #endregion
  1681. #region ICSLOTONWIP
  1682. var wipInfo = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPCODE == OPCODE);
  1683. if (send)
  1684. {
  1685. //发料
  1686. if (wipInfo != null)
  1687. {
  1688. throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "已有发料记录");
  1689. }
  1690. wipInfo = new ICSLOTONWIP();
  1691. wipInfo.ID = AppConfig.GetGuid();
  1692. }
  1693. else
  1694. {
  1695. //收料
  1696. if (wipInfo == null)
  1697. {
  1698. throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "没有发料记录");
  1699. }
  1700. }
  1701. wipInfo.LOTNO = LOTNO;
  1702. wipInfo.LOTSEQ = simInfo.LOTSEQ;
  1703. wipInfo.MOSEQ = MOSEQ;
  1704. wipInfo.MOCODE = MOCODE;
  1705. wipInfo.MODELCODE = "";
  1706. wipInfo.ITEMCODE = ITEMCODE;
  1707. wipInfo.ROUTECODE = ROUTECODE;
  1708. wipInfo.OPSEQ = OPSEQ;
  1709. wipInfo.OPCODE = OPCODE;
  1710. wipInfo.SHIFTTYPECODE = "";
  1711. wipInfo.EQPCODE = EQPCODE;
  1712. wipInfo.ACTION = "GOOD";
  1713. wipInfo.NGTIMES = 0;
  1714. wipInfo.Processed = 0;
  1715. wipInfo.LOTQTY = simInfo.LOTQTY;
  1716. wipInfo.GOODQTY = GOODQTY;
  1717. wipInfo.NGQTY = 0;
  1718. wipInfo.RcvNGQTY = RcvNGQTY;
  1719. wipInfo.WorkPoint = AppConfig.WorkPointCode;
  1720. wipInfo.EATTRIBUTE1 = simInfo.OPListAttr;
  1721. wipInfo.UserCodeBegin = VenCode;
  1722. wipInfo.UserCodeEnd = EndUser;
  1723. wipInfo.BeginTime = DateTime.Now;
  1724. wipInfo.EndTime = EndTime;
  1725. wipInfo.ACTIONRESULT = CollectStatus;
  1726. wipInfo.MUSER = AppConfig.UserCode;
  1727. wipInfo.MUSERName = AppConfig.UserName;
  1728. wipInfo.MTIME = DateTime.Now;
  1729. if (send)
  1730. {
  1731. db.ICSLOTONWIP.InsertOnSubmit(wipInfo);
  1732. }
  1733. db.SubmitChanges();
  1734. #endregion
  1735. #region ICSPO_PoMain
  1736. var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == POCode && a.PORow == PORow && a.Free1 == PRLineID);
  1737. if (line == null)
  1738. {
  1739. throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "不存在");
  1740. }
  1741. if (send)
  1742. {
  1743. //发料
  1744. line.INQty = Convert.ToDecimal(line.INQty) + LOTQTY;
  1745. line.MTIME = DateTime.Now;
  1746. if (line.Quantity < line.INQty)
  1747. {
  1748. throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "发料" + LOTQTY.ToString() + "后数量超出" + line.Quantity.ToString());
  1749. }
  1750. db.SubmitChanges();
  1751. }
  1752. #endregion
  1753. #region ICSWareHouseLotInfoLog
  1754. ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
  1755. loginfo.ID = AppConfig.GetGuid();
  1756. loginfo.TransNO = POCode;
  1757. loginfo.TransLine = PORow;
  1758. loginfo.ITEMCODE = ITEMCODE + "_" + OPCODE;
  1759. loginfo.LotNO = LOTNO;
  1760. loginfo.TransQTY = LOTQTY;
  1761. loginfo.Memo = OPCODE;
  1762. loginfo.MUSER = AppConfig.UserCode;
  1763. loginfo.MUSERName = AppConfig.UserName;
  1764. loginfo.MTIME = DateTime.Now;
  1765. loginfo.WorkPoint = AppConfig.WorkPointCode;
  1766. loginfo.TransType = TransType;
  1767. loginfo.BusinessCode = BusinessCode;
  1768. loginfo.EATTRIBUTE1 = PRLineID;
  1769. db.ICSWareHouseLotInfoLog.InsertOnSubmit(loginfo);
  1770. #endregion
  1771. #region 退镀
  1772. if (!send)
  1773. {
  1774. var lineop = db.ICSOP.SingleOrDefault(a => a.OPCODE == OPCODE && a.WorkPoint == AppConfig.WorkPointCode);
  1775. var lineR = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == LOTNO && a.ROUTECODE == ROUTECODE && a.OPCODE == OPCODE && a.OPSEQ == OPSEQ && a.WorkPoint == AppConfig.WorkPointCode);
  1776. if (lineop.OPDESC.Contains("退镀") && lineR.ISWWRW == true)
  1777. {
  1778. RecordPRLineProcessQTY(db, PRLineID, LOTQTY, 0);
  1779. //出入库
  1780. PoInMaterialOut4Rev(db, wipInfo.ID);
  1781. //关单
  1782. ClosePoByPRLine(db, PRLineID);
  1783. }
  1784. }
  1785. #endregion
  1786. }
  1787. }
  1788. db.SubmitChanges();
  1789. db.Transaction.Commit();
  1790. }
  1791. catch (Exception ex)
  1792. {
  1793. db.Transaction.Rollback();
  1794. throw ex;
  1795. }
  1796. finally
  1797. {
  1798. db.Connection.Close();
  1799. }
  1800. }
  1801. private static int RecordPRLineProcessQTY(FramDataContext db, string PRLineID, decimal OKQty, decimal NGQty)
  1802. {
  1803. string sql = @"
  1804. IF NOT EXISTS (SELECT QTY,OKQTY,NGQTY FROM dbo.ICSRWrecord WHERE PRlineID='{0}')
  1805. BEGIN
  1806. INSERT INTO [dbo].[ICSRWRecord]
  1807. ([PRlineID]
  1808. ,[QTY]
  1809. ,[OKQTY]
  1810. ,[NGQTY])
  1811. VALUES
  1812. (
  1813. '{0}'
  1814. ,(SELECT TOP 1 PRQTY FROM dbo.ICSMO2User WHERE PRlineID='{0}')
  1815. ,{1}
  1816. ,{2})
  1817. END
  1818. ELSE
  1819. BEGIN
  1820. UPDATE [dbo].[ICSRWRecord] SET OKQTY=OKQTY+{1}, NGQTY=NGQTY+{2} WHERE PRlineID='{0}'
  1821. END
  1822. ";
  1823. sql = string.Format(sql, PRLineID, OKQty, NGQty);
  1824. int I= db.ExecuteCommand(sql);
  1825. db.SubmitChanges();
  1826. return I;
  1827. }
  1828. private static void PoInMaterialOut4Rev(FramDataContext db, string ONWIPID)
  1829. {
  1830. var whcodes = db.Sys_EnumValues.Where(a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "009").FirstOrDefault();
  1831. if (whcodes == null)
  1832. throw new Exception("未维护默认仓库!");
  1833. string WHCode = whcodes.EnumText;
  1834. #region 采购入库信息查询
  1835. string sql = @"
  1836. SELECT 'Ahwit' AS [group],
  1837. CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
  1838. d.InvCode AS cmaterialoid,
  1839. f.name AS cunitid,
  1840. e.vchangerate AS vchangerate,
  1841. a.GOODQTY AS nshouldassistnum,
  1842. a.GOODQTY AS nshouldnum,
  1843. a.GOODQTY AS nassistnum,
  1844. e.norigprice AS ncostprice,
  1845. e.norigmny AS ncostmny,
  1846. CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
  1847. d.POCode AS vsourcebillcode,
  1848. d.WBS AS csourcebillhid,
  1849. d.Free5 AS cfirstbillbid,
  1850. a.WorkPoint AS org,
  1851. g.code AS corigcurrencyid,
  1852. h.code AS ctaxcodeid,'{2}' AS cwarehouseid,
  1853. i.code as creqstoorgoid ,
  1854. j. parentbilltype as cfirsttype,
  1855. j.pk_billtypecode as cfirsttranstype ,
  1856. k.parentbilltype as csourcetype ,
  1857. k.pk_billtypecode as csourcetranstype ,
  1858. d.VenCode AS cvendorid,
  1859. CAST(d.Free3 AS DECIMAL(18,2)) AS norignetprice,
  1860. CAST(d.Free3 AS DECIMAL(18,2)) AS nqtorignetprice,
  1861. CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS norigmny,
  1862. CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS nmny,
  1863. CAST(d.Free2 AS DECIMAL(18,2)) AS norigtaxnetprice,
  1864. CAST(d.Free2 AS DECIMAL(18,2)) AS nqtorigtaxnetprice,
  1865. CAST(d.Free2*a.GOODQTY-CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncaltaxmny,
  1866. CAST(d.Free2*a.GOODQTY AS DECIMAL(18,2)) AS ntaxmny,
  1867. CAST(d.Free4 AS DECIMAL(18,2)) AS ntaxrate,
  1868. CAST((d.Free2-d.Free3)*a.GOODQTY AS DECIMAL(18,2)) AS norigtax,
  1869. CAST(d.Free2*a.GOODQTY AS DECIMAL(18,2)) AS norigtaxmny
  1870. FROM ICSLOTONWIP a
  1871. INNER JOIN ICSMO2User c ON c.LOTNO+c.ROUTECODE+c.OPCODE+c.WorkPoint = a.LOTNO+a.RouteCode+a.OPCODE+a.WorkPoint
  1872. INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
  1873. INNER JOIN {1}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
  1874. INNER JOIN {1}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
  1875. INNER JOIN {1}.[dbo].[bd_currtype] g ON e.corigcurrencyid = g.pk_currtype
  1876. INNER JOIN {1}.[dbo].[bd_taxcode] h ON e.ctaxcodeid = h.pk_taxcode
  1877. INNER JOIN {1}.[dbo].[org_stockorg_v] i ON i.pk_vid = e.pk_reqstoorg_v
  1878. INNER JOIN {1}.[dbo].[bd_billtype] j ON j.pk_billtypeid = e.vfirsttrantype
  1879. INNER JOIN {1}.[dbo].[bd_billtype] k ON k.pk_billtypeid = e.vsourcetrantype
  1880. WHERE a.ID ='{0}'
  1881. ";
  1882. var infoERP = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "ERP" && a.WorkCode == AppConfig.WorkPointCode);
  1883. var infoMES = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "SYS" && a.WorkCode == AppConfig.WorkPointCode);
  1884. string erpDB = (infoERP.DBIpAddress == infoMES.DBIpAddress ? "" : "[" + infoERP.DBIpAddress + "].") + infoERP.DBName;
  1885. sql = string.Format(sql, ONWIPID, erpDB, WHCode);
  1886. var po = db.ExecuteQuery<CreatePODetailEntity>(sql).ToList();
  1887. if (po == null || po.Count() <= 0)
  1888. throw new Exception("采购入库信息查询失败!");
  1889. #endregion
  1890. #region 材料出库信息查询
  1891. sql = @"
  1892. SELECT 'Ahwit' AS [pk_group],
  1893. CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
  1894. d.InvCode AS cmaterialoid,
  1895. f.name AS cunitid,
  1896. f.name AS castunitid,
  1897. e.vchangerate AS vchangerate,
  1898. a.GOODQTY AS nshouldnum,
  1899. a.GOODQTY AS nshouldassistnum,
  1900. a.GOODQTY AS nnum,
  1901. a.GOODQTY AS nassistnum,
  1902. CAST(e.norigprice AS DECIMAL(18,2)) AS ncostprice,
  1903. CAST(a.GOODQTY*CAST(e.norigprice AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncostmny,
  1904. CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
  1905. CONVERT(varchar(100),GETDATE(),120) AS drequiredate,
  1906. d.InvCode AS ccostobject,
  1907. a.MOCODE AS vproductbatch,
  1908. a.WorkPoint AS pk_org,
  1909. x.cpmohid AS csourcebillbid,
  1910. x.ID AS csourcebillhid
  1911. FROM ICSLOTONWIP a
  1912. INNER JOIN ICSMO2User c ON c.LOTNO+c.ROUTECODE+c.OPCODE+c.WorkPoint = a.LOTNO+a.RouteCode+a.OPCODE+a.WorkPoint
  1913. INNER JOIN ICSMO x ON c.MOCODE=x.MOCODE AND c.MOSEQ=x.MOSEQ AND c.WorkPoint=x.WorkPoint
  1914. INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
  1915. INNER JOIN {1}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
  1916. INNER JOIN {1}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
  1917. WHERE a.ID ='{0}'
  1918. ";
  1919. sql = string.Format(sql, ONWIPID, erpDB);
  1920. var rd = db.ExecuteQuery<Create4DDetailEntity>(sql).ToList();
  1921. if (rd == null || rd.Count() <= 0)
  1922. throw new Exception("材料出库信息查询失败!");
  1923. #endregion
  1924. #region NC接口专用账户查询
  1925. var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
  1926. if (infoApiUser == null)
  1927. throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
  1928. string ApiUserCode = infoApiUser.DBUser;
  1929. string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
  1930. #endregion
  1931. NcApiInputArguments inputInfo = new NcApiInputArguments();
  1932. inputInfo.datasource = "design";
  1933. inputInfo.usercode = ApiUserCode;// AppConfig.UserCode;
  1934. inputInfo.password = ApiUserPassword;// AppConfig.FromMd5(AppConfig.UserPwd);
  1935. inputInfo.list = new List<object>();
  1936. #region 采购入库
  1937. CreatePOEntity PO = new CreatePOEntity();
  1938. PO.group = "Ahwit";
  1939. PO.org = AppConfig.WorkPointCode;
  1940. string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1941. PO.billmaker = AppConfig.UserCode;
  1942. PO.dbizdate = time;
  1943. PO.cpayfinorgvid = AppConfig.WorkPointCode;
  1944. PO.cfanaceorgvid = AppConfig.WorkPointCode;
  1945. PO.item = po;
  1946. inputInfo.list.Add(PO);
  1947. string inputJson = JsonConvert.SerializeObject(inputInfo);
  1948. log.Info("采购入库\r\n" + JsonConvert.SerializeObject(inputInfo.list));
  1949. string resStrCreatDeliveryPlan = HttpPost(urlCreatPO, inputJson);
  1950. NcApiOutArguments res = new NcApiOutArguments();
  1951. res = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlan);
  1952. if (res.flat == "0")
  1953. {
  1954. throw new Exception("生成采购入库单失败:" + res.list_info);
  1955. }
  1956. #endregion
  1957. #region 材料出库
  1958. inputInfo.list = new List<object>();
  1959. Create4DEntity RD = new Create4DEntity();
  1960. RD.pk_group = "Ahwit";
  1961. RD.pk_org = AppConfig.WorkPointCode;
  1962. RD.corpoid = AppConfig.WorkPointCode;
  1963. RD.cwarehouseid = WHCode;
  1964. RD.cfanaceorgoid = AppConfig.WorkPointCode;
  1965. RD.cfanaceorgvid = AppConfig.WorkPointCode;
  1966. RD.vbillcode = "";
  1967. RD.dbilldate = time;
  1968. RD.creationtime = time;
  1969. RD.list = rd;
  1970. inputInfo.list.Add(RD);
  1971. string inputJsonRD = JsonConvert.SerializeObject(inputInfo);
  1972. log.Info("材料出库\r\n" + JsonConvert.SerializeObject(inputInfo.list));
  1973. string resStrCreatDeliveryPlanRD = HttpPost(urlCreat4D, inputJsonRD);
  1974. NcApiOutArguments resRD = new NcApiOutArguments();
  1975. resRD = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlanRD);
  1976. if (resRD.flat == "0")
  1977. {
  1978. throw new Exception("生成材料出库单失败:" + resRD.list_info);
  1979. }
  1980. #endregion
  1981. }
  1982. private static void ClosePoByPRLine(FramDataContext db, string PRLineID)
  1983. {
  1984. #region 原采购订单行完成度查询
  1985. //1.正常委外本工序对应采购订单
  1986. //2.返工委外非退镀本工序对应采购订单
  1987. //3.返工委外退镀本工序对应采购订单,不关闭,已在收料时关闭
  1988. //4.返工工序对应 原采购订单
  1989. var lineRwrecord = db.ICSRWRecord.SingleOrDefault(a => a.PRlineID == PRLineID);
  1990. if (lineRwrecord == null)
  1991. {
  1992. throw new Exception("获取进度失败PRLineID" + PRLineID);
  1993. }
  1994. List<Close4POEntity> closepolines = new List<Close4POEntity>();
  1995. if (lineRwrecord.QTY != lineRwrecord.OKQTY + lineRwrecord.NGQTY)
  1996. {
  1997. return;
  1998. }
  1999. var lineMo2User = db.ICSMO2User.SingleOrDefault(a => a.PRLineID == lineRwrecord.PRlineID);
  2000. if (lineMo2User == null)
  2001. {
  2002. throw new Exception("派工记录表无此请购记录,prline:" + lineRwrecord.PRlineID);
  2003. }
  2004. var linePO = db.ICSPO_PoMain.SingleOrDefault(a => a.Free1 == lineRwrecord.PRlineID && a.WorkPoint == lineMo2User.WorkPoint);
  2005. if (linePO == null)
  2006. {
  2007. throw new Exception("采购订单行信息查询失败,prline:" + lineRwrecord.PRlineID);
  2008. }
  2009. List<Close4POEntity> closePolines = new List<Close4POEntity>();
  2010. Close4POEntity closepoline = new Close4POEntity();
  2011. closepoline.POCode = linePO.POCode;
  2012. closepoline.PORow = linePO.PORow;
  2013. closePolines.Add(closepoline);
  2014. #endregion
  2015. #region NC接口专用账户查询
  2016. var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
  2017. if (infoApiUser == null)
  2018. throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
  2019. string ApiUserCode = infoApiUser.DBUser;
  2020. string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
  2021. #endregion
  2022. #region 关闭采购订单行
  2023. NcApiInputArguments inputInfo = new NcApiInputArguments();
  2024. inputInfo.datasource = "design";
  2025. inputInfo.usercode = ApiUserCode;
  2026. inputInfo.password = ApiUserPassword;
  2027. inputInfo.list = new List<object>();
  2028. if (closePolines != null && closePolines.Count > 0)
  2029. {
  2030. //1.此处虽然是list,但是接口只能处理一行,要注意
  2031. //2.阿威特 poline和prline为一对一的
  2032. inputInfo.list = new List<object>();
  2033. inputInfo.list.Add(closePolines[0]);
  2034. string inputJsonClosepoline = JsonConvert.SerializeObject(inputInfo);
  2035. log.Info("关闭采购订单行\r\n" + JsonConvert.SerializeObject(inputInfo.list));
  2036. string resStrClose = HttpPost(urlClosePOLine, inputJsonClosepoline);
  2037. NcApiOutArguments resClose = new NcApiOutArguments();
  2038. resClose = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrClose);
  2039. if (resClose.flat == "0")
  2040. {
  2041. throw new Exception("关闭采购订单行失败:" + resClose.list_info);
  2042. }
  2043. }
  2044. #endregion
  2045. }
  2046. /// <summary>
  2047. /// 删除发料但未收料
  2048. /// </summary>
  2049. /// <param name="ds"></param>
  2050. /// <param name="conn"></param>
  2051. public static void DeleteWW(DataSet ds, string conn)
  2052. {
  2053. List<FormICSCollectWWDataDeleteUIModel> infolist = null;
  2054. FramDataContext db = new FramDataContext(conn);
  2055. db.Connection.Open();
  2056. db.Transaction = db.Connection.BeginTransaction();
  2057. try
  2058. {
  2059. foreach (DataTable dt in ds.Tables)
  2060. {
  2061. #region 主数据
  2062. //dt.Rows排序为OPSEQ正序
  2063. string MOCODE = dt.Rows[0]["MOCODE"].ToString();
  2064. int MOSEQ = Convert.ToInt32(dt.Rows[0]["MOSEQ"].ToString());
  2065. string LOTNO = dt.Rows[0]["LotNo"].ToString();
  2066. string ITEMCODE = dt.Rows[0]["ITEMCODE"].ToString();
  2067. decimal LOTQTY = Convert.ToDecimal(dt.Rows[0]["LOTQTY"].ToString());
  2068. string ROUTECODE = dt.Rows[0]["ROUTECODE"].ToString();
  2069. string OPCODE = dt.Rows[0]["OPCODE"].ToString();
  2070. int OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
  2071. string EQPCODE = dt.Rows[0]["EQPCode"].ToString();
  2072. //string EQPName = dt.Rows[0]["EQPName"].ToString();
  2073. string CtrlType = dt.Rows[0]["CtrlType"].ToString();
  2074. string VenCode = dt.Rows[0]["VenCode"].ToString();
  2075. //string VenName = dt.Rows[0]["VenName"].ToString();
  2076. string wp = dt.Rows[0]["WorkPoint"].ToString();
  2077. #endregion
  2078. #region ICSLOTSIMULATION
  2079. var simInfo = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == LOTNO && a.ROUTECODE == ROUTECODE);
  2080. if (simInfo == null)
  2081. {
  2082. throw new Exception("跟踪单开工表(Sim)无记录");
  2083. }
  2084. //1.工艺路线详情
  2085. ICSITEMROUTE2OPLot[] RouteOp = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo == simInfo.LOTNO && a.ROUTECODE == simInfo.ROUTECODE).OrderBy(a => a.OPSEQ).ToArray();
  2086. if (RouteOp.Count() == 0)
  2087. {
  2088. throw new Exception("跟踪单:" + LOTNO + "产品-途程-工序绑定信息已被删除");
  2089. }
  2090. //2.起始工序
  2091. int startSeq = RouteOp[0].OPSEQ;
  2092. if (OPSEQ == startSeq)
  2093. {
  2094. //如果是起始工序,删除
  2095. db.ICSLOTSIMULATION.DeleteOnSubmit(simInfo);
  2096. }
  2097. else
  2098. {
  2099. //否则还原工序
  2100. //1.获取上道工序完工信息
  2101. int preOpSeq = RouteOp.Where(a => a.OPSEQ < OPSEQ).Last().OPSEQ;
  2102. var lineOnwipPreOP = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPSEQ == preOpSeq);
  2103. //2.还原
  2104. simInfo.LOTQTY = Convert.ToDecimal(lineOnwipPreOP.LOTQTY);
  2105. simInfo.OPSEQ = lineOnwipPreOP.OPSEQ;
  2106. simInfo.OPCODE = lineOnwipPreOP.OPCODE;
  2107. simInfo.GOODQTY = lineOnwipPreOP.GOODQTY;
  2108. simInfo.NGQTY = lineOnwipPreOP.NGQTY;
  2109. if (simInfo.NGQTY > 0)
  2110. {
  2111. simInfo.PRODUCTSTATUS = "NG";
  2112. simInfo.LACTION = "NG";
  2113. simInfo.ACTIONLIST = "NG";
  2114. }
  2115. else
  2116. {
  2117. simInfo.PRODUCTSTATUS = "GOOD";
  2118. simInfo.LACTION = "GOOD";
  2119. simInfo.ACTIONLIST = "GOOD";
  2120. }
  2121. simInfo.CollectStatus = "COLLECT_END";
  2122. simInfo.LOTStatus = "删除发料回退";
  2123. simInfo.EQPCODE = lineOnwipPreOP.EQPCODE;
  2124. simInfo.MUSER = AppConfig.UserCode;
  2125. simInfo.MUSERName = AppConfig.UserName;
  2126. simInfo.MTIME = DateTime.Now;
  2127. simInfo.OPList = simInfo.EATTRIBUTE1;//发料时保存的OPList
  2128. simInfo.OPListAttr = lineOnwipPreOP.EATTRIBUTE1;//并行,串行
  2129. simInfo.EATTRIBUTE1 = null;
  2130. db.SubmitChanges();
  2131. }
  2132. db.SubmitChanges();
  2133. #endregion
  2134. for (int i = 0; i < dt.Rows.Count; i++)
  2135. {
  2136. #region 行数据
  2137. OPCODE = dt.Rows[0]["OPCODE"].ToString();
  2138. OPSEQ = Convert.ToInt32(dt.Rows[0]["OPSEQ"].ToString());
  2139. string POCode = dt.Rows[0]["POCode"].ToString();
  2140. string PORow = dt.Rows[0]["PORow"].ToString();
  2141. string PRLineID = dt.Rows[0]["PRLine"].ToString();
  2142. #endregion
  2143. #region ICSLOTONWIP删除开工记录
  2144. var wipInfo = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == LOTNO && a.LOTSEQ == simInfo.LOTSEQ && a.OPCODE == OPCODE && a.WorkPoint == wp);
  2145. if (wipInfo == null)
  2146. {
  2147. throw new Exception("跟踪单" + LOTNO + "工序" + OPCODE + "没有发料记录");
  2148. }
  2149. db.ICSLOTONWIP.DeleteOnSubmit(wipInfo);
  2150. #endregion
  2151. #region ICSPO_PoMain发料数量回退
  2152. var line = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == POCode && a.PORow == PORow && a.Free1 == PRLineID && a.WorkPoint == wp);
  2153. if (line == null)
  2154. {
  2155. throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "不存在");
  2156. }
  2157. line.INQty = Convert.ToDecimal(line.INQty) - LOTQTY;
  2158. line.MTIME = DateTime.Now;
  2159. if (line.INQty < 0)
  2160. {
  2161. throw new Exception("PO单:" + POCode + ",行: " + PORow + ",PrLineID(Free1): " + PRLineID + "撤销发料" + LOTQTY.ToString() + "后数量,已发数量<0");
  2162. }
  2163. db.SubmitChanges();
  2164. #endregion
  2165. #region ICSWWDataDeleteLog保存
  2166. var loginfo = db.ICSWareHouseLotInfoLog.SingleOrDefault(a => a.TransNO == POCode && a.TransLine == PORow && a.LotNO == LOTNO && a.Memo == OPCODE
  2167. && a.BusinessCode == "委外发料" && a.TransType == "发");
  2168. //loginfo.MUSER = AppConfig.UserCode;
  2169. //loginfo.MUSERName = AppConfig.UserName;
  2170. //loginfo.MTIME = DateTime.Now;
  2171. //loginfo.TransType = "发,删";
  2172. //loginfo.BusinessCode = "委外发料,删";
  2173. ICSWWDataDeleteLog dlog = new ICSWWDataDeleteLog();
  2174. dlog.ID = AppConfig.GetGuid();
  2175. dlog.TransNO = loginfo.TransNO;
  2176. dlog.TransLine = loginfo.TransLine;
  2177. dlog.ITEMCODE = loginfo.ITEMCODE;
  2178. dlog.LotNO = loginfo.LotNO;
  2179. dlog.TransQTY = loginfo.TransQTY;
  2180. dlog.Memo = loginfo.Memo;
  2181. dlog.TransType = loginfo.TransType;
  2182. dlog.BusinessCode = loginfo.BusinessCode;
  2183. dlog.MUSER = AppConfig.UserCode;
  2184. dlog.MUSERName = AppConfig.UserName;
  2185. dlog.MTIME = DateTime.Now;
  2186. dlog.WorkPoint = loginfo.WorkPoint;
  2187. dlog.EATTRIBUTE3 = loginfo.EATTRIBUTE1;
  2188. db.ICSWWDataDeleteLog.InsertOnSubmit(dlog);
  2189. #endregion
  2190. #region ICSWareHouseLotInfoLog删除
  2191. db.ICSWareHouseLotInfoLog.DeleteOnSubmit(loginfo);
  2192. #endregion
  2193. }
  2194. }
  2195. db.SubmitChanges();
  2196. db.Transaction.Commit();
  2197. }
  2198. catch (Exception ex)
  2199. {
  2200. db.Transaction.Rollback();
  2201. db.Connection.Close();
  2202. throw ex;
  2203. }
  2204. }
  2205. private static void xx(FramDataContext db, string id, decimal qty)
  2206. {
  2207. var whcodes = db.Sys_EnumValues.Where(a => a.WorkPointCode == AppConfig.WorkPointCode && a.EnumKey == "009").FirstOrDefault();
  2208. if (whcodes == null)
  2209. throw new Exception("未维护默认仓库!");
  2210. string whcode = whcodes.EnumText;
  2211. string sql = @"
  2212. SELECT
  2213. 'Ahwit' AS [group],
  2214. CAST((row_number() over (ORDER BY C.id))*10 AS VARCHAR(100)) AS crowno,
  2215. d.InvCode AS cmaterialoid,
  2216. f.name AS cunitid,
  2217. e.vchangerate AS vchangerate,
  2218. {1} AS nshouldassistnum,
  2219. {1} AS nshouldnum,
  2220. {1} AS nassistnum,
  2221. e.norigprice AS ncostprice,
  2222. e.norigmny AS ncostmny,
  2223. CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
  2224. d.POCode AS vsourcebillcode,
  2225. d.WBS AS csourcebillhid,
  2226. d.Free5 AS cfirstbillbid,
  2227. C.WorkPoint AS org,
  2228. g.code AS corigcurrencyid,
  2229. h.code AS ctaxcodeid,
  2230. '{3}' AS cwarehouseid,
  2231. i.code as creqstoorgoid ,
  2232. j. parentbilltype as cfirsttype,
  2233. j.pk_billtypecode as cfirsttranstype ,
  2234. k.parentbilltype as csourcetype ,
  2235. k.pk_billtypecode as csourcetranstype
  2236. ,d.VenCode AS cvendorid,
  2237. CAST(d.Free3 AS DECIMAL(18,2)) AS norignetprice,CAST(d.Free3 AS DECIMAL(18,2)) AS nqtorignetprice,
  2238. CAST(d.Free3*{1} AS DECIMAL(18,2))AS norigmny,
  2239. CAST(d.Free3*{1} AS DECIMAL(18,2)) AS nmny,
  2240. CAST(d.Free2 AS DECIMAL(18,2)) AS norigtaxnetprice,CAST(d.Free2 AS DECIMAL(18,2)) AS nqtorigtaxnetprice,
  2241. CAST(d.Free3*{1} AS DECIMAL(18,2)) AS ncaltaxmny,
  2242. CAST(d.Free2*{1} AS DECIMAL(18,2)) AS ntaxmny,
  2243. CAST(d.Free4 AS DECIMAL(18,2)) AS ntaxrate,
  2244. CAST((d.Free2-d.Free3)*{1} AS DECIMAL(18,2)) AS norigtax,
  2245. CAST(d.Free2*{1} AS DECIMAL(18,2)) AS norigtaxmny
  2246. FROM ICSMO2User c
  2247. INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
  2248. INNER JOIN {0}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
  2249. INNER JOIN {0}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
  2250. INNER JOIN {0}.[dbo].[bd_currtype] g ON e.corigcurrencyid = g.pk_currtype
  2251. INNER JOIN {0}.[dbo].[bd_taxcode] h ON e.ctaxcodeid = h.pk_taxcode
  2252. INNER JOIN {0}.[dbo].[org_stockorg_v] i ON i.pk_vid = e.pk_reqstoorg_v
  2253. INNER JOIN {0}.[dbo].[bd_billtype] j ON j.pk_billtypeid = e.vfirsttrantype
  2254. INNER JOIN {0}.[dbo].[bd_billtype] k ON k.pk_billtypeid = e.vsourcetrantype
  2255. WHERE C.ID ='{2}'
  2256. ";
  2257. var infoERP = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "ERP" && a.WorkCode == AppConfig.WorkPointCode);
  2258. var infoMES = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "SYS" && a.WorkCode == AppConfig.WorkPointCode);
  2259. string DB = (infoERP.DBIpAddress == infoMES.DBIpAddress ? "" : "[" + infoERP.DBIpAddress + "].") + infoERP.DBName;
  2260. sql = string.Format(sql, DB, qty, id, whcode);
  2261. var po = db.ExecuteQuery<CreatePODetailEntity>(sql).ToList();
  2262. if (po == null || po.Count() <= 0)
  2263. throw new Exception("采购入库信息查询失败!");
  2264. sql = @"
  2265. SELECT
  2266. 'Ahwit' AS [pk_group],
  2267. CAST((row_number() over (ORDER BY a.id))*10 AS VARCHAR(100)) AS crowno,
  2268. d.InvCode AS cmaterialoid,
  2269. f.name AS cunitid,
  2270. f.name AS castunitid,
  2271. e.vchangerate AS vchangerate,
  2272. {1} AS nshouldnum,
  2273. {1} AS nshouldassistnum,
  2274. {1} AS nnum,
  2275. {1} AS nassistnum,
  2276. CAST(e.norigprice AS DECIMAL(18,2)) AS ncostprice,
  2277. CAST({2}*CAST(e.norigprice AS DECIMAL(18,2)) AS DECIMAL(18,2)) AS ncostmny,
  2278. CONVERT(varchar(100),GETDATE(),120) AS dbizdate,
  2279. CONVERT(varchar(100),GETDATE(),120) AS drequiredate,
  2280. d.InvCode AS ccostobject,
  2281. b.MOCODE AS vproductbatch,
  2282. a.WorkPoint AS pk_org,
  2283. x.cpmohid AS csourcebillbid,
  2284. x.ID AS csourcebillhid
  2285. FROM ICSMO2User c
  2286. INNER JOIN ICSMO x ON c.MOCODE=x.MOCODE AND c.MOSEQ=x.MOSEQ AND c.WorkPoint=x.WorkPoint
  2287. INNER JOIN ICSPO_PoMain d ON c.PRLineID=d.Free1 AND c.WorkPoint=d.WorkPoint
  2288. INNER JOIN {0}.[dbo].[po_order_b] e ON d.Free5=e.pk_order_b
  2289. INNER JOIN {0}.[dbo].[bd_measdoc] f ON e.castunitid = f.pk_measdoc
  2290. WHERE c.ID ='{2}'
  2291. ";
  2292. sql = string.Format(sql, DB, qty, id);
  2293. var rd = db.ExecuteQuery<Create4DDetailEntity>(sql).ToList();
  2294. if (rd == null || rd.Count() <= 0)
  2295. throw new Exception("材料出库信息查询失败!");
  2296. var infoApiUser = db.Sys_DataBase.SingleOrDefault(a => a.DBSourceName == "UserNCAPI" && a.WorkCode == AppConfig.WorkPointCode);
  2297. if (infoApiUser == null)
  2298. throw new Exception("数据源中未维护调用NC接口的用户:UserNCAPI");
  2299. string ApiUserCode = infoApiUser.DBUser;
  2300. string ApiUserPassword = AppConfig.FromMd5(infoApiUser.DBPwd);
  2301. sql = @"
  2302. SELECT
  2303. '{0}' AS datasource,
  2304. '{1}' AS usercode,
  2305. '{2}' AS password,
  2306. B.POCode,
  2307. B.PORow
  2308. FROM
  2309. dbo.ICSMO2User A
  2310. INNER JOIN dbo.ICSPO_PoMain B ON B.Free1=A.PRLineID AND A.WorkPoint=B.WorkPoint
  2311. WHERE A.ID='{3}'
  2312. ";
  2313. sql = string.Format(sql, "design", ApiUserCode, ApiUserPassword, id);
  2314. List<Close4POEntity> closePoline = db.ExecuteQuery<Close4POEntity>(sql).ToList();
  2315. if (closePoline == null || closePoline.Count() <= 0)
  2316. throw new Exception("采购订单行信息查询失败!");
  2317. NcApiInputArguments inputInfo = new NcApiInputArguments();
  2318. inputInfo.datasource = "design";
  2319. inputInfo.usercode = ApiUserCode;// AppConfig.UserCode;
  2320. inputInfo.password = ApiUserPassword;// AppConfig.FromMd5(AppConfig.UserPwd);
  2321. inputInfo.list = new List<object>();
  2322. #region 采购入库
  2323. CreatePOEntity PO = new CreatePOEntity();
  2324. PO.group = "Ahwit";
  2325. PO.org = AppConfig.WorkPointCode;
  2326. string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2327. PO.billmaker = AppConfig.UserCode;
  2328. PO.dbizdate = time;
  2329. PO.cpayfinorgvid = AppConfig.WorkPointCode;
  2330. PO.cfanaceorgvid = AppConfig.WorkPointCode;
  2331. PO.item = po;
  2332. inputInfo.list.Add(PO);
  2333. string inputJson = JsonConvert.SerializeObject(inputInfo);
  2334. log.Info("采购入库\r\n" + inputJson);
  2335. string resStrCreatDeliveryPlan = HttpPost(urlCreatPO, inputJson);
  2336. NcApiOutArguments res = new NcApiOutArguments();
  2337. res = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlan);
  2338. if (res.flat == "0")
  2339. {
  2340. throw new Exception("生成采购入库单失败:" + res.list_info);
  2341. }
  2342. #endregion
  2343. inputInfo.list = new List<object>();
  2344. #region 材料出库
  2345. Create4DEntity RD = new Create4DEntity();
  2346. RD.pk_group = "Ahwit";
  2347. RD.pk_org = AppConfig.WorkPointCode;
  2348. RD.corpoid = AppConfig.WorkPointCode;
  2349. RD.cwarehouseid = whcode;
  2350. RD.cfanaceorgoid = AppConfig.WorkPointCode;
  2351. RD.cfanaceorgvid = AppConfig.WorkPointCode;
  2352. RD.vbillcode = "";
  2353. RD.dbilldate = time;
  2354. RD.creationtime = time;
  2355. RD.list = rd;
  2356. inputInfo.list.Add(RD);
  2357. string inputJsonRD = JsonConvert.SerializeObject(inputInfo);
  2358. log.Info("材料出库\r\n" + inputJsonRD);
  2359. string resStrCreatDeliveryPlanRD = HttpPost(urlCreat4D, inputJsonRD);
  2360. NcApiOutArguments resRD = new NcApiOutArguments();
  2361. resRD = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrCreatDeliveryPlanRD);
  2362. if (resRD.flat == "0")
  2363. {
  2364. throw new Exception("生成材料出库单失败:" + resRD.list_info);
  2365. }
  2366. #endregion
  2367. #region 关闭采购订单行
  2368. string inputJsonClosepoline = JsonConvert.SerializeObject(closePoline);
  2369. log.Info("关闭采购订单行\r\n" + inputJsonClosepoline);
  2370. string resStrClose = HttpPost(urlClosePOLine, inputJsonClosepoline);
  2371. NcApiOutArguments resClose = new NcApiOutArguments();
  2372. resClose = JsonConvert.DeserializeObject<NcApiOutArguments>(resStrClose);
  2373. if (res.flat == "0")
  2374. {
  2375. throw new Exception("关闭采购订单行失败:" + res.list_info);
  2376. }
  2377. #endregion
  2378. }
  2379. }
  2380. }