using System; using System.Collections.Generic; using System.Linq; using System.Text; using Models; using System.Data.SqlClient; using System.Data; namespace DAL { /// /// 团任务配置数据访问类 /// public class GroupsTaskAssignmentService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new GroupsTaskAssignment(), "GroupsTaskAssignment", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 GroupsTaskAssignment excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List gtaList = excuteSql(sql, param); //判断集合是否为空 if (gtaList == null || gtaList.Count == 0) //返回null return null; //返回单个对象 return gtaList[0]; } /// /// 根据Id查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public GroupsTaskAssignment GetGroupsTaskAssignmentByID(int id) { //调用获取单个对象的方法 return excuteType("select * from GroupsTaskAssignment where Id = @id", new SqlParameter("@id", id)); } /// /// 根据diid和ctid查询所有 /// /// public List GetAll(string DIId, string CTId) { return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId and CTId = @CTId", new SqlParameter("@DIId", DIId), new SqlParameter("@CTId", CTId)); } /// /// 根据diid查询所有 /// /// public List GetByDiid(string DIId) { return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId", new SqlParameter("@DIId", DIId)); } /// /// 根据ctid查询所有 /// /// public List GetAllByCTId(string CTId) { return excuteSql("select * from GroupsTaskAssignment where CTId = @CTId", new SqlParameter("@CTId", CTId)); } /// /// 根据uid和ctid查询所有 /// /// public List GetAllByUIdAndCTId(string UId, string CTId) { return excuteSql("select * from GroupsTaskAssignment where UId = @UId and CTId = @CTId", new SqlParameter("@UId", UId), new SqlParameter("@CTId", CTId)); } /// /// 批量添加方法 /// /// /// public bool AddGroupsTaskAssignment(List list) { SqlCommand cmd = SqlHelper.createCon().CreateCommand(); cmd.Connection.Open(); SqlTransaction trans = cmd.Connection.BeginTransaction(); try { foreach (GroupsTaskAssignment gta in list) { cmd.CommandText = "insert into GroupsTaskAssignment values(" + gta.DIId + "," + gta.CTId + "," + gta.UId + "," + gta.IsEnable + "," + gta.Operators + ",'" + gta.OperatorsDate + "')"; cmd.Transaction = trans; cmd.ExecuteNonQuery(); } trans.Commit(); cmd.Connection.Close(); return true; } catch { trans.Rollback(); cmd.Connection.Close(); return false; } } /// /// 删除用户对应页面权限 /// /// /// public bool DelGroupsTaskAssignment(int DIId, int CTId, int UId) { if (SqlHelper.ExecuteNonQuery("delete GroupsTaskAssignment where DIId = @DIId and CTId = @CTId and UId = @UId", CommandType.Text, new SqlParameter("@DIId", DIId), new SqlParameter("@CTId", CTId), new SqlParameter("@UId", UId)) > 0) return true; return false; } } }