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

315 lines
10 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Base.Config.DBHelper;
  6. using System.Data;
  7. using ICSSoft.Frame.Data.Entity;
  8. using System.Data.Linq;
  9. using System.Data.SqlClient;
  10. using ICSSoft.Base.Config.AppConfig;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSNCTPDAL
  14. {
  15. #region 新增和修改
  16. public static void Add(List<ICSNCTP> InfoList, string dsconn)
  17. {
  18. FramDataContext db = new FramDataContext(dsconn);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. foreach (ICSNCTP info in InfoList)
  24. {
  25. bool isNew = false;
  26. var line = db.ICSNCTP.SingleOrDefault(a => a.guid == info.guid);
  27. if (line == null)
  28. {
  29. isNew = true;
  30. line = new ICSNCTP();
  31. }
  32. //var codes = db.ICSEQPSTP.Where(a => a.ITEMCODE == info.ITEMCODE && a.OPCODE == info.OPCODE && a.EQPTypeCode == info.EQPTypeCode && a.ID != info.ID);
  33. //if (codes.ToList().Count > 0)
  34. //{
  35. // throw new Exception("已存在相同产品工序设备类型的标准工时");
  36. //}
  37. line.guid = info.guid;
  38. //line.NCTPType = info.NCTPType;
  39. line.ProductDate = info.ProductDate;
  40. line.ProductMO = info.ProductMO;
  41. line.ItemCode = info.ItemCode;
  42. line.ItemName = info.ItemName;
  43. line.ProjectCode = info.ProjectCode;
  44. line.OPCode = info.OPCode;
  45. line.ProductNum = info.ProductNum;
  46. line.EQPCode = info.EQPCode;
  47. line.EQPName = info.EQPName;
  48. line.UnitTP = info.UnitTP;
  49. line.TotalTP = info.TotalTP;
  50. line.ProductUser = info.ProductUser;
  51. line.Status = info.Status;
  52. line.DeptCheckUser = info.DeptCheckUser;
  53. line.TotalTP = info.TotalTP;
  54. line.DeptCheckTime = info.DeptCheckTime;
  55. line.MECheckUser = info.MECheckUser;
  56. line.MECheckTime = info.MECheckTime;
  57. line.MUSER = AppConfig.UserId;
  58. line.MUSERName = AppConfig.UserName;
  59. line.MTIME = DateTime.Now;
  60. line.WorkPoint = AppConfig.WorkPointCode;
  61. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  62. if (isNew)
  63. db.ICSNCTP.InsertOnSubmit(line);
  64. db.SubmitChanges();
  65. }
  66. db.Transaction.Commit();
  67. }
  68. catch (Exception ex)
  69. {
  70. db.Transaction.Rollback();
  71. throw ex;
  72. }
  73. }
  74. #endregion
  75. #region 新增和修改List
  76. public static string AddList(List<ICSNCTP> InfoList, string dsconn)
  77. {
  78. FramDataContext db = new FramDataContext(dsconn);
  79. db.Connection.Open();
  80. db.Transaction = db.Connection.BeginTransaction();
  81. try
  82. {
  83. string str = "";
  84. foreach (ICSNCTP info in InfoList)
  85. {
  86. var opcode = db.ICSOP.SingleOrDefault(a => a.OPCODE == info.OPCode);
  87. if (opcode == null)
  88. {
  89. str += "工序代码:" + info.OPCode + "不存在" + "\r\n";
  90. continue;
  91. }
  92. var eqp = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == info.EQPCode);
  93. if (eqp == null)
  94. {
  95. str += "设备编号:" + info.EQPCode + "不存在" + "\r\n";
  96. continue;
  97. }
  98. ICSNCTP line = new ICSNCTP();
  99. line.guid = AppConfig.GetGuid();
  100. line.ProductDate = info.ProductDate;
  101. line.ProductMO = info.ProductMO;
  102. line.ItemCode = info.ItemCode;
  103. line.ItemName = info.ItemName;
  104. line.ProjectCode = info.ProjectCode;
  105. line.OPCode = info.OPCode;
  106. line.ProductNum = info.ProductNum;
  107. line.EQPCode = info.EQPCode;
  108. line.EQPName = info.EQPName;
  109. line.UnitTP = info.UnitTP;
  110. line.TotalTP = info.TotalTP;
  111. line.ProductUser = info.ProductUser;
  112. line.Status = "新增";
  113. line.DeptCheckUser = info.DeptCheckUser;
  114. line.TotalTP = info.TotalTP;
  115. line.DeptCheckTime = info.DeptCheckTime;
  116. line.MECheckUser = info.MECheckUser;
  117. line.MECheckTime = info.MECheckTime;
  118. line.MUSER = AppConfig.UserId;
  119. line.MUSERName = AppConfig.UserName;
  120. line.MTIME = DateTime.Now;
  121. line.WorkPoint = AppConfig.WorkPointCode;
  122. line.EATTRIBUTE1 = info.EATTRIBUTE1;
  123. db.ICSNCTP.InsertOnSubmit(line);
  124. db.SubmitChanges();
  125. }
  126. db.Transaction.Commit();
  127. return str;
  128. }
  129. catch (Exception ex)
  130. {
  131. db.Transaction.Rollback();
  132. throw ex;
  133. }
  134. }
  135. #endregion
  136. #region 通过ID查询
  137. public static DataTable searchInfoByID(string ID, string dsconn)
  138. {
  139. string sql = @"select a.guid,
  140. a.ProductDate,
  141. a.ProductMO,
  142. a.ItemCode,
  143. a.ItemName,
  144. a.ProjectCode,
  145. a.OPCode,
  146. a.ProductNum,
  147. a.EQPCode,
  148. a.EQPName,
  149. a.UnitTP,
  150. a.TotalTP,
  151. a.ProductUser,
  152. a.Status,
  153. a.DeptCheckUser,
  154. a.DeptCheckTime,
  155. a.MECheckUser,
  156. a.MECheckTime,
  157. a.WorkPoint,
  158. a.MUSER,
  159. a.MUSERName,
  160. a.MTIME,
  161. a.EATTRIBUTE1,
  162. b.OPDESC
  163. FROM ICSNCTP a
  164. LEFT JOIN ICSOP b on a.OPCODE=b.OPCODE
  165. where a.guid='{0}'";
  166. sql = string.Format(sql, ID);
  167. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  168. return dt;
  169. }
  170. #endregion
  171. #region 是否存在
  172. public static bool IsIncluding(string ItemCode, string OPCode, string eqptype, string dsconn)
  173. {
  174. FramDataContext db = new FramDataContext(dsconn);
  175. db.Connection.Open();
  176. db.Transaction = db.Connection.BeginTransaction();
  177. try
  178. {
  179. var line = db.ICSNCTP.SingleOrDefault(a => a.ItemCode == ItemCode && a.OPCode == OPCode);
  180. if (line == null)
  181. return true;
  182. else
  183. return false;
  184. }
  185. catch (Exception ex)
  186. {
  187. db.Transaction.Rollback();
  188. throw ex;
  189. }
  190. }
  191. #endregion
  192. #region 删除
  193. public static void deleteInfo(List<string> codeList, string dsconn)
  194. {
  195. FramDataContext db = new FramDataContext(dsconn);
  196. db.Connection.Open();
  197. db.Transaction = db.Connection.BeginTransaction();
  198. try
  199. {
  200. var lines = db.ICSNCTP.Where(a => codeList.Contains(a.guid));
  201. db.ICSNCTP.DeleteAllOnSubmit(lines);
  202. db.SubmitChanges();
  203. db.Transaction.Commit();
  204. }
  205. catch (Exception ex)
  206. {
  207. db.Transaction.Rollback();
  208. throw ex;
  209. }
  210. }
  211. #endregion
  212. #region 部门审核
  213. public static void depCheck(string id, string dsconn)
  214. {
  215. FramDataContext db = new FramDataContext(dsconn);
  216. db.Connection.Open();
  217. db.Transaction = db.Connection.BeginTransaction();
  218. try
  219. {
  220. var line = db.ICSNCTP.SingleOrDefault(a => a.guid==id);
  221. line.Status = "已审核";
  222. line.DeptCheckUser = AppConfig.UserCode;
  223. line.DeptCheckTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  224. db.SubmitChanges();
  225. db.Transaction.Commit();
  226. }
  227. catch (Exception ex)
  228. {
  229. db.Transaction.Rollback();
  230. throw ex;
  231. }
  232. }
  233. #endregion
  234. #region 工艺审核
  235. public static void meCheck(string id, string dsconn)
  236. {
  237. FramDataContext db = new FramDataContext(dsconn);
  238. db.Connection.Open();
  239. db.Transaction = db.Connection.BeginTransaction();
  240. try
  241. {
  242. var line = db.ICSNCTP.SingleOrDefault(a => a.guid == id);
  243. line.MECheckUser = AppConfig.UserCode;
  244. line.MECheckTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  245. db.SubmitChanges();
  246. db.Transaction.Commit();
  247. }
  248. catch (Exception ex)
  249. {
  250. db.Transaction.Rollback();
  251. throw ex;
  252. }
  253. }
  254. #endregion
  255. #region 弃审
  256. public static void DiscardedTrialCheck(string id, string dsconn)
  257. {
  258. FramDataContext db = new FramDataContext(dsconn);
  259. db.Connection.Open();
  260. db.Transaction = db.Connection.BeginTransaction();
  261. try
  262. {
  263. var line = db.ICSNCTP.SingleOrDefault(a => a.guid == id);
  264. line.Status = "新增";
  265. line.DeptCheckUser = AppConfig.UserCode;
  266. line.DeptCheckTime = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  267. db.SubmitChanges();
  268. db.Transaction.Commit();
  269. }
  270. catch (Exception ex)
  271. {
  272. db.Transaction.Rollback();
  273. throw ex;
  274. }
  275. }
  276. #endregion
  277. }
  278. }