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

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