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

270 lines
9.5 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 ICSEquipmentDAL
  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.ICSEquipment.SingleOrDefault(a => a.EQPID == equipmentInfo.EQPID);
  26. if (line == null)
  27. {
  28. isNew = true;
  29. line = new ICSEquipment();
  30. line.EQPID = AppConfig.GetGuid();
  31. }
  32. var codes = db.ICSEquipment.Where(a => a.EQPCode == equipmentInfo.EQPCode && a.EQPID != line.EQPID);
  33. if (codes.ToList().Count > 0)
  34. {
  35. throw new Exception("设备编号已存在");
  36. }
  37. line.EQPCode = equipmentInfo.EQPCode;
  38. line.EQPName = equipmentInfo.EQPName;
  39. line.Model = equipmentInfo.Model;
  40. line.Type = equipmentInfo.Type;
  41. line.EQPStatus = equipmentInfo.EQPStatus;
  42. line.EQPDESC = equipmentInfo.EQPDESC;
  43. line.EType = equipmentInfo.EType;
  44. line.MTStatus = equipmentInfo.MTStatus;
  45. line.Company = equipmentInfo.Company;
  46. line.Address = equipmentInfo.Address;
  47. line.TelPhone = equipmentInfo.TelPhone;
  48. line.MUSER = equipmentInfo.MUSER;
  49. line.MUSERName = equipmentInfo.MUSERName;
  50. line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
  51. line.WorkPoint = equipmentInfo.WorkPoint;
  52. line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
  53. if (isNew)
  54. db.ICSEquipment.InsertOnSubmit(line);
  55. db.SubmitChanges();
  56. }
  57. db.SubmitChanges();
  58. db.Transaction.Commit();
  59. }
  60. catch (Exception ex)
  61. {
  62. db.Transaction.Rollback();
  63. throw new Exception(ex.Message);
  64. }
  65. }
  66. #endregion
  67. #region 班次代码是否存在
  68. public static bool IsIncludingShiftCode(string shiftcode, string dsconn)
  69. {
  70. FramDataContext db = new FramDataContext(dsconn);
  71. db.Connection.Open();
  72. db.Transaction = db.Connection.BeginTransaction();
  73. try
  74. {
  75. var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTCODE == shiftcode);
  76. if (line == null)
  77. return true;
  78. else
  79. return false;
  80. }
  81. catch (Exception ex)
  82. {
  83. db.Transaction.Rollback();
  84. throw ex;
  85. }
  86. }
  87. #endregion
  88. //#region 班次次序是否存在
  89. //public static bool IsIncludingInShiftSeq(int shiftsqe, string shifttypeid)
  90. //{
  91. // FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  92. // db.Connection.Open();
  93. // db.Transaction = db.Connection.BeginTransaction();
  94. // try
  95. // {
  96. // var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTSEQ == shiftsqe && a.SHIFTTYPEID == shifttypeid);
  97. // if (line == null)
  98. // return true;
  99. // else
  100. // return false;
  101. // }
  102. // catch (Exception ex)
  103. // {
  104. // db.Transaction.Rollback();
  105. // throw ex;
  106. // }
  107. //}
  108. //#endregion
  109. public static List<FormICSEquipmentUIModel> SearchEquipmentInfoByCode(string id, string dsconn)
  110. {
  111. List<FormICSEquipmentUIModel> returnshift = new List<FormICSEquipmentUIModel>();
  112. string sql = @"select a.EQPCode,a.EQPName,a.Model,a.Type,a.EQPStatus,a.EQPDESC,a.EType,a.Company,a.Address,a.TelPhone,b.TypeCODE,a.MUSERName,a.MTIME,a.EATTRIBUTE1,a.mtstatus
  113. from ICSEquipment a left join ICSEquipmentType b on a.EType=b.TypeCODE where EQPID='{0}'";
  114. sql = string.Format(sql, id);
  115. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  116. foreach (DataRow dr in dt.Rows)
  117. {
  118. FormICSEquipmentUIModel equipmentInfo = new FormICSEquipmentUIModel();
  119. equipmentInfo.EQPID = id;
  120. equipmentInfo.EQPCode = dr["EQPCode"].ToString();
  121. equipmentInfo.EQPName = dr["EQPName"].ToString();
  122. equipmentInfo.Model = dr["Model"].ToString();
  123. equipmentInfo.Type = dr["Type"].ToString();
  124. equipmentInfo.EQPStatus = dr["EQPStatus"].ToString();
  125. equipmentInfo.EQPDESC = dr["EQPDESC"].ToString();
  126. equipmentInfo.EType = dr["EType"].ToString();
  127. equipmentInfo.Company = dr["Company"].ToString();
  128. equipmentInfo.Address = dr["Address"].ToString();
  129. equipmentInfo.TelPhone = dr["TelPhone"].ToString();
  130. //equipmentInfo.SS = new FormICSSSUIModel();
  131. //equipmentInfo.SS.SSCODE = dr["SSCODE"].ToString();
  132. //equipmentInfo.SS.SSDESC = dr["SSDESC"].ToString();
  133. equipmentInfo.MUSERName = dr["MUSERName"].ToString();
  134. equipmentInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
  135. equipmentInfo.MTStatus = dr["mtstatus"].ToString();
  136. equipmentInfo.EATTRIBUTE1 = dr["EATTRIBUTE1"].ToString();//设备属性
  137. if (!returnshift.Contains(equipmentInfo))
  138. {
  139. returnshift.Add(equipmentInfo);
  140. }
  141. }
  142. return returnshift;
  143. }
  144. public static DataTable SelectShiftTypeCode()
  145. {
  146. string sql = @"select SHIFTTYPECODE as [班制代码]
  147. from dbo.ICSSHIFTTYPE
  148. where 1=1";
  149. sql = string.Format(sql);
  150. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  151. return dt;
  152. }
  153. public static DataTable SelectShiftTypeId(string str)
  154. {
  155. string sql = @"select ID
  156. from dbo.ICSSHIFTTYPE
  157. where SHIFTTYPECODE='" + str + "'";
  158. sql = string.Format(sql);
  159. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  160. return dt;
  161. }
  162. #region delete
  163. public static void delete(List<String> guidList)
  164. {
  165. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  166. db.Connection.Open();
  167. db.Transaction = db.Connection.BeginTransaction();
  168. try
  169. {
  170. var lines = db.ICSEquipment.Where(a => guidList.Contains(a.EQPID));
  171. db.ICSEquipment.DeleteAllOnSubmit(lines);
  172. db.SubmitChanges();
  173. db.Transaction.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. db.Transaction.Rollback();
  178. throw ex;
  179. }
  180. }
  181. #endregion
  182. public static DataTable GetShiftCode()
  183. {
  184. try
  185. {
  186. string sql = @"select TOP 1 [SHIFTCODE]
  187. FROM [dbo].[ICSSHIFT] order by SHIFTCODE desc";
  188. return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  189. }
  190. catch (Exception ex)
  191. {
  192. throw ex;
  193. }
  194. }
  195. // public static DataTable GetShiftSeqCode()
  196. // {
  197. // try
  198. // {
  199. // string sql = @"select TOP 1 [SHIFTSEQ]
  200. // FROM [dbo].[ICSSHIFT] order by [SHIFTTYPEID] desc";
  201. // return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  202. // }
  203. // catch (Exception ex)
  204. // {
  205. // throw ex;
  206. // }
  207. // }
  208. public static ICSEquipment GetEQPByCode(string code, string workpoint, string dsconn)
  209. {
  210. FramDataContext db = new FramDataContext(dsconn);
  211. db.Connection.Open();
  212. db.Transaction = db.Connection.BeginTransaction();
  213. try
  214. {
  215. var line = db.ICSEquipment.SingleOrDefault(a => a.EQPCode == code && a.WorkPoint == workpoint);
  216. if (line != null)
  217. {
  218. return line;
  219. }
  220. else
  221. {
  222. return null;
  223. }
  224. }
  225. catch (Exception ex)
  226. {
  227. db.Transaction.Rollback();
  228. throw new Exception(ex.Message);
  229. }
  230. }
  231. }
  232. }