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

208 lines
6.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 ICSECG2ECDAL
  13. {
  14. #region 增加修改
  15. public static void AddAndEdit(DataTable dt, string ecgid, string ecgcode, string Appconstr)
  16. {
  17. FramDataContext db = new FramDataContext(Appconstr);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. for (int i = 0; i < dt.Rows.Count; i++)
  23. {
  24. ICSECG2EC line = new ICSECG2EC();
  25. line.ECGID = ecgid;
  26. line.ECID = dt.Rows[i]["ID"].ToString();
  27. line.ECGCODE = ecgcode;
  28. line.ECODE = dt.Rows[i]["不良代码"].ToString();
  29. line.MUSER = AppConfig.UserId;
  30. line.MUSERName = AppConfig.UserName;
  31. line.WorkPoint = AppConfig.WorkPointCode;
  32. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  33. db.ICSECG2EC.InsertOnSubmit(line);
  34. }
  35. db.SubmitChanges();
  36. db.Transaction.Commit();
  37. }
  38. catch (Exception ex)
  39. {
  40. db.Transaction.Rollback();
  41. throw new Exception(ex.Message);
  42. }
  43. }
  44. #endregion
  45. public static List<FormICSECG2ECUIModel> SearchEcg2EcInfoByCode(string ecgid, string ecid, string dsconn)
  46. {
  47. List<FormICSECG2ECUIModel> returnshift = new List<FormICSECG2ECUIModel>();
  48. string sql = @"select b.ID as ECGID,
  49. c.ID as ECID,
  50. b.ECGCODE as ECGCODE,
  51. c.ECODE as ECODE,
  52. a.MUSERName as MUSERName,
  53. a.MTIME as MTIME
  54. from ICSECG2EC a
  55. left join ICSECG b on a.ECGID=b.ID
  56. left join ICSEC c on a.ECID=c.ID
  57. where b.ID='" + ecgid + "'and c.ID='" + ecid + "'";
  58. sql = string.Format(sql);
  59. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  60. foreach (DataRow dr in dt.Rows)
  61. {
  62. FormICSECG2ECUIModel shiftInfo = new FormICSECG2ECUIModel();
  63. shiftInfo.ecg = new FormICSECGUIModel();
  64. shiftInfo.ecg.ID = dr["ECGID"].ToString();
  65. shiftInfo.ecg.ECGCODE = dr["ECGCODE"].ToString();
  66. shiftInfo.ec = new FormICSECUIModel();
  67. shiftInfo.ec.ID = dr["ECID"].ToString();
  68. shiftInfo.ec.ECODE = dr["ECODE"].ToString();
  69. shiftInfo.MUSERName = dr["MUSERName"].ToString();
  70. shiftInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
  71. if (!returnshift.Contains(shiftInfo))
  72. {
  73. returnshift.Add(shiftInfo);
  74. }
  75. }
  76. return returnshift;
  77. }
  78. // public static List<FormICSOPUIModel> SearchOPInfoList(string str,string dsconn)
  79. // {
  80. // try
  81. // {
  82. // List<FormICSOPUIModel> returntype = new List<FormICSOPUIModel>();
  83. // string sql = @"select a.OPCODE,a.OPDESC
  84. // from dbo.ICSITEMROUTE2OP b
  85. // left join dbo.ICSOP a on b.OPID=a.ID
  86. // WHERE ITEMCODE='" + str + "'";
  87. // sql = string.Format(sql);
  88. // DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  89. // foreach (DataRow dr in dt.Rows)
  90. // {
  91. // FormICSOPUIModel typemodel = new FormICSOPUIModel();
  92. // typemodel.OPCODE = dr["OPCODE"].ToString();
  93. // typemodel.OPDESC = dr["OPDESC"].ToString();
  94. // if (!returntype.Contains(typemodel))
  95. // returntype.Add(typemodel);
  96. // }
  97. // return returntype;
  98. // }
  99. // catch (Exception ex)
  100. // {
  101. // throw ex;
  102. // }
  103. // }
  104. #region 根据不良代码组代码查找不良代码组id
  105. public static DataTable SelectECGId(string str, string wp)
  106. {
  107. string sql = @"select ID
  108. from dbo.ICSECG
  109. where ECGCODE='" + str + "' and WorkPoint='" + wp + "'";
  110. sql = string.Format(sql);
  111. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  112. return dt;
  113. }
  114. #endregion
  115. #region 根据不良代码代码查找不良代码id
  116. public static DataTable SelectECId(string str, string wp)
  117. {
  118. string sql = @"select ID
  119. from dbo.ICSEC
  120. where ECODE='" + str + "'and WorkPoint='" + wp + "'";
  121. sql = string.Format(sql);
  122. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  123. return dt;
  124. }
  125. #endregion
  126. #region delete
  127. public static void delete(List<String> guidList)
  128. {
  129. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  130. db.Connection.Open();
  131. db.Transaction = db.Connection.BeginTransaction();
  132. try
  133. {
  134. var lines = db.ICSECG2EC.Where(a => guidList.Contains(a.ECGID) && guidList.Contains(a.ECID));
  135. db.ICSECG2EC.DeleteAllOnSubmit(lines);
  136. db.SubmitChanges();
  137. db.Transaction.Commit();
  138. }
  139. catch (Exception ex)
  140. {
  141. db.Transaction.Rollback();
  142. throw ex;
  143. }
  144. }
  145. #endregion
  146. public static void Save(List<string> ecidList, List<string> ecgidList)
  147. {
  148. try
  149. {
  150. for (int i = 0; i < ecidList.Count; i++)
  151. {
  152. string sql = @"UPDATE dbo.ICSECG2EC SET ECGID='{0}' WHERE ECID='{1}'";
  153. sql = string.Format(sql,ecgidList[i],ecidList[i]);
  154. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. throw ex;
  160. }
  161. }
  162. }
  163. }