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

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