123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- namespace DAL
- {
- /// <summary>
- /// 团任务配置数据访问类
- /// </summary>
- public class GroupsTaskAssignmentService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<GroupsTaskAssignment> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<GroupsTaskAssignment>.excuteSql(new GroupsTaskAssignment(), "GroupsTaskAssignment", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- GroupsTaskAssignment excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<GroupsTaskAssignment> gtaList = excuteSql(sql, param);
- //判断集合是否为空
- if (gtaList == null || gtaList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return gtaList[0];
- }
- /// <summary>
- /// 根据Id查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public GroupsTaskAssignment GetGroupsTaskAssignmentByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from GroupsTaskAssignment where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据diid和ctid查询所有
- /// </summary>
- /// <returns></returns>
- public List<GroupsTaskAssignment> GetAll(string DIId, string CTId)
- {
- return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId and CTId = @CTId", new SqlParameter("@DIId", DIId), new SqlParameter("@CTId", CTId));
- }
- /// <summary>
- /// 根据diid查询所有
- /// </summary>
- /// <returns></returns>
- public List<GroupsTaskAssignment> GetByDiid(string DIId)
- {
- return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId", new SqlParameter("@DIId", DIId));
- }
- /// <summary>
- /// 根据ctid查询所有
- /// </summary>
- /// <returns></returns>
- public List<GroupsTaskAssignment> GetAllByCTId(string CTId)
- {
- return excuteSql("select * from GroupsTaskAssignment where CTId = @CTId", new SqlParameter("@CTId", CTId));
- }
- /// <summary>
- /// 根据uid和ctid查询所有
- /// </summary>
- /// <returns></returns>
- public List<GroupsTaskAssignment> GetAllByUIdAndCTId(string UId, string CTId)
- {
- return excuteSql("select * from GroupsTaskAssignment where UId = @UId and CTId = @CTId", new SqlParameter("@UId", UId), new SqlParameter("@CTId", CTId));
- }
- /// <summary>
- /// 批量添加方法
- /// </summary>
- /// <param name="list"></param>
- /// <returns></returns>
- public bool AddGroupsTaskAssignment(List<GroupsTaskAssignment> 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;
- }
- }
- /// <summary>
- /// 删除用户对应页面权限
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
|