华恒Mes鼎捷代码
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.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. using ICSSoft.Frame.APP.Entity;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class IcsAGVLocationDAL
  14. {
  15. #region 新增和修改
  16. public static void Add(List<IcsAGVLocation> InfoList, string dsconn)
  17. {
  18. FramDataContext db = new FramDataContext(dsconn);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. foreach (IcsAGVLocation info in InfoList)
  24. {
  25. bool isNew = false;
  26. var line = db.IcsAGVLocation.SingleOrDefault(a => a.ID == info.ID);
  27. var exists = db.IcsAGVLocation.Where(a => a.ID != info.ID && a.LocationCode == info.LocationCode).FirstOrDefault();
  28. if (exists != null)
  29. throw new Exception("点位编码:"+info.LocationCode+"已存在!");
  30. if (line == null)
  31. {
  32. isNew = true;
  33. line = new IcsAGVLocation();
  34. line.ID = AppConfig.GetGuid();
  35. line.LocationCode = info.LocationCode;
  36. }
  37. line.LocationName = info.LocationName;
  38. line.Workpoint = AppConfig.WorkPointCode;
  39. line.Muser = AppConfig.UserCode;
  40. line.MuserName = AppConfig.UserName;
  41. line.Mtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  42. if (isNew)
  43. db.IcsAGVLocation.InsertOnSubmit(line);
  44. db.SubmitChanges();
  45. }
  46. db.Transaction.Commit();
  47. }
  48. catch (Exception ex)
  49. {
  50. db.Transaction.Rollback();
  51. throw ex;
  52. }
  53. }
  54. #endregion
  55. #region 通过ID查询
  56. public static IcsAGVLocation searchInfoByID(string ID, string dsconn)
  57. {
  58. FramDataContext db = new FramDataContext(dsconn);
  59. db.Connection.Open();
  60. try {
  61. var rtn=db.IcsAGVLocation.FirstOrDefault(a => a.ID == ID);
  62. if (rtn == null)
  63. throw new Exception("获取信息失败!");
  64. else
  65. return rtn;
  66. }
  67. catch (Exception ex)
  68. {
  69. throw ex;
  70. }
  71. }
  72. #endregion
  73. #region 删除
  74. public static void deleteInfo(List<string> codeList, string dsconn)
  75. {
  76. FramDataContext db = new FramDataContext(dsconn);
  77. db.Connection.Open();
  78. db.Transaction = db.Connection.BeginTransaction();
  79. try
  80. {
  81. var lines = db.IcsAGVLocation.Where(a => codeList.Contains(a.ID));
  82. db.IcsAGVLocation.DeleteAllOnSubmit(lines);
  83. db.SubmitChanges();
  84. db.Transaction.Commit();
  85. }
  86. catch (Exception ex)
  87. {
  88. db.Transaction.Rollback();
  89. throw ex;
  90. }
  91. }
  92. #endregion
  93. }
  94. }