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

104 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 ICSMODELDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSMODEL MODEL, 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.ICSMODEL.SingleOrDefault(a => a.ID == MODEL.ID);
  24. if (line == null)
  25. {
  26. isNew = true;
  27. line = new ICSMODEL();
  28. line.ID = AppConfig.GetGuid();
  29. }
  30. var codes = db.ICSMODEL.Where(a => a.MODELCODE == MODEL.MODELCODE && a.ID != line.ID);
  31. if (codes.ToList().Count > 0)
  32. {
  33. throw new Exception("产品别代码已存在");
  34. }
  35. line.MODELCODE = MODEL.MODELCODE;
  36. line.MODELDESC = MODEL.MODELDESC;
  37. line.MUSER = MODEL.MUSER;
  38. line.MUSERName = MODEL.MUSERName;
  39. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  40. line.WorkPoint = AppConfig.WorkPointCode;
  41. if (isNew) db.ICSMODEL.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 ICSMODEL select(String guid, String Appconstr)
  54. {
  55. FramDataContext db = new FramDataContext(Appconstr);
  56. db.Connection.Open();
  57. db.Transaction = db.Connection.BeginTransaction();
  58. ICSMODEL entity = new ICSMODEL();
  59. try
  60. {
  61. var line = db.ICSMODEL.SingleOrDefault(a => a.ID == guid);
  62. return (ICSMODEL)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 line = db.ICSINVENTORY.Where(a => codeList.Contains(a.INVCLASS));
  79. if(line.Count()>0){
  80. throw new Exception("产品别已经关联存货档案无法删除!!");
  81. }
  82. var lines = db.ICSMODEL.Where(a => guidList.Contains(a.ID));
  83. db.ICSMODEL.DeleteAllOnSubmit(lines);
  84. db.SubmitChanges();
  85. db.Transaction.Commit();
  86. }
  87. catch (Exception ex)
  88. {
  89. db.Transaction.Rollback();
  90. throw ex;
  91. }
  92. }
  93. #endregion
  94. }
  95. }