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

186 lines
6.4 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 ICSShifTypeDAL
  13. {
  14. #region 新增和修改
  15. public static void Add(List<FormICSShifTypeUIModel> typeInfoList, string dsconn)
  16. {
  17. FramDataContext db = new FramDataContext(dsconn);
  18. db.Connection.Open();
  19. db.Transaction = db.Connection.BeginTransaction();
  20. try
  21. {
  22. foreach (FormICSShifTypeUIModel typeinfo in typeInfoList)
  23. {
  24. bool isNew = false;
  25. var line = db.ICSSHIFTTYPE.SingleOrDefault(a => a.ID == typeinfo.ID);
  26. if (line == null)
  27. {
  28. isNew = true;
  29. line = new ICSSHIFTTYPE();
  30. line.ID = AppConfig.GetGuid();
  31. line.SHIFTTYPECODE = typeinfo.SHIFTTYPECODE;
  32. }
  33. line.SHIFTTYPEDESC = typeinfo.SHIFTTYPEDESC;
  34. line.EFFDATE = Convert.ToDateTime(typeinfo.EFFDATE);
  35. line.IVLDATE = Convert.ToDateTime(typeinfo.IVLDATE);
  36. line.MUSER = AppConfig.UserId;
  37. line.MUSERName = AppConfig.UserName;
  38. line.MTIME = DateTime.Now;
  39. line.WorkPoint = AppConfig.WorkPointCode;
  40. if (isNew)
  41. db.ICSSHIFTTYPE.InsertOnSubmit(line);
  42. db.SubmitChanges();
  43. }
  44. db.Transaction.Commit();
  45. }
  46. catch (Exception ex)
  47. {
  48. db.Transaction.Rollback();
  49. throw ex;
  50. }
  51. }
  52. #endregion
  53. #region 通过班制id查询
  54. public static List<FormICSShifTypeUIModel> SearchTypeInfoByCode(string typeID, string dsconn)
  55. {
  56. List<FormICSShifTypeUIModel> returntype = new List<FormICSShifTypeUIModel>();
  57. string sql = @"select ID,SHIFTTYPECODE,SHIFTTYPEDESC,EFFDATE,IVLDATE
  58. from ICSSHIFTTYPE
  59. where ID='{0}'";
  60. sql = string.Format(sql, typeID);
  61. DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
  62. foreach (DataRow dr in dt.Rows)
  63. {
  64. FormICSShifTypeUIModel returnInfo = new FormICSShifTypeUIModel();
  65. returnInfo.ID = dr["ID"].ToString();
  66. returnInfo.SHIFTTYPECODE = dr["SHIFTTYPECODE"].ToString();
  67. returnInfo.SHIFTTYPEDESC = dr["SHIFTTYPEDESC"].ToString();
  68. returnInfo.EFFDATE = Convert.ToDateTime(dr["EFFDATE"].ToString());
  69. returnInfo.IVLDATE = Convert.ToDateTime(dr["IVLDATE"].ToString());
  70. returntype.Add(returnInfo);
  71. }
  72. return returntype;
  73. }
  74. #endregion
  75. #region 班制代码是否存在
  76. public static bool IsIncluding(string SHIFTTYPECODE, string dsconn)
  77. {
  78. FramDataContext db = new FramDataContext(dsconn);
  79. db.Connection.Open();
  80. db.Transaction = db.Connection.BeginTransaction();
  81. try
  82. {
  83. var line = db.ICSSHIFTTYPE.SingleOrDefault(a => a.SHIFTTYPECODE == SHIFTTYPECODE);
  84. if (line == null)
  85. return true;
  86. else
  87. return false;
  88. }
  89. catch (Exception ex)
  90. {
  91. db.Transaction.Rollback();
  92. throw ex;
  93. }
  94. }
  95. #endregion
  96. #region 判断是否在班次中
  97. public static bool IncludingShift(List<string> idList, string dsconn)
  98. {
  99. FramDataContext db = new FramDataContext(dsconn);
  100. db.Connection.Open();
  101. db.Transaction = db.Connection.BeginTransaction();
  102. try
  103. {
  104. bool flag = false;
  105. var lines = db.ICSSHIFT.Where(a => idList.Contains(a.SHIFTTYPEID));
  106. if (lines.Count() != 0)
  107. flag = true;
  108. return flag;
  109. //bool flag=false;
  110. //foreach (string test in idList)
  111. //{
  112. // var lines = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTTYPEID == test);
  113. // if (lines != null)
  114. // flag = true;
  115. //}
  116. //return flag;
  117. //var lines = db.ICSSHIFT.Where(a => idList.Contains(a.SHIFTTYPEID));
  118. //if (lines == null)
  119. // return true;
  120. //else
  121. // return false;
  122. }
  123. catch (Exception ex)
  124. {
  125. //db.Transaction.Rollback();
  126. throw ex;
  127. }
  128. }
  129. #endregion
  130. #region 删除
  131. public static void deleteInfo(List<string> idList, string dsconn)
  132. {
  133. FramDataContext db = new FramDataContext(dsconn);
  134. db.Connection.Open();
  135. db.Transaction = db.Connection.BeginTransaction();
  136. try
  137. {
  138. var lines = db.ICSSHIFTTYPE.Where(a => idList.Contains(a.ID));
  139. db.ICSSHIFTTYPE.DeleteAllOnSubmit(lines);
  140. db.SubmitChanges();
  141. db.Transaction.Commit();
  142. }
  143. catch (Exception ex)
  144. {
  145. db.Transaction.Rollback();
  146. throw ex;
  147. }
  148. }
  149. #endregion
  150. #region 查询最大的班制代码
  151. public static string SearchMaxCode(string dsconn)
  152. {
  153. FramDataContext db = new FramDataContext(dsconn);
  154. db.Connection.Open();
  155. db.Transaction = db.Connection.BeginTransaction();
  156. try
  157. {
  158. string lines = db.ICSSHIFTTYPE.Max(a=>a.SHIFTTYPECODE);
  159. return lines;
  160. //db.ICSSHIFTTYPE.DeleteAllOnSubmit(lines);
  161. //db.SubmitChanges();
  162. //db.Transaction.Commit();
  163. }
  164. catch (Exception ex)
  165. {
  166. db.Transaction.Rollback();
  167. throw ex;
  168. }
  169. }
  170. #endregion
  171. }
  172. }