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

209 lines
7.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.AppConfig;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.Linq;
  10. using ICSSoft.Base.Config.DBHelper;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSOQCCKGROUPDAL
  14. {
  15. public static void AddandEdit(ICSOQCCKGROUP MODEL, string Appconstr)
  16. {
  17. FramDataContext db = new FramDataContext(Appconstr);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. bool isNew = false;
  23. var line = db.ICSOQCCKGROUP.SingleOrDefault(a => a.ID == MODEL.ID && a.WorkPoint==MODEL.WorkPoint);
  24. var codes = db.ICSOQCCKGROUP.Where(a => a.CKGROUP == MODEL.CKGROUP && a.WorkPoint == MODEL.WorkPoint && a.ID != MODEL.ID);
  25. if (codes.ToList().Count > 0)
  26. {
  27. throw new Exception("检验项目编码已存在!");
  28. }
  29. if (line == null)
  30. {
  31. isNew = true;
  32. line = new ICSOQCCKGROUP();
  33. line.ID = MODEL.ID;
  34. }
  35. line.CKGROUP = MODEL.CKGROUP;
  36. line.CKGROUPDNAME = MODEL.CKGROUPDNAME;
  37. line.CKGROUPDESC = MODEL.CKGROUPDESC;
  38. line.ISREF = MODEL.ISREF;
  39. line.MUSERName = MODEL.MUSERName;
  40. line.MUSER = MODEL.MUSER;
  41. line.MTIME = MODEL.MTIME;
  42. line.WorkPoint = AppConfig.WorkPointCode;
  43. if (isNew) db.ICSOQCCKGROUP.InsertOnSubmit(line);
  44. db.SubmitChanges();
  45. db.Transaction.Commit();
  46. }
  47. catch (Exception ex)
  48. {
  49. db.Transaction.Rollback();
  50. throw new Exception(ex.Message);
  51. }
  52. }
  53. public static void delete(List<String> guidList)
  54. {
  55. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  56. db.Connection.Open();
  57. db.Transaction = db.Connection.BeginTransaction();
  58. try
  59. {
  60. var lines = db.ICSOQCCKGROUP.Where(a => guidList.Contains(a.ID) && a.WorkPoint == AppConfig.WorkPointCode);
  61. foreach (var item in lines)
  62. {
  63. var list = db.ICSOQCCKLIST.Where(a => a.CKGROUPCode == item.CKGROUP && a.WorkPoint == item.WorkPoint);
  64. if (list != null && list.Count() > 0)
  65. throw new Exception("检验项目编码:" + item.CKGROUP + " 已被引用,不能删除!");
  66. }
  67. db.ICSOQCCKGROUP.DeleteAllOnSubmit(lines);
  68. db.SubmitChanges();
  69. db.Transaction.Commit();
  70. }
  71. catch (Exception ex)
  72. {
  73. db.Transaction.Rollback();
  74. throw ex;
  75. }
  76. }
  77. #region 获取检验方式
  78. public static DataTable SearchData(string dsconn)
  79. {
  80. try
  81. {
  82. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00015' AND WorkPointCode = '{0}' ";
  83. sql = string.Format(sql, AppConfig.WorkPointCode);
  84. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  85. return dt;
  86. }
  87. catch (Exception ex)
  88. {
  89. throw ex;
  90. }
  91. }
  92. public static DataTable SearchData(string EnumText, string dsconn)
  93. {
  94. try
  95. {
  96. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00015' AND EnumText = '{0}' AND WorkPointCode = '{1}' ";
  97. sql = string.Format(sql, EnumText, AppConfig.WorkPointCode);
  98. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  99. return dt;
  100. }
  101. catch (Exception ex)
  102. {
  103. throw ex;
  104. }
  105. }
  106. #endregion
  107. #region 获取检验属性
  108. public static DataTable SearchDataa(string dsconn)
  109. {
  110. try
  111. {
  112. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00016' AND WorkPointCode = '{0}' ";
  113. sql = string.Format(sql, AppConfig.WorkPointCode);
  114. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  115. return dt;
  116. }
  117. catch (Exception ex)
  118. {
  119. throw ex;
  120. }
  121. }
  122. public static DataTable SearchDataa(string EnumText, string dsconn)
  123. {
  124. try
  125. {
  126. string sql = @"SELECT EnumKey, EnumText FROM Sys_EnumValues WHERE 1=1 AND EnumKey = '00016' AND EnumText = '{0}' AND WorkPointCode = '{1}' ";
  127. sql = string.Format(sql, EnumText, AppConfig.WorkPointCode);
  128. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  129. return dt;
  130. }
  131. catch (Exception ex)
  132. {
  133. throw ex;
  134. }
  135. }
  136. #endregion
  137. public static ICSOQCCKGROUP search(string CKGROUP, String Appconstr)
  138. {
  139. FramDataContext db = new FramDataContext(Appconstr);
  140. db.Connection.Open();
  141. db.Transaction = db.Connection.BeginTransaction();
  142. ICSOQCCKGROUP entity = new ICSOQCCKGROUP();
  143. try
  144. {
  145. var line = db.ICSOQCCKGROUP.SingleOrDefault(a => a.CKGROUP == CKGROUP && a.WorkPoint == AppConfig.WorkPointCode);
  146. return (ICSOQCCKGROUP)line;
  147. }
  148. catch (Exception ex)
  149. {
  150. throw new Exception(ex.Message);
  151. }
  152. }
  153. public static string AddList(List<ICSOQCCKGROUP> InfoList, string Appconstr)
  154. {
  155. FramDataContext db = new FramDataContext(Appconstr);
  156. db.Connection.Open();
  157. db.Transaction = db.Connection.BeginTransaction();
  158. try
  159. {
  160. string str = "OK";
  161. foreach (ICSOQCCKGROUP info in InfoList)
  162. {
  163. bool isNew = false;
  164. var line = db.ICSOQCCKGROUP.SingleOrDefault(a => a.CKGROUP == info.CKGROUP && a.WorkPoint == info.WorkPoint);
  165. if (line == null)
  166. {
  167. isNew = true;
  168. line = new ICSOQCCKGROUP();
  169. line.ID = AppConfig.GetGuid();
  170. }
  171. line.CKGROUP = info.CKGROUP;
  172. line.CKGROUPDESC = info.CKGROUPDESC;
  173. line.CKGROUPDNAME = info.CKGROUPDNAME;
  174. line.ISREF = info.ISREF;
  175. line.MUSER = info.MUSER;
  176. line.MUSERName = info.MUSERName;
  177. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
  178. line.WorkPoint = AppConfig.WorkPointCode;
  179. line.EATTRIBUTE1 = null;
  180. if (isNew) db.ICSOQCCKGROUP.InsertOnSubmit(line);
  181. db.SubmitChanges();
  182. }
  183. db.Transaction.Commit();
  184. return str;
  185. }
  186. catch (Exception ex)
  187. {
  188. db.Transaction.Rollback();
  189. throw new Exception(ex.Message);
  190. }
  191. }
  192. }
  193. }