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

219 lines
8.1 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 System.Data;
  7. using ICSSoft.Base.Config.DBHelper;
  8. namespace ICSSoft.Frame.Data.DAL
  9. {
  10. public class ICSLOTONWIPInspectionDAL
  11. {
  12. public static string Add(Entity.ICSLOTONWIPInspection info, string dsconn)
  13. {
  14. FramDataContext db = new FramDataContext(dsconn);
  15. db.Connection.Open();
  16. db.Transaction = db.Connection.BeginTransaction();
  17. try
  18. {
  19. if (info.TransNO == null)
  20. {
  21. string flag = DateTime.Now.ToString("yyyyMMdd");
  22. int flowLen = 5;
  23. int flow = 1;
  24. string maxFlow = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(flag)).Max(a => a.TransNO);
  25. if (!string.IsNullOrEmpty(maxFlow))
  26. {
  27. if (maxFlow.Length < flag.Length + flowLen)
  28. {
  29. throw new Exception(maxFlow + "最新单号规则错误!流水码应是" + flowLen.ToString() + "位");
  30. }
  31. bool b = Int32.TryParse(maxFlow.Substring(flag.Length, flowLen), out flow);
  32. if (!b)
  33. {
  34. throw new Exception(maxFlow + "最新单号流水码不是数字");
  35. }
  36. flow++;
  37. }
  38. info.TransNO = flag + flow.ToString().PadLeft(flowLen, '0');
  39. }
  40. else
  41. {
  42. //int Again = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO.Split('-').Length <= 1 ? 0 : Convert.ToInt32(a.TransNO.Split('-')[1]));
  43. int f = 0;
  44. string s = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO);
  45. if (!s.Contains("-"))
  46. {
  47. f = 0;
  48. }
  49. else
  50. {
  51. f = Convert.ToInt32(s.Split('-')[1]);
  52. }
  53. info.TransNO = info.TransNO + "-" + (f + 1).ToString();
  54. }
  55. db.ICSLOTONWIPInspection.InsertOnSubmit(info);
  56. db.SubmitChanges();
  57. db.Transaction.Commit();
  58. return info.TransNO;
  59. }
  60. catch (Exception ex)
  61. {
  62. db.Transaction.Rollback();
  63. throw ex;
  64. }
  65. }
  66. public static void AddList(List<ICSLOTONWIPInspection> infos, string dsconn)
  67. {
  68. FramDataContext db = new FramDataContext(dsconn);
  69. db.Connection.Open();
  70. db.Transaction = db.Connection.BeginTransaction();
  71. try
  72. {
  73. foreach (var info in infos)
  74. {
  75. if (info.TransNO == null)
  76. {
  77. string flag = DateTime.Now.ToString("yyyyMMdd");
  78. int flowLen = 5;
  79. int flow = 1;
  80. string maxFlow = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(flag)).Max(a => a.TransNO);
  81. if (!string.IsNullOrEmpty(maxFlow))
  82. {
  83. if (maxFlow.Length < flag.Length + flowLen)
  84. {
  85. throw new Exception(maxFlow + "最新单号规则错误!流水码应是" + flowLen.ToString() + "位");
  86. }
  87. bool b = Int32.TryParse(maxFlow.Substring(flag.Length, flowLen), out flow);
  88. if (!b)
  89. {
  90. throw new Exception(maxFlow + "最新单号流水码不是数字");
  91. }
  92. flow++;
  93. }
  94. info.TransNO = flag + flow.ToString().PadLeft(flowLen, '0');
  95. }
  96. else
  97. {
  98. //int Again = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO.Split('-').Length <= 1 ? 0 : Convert.ToInt32(a.TransNO.Split('-')[1]));
  99. int f = 0;
  100. string s = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO);
  101. if (!s.Contains("-"))
  102. {
  103. f = 0;
  104. }
  105. else
  106. {
  107. f = Convert.ToInt32(s.Split('-')[1]);
  108. }
  109. info.TransNO = info.TransNO + "-" + (f + 1).ToString();
  110. }
  111. db.ICSLOTONWIPInspection.InsertOnSubmit(info);
  112. db.SubmitChanges();
  113. }
  114. db.Transaction.Commit();
  115. }
  116. catch (Exception ex)
  117. {
  118. db.Transaction.Rollback();
  119. throw ex;
  120. }
  121. }
  122. public static DataTable QueryInspectionInfo(string LOTNO, string conn)
  123. {
  124. string sql = @"
  125. SELECT
  126. WIP.LOTNO,
  127. WIP.OPSEQ,
  128. WIP.OPCODE,
  129. OP.OPDESC,
  130. WIPD.MUSERName ,
  131. A.TransNO,
  132. A.CheckMode,
  133. A.IsCalc,
  134. A.Quantity,
  135. A.MUSERName ,
  136. B.Enable,
  137. B.Status,
  138. B.BeginDateTime,
  139. B.EndDateTime,
  140. B.OKQuantity,
  141. B.NGQuantity,
  142. B.MUSERName AS ,
  143. B.EqpCode,
  144. C.UNIT
  145. FROM dbo.ICSLOTONWIP WIP
  146. LEFT JOIN dbo.ICSOP OP ON OP.OPCODE=WIP.OPCODE AND OP.WorkPoint=WIP.WorkPoint
  147. LEFT JOIN dbo.ICSLOTONWIPDetail WIPD ON WIPD.LOTNO=WIP.LOTNO AND WIPD.OPCODE=WIP.OPCODE
  148. LEFT JOIN dbo.ICSLOTONWIPInspection A ON A.DetailID=WIPD.ID
  149. LEFT JOIN dbo.ICSLOTONWIPCheck B ON B.FORTRANID=A.ID
  150. LEFT JOIN dbo.ICSLOTONWIPCheckDetail C ON C.FORTRANID=B.ID AND C.TYPE=''
  151. WHERE A.TransNO IS NOT NULL {0}
  152. ORDER BY WIP.OPSEQ,A.MTIME,B.BeginDateTime
  153. ";
  154. if (string.IsNullOrEmpty(LOTNO))
  155. {
  156. sql = string.Format(sql, "");
  157. }
  158. else
  159. {
  160. sql = string.Format(sql, " AND WIP.LOTNO='" + LOTNO + "'");
  161. }
  162. return DBHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
  163. }
  164. public static DataTable QueryXunjian(string WIPDetail_ID, string WorkPoint, string dsconn)
  165. {
  166. string sql = @"
  167. SELECT
  168. wip.MOCODE,
  169. wip.MOSEQ,
  170. det.ID AS DetailID,
  171. det.LOTNO,
  172. det.ROUTECODE,
  173. wip.OPSEQ,
  174. det.OPCODE,
  175. OP.OPDESC,
  176. det.ITEMCODE,
  177. inv.INVMODELGROUP AS CustITEMCODE,
  178. inv.[version] AS ItemVersion,
  179. det.MUSERName AS OPUser,
  180. det.EQPCode AS EQPCODE,
  181. e.TransNO,
  182. ROUND(ISNULL(e.Quantity,0),0) AS Quantity,
  183. Convert(int,0) as CurrentQTY,
  184. e.MUSERName AS xjUser,
  185. e.MTIME AS LastXJTIME,
  186. chk.MUSERName AS chkUser,
  187. chk.BeginDateTime,
  188. chk.EndDateTime,
  189. chk.Status
  190. FROM ICSLOTONWIPDetail det
  191. INNER JOIN ICSLOTONWIP wip ON wip.LOTNO=det.LOTNO AND wip.ROUTECODE=det.ROUTECODE AND wip.OPCODE=det.OPCODE AND wip.WorkPoint=det.WorkPoint
  192. LEFT JOIN ICSLOTONWIPInspection e ON det.ID=e.DetailID AND det.WorkPoint=e.WorkPoint AND e.CheckMode=''
  193. LEFT JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1'
  194. LEFT JOIN dbo.ICSOP OP ON OP.OPCODE=det.OPCODE AND OP.WorkPoint=det.WorkPoint
  195. LEFT JOIN dbo.ICSINVENTORY inv ON inv.INVCODE=det.ITEMCODE AND inv.WorkPoint=det.WorkPoint
  196. WHERE det.CollectStatus='COLLECT_BEGIN'
  197. AND det.WorkPoint='{0}'
  198. AND ISNULL(e.MTIME,'')=ISNULL((SELECT MAX(MTIME) FROM ICSLOTONWIPInspection WHERE DetailID=DET.ID AND WorkPoint=det.WorkPoint AND CheckMode=''),'')
  199. AND det.BeginDateTime >'2022-03-29'
  200. ";
  201. sql = string.Format(sql, WorkPoint);
  202. if (!string.IsNullOrEmpty(WIPDetail_ID))
  203. {
  204. sql += " AND det.ID='" + WIPDetail_ID + "'";
  205. }
  206. return DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  207. }
  208. }
  209. }