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

222 lines
7.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.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 ICSEQPMaintainLogDAL
  13. {
  14. #region 增加修改
  15. public static void AddAndEdit(List<FormICSEQPMaintainLogUIModel> equipmentInfoList, string dsconn)
  16. {
  17. FramDataContext db = new FramDataContext(dsconn);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. foreach (FormICSEQPMaintainLogUIModel equipmentInfo in equipmentInfoList)
  23. {
  24. ICSEQPMaintainLog line = new ICSEQPMaintainLog();
  25. line.Guid = equipmentInfo.Guid;
  26. line.EQPID = equipmentInfo.EQPID;
  27. line.EQPCode = equipmentInfo.EQPCode;
  28. line.MaintainItem = equipmentInfo.MaintainItem;
  29. line.MEMO = equipmentInfo.MEMO;
  30. line.RESULT = equipmentInfo.RESULT;
  31. line.MUSER = equipmentInfo.MUSER;
  32. line.MUSERName = equipmentInfo.MUSERName;
  33. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  34. line.WorkPoint = equipmentInfo.WorkPoint;
  35. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  36. db.ICSEQPMaintainLog.InsertOnSubmit(line);
  37. db.SubmitChanges();
  38. }
  39. db.SubmitChanges();
  40. db.Transaction.Commit();
  41. }
  42. catch (Exception ex)
  43. {
  44. db.Transaction.Rollback();
  45. throw new Exception(ex.Message);
  46. }
  47. }
  48. #endregion
  49. #region 班次代码是否存在
  50. public static bool IsIncludingShiftCode(string shiftcode, string dsconn)
  51. {
  52. FramDataContext db = new FramDataContext(dsconn);
  53. db.Connection.Open();
  54. db.Transaction = db.Connection.BeginTransaction();
  55. try
  56. {
  57. var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTCODE == shiftcode);
  58. if (line == null)
  59. return true;
  60. else
  61. return false;
  62. }
  63. catch (Exception ex)
  64. {
  65. db.Transaction.Rollback();
  66. throw ex;
  67. }
  68. }
  69. #endregion
  70. //#region 班次次序是否存在
  71. //public static bool IsIncludingInShiftSeq(int shiftsqe, string shifttypeid)
  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.ICSSHIFT.SingleOrDefault(a => a.SHIFTSEQ == shiftsqe && a.SHIFTTYPEID == shifttypeid);
  79. // if (line == null)
  80. // return true;
  81. // else
  82. // return false;
  83. // }
  84. // catch (Exception ex)
  85. // {
  86. // db.Transaction.Rollback();
  87. // throw ex;
  88. // }
  89. //}
  90. //#endregion
  91. public static List<FormICSEQPMaintainPlanUIModel> SearchEQPMaintainPlanInfoByID(string id, string dsconn)
  92. {
  93. List<FormICSEQPMaintainPlanUIModel> returnshift = new List<FormICSEQPMaintainPlanUIModel>();
  94. string sql = @"select a.GUID,b.EQPID,b.EQPCode,a.MaintainItem,a.CycleType,a.Frequency,a.MUSERName,a.MTIME
  95. from ICSEQPMaintainPlan a
  96. left join ICSEquipment b on a.EQPCode=b.EQPCode
  97. where a.GUID='{0}'";
  98. sql = string.Format(sql, id);
  99. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  100. foreach (DataRow dr in dt.Rows)
  101. {
  102. FormICSEQPMaintainPlanUIModel equipmentInfo = new FormICSEQPMaintainPlanUIModel();
  103. equipmentInfo.GUID = dr["GUID"].ToString();
  104. equipmentInfo.equipment = new FormICSEquipmentUIModel();
  105. equipmentInfo.equipment.EQPID=dr["EQPID"].ToString();
  106. equipmentInfo.equipment.EQPCode = dr["EQPCode"].ToString();
  107. equipmentInfo.MaintainItem = dr["MaintainItem"].ToString();
  108. equipmentInfo.CycleType = dr["CycleType"].ToString();
  109. equipmentInfo.Frequency =Convert.ToInt32(dr["Frequency"].ToString());
  110. equipmentInfo.MUSERName = dr["MUSERName"].ToString();
  111. equipmentInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
  112. if (!returnshift.Contains(equipmentInfo))
  113. {
  114. returnshift.Add(equipmentInfo);
  115. }
  116. }
  117. return returnshift;
  118. }
  119. public static DataTable SelectShiftTypeCode()
  120. {
  121. string sql = @"select SHIFTTYPECODE as [班制代码]
  122. from dbo.ICSSHIFTTYPE
  123. where 1=1";
  124. sql = string.Format(sql);
  125. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  126. return dt;
  127. }
  128. public static DataTable SelectShiftTypeId(string str)
  129. {
  130. string sql = @"select ID
  131. from dbo.ICSSHIFTTYPE
  132. where SHIFTTYPECODE='" + str + "'";
  133. sql = string.Format(sql);
  134. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  135. return dt;
  136. }
  137. #region delete
  138. public static void delete(List<String> guidList)
  139. {
  140. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  141. db.Connection.Open();
  142. db.Transaction = db.Connection.BeginTransaction();
  143. try
  144. {
  145. var lines = db.ICSEQPMaintainPlan.Where(a => guidList.Contains(a.GUID));
  146. db.ICSEQPMaintainPlan.DeleteAllOnSubmit(lines);
  147. db.SubmitChanges();
  148. db.Transaction.Commit();
  149. }
  150. catch (Exception ex)
  151. {
  152. db.Transaction.Rollback();
  153. throw ex;
  154. }
  155. }
  156. #endregion
  157. public static DataTable GetShiftCode()
  158. {
  159. try
  160. {
  161. string sql = @"select TOP 1 [SHIFTCODE]
  162. FROM [dbo].[ICSSHIFT] order by SHIFTCODE desc";
  163. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  164. }
  165. catch (Exception ex)
  166. {
  167. throw ex;
  168. }
  169. }
  170. // public static DataTable GetShiftSeqCode()
  171. // {
  172. // try
  173. // {
  174. // string sql = @"select TOP 1 [SHIFTSEQ]
  175. // FROM [dbo].[ICSSHIFT] order by [SHIFTTYPEID] desc";
  176. // return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  177. // }
  178. // catch (Exception ex)
  179. // {
  180. // throw ex;
  181. // }
  182. // }
  183. }
  184. }