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

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