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

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