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

109 lines
3.4 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. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSECSGDAL
  14. {
  15. #region AddandEdit
  16. public static void AddandEdit(ICSECSG ItemLot, string Appconstr)
  17. {
  18. FramDataContext db = new FramDataContext(Appconstr);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. bool isNew = false;
  24. var line = db.ICSECSG.SingleOrDefault(a => a.ID == ItemLot.ID);
  25. if (line == null)
  26. {
  27. isNew = true;
  28. line = new ICSECSG();
  29. line.ID = AppConfig.GetGuid();
  30. }
  31. var codes = db.ICSECSG.Where(a => a.ECSGCODE == ItemLot.ECSGCODE && a.ID != line.ID);
  32. if (codes.ToList().Count > 0)
  33. {
  34. throw new Exception("不良原因组代码已存在");
  35. }
  36. line.ECSGCODE = ItemLot.ECSGCODE;
  37. line.ECSGDESC = ItemLot.ECSGDESC;
  38. line.MUSER = ItemLot.MUSER;
  39. line.MUSERName = ItemLot.MUSERName;
  40. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  41. line.WorkPoint = AppConfig.WorkPointCode;
  42. if (isNew) db.ICSECSG.InsertOnSubmit(line);
  43. db.SubmitChanges();
  44. db.Transaction.Commit();
  45. }
  46. catch (Exception ex)
  47. {
  48. db.Transaction.Rollback();
  49. throw new Exception(ex.Message);
  50. }
  51. }
  52. #endregion
  53. #region select
  54. public static ICSECSG select(String guid, String Appconstr)
  55. {
  56. FramDataContext db = new FramDataContext(Appconstr);
  57. db.Connection.Open();
  58. db.Transaction = db.Connection.BeginTransaction();
  59. ICSECSG entity = new ICSECSG();
  60. try
  61. {
  62. var line = db.ICSECSG.SingleOrDefault(a => a.ID == guid);
  63. return (ICSECSG)line;
  64. }
  65. catch (Exception ex)
  66. {
  67. throw new Exception(ex.Message);
  68. }
  69. }
  70. #endregion
  71. #region delete
  72. public static void delete(List<String> guidList, List<string> codeList)
  73. {
  74. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  75. db.Connection.Open();
  76. db.Transaction = db.Connection.BeginTransaction();
  77. try
  78. {
  79. var lines = db.ICSECSG.Where(a => guidList.Contains(a.ID));
  80. var line = db.ICSECSG2ECS.Where(a => codeList.Contains(a.ECSGCODE));
  81. if (line.Count() != 0)
  82. {
  83. throw new Exception("该不良原因组已与不良原因关联,无法删除!");
  84. }
  85. db.ICSECSG.DeleteAllOnSubmit(lines);
  86. db.SubmitChanges();
  87. db.Transaction.Commit();
  88. }
  89. catch (Exception ex)
  90. {
  91. db.Transaction.Rollback();
  92. throw ex;
  93. }
  94. }
  95. #endregion
  96. }
  97. }