华恒Mes鼎捷代码
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.

383 lines
16 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 ICSRdrecord2LOTDAL
  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. bool isNew = false;
  25. var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == info.ID && a.WorkPoint == AppConfig.WorkPointCode);
  26. if (line == null)
  27. {
  28. isNew = true;
  29. line = new ICSITEMLot();
  30. line.ID = AppConfig.GetGuid();
  31. }
  32. line.LotNO = info.LotNO;
  33. line.MCODE = info.MCODE;
  34. line.TransNO = info.TransNO;
  35. line.TransLine = info.TransLine;
  36. line.VENDORITEMCODE = info.VENDORITEMCODE;
  37. line.VENDORCODE = info.VENDORCODE;
  38. line.VenderLotNO = info.VenderLotNO;
  39. line.PRODUCTDATE = info.PRODUCTDATE;
  40. line.LOTQTY = info.LOTQTY;
  41. line.EATTRIBUTE3 = info.LOTQTY;
  42. line.EATTRIBUTE4 = 0;
  43. line.ACTIVE = info.ACTIVE;
  44. line.Exdate = info.Exdate;
  45. line.TYPE = info.TYPE;
  46. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  47. line.MUSER = AppConfig.UserCode;
  48. line.MUSERName = AppConfig.UserName;
  49. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  50. line.WorkPoint = AppConfig.WorkPointCode;
  51. if (isNew)
  52. {
  53. db.ICSITEMLot.InsertOnSubmit(line);
  54. }
  55. db.SubmitChanges();
  56. }
  57. db.Transaction.Commit();
  58. }
  59. catch (Exception ex)
  60. {
  61. db.Transaction.Rollback();
  62. throw ex;
  63. }
  64. }
  65. #endregion
  66. #region 更新打印信息
  67. public static void updatePrint(List<ICSITEMLot> InfoList, string dsconn)
  68. {
  69. FramDataContext db = new FramDataContext(dsconn);
  70. db.Connection.Open();
  71. db.Transaction = db.Connection.BeginTransaction();
  72. try
  73. {
  74. foreach (ICSITEMLot info in InfoList)
  75. {
  76. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  77. if (line == null)
  78. {
  79. continue;
  80. }
  81. if (line.PrintTimes == null)
  82. line.PrintTimes = 1;
  83. else
  84. line.PrintTimes ++;
  85. line.lastPrintUSERID = info.lastPrintUSERID;
  86. line.lastPrintTime = info.lastPrintTime;
  87. db.SubmitChanges();
  88. }
  89. db.Transaction.Commit();
  90. }
  91. catch (Exception ex)
  92. {
  93. db.Transaction.Rollback();
  94. throw ex;
  95. }
  96. }
  97. #endregion
  98. #region 更新打印信息
  99. public static void updateGoodPrint(List<ICSITEMLot> InfoList, string dsconn)
  100. {
  101. FramDataContext db = new FramDataContext(dsconn);
  102. db.Connection.Open();
  103. db.Transaction = db.Connection.BeginTransaction();
  104. try
  105. {
  106. foreach (ICSITEMLot info in InfoList)
  107. {
  108. var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
  109. if (line == null)
  110. {
  111. continue;
  112. }
  113. line.TimesPrint = info.TimesPrint;
  114. line.lastPrintUSERID = info.lastPrintUSERID;
  115. line.lastPrintTime = info.lastPrintTime;
  116. db.SubmitChanges();
  117. }
  118. db.Transaction.Commit();
  119. }
  120. catch (Exception ex)
  121. {
  122. db.Transaction.Rollback();
  123. throw ex;
  124. }
  125. }
  126. #endregion
  127. #region 通过代码、行号查询
  128. public static FormICSRdrecord2LOTUIModel SearchInfo(string CODE, string RowNo, string dsconn)
  129. {
  130. FramDataContext db = new FramDataContext(dsconn);
  131. db.Connection.Open();
  132. #region
  133. try
  134. {
  135. FormICSRdrecord2LOTUIModel info = new FormICSRdrecord2LOTUIModel();
  136. info.rdrecord = db.ICSINVReceiptDetail.SingleOrDefault(a => a.ReceiptNO == CODE && a.ReceiptLine == Convert.ToInt32(RowNo) && a.WorkPoint == AppConfig.WorkPointCode);
  137. if(info.rdrecord!=null)
  138. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.rdrecord.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  139. var infos = db.ICSITEMLot.Where(a => a.TransNO == CODE && a.TransLine == RowNo && a.WorkPoint == AppConfig.WorkPointCode);
  140. info.SumQty = Convert.ToDecimal(infos.AsEnumerable().Sum(a => a.LOTQTY));
  141. info.SumNo = infos.Count();
  142. var infoMaxs = db.ICSITEMLot.Where(a => a.LotNO.Contains(info.rdrecord.MOCODE + info.rdrecord.MOSEQ) && a.WorkPoint == AppConfig.WorkPointCode);
  143. if (infoMaxs.Count() == 0)
  144. info.MaxNo = 0;
  145. else
  146. {
  147. string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
  148. info.MaxNo =Convert.ToInt32(lotno.Substring(lotno.Length - 5));
  149. }
  150. if (infos != null && infos.Count() > 0)
  151. {
  152. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  153. if (VenderLotNO != null && VenderLotNO.Count()>0)
  154. {
  155. info.VenderLotNO = VenderLotNO.ToList()[0];
  156. return info;
  157. }
  158. }
  159. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  160. info.TodayMOCount = infoTodays.Distinct().Count();
  161. return info;
  162. }
  163. catch (Exception ex)
  164. {
  165. throw ex;
  166. }
  167. #endregion
  168. }
  169. public static FormICSRdrecord2LOTUIModelX Search_Info(string CODE, string RowNo, string dsconn)
  170. {
  171. FramDataContext db = new FramDataContext(dsconn);
  172. db.Connection.Open();
  173. #region
  174. try
  175. {
  176. string Row_NO = RowNo.ToString();
  177. FormICSRdrecord2LOTUIModelX info = new FormICSRdrecord2LOTUIModelX();
  178. info.icsmo = db.ICSMO.SingleOrDefault(a => a.MOCODE == CODE && a.MOSEQ == Row_NO && a.WorkPoint == AppConfig.WorkPointCode);
  179. if (info.icsmo != null)
  180. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  181. info.icsitems = db.ICSITEMLot.Where(a => a.MCODE == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode && a.TransNO == info.icsmo.MOCODE && a.TransLine == info.icsmo.MOSEQ).FirstOrDefault();
  182. var infos = db.ICSITEMLot.Where(a => a.MCODE == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  183. info.SumQty = Convert.ToDecimal(info.icsmo.MOPLANQTY);
  184. //info.SumNo = infos.Count();
  185. try
  186. {
  187. string sql = @"SELECT count(B.MCODE) as num, b.MCODE, B.LOTQTY FROM ICSMO M
  188. LEFT JOIN ICSITEMLot B ON M.ITEMCODE = B.MCODE AND M.WorkPoint=B.WorkPoint AND M.MOCODE = B.TransNO AND CONVERT(int, M.MOSEQ) = B.TransLine
  189. LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
  190. WHERE M.MOCODE = '{0}'
  191. AND M.MOSEQ = '{1}'
  192. AND M.WorkPoint = '{2}' AND B.MCODE = '{3}'
  193. group by b.MCODE, B.LOTQTY
  194. ";
  195. sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode, info.icsmo.ITEMCODE);
  196. DataTable ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  197. if (ds.Rows.Count == 0 || ds == null)
  198. {
  199. info.SumNo = 0;
  200. }
  201. else
  202. {
  203. info.SumNo = 0;
  204. for (int i = 0; i < ds.Rows.Count; i++)
  205. {
  206. info.SumNo += Int32.Parse(ds.Rows[i]["num"].ToString());
  207. }
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. throw ex;
  213. }
  214. var infoMaxs = db.ICSITEMLot.Where(a => a.TransNO == info.icsmo.MOCODE && a.TransLine == info.icsmo.MOSEQ && a.WorkPoint == AppConfig.WorkPointCode);
  215. if (infoMaxs.Count() == 0)
  216. info.MaxNo = 0;
  217. else
  218. {
  219. string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
  220. info.MaxNo = Convert.ToInt32(lotno.Substring(lotno.Length - 5));
  221. }
  222. if (infos != null && infos.Count() > 0)
  223. {
  224. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  225. if (VenderLotNO != null && VenderLotNO.Count() > 0)
  226. {
  227. info.VenderLotNO = VenderLotNO.ToList()[0];
  228. return info;
  229. }
  230. }
  231. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  232. info.TodayMOCount = infoTodays.Distinct().Count();
  233. return info;
  234. }
  235. catch (Exception ex)
  236. {
  237. throw ex;
  238. }
  239. #endregion
  240. }
  241. #endregion
  242. #region 通过主表行和子表
  243. #region 原逻辑
  244. //public static DataSet SearchData(string CODE, int RowNo, string dsconn)
  245. //{
  246. // try
  247. // {
  248. // string sql = @"SELECT
  249. // a.ReceiptNO,
  250. // a.ReceiptLine,
  251. // a.RECSTATUS,
  252. // a.TYPE,
  253. // a.ITEMCODE,
  254. // a.PLANQTY,
  255. // b.INVNAME,
  256. // b.INVSTD
  257. // FROM
  258. // ICSINVReceiptDetail a
  259. // LEFT JOIN ICSINVENTORY b ON a.ITEMCODE=b.INVCODE
  260. // WHERE
  261. // a.ReceiptNO='{0}'
  262. // AND ReceiptLine='{1}'
  263. // AND a.WorkPoint = '{2}'
  264. // AND b.WorkPoint = '{2}'
  265. // ";
  266. // sql += @"SELECT
  267. // CASE WHEN c.LotNO IS NULL THEN 'Y' ELSE '' END AS isSelect,
  268. // a.ID,
  269. // b.MOCODE,
  270. // b.MOSEQ,
  271. // a.TransNO,
  272. // a.TransLine,
  273. // a.LOTNO,
  274. // CAST(CASE WHEN c.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
  275. // a.LOTQTY,
  276. // a.VenderLotNO,
  277. // a.PRODUCTDATE,
  278. // a.MUSERName
  279. // FROM
  280. // ICSITEMLot a
  281. // LEFT JOIN ICSINVReceiptDetail b ON a.TransNO=b.ReceiptNO AND a.TransLine=b.ReceiptLine AND a.WorkPoint=b.WorkPoint
  282. // LEFT JOIN ICSWareHouseLotInfo c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
  283. // WHERE
  284. // a.TransNO = '{0}'
  285. // AND a.TransLine = '{1}'
  286. // AND a.WorkPoint = '{2}'
  287. // ORDER BY
  288. // a.LOTNO
  289. // ";
  290. // sql = string.Format(sql,CODE,RowNo,AppConfig.WorkPointCode);
  291. // DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
  292. // return ds;
  293. // }
  294. // catch (Exception ex)
  295. // {
  296. // throw ex;
  297. // }
  298. //}
  299. #endregion
  300. public static DataSet SearchData(string CODE, string RowNo, string dsconn)
  301. {
  302. try
  303. {
  304. string sql = @"SELECT
  305. A.MOCODE,
  306. A.MOSEQ,
  307. '' as RECSTATUS,
  308. '' as TYPE,
  309. A.ITEMCODE,
  310. A.MOPLANQTY,
  311. C.INVNAME,
  312. C.INVSTD
  313. FROM ICSMO A
  314. LEFT JOIN ICSINVENTORY C ON A.ITEMCODE = C.INVCODE
  315. WHERE
  316. A.MOCODE='{0}'
  317. AND A.MOSEQ='{1}'
  318. AND A.WorkPoint = '{2}'
  319. ";
  320. sql += @"SELECT
  321. CASE WHEN C.LOTNO IS NULL THEN 'Y' ELSE '' END AS isSelect,
  322. B.ID,
  323. M.MOCODE,
  324. M.MOSEQ,
  325. B.TransNO,
  326. B.TransLine,
  327. B.LOTNO,
  328. CAST(CASE WHEN C.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
  329. B.LOTQTY,
  330. B.VenderLotNO,
  331. B.PRODUCTDATE,
  332. M.MUSERName,
  333. A.INVUOM
  334. FROM ICSMO M
  335. LEFT JOIN ICSINVENTORY A ON M.ITEMCODE = A.INVCODE
  336. LEFT JOIN ICSITEMLot B ON M.ITEMCODE = B.MCODE AND M.WorkPoint=B.WorkPoint AND M.MOCODE = B.TransNO AND CONVERT(int, M.MOSEQ) = B.TransLine
  337. LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
  338. WHERE M.MOCODE = '{0}'
  339. AND M.MOSEQ = '{1}'
  340. AND M.WorkPoint = '{2}' AND B.LOTNO !=''
  341. ORDER BY M.MOCODE
  342. ";
  343. sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode);
  344. DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
  345. return ds;
  346. }
  347. catch (Exception ex)
  348. {
  349. throw ex;
  350. }
  351. }
  352. #endregion
  353. #region 删除
  354. public static void deleteInfo(List<string> codeList, string dsconn)
  355. {
  356. FramDataContext db = new FramDataContext(dsconn);
  357. db.Connection.Open();
  358. db.Transaction = db.Connection.BeginTransaction();
  359. try
  360. {
  361. var lines = db.ICSITEMLot.Where(a => codeList.Contains(a.ID));
  362. db.ICSITEMLot.DeleteAllOnSubmit(lines);
  363. db.SubmitChanges();
  364. db.Transaction.Commit();
  365. }
  366. catch (Exception ex)
  367. {
  368. db.Transaction.Rollback();
  369. throw ex;
  370. }
  371. }
  372. #endregion
  373. }
  374. }