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

177 lines
5.6 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 ICSECSG2ECSDAL
  13. {
  14. #region 增加修改
  15. public static void AddAndEdit(DataTable dt, string ecsgid, string ecsgcode, 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. ICSECSG2ECS line = new ICSECSG2ECS();
  25. line.ECSGID = ecsgid;
  26. line.ECSID = dt.Rows[i]["ID"].ToString();
  27. line.ECSGCODE = ecsgcode;
  28. line.ECSCODE = 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.ICSECSG2ECS.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<FormICSECSG2ECSUIModel> SearchEcg2EcInfoByCode(string ecsgid, string ecsid, string dsconn)
  46. {
  47. List<FormICSECSG2ECSUIModel> returnshift = new List<FormICSECSG2ECSUIModel>();
  48. string sql = @"select b.ID as ECSGID,
  49. c.ID as ECSID,
  50. b.ECSGCODE as ECSGCODE,
  51. c.ECSCODE as ECSCODE,
  52. a.MUSERName as MUSERName,
  53. a.MTIME as MTIME
  54. from ICSECSG2ECS a
  55. left join ICSECSG b on a.ECSGID=b.ID
  56. left join ICSECS c on a.ECSID=c.ID
  57. where b.ID='" + ecsgid + "'and c.ID='" + ecsid + "'";
  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. FormICSECSG2ECSUIModel shiftInfo = new FormICSECSG2ECSUIModel();
  63. shiftInfo.ecsg = new FormICSECSGUIModel();
  64. shiftInfo.ecsg.ID = dr["ECSGID"].ToString();
  65. shiftInfo.ecsg.ECSGCODE = dr["ECSGCODE"].ToString();
  66. shiftInfo.ecs = new FormICSECSUIModel();
  67. shiftInfo.ecs.ID = dr["ECSID"].ToString();
  68. shiftInfo.ecs.ECSCODE = dr["ECSCODE"].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. #region 根据不良代码组代码查找不良代码组id
  79. public static DataTable SelectECGId(string str, string wp)
  80. {
  81. string sql = @"select ID
  82. from dbo.ICSECG
  83. where ECGCODE='" + str + "' and WorkPoint='" + wp + "'";
  84. sql = string.Format(sql);
  85. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  86. return dt;
  87. }
  88. #endregion
  89. #region 根据不良代码代码查找不良代码id
  90. public static DataTable SelectECId(string str, string wp)
  91. {
  92. string sql = @"select ID
  93. from dbo.ICSEC
  94. where ECODE='" + str + "'and WorkPoint='" + wp + "'";
  95. sql = string.Format(sql);
  96. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  97. return dt;
  98. }
  99. #endregion
  100. #region delete
  101. public static void delete(List<String> guidList)
  102. {
  103. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  104. db.Connection.Open();
  105. db.Transaction = db.Connection.BeginTransaction();
  106. try
  107. {
  108. var lines = db.ICSECSG2ECS.Where(a => guidList.Contains(a.ECSGID) && guidList.Contains(a.ECSID));
  109. db.ICSECSG2ECS.DeleteAllOnSubmit(lines);
  110. db.SubmitChanges();
  111. db.Transaction.Commit();
  112. }
  113. catch (Exception ex)
  114. {
  115. db.Transaction.Rollback();
  116. throw ex;
  117. }
  118. }
  119. #endregion
  120. public static void Save(List<string> ecidList, List<string> ecgidList)
  121. {
  122. try
  123. {
  124. for (int i = 0; i < ecidList.Count; i++)
  125. {
  126. string sql = @"UPDATE dbo.ICSECG2EC SET ECGID='{0}' WHERE ECID='{1}'";
  127. sql = string.Format(sql,ecgidList[i],ecidList[i]);
  128. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. throw ex;
  134. }
  135. }
  136. }
  137. }