华恒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.

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