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

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