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

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