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

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