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

247 lines
8.0 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 ICSEquipmentTypeDAL
  13. {
  14. #region 增加修改
  15. public static void AddAndEdit(List<FormICSEquipmentUIModel> 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 (FormICSEquipmentUIModel equipmentInfo in equipmentInfoList)
  23. {
  24. bool isNew = false;
  25. var line = db.ICSEquipmentType.SingleOrDefault(a =>a.TypeCODE == equipmentInfo.TypeCODE);
  26. if (line == null)
  27. {
  28. isNew = true;
  29. line = new ICSEquipmentType();
  30. line.ID = AppConfig.GetGuid();
  31. }
  32. var codes = db.ICSEquipmentType.Where(a => a.TypeCODE == equipmentInfo.TypeCODE && a.ID != line.ID);
  33. if (codes.ToList().Count > 0)
  34. {
  35. throw new Exception("设备组代码已存在");
  36. }
  37. line.TypeCODE = equipmentInfo.TypeCODE;
  38. line.TypeDESC = equipmentInfo.TypeDESC;
  39. line.MUSER = equipmentInfo.MUSER;
  40. line.SEGCODE = equipmentInfo.SEGCODE;
  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.ICSEquipmentType.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<FormICSEquipmentUIModel> SearchEquipmentInfoByCode(string id, string dsconn)
  102. {
  103. List<FormICSEquipmentUIModel> returnshift = new List<FormICSEquipmentUIModel>();
  104. string sql = @"select '' as isSelect,ID,TypeCODE,TypeDESC,SEGCODE,MUSERName,MTIME from ICSEquipmentType where ID='{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. FormICSEquipmentUIModel equipmentInfo = new FormICSEquipmentUIModel();
  110. equipmentInfo.TypeCODE = dr["TypeCODE"].ToString();
  111. equipmentInfo.TypeDESC = dr["TypeDESC"].ToString();
  112. equipmentInfo.SEGCODE = dr["SEGCODE"].ToString();
  113. equipmentInfo.MUSERName = dr["MUSERName"].ToString();
  114. equipmentInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
  115. if (!returnshift.Contains(equipmentInfo))
  116. {
  117. returnshift.Add(equipmentInfo);
  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.ICSEquipmentType.Where(a => guidList.Contains(a.ID));
  149. db.ICSEquipmentType.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. #region 判断设备类型是否和设备关联
  187. public static bool IncludingEquipment(List<string> idList, string dsconn)
  188. {
  189. FramDataContext db = new FramDataContext(dsconn);
  190. db.Connection.Open();
  191. db.Transaction = db.Connection.BeginTransaction();
  192. try
  193. {
  194. bool flag = false;
  195. var lines = db.ICSEquipment.Where(a => idList.Contains(a.EType));
  196. if (lines.Count() != 0)
  197. flag = true;
  198. return flag;
  199. }
  200. catch (Exception ex)
  201. {
  202. //db.Transaction.Rollback();
  203. throw ex;
  204. }
  205. }
  206. #endregion
  207. }
  208. }