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

148 lines
5.0 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. namespace ICSSoft.Frame.Data.DAL
  8. {
  9. public class ICSEQPShutdownDAL
  10. {
  11. public static void AddAndEdit(List<Entity.FormICSEQPShutdownUIModel> listInfo, bool add)
  12. {
  13. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  14. db.Connection.Open();
  15. db.Transaction = db.Connection.BeginTransaction();
  16. try
  17. {
  18. foreach (FormICSEQPShutdownUIModel info in listInfo)
  19. {
  20. var line = db.ICSEquipmentShutdown.SingleOrDefault(a => a.EQPID == info.EQPID && a.WorkPoint == AppConfig.WorkPointCode);
  21. if (add)
  22. {
  23. if (line != null)
  24. {
  25. throw new Exception(info.EQPCode + "," + info.EQPName + "已维护");
  26. }
  27. line = new ICSEquipmentShutdown();
  28. }
  29. else
  30. {
  31. if (line == null)
  32. {
  33. throw new Exception(info.EQPCode + "," + info.EQPName + "已被移除,无法修改");
  34. }
  35. }
  36. line.EQPID = info.EQPID;
  37. line.TStart = Convert.ToDateTime(info.TStart);
  38. line.TEnd = Convert.ToDateTime(info.TEnd);
  39. line.MUSER = info.MUSER;
  40. line.MUSERName = info.MUSERName;
  41. line.MTIME = Convert.ToDateTime(info.MTIME);
  42. line.WorkPoint = info.WorkPoint;
  43. line.Reason = info.Reason;
  44. line.EATTRIBUTE1 = "SHUTDOWN";
  45. if (add)
  46. db.ICSEquipmentShutdown.InsertOnSubmit(line);
  47. db.SubmitChanges();
  48. }
  49. db.SubmitChanges();
  50. db.Transaction.Commit();
  51. }
  52. catch (Exception ex)
  53. {
  54. db.Transaction.Rollback();
  55. throw new Exception(ex.Message);
  56. }
  57. }
  58. public static void Delete(List<string> listID)
  59. {
  60. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  61. db.Connection.Open();
  62. db.Transaction = db.Connection.BeginTransaction();
  63. try
  64. {
  65. var lines = db.ICSEquipmentShutdown.Where(a => listID.Contains(a.EQPID) && a.WorkPoint == AppConfig.WorkPointCode);
  66. db.ICSEquipmentShutdown.DeleteAllOnSubmit(lines);
  67. db.SubmitChanges();
  68. db.Transaction.Commit();
  69. }
  70. catch (Exception ex)
  71. {
  72. db.Transaction.Rollback();
  73. throw ex;
  74. }
  75. }
  76. public static FormICSEQPShutdownUIModel Select(string id)
  77. {
  78. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  79. db.Connection.Open();
  80. try
  81. {
  82. //var lines = db.ICSEquipmentShutdown.Where(a => a.EQPID==id && a.WorkPoint == AppConfig.WorkPointCode).ToArray();
  83. string sql = @"
  84. SELECT
  85. A.EQPID,
  86. B.EQPCode,
  87. B.EQPName,
  88. B.EQPDESC,
  89. B.Model,
  90. B.[Type],
  91. B.EType,
  92. B.EATTRIBUTE1,
  93. A.TStart,
  94. A.TEnd,
  95. A.Reason
  96. FROM [dbo].[ICSEquipmentShutdown] A
  97. LEFT JOIN dbo.ICSEquipment B
  98. ON A.EQPID = B.EQPID
  99. AND A.WorkPoint = B.WorkPoint
  100. WHERE 1 = 1 AND A.EQPID='" + id + "'AND A.WorkPoint = '" + AppConfig.WorkPointCode + "';";
  101. List<FormICSEQPShutdownUIModel> lines = db.ExecuteQuery<FormICSEQPShutdownUIModel>(sql).ToList();
  102. if (lines.Count() == 0)
  103. {
  104. return null;
  105. }
  106. return lines[0];
  107. }
  108. catch (Exception ex)
  109. {
  110. db.Connection.Close();
  111. throw ex;
  112. }
  113. }
  114. public static ICSEquipmentShutdown SelectSuspendInfo(string lot, string route, string op, string user)
  115. {
  116. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  117. db.Connection.Open();
  118. db.Transaction = db.Connection.BeginTransaction();
  119. try
  120. {
  121. var lines = db.ICSEquipmentShutdown.Where(a => a.LOTNO == lot
  122. && a.ROUTECODE == route
  123. && a.OPCODE == op
  124. && a.OPUserCode == user
  125. && a.EATTRIBUTE1.ToUpper() == "SUSPEND"
  126. && a.TEnd == null
  127. && a.WorkPoint == AppConfig.WorkPointCode).ToList<ICSEquipmentShutdown>();
  128. return lines[0];
  129. }
  130. catch (Exception ex)
  131. {
  132. db.Transaction.Rollback();
  133. throw ex;
  134. }
  135. }
  136. }
  137. }