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

179 lines
5.8 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 ICSMODEL2ECGDAL
  13. {
  14. #region 增加修改
  15. public static void AddAndEdit(DataTable dt, string itemid, string itemcode, 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. ICSMODEL2ECG line = new ICSMODEL2ECG();
  25. line.MODELID = itemid;
  26. line.ECGID = dt.Rows[i]["ID"].ToString();
  27. line.MODELCODE = itemcode;
  28. line.ECGCODE = dt.Rows[i]["不良代码组代码"].ToString();
  29. line.ROUTECODE = dt.Rows[i]["途程代码"].ToString();
  30. line.OPCODE = dt.Rows[i]["工序代码"].ToString();
  31. line.RESCODE = dt.Rows[i]["资源代码"].ToString();
  32. line.MUSER = AppConfig.UserId;
  33. line.MUSERName = AppConfig.UserName;
  34. line.WorkPoint = AppConfig.WorkPointCode;
  35. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  36. db.ICSMODEL2ECG.InsertOnSubmit(line);
  37. }
  38. db.SubmitChanges();
  39. db.Transaction.Commit();
  40. }
  41. catch (Exception ex)
  42. {
  43. db.Transaction.Rollback();
  44. throw new Exception(ex.Message);
  45. }
  46. }
  47. #endregion
  48. public static List<FormICSECSG2ECSUIModel> SearchEcg2EcInfoByCode(string ecsgid, string ecsid, string dsconn)
  49. {
  50. List<FormICSECSG2ECSUIModel> returnshift = new List<FormICSECSG2ECSUIModel>();
  51. string sql = @"select b.ID as ECSGID,
  52. c.ID as ECSID,
  53. b.ECSGCODE as ECSGCODE,
  54. c.ECSCODE as ECSCODE,
  55. a.MUSERName as MUSERName,
  56. a.MTIME as MTIME
  57. from ICSECSG2ECS a
  58. left join ICSECSG b on a.ECSGID=b.ID
  59. left join ICSECS c on a.ECSID=c.ID
  60. where b.ID='" + ecsgid + "'and c.ID='" + ecsid + "'";
  61. sql = string.Format(sql);
  62. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  63. foreach (DataRow dr in dt.Rows)
  64. {
  65. FormICSECSG2ECSUIModel shiftInfo = new FormICSECSG2ECSUIModel();
  66. shiftInfo.ecsg = new FormICSECSGUIModel();
  67. shiftInfo.ecsg.ID = dr["ECSGID"].ToString();
  68. shiftInfo.ecsg.ECSGCODE = dr["ECSGCODE"].ToString();
  69. shiftInfo.ecs = new FormICSECSUIModel();
  70. shiftInfo.ecs.ID = dr["ECSID"].ToString();
  71. shiftInfo.ecs.ECSCODE = dr["ECSCODE"].ToString();
  72. shiftInfo.MUSERName = dr["MUSERName"].ToString();
  73. shiftInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
  74. if (!returnshift.Contains(shiftInfo))
  75. {
  76. returnshift.Add(shiftInfo);
  77. }
  78. }
  79. return returnshift;
  80. }
  81. #region 根据不良代码组代码查找不良代码组id
  82. public static DataTable SelectECGId(string str, string wp)
  83. {
  84. string sql = @"select ID
  85. from dbo.ICSECG
  86. where ECGCODE='" + str + "' and WorkPoint='" + wp + "'";
  87. sql = string.Format(sql);
  88. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  89. return dt;
  90. }
  91. #endregion
  92. #region 根据不良代码代码查找不良代码id
  93. public static DataTable SelectECId(string str, string wp)
  94. {
  95. string sql = @"select ID
  96. from dbo.ICSEC
  97. where ECODE='" + str + "'and WorkPoint='" + wp + "'";
  98. sql = string.Format(sql);
  99. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  100. return dt;
  101. }
  102. #endregion
  103. #region delete
  104. public static void delete(List<String> guidList)
  105. {
  106. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  107. db.Connection.Open();
  108. db.Transaction = db.Connection.BeginTransaction();
  109. try
  110. {
  111. var lines = db.ICSMODEL2ECG.Where(a => guidList.Contains(a.MODELID) && guidList.Contains(a.ECGID));
  112. db.ICSMODEL2ECG.DeleteAllOnSubmit(lines);
  113. db.SubmitChanges();
  114. db.Transaction.Commit();
  115. }
  116. catch (Exception ex)
  117. {
  118. db.Transaction.Rollback();
  119. throw ex;
  120. }
  121. }
  122. #endregion
  123. public static void Save(List<string> ecidList, List<string> ecgidList)
  124. {
  125. try
  126. {
  127. for (int i = 0; i < ecidList.Count; i++)
  128. {
  129. string sql = @"UPDATE dbo.ICSECG2EC SET ECGID='{0}' WHERE ECID='{1}'";
  130. sql = string.Format(sql,ecgidList[i],ecidList[i]);
  131. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. throw ex;
  137. }
  138. }
  139. }
  140. }