锐腾搅拌上料功能
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 ICSCREWDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSCREW 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.ICSCREW.SingleOrDefault(a => a.ID == ItemLot.ID);
  24. if (line == null)
  25. {
  26. isNew = true;
  27. line = new ICSCREW();
  28. line.ID = AppConfig.GetGuid();
  29. }
  30. var codes = db.ICSCREW.Where(a => a.CREWCODE == ItemLot.CREWCODE && a.ID != line.ID);
  31. if (codes.ToList().Count > 0)
  32. {
  33. throw new Exception("班组代码已存在");
  34. }
  35. line.CREWCODE = ItemLot.CREWCODE;
  36. line.CREWDESC = ItemLot.CREWDESC;
  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.ICSCREW.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 ICSCREW select(String guid, String Appconstr)
  54. {
  55. FramDataContext db = new FramDataContext(Appconstr);
  56. db.Connection.Open();
  57. db.Transaction = db.Connection.BeginTransaction();
  58. ICSCREW entity = new ICSCREW();
  59. try
  60. {
  61. var line = db.ICSCREW.SingleOrDefault(a => a.ID == guid);
  62. return (ICSCREW)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.ICSCREW.Where(a => guidList.Contains(a.ID));
  79. var line = db.ICSRES.Where(a => CodeList.Contains(a.CREWCODE));
  80. if(line.Count()!=0){
  81. throw new Exception("班组代码在岗位资源已经使用,无法删除!");
  82. }
  83. db.ICSCREW.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. }