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

89 lines
2.8 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 ICSSoft.Base.Config.AppConfig;
  9. namespace ICSSoft.Frame.Data.DAL
  10. {
  11. public class FormICSAutoCMPOPADDDLL
  12. {
  13. public static void AddorEdit(List<ICSAutoCMPOP> list,string conn) {
  14. FramDataContext frame = new FramDataContext(conn);
  15. frame.Connection.Open();
  16. frame.Transaction = frame.Connection.BeginTransaction();
  17. try {
  18. foreach (ICSAutoCMPOP op in list) {
  19. bool isnew = false;
  20. var isexist = frame.ICSAutoCMPOP.Where(a => a.id != op.id && a.opcode == op.opcode).FirstOrDefault(); ;
  21. if (isexist != null) {
  22. throw new Exception("工序:"+op.opcode+"已维护");
  23. }
  24. var autoop = frame.ICSAutoCMPOP.Where(a => a.id == op.id).FirstOrDefault();
  25. if (autoop == null) {
  26. isnew = true;
  27. autoop = new ICSAutoCMPOP();
  28. autoop.id = AppConfig.GetGuid();
  29. }
  30. autoop.opcode = op.opcode;
  31. autoop.Mtime = DateTime.Now;
  32. autoop.Muser = AppConfig.UserCode;
  33. autoop.Musername = AppConfig.UserName;
  34. autoop.Status = op.Status;
  35. if (isnew)
  36. frame.ICSAutoCMPOP.InsertOnSubmit(autoop);
  37. frame.SubmitChanges();
  38. }
  39. frame.Transaction.Commit();
  40. }
  41. catch (Exception ex) {
  42. frame.Transaction.Rollback();
  43. throw ex;
  44. }
  45. }
  46. public static ICSAutoCMPOP Search(string id, string conn)
  47. {
  48. FramDataContext frame = new FramDataContext(conn);
  49. frame.Connection.Open();
  50. try
  51. {
  52. return frame.ICSAutoCMPOP.Where(a => a.id == id).FirstOrDefault();
  53. }
  54. catch (Exception ex)
  55. {
  56. throw ex;
  57. }
  58. }
  59. public static void Delete(List<string> id, string conn)
  60. {
  61. FramDataContext frame = new FramDataContext(conn);
  62. frame.Connection.Open();
  63. frame.Transaction = frame.Connection.BeginTransaction();
  64. try
  65. {
  66. frame.ICSAutoCMPOP.DeleteAllOnSubmit(frame.ICSAutoCMPOP.Where(a => id.Contains(a.id)));
  67. frame.SubmitChanges();
  68. frame.Transaction.Commit();
  69. }
  70. catch (Exception ex)
  71. {
  72. frame.Transaction.Rollback();
  73. throw ex;
  74. }
  75. }
  76. }
  77. }