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

110 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.DBHelper;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using ICSSoft.Base.Config.AppConfig;
  10. namespace ICSSoft.Frame.Data.DAL
  11. {
  12. public class ICSVendorDAL
  13. {
  14. #region AddandEdit
  15. public static void AddandEdit(ICSVendor vendorLot, 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.ICSVendor.SingleOrDefault(a => a.ID == vendorLot.ID);
  24. if (line == null)
  25. {
  26. isNew = true;
  27. line = new ICSVendor();
  28. line.ID = AppConfig.GetGuid();
  29. }
  30. var codes = db.ICSVendor.Where(a => a.VendorCode == vendorLot.VendorCode && a.ID != line.ID);
  31. if (codes.ToList().Count > 0)
  32. {
  33. throw new Exception("厂商代码已存在");
  34. }
  35. line.VendorCode = vendorLot.VendorCode;
  36. line.VendorName = vendorLot.VendorName;
  37. line.MUSER = vendorLot.MUSER;
  38. line.MUSERName = vendorLot.MUSERName;
  39. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  40. line.WorkPoint = AppConfig.WorkPointCode;
  41. line.EATTRIBUTE1 = null;
  42. if (isNew) db.ICSVendor.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 ICSVendor select(String guid, String Appconstr)
  55. {
  56. FramDataContext db = new FramDataContext(Appconstr);
  57. db.Connection.Open();
  58. db.Transaction = db.Connection.BeginTransaction();
  59. ICSVendor entity = new ICSVendor();
  60. try
  61. {
  62. var line = db.ICSVendor.SingleOrDefault(a => a.ID == guid);
  63. return (ICSVendor)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.ICSVendor.Where(a => guidList.Contains(a.ID));
  80. //var line = db.ICSRES.Where(a => codeList.Contains(a.DCTCODE));
  81. //if(line.Count()!=0){
  82. // throw new Exception("DCT指令在资源维护已经使用,无法删除!");
  83. //}
  84. db.ICSVendor.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. }