华恒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.

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