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

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