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

234 lines
11 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 FormICSBatchsQueryDAL
  13. {
  14. #region 新增和修改
  15. public static void AddBatch(List<ICSInvBatch> batchInfo, string dsconn)
  16. {
  17. FramDataContext db = new FramDataContext(dsconn);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. foreach (ICSInvBatch Batch in batchInfo)
  23. {
  24. bool isNew = false;
  25. var line = db.ICSInvBatch.SingleOrDefault(a => a.ID == Batch.ID);
  26. if (line == null)
  27. {
  28. isNew = true;
  29. line = new ICSInvBatch();
  30. line.ID = AppConfig.GetGuid();
  31. }
  32. line.MOCode = Batch.MOCode;
  33. line.MORow = Batch.MORow;
  34. line.InvCode = Batch.InvCode;
  35. line.SSCODE = Batch.SSCODE;
  36. line.Batch = Batch.Batch;
  37. line.EATTRIBUTE1 = Batch.EATTRIBUTE1;
  38. line.MUSER = AppConfig.UserCode;
  39. line.MUSERName = AppConfig.UserName;
  40. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  41. line.WorkPoint = AppConfig.WorkPointCode;
  42. db.ICSInvBatch.InsertOnSubmit(line);
  43. db.SubmitChanges();
  44. }
  45. db.Transaction.Commit();
  46. }
  47. catch (Exception ex)
  48. {
  49. db.Transaction.Rollback();
  50. throw ex;
  51. }
  52. }
  53. #endregion
  54. #region 通过代码、行号查询
  55. public static FormICSRdrecord2LOTUIModel SearchInfo(string CODE, string RowNo, string dsconn)
  56. {
  57. FramDataContext db = new FramDataContext(dsconn);
  58. db.Connection.Open();
  59. #region
  60. try
  61. {
  62. FormICSRdrecord2LOTUIModel info = new FormICSRdrecord2LOTUIModel();
  63. info.rdrecord = db.ICSINVReceiptDetail.SingleOrDefault(a => a.ReceiptNO == CODE && a.ReceiptLine == Convert.ToInt32(RowNo) && a.WorkPoint == AppConfig.WorkPointCode);
  64. if(info.rdrecord!=null)
  65. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.rdrecord.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  66. var infos = db.ICSITEMLot.Where(a => a.TransNO == CODE && a.TransLine == RowNo && a.WorkPoint == AppConfig.WorkPointCode);
  67. info.SumQty = Convert.ToDecimal(infos.AsEnumerable().Sum(a => a.LOTQTY));
  68. info.SumNo = infos.Count();
  69. var infoMaxs = db.ICSITEMLot.Where(a => a.LotNO.Contains(info.rdrecord.MOCODE + info.rdrecord.MOSEQ) && a.WorkPoint == AppConfig.WorkPointCode);
  70. if (infoMaxs.Count() == 0)
  71. info.MaxNo = 0;
  72. else
  73. {
  74. string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
  75. info.MaxNo =Convert.ToInt32(lotno.Substring(lotno.Length - 5));
  76. }
  77. if (infos != null && infos.Count() > 0)
  78. {
  79. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  80. if (VenderLotNO != null && VenderLotNO.Count()>0)
  81. {
  82. info.VenderLotNO = VenderLotNO.ToList()[0];
  83. return info;
  84. }
  85. }
  86. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  87. info.TodayMOCount = infoTodays.Distinct().Count();
  88. return info;
  89. }
  90. catch (Exception ex)
  91. {
  92. throw ex;
  93. }
  94. #endregion
  95. }
  96. public static FormICSRdrecord2LOTUIModelX Search_Info(string CODE, string RowNo, string dsconn)
  97. {
  98. FramDataContext db = new FramDataContext(dsconn);
  99. db.Connection.Open();
  100. #region
  101. try
  102. {
  103. string Row_NO = RowNo.ToString();
  104. FormICSRdrecord2LOTUIModelX info = new FormICSRdrecord2LOTUIModelX();
  105. info.icsmo = db.ICSMO.SingleOrDefault(a => a.MOCODE == CODE && a.MOSEQ == Row_NO && a.WorkPoint == AppConfig.WorkPointCode);
  106. if (info.icsmo != null)
  107. info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  108. info.icsitems = db.ICSITEMLot.Where(a => a.ItemCode == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode && a.TransNO == info.icsmo.MOCODE && a.TransLine == info.icsmo.MOSEQ).FirstOrDefault();
  109. var infos = db.ICSITEMLot.Where(a => a.ItemCode == info.icsmo.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
  110. info.SumQty = Convert.ToDecimal(info.icsmo.MOPLANQTY);
  111. //info.SumNo = infos.Count();
  112. try
  113. {
  114. string sql = @"SELECT count(B.ItemCode) as num, b.ItemCode, B.LOTQTY FROM ICSMO M
  115. LEFT JOIN ICSITEMLot B ON M.ITEMCODE = B.ItemCode AND M.WorkPoint=B.WorkPoint AND M.MOCODE = B.TransNO AND CONVERT(int, M.MOSEQ) = B.TransLine
  116. LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
  117. WHERE M.MOCODE = '{0}'
  118. AND M.MOSEQ = '{1}'
  119. AND M.WorkPoint = '{2}' AND B.ItemCode = '{3}'
  120. group by b.ItemCode, B.LOTQTY
  121. ";
  122. sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode, info.icsmo.ITEMCODE);
  123. DataTable ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  124. if (ds.Rows.Count == 0 || ds == null)
  125. {
  126. info.SumNo = 0;
  127. }
  128. else
  129. {
  130. info.SumNo = 0;
  131. for (int i = 0; i < ds.Rows.Count; i++)
  132. {
  133. info.SumNo += Int32.Parse(ds.Rows[i]["num"].ToString());
  134. }
  135. }
  136. }
  137. catch (Exception ex)
  138. {
  139. throw ex;
  140. }
  141. var infoMaxs = db.ICSITEMLot.Where(a => a.TransNO == info.icsmo.MOCODE && a.TransLine == info.icsmo.MOSEQ && a.WorkPoint == AppConfig.WorkPointCode);
  142. if (infoMaxs.Count() == 0)
  143. info.MaxNo = 0;
  144. else
  145. {
  146. string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
  147. info.MaxNo = Convert.ToInt32(lotno.Substring(lotno.Length - 5));
  148. }
  149. if (infos != null && infos.Count() > 0)
  150. {
  151. var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
  152. if (VenderLotNO != null && VenderLotNO.Count() > 0)
  153. {
  154. info.VenderLotNO = VenderLotNO.ToList()[0];
  155. return info;
  156. }
  157. }
  158. var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
  159. info.TodayMOCount = infoTodays.Distinct().Count();
  160. return info;
  161. }
  162. catch (Exception ex)
  163. {
  164. throw ex;
  165. }
  166. #endregion
  167. }
  168. #endregion
  169. #region 通过主表行和子表
  170. public static DataSet SearchData(string CODE, string RowNo, string dsconn)
  171. {
  172. try
  173. {
  174. string sql = @"SELECT
  175. A.MOCODE,
  176. A.MOSEQ,
  177. A.MOPLANLINE,
  178. '' as RECSTATUS,
  179. '' as TYPE,
  180. A.ITEMCODE,
  181. A.MOPLANQTY,
  182. C.INVNAME,
  183. C.INVSTD
  184. FROM ICSMO A
  185. LEFT JOIN ICSINVENTORY C ON A.ITEMCODE = C.INVCODE
  186. WHERE
  187. A.MOCODE='{0}'
  188. AND A.MOSEQ='{1}'
  189. AND A.WorkPoint = '{2}'
  190. ";
  191. // sql += @"SELECT
  192. // CASE WHEN C.LOTNO IS NULL THEN 'Y' ELSE '' END AS isSelect,
  193. // B.ID,
  194. // M.MOCODE,
  195. // M.MOSEQ,
  196. // B.TransNO,
  197. // B.TransLine,
  198. // B.LOTNO,
  199. // CAST(CASE WHEN C.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
  200. // B.LOTQTY,
  201. // B.VenderLotNO,
  202. // B.PRODUCTDATE,
  203. // M.MUSERName,
  204. // A.INVUOM
  205. // FROM ICSMO M
  206. // LEFT JOIN ICSINVENTORY A ON M.ITEMCODE = A.INVCODE
  207. // LEFT JOIN ICSITEMLot B ON M.ITEMCODE = B.ItemCode AND M.WorkPoint=B.WorkPoint AND M.MOCODE = B.TransNO AND CONVERT(int, M.MOSEQ) = B.TransLine
  208. // LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
  209. // WHERE M.MOCODE = '{0}'
  210. // AND M.MOSEQ = '{1}'
  211. // AND M.WorkPoint = '{2}'
  212. // ORDER BY M.MOCODE
  213. // ";
  214. sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode);
  215. DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
  216. return ds;
  217. }
  218. catch (Exception ex)
  219. {
  220. throw ex;
  221. }
  222. }
  223. #endregion
  224. }
  225. }