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

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