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

416 lines
16 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.AppConfig;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.Linq;
  10. using ICSSoft.Base.Config.DBHelper;
  11. using System.Data.SqlClient;
  12. namespace ICSSoft.Frame.Data.DAL
  13. {
  14. public class ICSROUTEDAL
  15. {
  16. #region 增加和修改List
  17. public static void AddList(List<ICSROUTE> InfoList, string Appconstr)
  18. {
  19. FramDataContext db = new FramDataContext(Appconstr);
  20. db.Connection.Open();
  21. db.Transaction = db.Connection.BeginTransaction();
  22. try
  23. {
  24. foreach (ICSROUTE info in InfoList)
  25. {
  26. bool isNew = false;
  27. var line = db.ICSROUTE.SingleOrDefault(a => a.ROUTECODE == info.ROUTECODE);
  28. if (line == null)
  29. {
  30. isNew = true;
  31. line = new ICSROUTE();
  32. line.ID = AppConfig.GetGuid();
  33. }
  34. line.ROUTECODE = info.ROUTECODE;
  35. line.ROUTEDESC = info.ROUTEDESC;
  36. line.ROUTETYPE = info.ROUTETYPE;
  37. //line.EFFDATE = info.EFFDATE;
  38. //line.IVLDATE = info.IVLDATE;
  39. line.ENABLED = info.ENABLED;
  40. line.MUSER = info.MUSER;
  41. line.MUSERName = info.MUSERName;
  42. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  43. line.WorkPoint = AppConfig.WorkPointCode;
  44. line.EATTRIBUTE1 = null;
  45. if (isNew) db.ICSROUTE.InsertOnSubmit(line);
  46. db.SubmitChanges();
  47. }
  48. db.Transaction.Commit();
  49. }
  50. catch (Exception ex)
  51. {
  52. db.Transaction.Rollback();
  53. throw new Exception(ex.Message);
  54. }
  55. }
  56. public static string AddList(List<ICSROUTE> RouteLists, List<ICSROUTE2OP> OPLists, string Appconstr)
  57. {
  58. string isSuccess = "OK";
  59. SqlConnection conn = new System.Data.SqlClient.SqlConnection(Appconstr);
  60. conn.Open();
  61. SqlTransaction sqlTran = conn.BeginTransaction();
  62. SqlCommand cmd = new SqlCommand();
  63. cmd.Transaction = sqlTran;
  64. cmd.Connection = conn;
  65. try
  66. {
  67. string sql = "";
  68. foreach (ICSROUTE RouteList in RouteLists)
  69. {
  70. sql = @"
  71. IF NOT EXISTS (SELECT * FROM ICSROUTE WHERE 1=1 AND ROUTECODE = '{1}')
  72. BEGIN
  73. DELETE FROM ICSROUTE WHERE 1=1 AND ROUTECODE = '{1}'
  74. UPDATE ICSROUTE2OP SET ROUTEID = '{0}' WHERE ROUTECODE = '{1}' END
  75. INSERT INTO ICSROUTE
  76. (ID, ROUTECODE, ROUTEDESC, ROUTETYPE, ENABLED, MUSER, MUSERName, MTIME, WorkPoint)
  77. VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}') ";
  78. sql = string.Format(sql, RouteList.ID, RouteList.ROUTECODE, RouteList.ROUTEDESC, RouteList.ROUTETYPE, RouteList.ENABLED, RouteList.MUSER, RouteList.MUSERName, AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"), RouteList.WorkPoint);
  79. cmd.CommandText = sql;
  80. cmd.ExecuteNonQuery();
  81. DataTable dt = new DataTable();
  82. foreach (ICSROUTE2OP OPList in OPLists)
  83. {
  84. if (RouteList.ROUTECODE == OPList.ROUTECODE)
  85. {
  86. sql = @"SELECT * FROM ICSROUTE2OP WHERE 1=1 AND ROUTECODE = '{0}' AND OPCODE = '{1}' AND WorkPoint = '{2}' ";
  87. sql = string.Format(sql, OPList.ROUTECODE, OPList.OPCODE, OPList.WORKPOINT);
  88. dt = SQlReturnData(sql, cmd);
  89. if (dt.Rows.Count > 0 && dt != null)
  90. {
  91. cmd.Transaction.Rollback();
  92. return "途程代码:" + OPList.ROUTECODE + "下,工序代码" + OPList.OPCODE + "已经存在,请确认";
  93. }
  94. else
  95. {
  96. sql = @"SELECT * FROM ICSROUTE2OP WHERE 1=1 AND ROUTECODE = '{0}' AND OPSEQ = '{1}' AND WorkPoint = '{2}' ";
  97. sql = string.Format(sql, OPList.ROUTECODE, OPList.OPSEQ, OPList.WORKPOINT);
  98. dt = SQlReturnData(sql, cmd);
  99. if (dt.Rows.Count > 0 && dt != null)
  100. {
  101. cmd.Transaction.Rollback();
  102. return "途程代码:" + OPList.ROUTECODE + "下,工序次序" + OPList.OPSEQ + "已经存在,请确认";
  103. }
  104. else
  105. {
  106. sql = @"
  107. IF EXISTS (SELECT * FROM ICSROUTE2OP WHERE 1=1 AND ROUTECODE = '{2}' AND OPCODE = '{3}')
  108. BEGIN DELETE FROM ICSROUTE2OP WHERE 1=1 AND ROUTECODE = '{2}' AND OPCODE = '{3}' AND OPSEQ = '{4}' END
  109. INSERT INTO ICSROUTE2OP
  110. (ROUTEID, OPID, ROUTECODE, OPCODE, OPSEQ, OPCONTROL, MUSER, MUSERName, MTIME, WORKPOINT)
  111. VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}') ";
  112. sql = string.Format(sql, OPList.ROUTEID, OPList.OPID, OPList.ROUTECODE, OPList.OPCODE, OPList.OPSEQ, OPList.OPCONTROL, OPList.MUSER, OPList.MUSERName, AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"), OPList.WORKPOINT);
  113. cmd.CommandText = sql;
  114. cmd.ExecuteNonQuery();
  115. }
  116. }
  117. }
  118. }
  119. }
  120. cmd.Transaction.Commit();
  121. return isSuccess;
  122. }
  123. catch (Exception ex)
  124. {
  125. cmd.Transaction.Rollback();
  126. return ex.Message;
  127. }
  128. }
  129. #endregion
  130. #region 增加和修改
  131. public static void AddandEdit(ICSROUTE routeLot, string Appconstr)
  132. {
  133. FramDataContext db = new FramDataContext(Appconstr);
  134. db.Connection.Open();
  135. db.Transaction = db.Connection.BeginTransaction();
  136. try
  137. {
  138. bool isNew = false;
  139. var line = db.ICSROUTE.SingleOrDefault(a => a.ID == routeLot.ID);
  140. if (line == null)
  141. {
  142. isNew = true;
  143. line = new ICSROUTE();
  144. line.ID = AppConfig.GetGuid();
  145. }
  146. var codes = db.ICSROUTE.Where(a => a.ROUTECODE == routeLot.ROUTECODE && a.ID != line.ID);
  147. if (codes.ToList().Count > 0)
  148. {
  149. throw new Exception("途程代码已存在");
  150. }
  151. line.ROUTECODE = routeLot.ROUTECODE;
  152. line.ROUTEDESC = routeLot.ROUTEDESC;
  153. line.ROUTETYPE = routeLot.ROUTETYPE;
  154. line.EFFDATE = routeLot.EFFDATE;
  155. line.IVLDATE = routeLot.IVLDATE;
  156. line.ENABLED = routeLot.ENABLED;
  157. line.MUSER = routeLot.MUSER;
  158. line.MUSERName = routeLot.MUSERName;
  159. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  160. line.WorkPoint = AppConfig.WorkPointCode;
  161. line.EATTRIBUTE1 = null;
  162. if (isNew) db.ICSROUTE.InsertOnSubmit(line);
  163. db.SubmitChanges();
  164. db.Transaction.Commit();
  165. }
  166. catch (Exception ex)
  167. {
  168. db.Transaction.Rollback();
  169. throw new Exception(ex.Message);
  170. }
  171. }
  172. #endregion
  173. #region 根据id查询途程信息
  174. public static ICSROUTE select(String guid, String Appconstr)
  175. {
  176. FramDataContext db = new FramDataContext(Appconstr);
  177. db.Connection.Open();
  178. db.Transaction = db.Connection.BeginTransaction();
  179. ICSROUTE entity = new ICSROUTE();
  180. try
  181. {
  182. var line = db.ICSROUTE.SingleOrDefault(a => a.ID == guid);
  183. return (ICSROUTE)line;
  184. }
  185. catch (Exception ex)
  186. {
  187. throw new Exception(ex.Message);
  188. }
  189. }
  190. public static ICSROUTE search(string ROUTECODE, String Appconstr)
  191. {
  192. FramDataContext db = new FramDataContext(Appconstr);
  193. db.Connection.Open();
  194. db.Transaction = db.Connection.BeginTransaction();
  195. ICSROUTE entity = new ICSROUTE();
  196. try
  197. {
  198. var line = db.ICSROUTE.SingleOrDefault(a => a.ROUTECODE == ROUTECODE);
  199. return (ICSROUTE)line;
  200. }
  201. catch (Exception ex)
  202. {
  203. throw new Exception(ex.Message);
  204. }
  205. }
  206. public static ICSROUTE2OP select(string ROUTECODE, string OPCODE, string Appconstr)
  207. {
  208. FramDataContext db = new FramDataContext(Appconstr);
  209. db.Connection.Open();
  210. db.Transaction = db.Connection.BeginTransaction();
  211. try
  212. {
  213. var line = db.ICSROUTE2OP.SingleOrDefault(a => a.ROUTECODE == ROUTECODE && a.OPCODE == OPCODE);
  214. return (ICSROUTE2OP)line;
  215. }
  216. catch (Exception ex)
  217. {
  218. throw new Exception(ex.Message);
  219. }
  220. }
  221. public static ICSROUTE2OP search(string ROUTECODE, int OPSEQ, string Appconstr)
  222. {
  223. FramDataContext db = new FramDataContext(Appconstr);
  224. db.Connection.Open();
  225. db.Transaction = db.Connection.BeginTransaction();
  226. try
  227. {
  228. var line = db.ICSROUTE2OP.SingleOrDefault(a => a.ROUTECODE == ROUTECODE && a.OPSEQ == OPSEQ);
  229. return (ICSROUTE2OP)line;
  230. }
  231. catch (Exception ex)
  232. {
  233. throw new Exception(ex.Message);
  234. }
  235. }
  236. #endregion
  237. #region 删除
  238. public static void delete(List<String> guidList, List<string> codeList)
  239. {
  240. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  241. db.Connection.Open();
  242. db.Transaction = db.Connection.BeginTransaction();
  243. try
  244. {
  245. var lines = db.ICSROUTE.Where(a => guidList.Contains(a.ID));
  246. //var line = db.ICSRES.Where(a => codeList.Contains(a.DCTCODE));
  247. //if(line.Count()!=0){
  248. // throw new Exception("DCT指令在资源维护已经使用,无法删除!");
  249. //}
  250. db.ICSROUTE.DeleteAllOnSubmit(lines);
  251. db.SubmitChanges();
  252. db.Transaction.Commit();
  253. }
  254. catch (Exception ex)
  255. {
  256. db.Transaction.Rollback();
  257. throw ex;
  258. }
  259. }
  260. #endregion
  261. #region 判断途程和工序的关系维护中是否已使用该途程
  262. public static bool isIncludingInICSROUTE2OP(List<string> idList, string dsconn)
  263. {
  264. FramDataContext db = new FramDataContext(dsconn);
  265. db.Connection.Open();
  266. db.Transaction = db.Connection.BeginTransaction();
  267. try
  268. {
  269. bool flag = false;
  270. var lines = db.ICSROUTE2OP.Where(a => idList.Contains(a.ROUTEID));
  271. if (lines.Count() != 0)
  272. flag = true;
  273. return flag;
  274. }
  275. catch (Exception ex)
  276. {
  277. //db.Transaction.Rollback();
  278. throw ex;
  279. }
  280. }
  281. public static List<ICSROUTE2OP> IncludingInICSROUTE2OP(List<string> idList, string dsconn)
  282. {
  283. FramDataContext db = new FramDataContext(dsconn);
  284. db.Connection.Open();
  285. db.Transaction = db.Connection.BeginTransaction();
  286. try
  287. {
  288. List<ICSROUTE2OP> lines = db.ICSROUTE2OP.Where(a => idList.Contains(a.ROUTEID)).ToList();
  289. return lines;
  290. }
  291. catch (Exception ex)
  292. {
  293. //db.Transaction.Rollback();
  294. throw ex;
  295. }
  296. }
  297. #endregion
  298. #region 判断产品和途程的关系维护中是否已使用该途程
  299. public static bool isIncludingInICSITEM2ROUTE(List<string> idList, string dsconn)
  300. {
  301. FramDataContext db = new FramDataContext(dsconn);
  302. db.Connection.Open();
  303. db.Transaction = db.Connection.BeginTransaction();
  304. try
  305. {
  306. bool flag = false;
  307. var lines = db.ICSITEM2ROUTE.Where(a => idList.Contains(a.ROUTEID));
  308. if (lines.Count() != 0)
  309. flag = true;
  310. return flag;
  311. }
  312. catch (Exception ex)
  313. {
  314. //db.Transaction.Rollback();
  315. throw ex;
  316. }
  317. }
  318. public static List<ICSITEM2ROUTE> IncludingInICSITEM2ROUTE(List<string> idList, string dsconn)
  319. {
  320. FramDataContext db = new FramDataContext(dsconn);
  321. db.Connection.Open();
  322. try
  323. {
  324. List<ICSITEM2ROUTE> lines = db.ICSITEM2ROUTE.Where(a => idList.Contains(a.ROUTEID)).ToList();
  325. return lines;
  326. }
  327. catch (Exception ex)
  328. {
  329. //db.Transaction.Rollback();
  330. throw ex;
  331. }
  332. }
  333. #endregion
  334. #region 判断产品、途程和工序的关系维护中是否已使用该途程
  335. public static bool isIncludingInICSITEMROUTE2OP(List<string> idList, string dsconn)
  336. {
  337. FramDataContext db = new FramDataContext(dsconn);
  338. db.Connection.Open();
  339. db.Transaction = db.Connection.BeginTransaction();
  340. try
  341. {
  342. bool flag = false;
  343. var lines = db.ICSITEMROUTE2OP.Where(a => idList.Contains(a.ROUTEID));
  344. if (lines.Count() != 0)
  345. flag = true;
  346. return flag;
  347. }
  348. catch (Exception ex)
  349. {
  350. //db.Transaction.Rollback();
  351. throw ex;
  352. }
  353. }
  354. public static List<ICSITEMROUTE2OP> IncludingInICSITEMROUTE2OP(List<string> idList, string dsconn)
  355. {
  356. FramDataContext db = new FramDataContext(dsconn);
  357. db.Connection.Open();
  358. try
  359. {
  360. List<ICSITEMROUTE2OP> lines = db.ICSITEMROUTE2OP.Where(a => idList.Contains(a.ROUTEID)).ToList();
  361. return lines;
  362. }
  363. catch (Exception ex)
  364. {
  365. //db.Transaction.Rollback();
  366. throw ex;
  367. }
  368. }
  369. #endregion
  370. #region 获取工序信息
  371. public static DataTable GetOPCODE(string OPCODE, string WorkPoint, string dsconn)
  372. {
  373. string sql = @"SELECT ID, OPCODE, OPDESC, OPCONTROL FROM ICSOP WHERE 1=1 AND OPCODE = '{0}' AND WorkPoint = '{1}' ";
  374. sql = string.Format(sql, OPCODE, WorkPoint);
  375. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  376. return dt;
  377. }
  378. #endregion
  379. public static DataTable SQlReturnData(string SQL, SqlCommand cmd)
  380. {
  381. DataTable dt = new DataTable();
  382. SqlDataAdapter dr = new System.Data.SqlClient.SqlDataAdapter();
  383. cmd.CommandText = SQL;
  384. dr.SelectCommand = cmd;
  385. dr.Fill(dt);
  386. return dt;
  387. }
  388. }
  389. }