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

311 lines
14 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using ICSSoft.Frame.Data.Entity;
  7. using ICSSoft.Base.Config.AppConfig;
  8. using ICSSoft.Base.Config.DBHelper;
  9. using System.Data.Sql;
  10. using System.Data.Linq;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSMaterialPickDAL
  14. {
  15. public static void CheckInfo(FramDataContext db,ICSLOTSIMULATION simulation)
  16. {
  17. try
  18. {
  19. var user = db.Sys_User.SingleOrDefault(a=>a.UserCode==simulation.MUSER);
  20. if (user == null)
  21. throw new Exception("用户不存在!");
  22. var mouser = db.ICSMO2User.SingleOrDefault(a=>a.LOTNO==simulation.LOTNO && a.OPCODE==simulation.OPCODE);
  23. if (mouser == null)
  24. throw new Exception("批次工序派工信息不存在!");
  25. var mo = db.ICSMO.SingleOrDefault(a => a.MOCODE==mouser.MOCODE && a.MOSEQ==mouser.MOSEQ.ToString());
  26. if (mo == null)
  27. throw new Exception("工单信息不存在!");
  28. var moroute = db.ICSMO2ROUTE.SingleOrDefault(a => a.MOID == mo.ID);
  29. if (moroute == null)
  30. throw new Exception("工单未关联途程!");
  31. var itemop = db.ICSITEMROUTE2OP.SingleOrDefault(a => a.ITEMCODE==mo.ITEMCODE && a.ROUTECODE==moroute.ROUTECODE && a.OPCODE==mouser.OPCODE);
  32. if (itemop == null)
  33. throw new Exception("产品途程工序不存在!");
  34. var sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  35. var itemops = db.ICSITEMROUTE2OP.Where(a => a.ITEMCODE == itemop.ITEMCODE && a.ROUTECODE == itemop.ROUTECODE && a.OPSEQ < itemop.OPSEQ);
  36. if (sim == null && itemops != null && itemops.Count() > 0)
  37. throw new Exception("请从第一道工序开始报工!");
  38. //判断
  39. if (sim != null)
  40. {
  41. //如果是完工判断是否是当前工序、设备
  42. if (sim.CollectStatus == "COLLECT_BEGIN")
  43. {
  44. if(sim.OPCODE != simulation.OPCODE)
  45. throw new Exception(string.Format("应采集工序:{0}!", sim.OPCODE));
  46. if (sim.EQPCODE != simulation.EQPCODE)
  47. throw new Exception(string.Format("应采集设备:{0}!", sim.EQPCODE));
  48. }
  49. //开始下道工序时判断下一道工序是否正确
  50. else if (sim.CollectStatus == "COLLECT_END")
  51. {
  52. }
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. throw ex;
  58. }
  59. }
  60. public static void SaveStart(FramDataContext db, ICSLOTSIMULATION simulation)
  61. {
  62. try
  63. {
  64. var user = db.Sys_User.SingleOrDefault(a => a.UserCode == simulation.MUSER);
  65. var mouser = db.ICSMO2User.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE);
  66. var lot = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == simulation.LOTNO);
  67. var simulationNew = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO);
  68. #region simulation
  69. //ICSLOTSIMULATION simulationNew = new ICSLOTSIMULATION();
  70. if (simulationNew == null)
  71. {
  72. simulationNew = new ICSLOTSIMULATION();
  73. simulationNew.ID = AppConfig.GetGuid();
  74. simulationNew.LOTNO = simulation.LOTNO;
  75. simulationNew.MOCODE = mouser.MOCODE;
  76. //simulationNew.LOTSEQ = 0;
  77. simulationNew.LOTQTY = Convert.ToInt32(lot.LOTQTY);
  78. simulationNew.GOODQTY = simulationNew.LOTQTY;
  79. simulationNew.NGQTY = 0;
  80. simulationNew.LOTStatus = "新增";
  81. simulationNew.MODELCODE = "";
  82. simulationNew.ITEMCODE = lot.ItemCode;
  83. simulationNew.FROMROUTE = "";
  84. simulationNew.FROMOP = "";
  85. simulationNew.ROUTECODE = mouser.RouteCode;
  86. simulationNew.RESCODE = "";
  87. simulationNew.CHECKLOTNO = "";
  88. simulationNew.CARTONCODE = "";
  89. simulationNew.PALLETCODE = "";
  90. simulationNew.PRODUCTSTATUS = "GOOD";
  91. simulationNew.LACTION = "GOOD";
  92. simulationNew.ACTIONLIST = "GOOD";
  93. simulationNew.NGTIMES = 0;
  94. simulationNew.ISCOM = "0";
  95. simulationNew.ISHOLD = 0;
  96. simulationNew.SHELFNO = "";
  97. simulationNew.MOSEQ = mouser.MOSEQ;
  98. simulationNew.CollectStatus = "COLLECT_BEGIN";
  99. simulationNew.LOTSEQ = 1;
  100. simulationNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  101. }
  102. else
  103. {
  104. if (simulationNew.OPCODE == simulation.OPCODE)
  105. {
  106. simulationNew.CollectStatus = "COLLECT_END";
  107. }
  108. else
  109. {
  110. simulationNew.CollectStatus = "COLLECT_BEGIN";
  111. simulationNew.LOTSEQ = simulation.LOTSEQ + 1;
  112. }
  113. }
  114. simulationNew.OPCODE = simulation.OPCODE;
  115. simulationNew.EQPCODE = simulation.EQPCODE;
  116. simulationNew.EndTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  117. simulationNew.MUSER = AppConfig.UserCode;
  118. simulationNew.MUSERName = AppConfig.UserName;
  119. simulationNew.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  120. simulationNew.WorkPoint = AppConfig.WorkPointCode;
  121. #endregion
  122. ICSLOTONWIP onwip = db.ICSLOTONWIP.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.LOTSEQ == simulation.LOTSEQ);
  123. #region onwip
  124. ICSLOTONWIP onwipNew = new ICSLOTONWIP();
  125. onwipNew.ID = AppConfig.GetGuid();
  126. onwipNew.LOTNO = onwip.LOTNO;
  127. onwipNew.MOCODE = onwip.MOCODE;
  128. onwipNew.LOTSEQ = onwip.LOTSEQ;
  129. onwipNew.MODELCODE = onwip.MODELCODE;
  130. onwipNew.ITEMCODE = onwip.ITEMCODE;
  131. onwipNew.ROUTECODE = onwip.ROUTECODE;
  132. onwipNew.OPCODE = onwip.OPCODE;
  133. onwipNew.SEGCODE = onwip.SEGCODE;
  134. onwipNew.SSCODE = onwip.SSCODE;
  135. onwipNew.RESCODE = onwip.RESCODE;
  136. onwipNew.EQPCODE = simulationNew.EQPCODE;
  137. onwipNew.SHIFTTYPECODE = onwip.SHIFTTYPECODE;
  138. onwipNew.ACTION = onwip.ACTION;
  139. onwipNew.ACTIONRESULT = onwip.ACTIONRESULT;
  140. onwipNew.NGTIMES = onwip.NGTIMES;
  141. onwipNew.SHELFNO = onwip.SHELFNO;
  142. onwipNew.MOSEQ = onwip.MOSEQ;
  143. onwipNew.Processed = onwip.Processed;
  144. onwipNew.LOTQTY = onwip.LOTQTY;
  145. onwipNew.GOODQTY = onwip.GOODQTY;
  146. onwipNew.NGQTY = onwip.NGQTY;
  147. // onwipNew.SEQ = simulationNew.SEQ;
  148. onwipNew.BeginTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  149. onwipNew.MUSER = AppConfig.UserCode;
  150. onwipNew.MUSERName = AppConfig.UserName;
  151. onwipNew.MTIME = DateTime.Now;
  152. onwipNew.WorkPoint = AppConfig.WorkPointCode;
  153. onwipNew.UserCodeBegin = simulation.MUSER;
  154. #endregion
  155. }
  156. catch (Exception ex)
  157. {
  158. throw ex;
  159. }
  160. }
  161. #region 根据工单查询子件机汇总信息
  162. public static DataSet select(String MOCode, String TransNO, String Appconstr)
  163. {
  164. try
  165. {
  166. string sql = @" SELECT
  167. a.VouchCode as MOCODE ,
  168. a.VouchRow as MOSEQ,
  169. a.InvCode as ITEMCODE,
  170. a.VoucherNO as MOVER,
  171. b.INVNAME,
  172. b.INVSTD AS INVTYPE,
  173. a.SubInvCode AS MOBITEMCODE,
  174. d.INVNAME AS CINVNAME,
  175. d.INVSTD AS CINVTYPE,
  176. d.INVUOM,
  177. CAST(ISNULL(a.Quantity, 0) AS DECIMAL(18,2)) AS QTY,
  178. --CAST(ISNULL(f.HasQuantity, 0) AS DECIMAL(18,2)) AS QTYS, D.EATTRIBUTE1
  179. CAST(ISNULL(A.HasQuantity, 0) AS DECIMAL(18,2)) AS QTYS, D.EATTRIBUTE1
  180. --ISNULL(f.HasQuantity, 0) AS QTYS
  181. FROM
  182. ICSMaterialPick a
  183. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.INVCODE
  184. LEFT JOIN ICSINVENTORY d ON a.SubInvCode = d.INVCODE
  185. LEFT JOIN ICSMOPickLog f ON a.VouchCode=f.MOCODE AND a.VouchRow=f.MOSEQ
  186. WHERE a.VouchCode='{0}' AND
  187. a.WorkPoint = '{1}' AND ISNULL(b.INVCLASS, '') <> 'I09'
  188. ORDER BY a.VouchRow,a.SubInvCode
  189. ";
  190. sql += @"
  191. SELECT c.MOCODE ,
  192. c.SubInvCode as MOBITEMCODE,
  193. c.CINVNAME,
  194. c.CINVTYPE,
  195. c.INVUOM,
  196. CAST(ISNULL(c.MOBITEMQTY, 0) AS DECIMAL(18,2)) AS MOBITEMQTY
  197. -- ISNULL(f.HasQuantity, 0) AS MOBITEMQTY
  198. FROM
  199. (
  200. SELECT
  201. a.VouchCode as MOCODE,
  202. a.VouchRow as MOSEQ,
  203. a.SubInvCode,
  204. b.INVNAME AS CINVNAME,
  205. b.INVSTD AS CINVTYPE,
  206. b.INVUOM,
  207. b.INVMACHINETYPE,
  208. SUM(a.Quantity) AS MOBITEMQTY
  209. FROM ICSMaterialPick a
  210. LEFT JOIN ICSINVENTORY b ON a.SubInvCode = b.INVCODE AND a.WorkPoint=b.WorkPoint
  211. WHERE a.VouchCode='{0}' AND
  212. a.WorkPoint = '{1}' --AND ISNULL(b.INVCLASS, '') <> 'I09'
  213. GROUP BY a.VouchCode,a.SubInvCode,a.VouchRow, b.INVNAME,b.INVSTD,b.INVUOM,b.INVMACHINETYPE
  214. )c
  215. LEFT JOIN ICSMOPickLog f ON c.MOCode=f.MOCODE AND c.MOSEQ=f.MOSEQ
  216. ORDER BY c.SubInvCode
  217. ";
  218. sql = string.Format(sql, MOCode, AppConfig.WorkPointCode, TransNO);
  219. DataSet ds = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql);
  220. return ds;
  221. }
  222. catch (Exception ex)
  223. {
  224. throw new Exception(ex.Message);
  225. }
  226. }
  227. #endregion
  228. #region 根据工单查询拣料表信息
  229. public static DataSet GetGauge(String MOCode, String Appconstr)
  230. {
  231. try
  232. {
  233. string sql = @" SELECT c.VouchCode as MOCODE,
  234. c.SubInvCode as MOBITEMCODE,
  235. c.INVNAME as CINVNAME,
  236. c.INVSTD as CINVTYPE,
  237. c.INVUOM,
  238. CAST(ISNULL(c.MOBITEMQTY, 0) AS DECIMAL(18,2)) AS MOBITEMQTY,
  239. CAST( ISNULL(e.QTYTotal, 0) AS DECIMAL(18,2)) AS QTYTotal,
  240. CAST( ISNULL(f.QTYXBC, 0) AS DECIMAL(18,2)) AS QTYXBC,
  241. CASE WHEN ISNULL(c.MOBITEMQTY, 0)-ISNULL(f.QTYXBC, 0) < 0 THEN '0' ELSE CAST(ISNULL(c.MOBITEMQTY, 0)-ISNULL(f.QTYXBC, 0) AS DECIMAL(18,2) ) END AS QTYNeed,
  242. d.WHCode,
  243. d.BinCode,
  244. d.LotNO,
  245. g.VenderLotNO AS cTVBatch,
  246. CAST( ISNULL(d.LotQty, 0) AS DECIMAL(18,2)) QTY,
  247. d.MTIME
  248. FROM
  249. (
  250. SELECT
  251. a.VouchCode ,
  252. a.SubInvCode,
  253. b.INVNAME,
  254. b.INVSTD,
  255. b.INVUOM,
  256. b.INVMACHINETYPE,
  257. SUM(a.Quantity) AS MOBITEMQTY
  258. FROM ICSMaterialPick a
  259. LEFT JOIN ICSINVENTORY b ON a.SubInvCode = b.INVCODE AND a.WorkPoint=b.WorkPoint
  260. WHERE a.VouchCode='{0}' AND
  261. a.WorkPoint = '{1}' --AND ISNULL(b.INVCLASS, '') <> 'I09'
  262. GROUP BY a.MOCODE,a.VouchCode,a.VouchRow,a.SubInvCode,b.INVNAME,b.INVSTD,b.INVUOM,b.INVMACHINETYPE
  263. )c
  264. LEFT JOIN ICSWareHouseLotInfo d ON c.SubInvCode=d.INVCode AND d.WorkPoint='{1}' AND d.LotQty>0
  265. LEFT JOIN ICSITEMLot g ON g.LotNO=d.LotNO
  266. LEFT JOIN (SELECT INVCode,SUM(LotQty) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode) e ON c.SubInvCode=e.INVCode
  267. LEFT JOIN (SELECT INVCode,WHCode,SUM(LotQty) AS QTYXBC FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WHCode) f ON c.SubInvCode=f.INVCode AND c.INVMACHINETYPE=f.WHCode
  268. ORDER BY c.SubInvCode,d.MTIME,d.LotNO
  269. ";
  270. sql = string.Format(sql, MOCode, AppConfig.WorkPointCode);
  271. DataSet ds = DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql);
  272. return ds;
  273. }
  274. catch (Exception ex)
  275. {
  276. throw new Exception(ex.Message);
  277. }
  278. }
  279. #endregion
  280. }
  281. }