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

375 lines
15 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.DBHelper;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using ICSSoft.Base.Config.AppConfig;
  10. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSMbarcodeLOTDAL
  13. {
  14. // public static string EATTRIBUTE3RMC = "人民厂条码";
  15. // public static string EATTRIBUTE3LX = "良信条码";
  16. // public static string EATTRIBUTE3INV = "产品条码";
  17. #region 新增和修改
  18. public static void Add(List<ICSITEMLot> InfoList, string dsconn)
  19. {
  20. FramDataContext db = new FramDataContext(dsconn);
  21. db.Connection.Open();
  22. db.Transaction = db.Connection.BeginTransaction();
  23. try
  24. {
  25. foreach (ICSITEMLot info in InfoList)
  26. {
  27. var inv = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.ItemCode && a.WorkPoint == AppConfig.WorkPointCode);
  28. if (inv == null)
  29. throw new Exception("物料不存在!");
  30. var lines = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  31. if (lines != null)
  32. throw new Exception("条码已存在!");
  33. bool isNew = false;
  34. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == info.ID && a.WorkPoint == AppConfig.WorkPointCode);
  35. if (line == null)
  36. {
  37. isNew = true;
  38. line = new ICSITEMLot();
  39. line.ID = AppConfig.GetGuid();
  40. }
  41. line.LotNO = info.LotNO;
  42. line.ItemCode = info.ItemCode;
  43. line.TransNO = info.TransNO;
  44. line.TransLine = info.TransLine;
  45. line.VENDORITEMCODE = info.VENDORITEMCODE;
  46. line.VENDORCODE = info.VENDORCODE;
  47. line.VenderLotNO = info.VenderLotNO;
  48. line.PRODUCTDATE = info.PRODUCTDATE;
  49. line.LOTQTY = info.LOTQTY;
  50. line.EATTRIBUTE3 = info.LOTQTY;
  51. line.EATTRIBUTE4 = 0;
  52. line.ACTIVE = info.ACTIVE;
  53. line.Exdate = info.Exdate;
  54. if (info.TYPE == "I02")
  55. {
  56. line.TYPE = "半成品";
  57. }
  58. else
  59. {
  60. line.TYPE = "成品";
  61. }
  62. line.MUSER = AppConfig.UserCode;
  63. line.MUSERName = AppConfig.UserName;
  64. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  65. line.WorkPoint = AppConfig.WorkPointCode;
  66. if (isNew)
  67. {
  68. db.ICSITEMLot.InsertOnSubmit(line);
  69. }
  70. db.SubmitChanges();
  71. }
  72. db.Transaction.Commit();
  73. }
  74. catch (Exception ex)
  75. {
  76. db.Transaction.Rollback();
  77. throw ex;
  78. }
  79. }
  80. #endregion
  81. #region 成品条码新增和修改
  82. public static void AddInv(List<ICSITEMLot> InfoList, string dsconn)
  83. {
  84. FramDataContext db = new FramDataContext(dsconn);
  85. db.Connection.Open();
  86. db.Transaction = db.Connection.BeginTransaction();
  87. try
  88. {
  89. foreach (ICSITEMLot info in InfoList)
  90. {
  91. var inv = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.ItemCode && a.WorkPoint == AppConfig.WorkPointCode);
  92. if (inv == null)
  93. throw new Exception("物料不存在!");
  94. var lines = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  95. if (lines != null)
  96. throw new Exception("条码已存在!");
  97. bool isNew = false;
  98. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == info.ID && a.WorkPoint == AppConfig.WorkPointCode);
  99. if (line == null)
  100. {
  101. isNew = true;
  102. line = new ICSITEMLot();
  103. line.ID = AppConfig.GetGuid();
  104. }
  105. line.LotNO = info.LotNO;
  106. line.ItemCode = info.ItemCode;
  107. line.TransNO = info.TransNO;
  108. line.TransLine = info.TransLine;
  109. line.VENDORITEMCODE = info.VENDORITEMCODE;
  110. line.VENDORCODE = info.VENDORCODE;
  111. line.VenderLotNO = info.VenderLotNO;
  112. line.PRODUCTDATE = info.PRODUCTDATE;
  113. line.LOTQTY = info.LOTQTY;
  114. line.EATTRIBUTE3 = info.LOTQTY;
  115. line.EATTRIBUTE4 = 0;
  116. line.ACTIVE = info.ACTIVE;
  117. line.Exdate = info.Exdate;
  118. line.TYPE = info.TYPE;
  119. line.MUSER = AppConfig.UserCode;
  120. line.MUSERName = AppConfig.UserName;
  121. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  122. line.WorkPoint = AppConfig.WorkPointCode;
  123. if (isNew)
  124. {
  125. db.ICSITEMLot.InsertOnSubmit(line);
  126. }
  127. db.SubmitChanges();
  128. }
  129. db.Transaction.Commit();
  130. }
  131. catch (Exception ex)
  132. {
  133. db.Transaction.Rollback();
  134. throw ex;
  135. }
  136. }
  137. #endregion
  138. #region 更新打印信息
  139. public static void updatePrint(List<ICSITEMLot> InfoList, string dsconn)
  140. {
  141. FramDataContext db = new FramDataContext(dsconn);
  142. db.Connection.Open();
  143. db.Transaction = db.Connection.BeginTransaction();
  144. try
  145. {
  146. foreach (ICSITEMLot info in InfoList)
  147. {
  148. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  149. if (line == null)
  150. {
  151. continue;
  152. }
  153. if (line.PrintTimes == null)
  154. {
  155. line.PrintTimes = 1;
  156. }
  157. else
  158. {
  159. line.PrintTimes++;
  160. }
  161. line.lastPrintUSERID = info.lastPrintUSERID;
  162. line.lastPrintTime = info.lastPrintTime;
  163. db.SubmitChanges();
  164. }
  165. db.Transaction.Commit();
  166. }
  167. catch (Exception ex)
  168. {
  169. db.Transaction.Rollback();
  170. throw ex;
  171. }
  172. }
  173. #endregion
  174. #region 通过代码、行号查询
  175. public static FormICSRdrecord2LOTUIModel SearchInfo(string CODE,string RowNo, string dsconn)
  176. {
  177. FramDataContext db = new FramDataContext(dsconn);
  178. db.Connection.Open();
  179. try
  180. {
  181. FormICSRdrecord2LOTUIModel info = new FormICSRdrecord2LOTUIModel();
  182. info.rdrecords = db.ICSMO.SingleOrDefault(a => a.MOCODE == CODE && a.MOSEQ== RowNo && a.WorkPoint == AppConfig.WorkPointCode);
  183. if (info.rdrecords != null)
  184. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.rdrecords.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  185. if (info.inventory == null)
  186. throw new Exception("物料不存在!");
  187. var infos = db.ICSITEMLot.Where(a => a.TransNO == CODE && a.TransLine == RowNo&& a.WorkPoint == AppConfig.WorkPointCode);
  188. info.SumQty = Convert.ToDecimal(infos.AsEnumerable().Sum(a => a.LOTQTY));
  189. info.SumNo = infos.Count();
  190. var infoMaxs = db.ICSITEMLot.Where(a => a.LotNO.Contains(info.rdrecords.MOCODE + info.rdrecords.MOSEQ) && a.WorkPoint == AppConfig.WorkPointCode);
  191. if (infoMaxs.Count() == 0)
  192. info.MaxNo = 0;
  193. else
  194. {
  195. string lotno = infoMaxs.OrderByDescending(a => a.LotNO.Substring(a.LotNO.Length - 5)).FirstOrDefault().LotNO;
  196. info.MaxNo =Convert.ToInt32(lotno.Substring(lotno.Length - 5));
  197. }
  198. if (infos != null && infos.Count() > 0)
  199. {
  200. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  201. if (VenderLotNO != null && VenderLotNO.Count()>0)
  202. {
  203. info.VenderLotNO = VenderLotNO.ToList()[0];
  204. return info;
  205. }
  206. }
  207. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  208. info.TodayMOCount = infoTodays.Distinct().Count();
  209. return info;
  210. }
  211. catch (Exception ex)
  212. {
  213. throw ex;
  214. }
  215. }
  216. #endregion
  217. #region 通过物料查询
  218. public static FormICSRdrecord2LOTUIModel SearchInfoInv(string CODE, string dsconn)
  219. {
  220. FramDataContext db = new FramDataContext(dsconn);
  221. db.Connection.Open();
  222. try
  223. {
  224. FormICSRdrecord2LOTUIModel info = new FormICSRdrecord2LOTUIModel();
  225. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == CODE && a.WorkPoint == AppConfig.WorkPointCode);
  226. if (info.inventory == null)
  227. throw new Exception("物料不存在!");
  228. var infos = db.ICSITEMLot.Where(a => a.TransNO == CODE && a.WorkPoint == AppConfig.WorkPointCode);
  229. string time = AppConfig.GetSeverDateTime("yyyy-MM-dd").ToString("yyyyMMdd");
  230. time = "RP" + time.Substring(2);
  231. var infoMaxs = db.ICSITEMLot.Where(a => a.LotNO.Contains(time) && a.WorkPoint == AppConfig.WorkPointCode);
  232. if (infoMaxs.Count() == 0)
  233. info.MaxNo = 0;
  234. else
  235. {
  236. string lotno = infoMaxs.OrderByDescending(a => a.LotNO.Substring(a.LotNO.Length - 4)).FirstOrDefault().LotNO;
  237. info.MaxNo = Convert.ToInt32(lotno.Substring(lotno.Length - 4));
  238. }
  239. if (infos != null && infos.Count() > 0)
  240. {
  241. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  242. if (VenderLotNO != null && VenderLotNO.Count() > 0)
  243. {
  244. info.VenderLotNO = VenderLotNO.ToList()[0];
  245. return info;
  246. }
  247. }
  248. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  249. info.TodayMOCount = infoTodays.Distinct().Count();
  250. return info;
  251. }
  252. catch (Exception ex)
  253. {
  254. throw ex;
  255. }
  256. }
  257. #endregion
  258. #region 通过主表行和子表
  259. public static DataSet SearchData(string CODE, string RowNo, string dsconn)
  260. {
  261. try
  262. {
  263. string sql = @"SELECT
  264. a.MOCODE,
  265. a.MOSEQ,
  266. a.MOPLANQTY,
  267. a.ITEMCODE,
  268. b.INVNAME,
  269. b.INVCLASS,
  270. b.INVSTD
  271. FROM
  272. ICSMO a
  273. LEFT JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE
  274. WHERE
  275. a.MOCODE='{0}'
  276. AND a.MOSEQ='{1}'
  277. AND a.WorkPoint = '{2}'
  278. AND b.WorkPoint = '{2}'
  279. ";
  280. sql += @"SELECT
  281. CASE WHEN ISNULL(a.PrintTimes,0) <=0 THEN 'Y' ELSE '' END AS isSelect,
  282. a.ID,
  283. b.MOCODE,
  284. b.MOSEQ,
  285. a.TransNO,
  286. a.TransLine,
  287. a.LOTNO,
  288. CAST(CASE WHEN c.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
  289. a.LOTQTY,
  290. a.PrintTimes,
  291. a.VenderLotNO,
  292. a.PRODUCTDATE,
  293. a.MUSERName,
  294. d.INVUOM
  295. FROM
  296. ICSITEMLot a
  297. LEFT JOIN ICSMO b ON a.TransNO=b.MOCODE AND a.TransLine=b.MOSEQ AND a.WorkPoint=b.WorkPoint
  298. LEFT JOIN ICSWareHouseLotInfo c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
  299. LEFT JOIN ICSINVENTORY d ON b.ITEMCODE=d.INVCODE
  300. WHERE
  301. a.TransNO = '{0}'
  302. AND a.TransLine = '{1}'
  303. AND a.WorkPoint = '{2}'
  304. AND ISNULL(a.EATTRIBUTE2, '') <> 'FP'
  305. ORDER BY
  306. a.LOTNO
  307. ";
  308. sql = string.Format(sql,CODE,RowNo,AppConfig.WorkPointCode);
  309. DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
  310. return ds;
  311. }
  312. catch (Exception ex)
  313. {
  314. throw ex;
  315. }
  316. }
  317. #endregion
  318. #region 删除
  319. public static void deleteInfo(List<string> codeList, string dsconn)
  320. {
  321. FramDataContext db = new FramDataContext(dsconn);
  322. db.Connection.Open();
  323. db.Transaction = db.Connection.BeginTransaction();
  324. try
  325. {
  326. var lines = db.ICSITEMLot.Where(a => codeList.Contains(a.ID));
  327. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  328. db.SubmitChanges();
  329. db.Transaction.Commit();
  330. }
  331. catch (Exception ex)
  332. {
  333. db.Transaction.Rollback();
  334. throw ex;
  335. }
  336. }
  337. #endregion
  338. }
  339. }