GroupsTaskAssignmentService.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 团任务配置数据访问类
  12. /// </summary>
  13. public class GroupsTaskAssignmentService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<GroupsTaskAssignment> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<GroupsTaskAssignment>.excuteSql(new GroupsTaskAssignment(), "GroupsTaskAssignment", sql, CommandType.Text, param);
  24. }
  25. /// <summary>
  26. /// 获取单个对象
  27. /// </summary>
  28. /// <param name="sql">sql语句</param>
  29. /// <param name="param">可变参数数组</param>
  30. /// <returns>返回空或者单个对象</returns>
  31. GroupsTaskAssignment excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<GroupsTaskAssignment> gtaList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (gtaList == null || gtaList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return gtaList[0];
  41. }
  42. /// <summary>
  43. /// 根据Id查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public GroupsTaskAssignment GetGroupsTaskAssignmentByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from GroupsTaskAssignment where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 根据diid和ctid查询所有
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<GroupsTaskAssignment> GetAll(string DIId, string CTId)
  57. {
  58. return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId and CTId = @CTId", new SqlParameter("@DIId", DIId), new SqlParameter("@CTId", CTId));
  59. }
  60. /// <summary>
  61. /// 根据diid查询所有
  62. /// </summary>
  63. /// <returns></returns>
  64. public List<GroupsTaskAssignment> GetByDiid(string DIId)
  65. {
  66. return excuteSql("select * from GroupsTaskAssignment where DIId = @DIId", new SqlParameter("@DIId", DIId));
  67. }
  68. /// <summary>
  69. /// 根据ctid查询所有
  70. /// </summary>
  71. /// <returns></returns>
  72. public List<GroupsTaskAssignment> GetAllByCTId(string CTId)
  73. {
  74. return excuteSql("select * from GroupsTaskAssignment where CTId = @CTId", new SqlParameter("@CTId", CTId));
  75. }
  76. /// <summary>
  77. /// 根据uid和ctid查询所有
  78. /// </summary>
  79. /// <returns></returns>
  80. public List<GroupsTaskAssignment> GetAllByUIdAndCTId(string UId, string CTId)
  81. {
  82. return excuteSql("select * from GroupsTaskAssignment where UId = @UId and CTId = @CTId", new SqlParameter("@UId", UId), new SqlParameter("@CTId", CTId));
  83. }
  84. /// <summary>
  85. /// 批量添加方法
  86. /// </summary>
  87. /// <param name="list"></param>
  88. /// <returns></returns>
  89. public bool AddGroupsTaskAssignment(List<GroupsTaskAssignment> list)
  90. {
  91. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  92. cmd.Connection.Open();
  93. SqlTransaction trans = cmd.Connection.BeginTransaction();
  94. try
  95. {
  96. foreach (GroupsTaskAssignment gta in list)
  97. {
  98. cmd.CommandText = "insert into GroupsTaskAssignment values(" + gta.DIId + "," + gta.CTId + "," + gta.UId + "," + gta.IsEnable + "," + gta.Operators + ",'" + gta.OperatorsDate + "')";
  99. cmd.Transaction = trans;
  100. cmd.ExecuteNonQuery();
  101. }
  102. trans.Commit();
  103. cmd.Connection.Close();
  104. return true;
  105. }
  106. catch
  107. {
  108. trans.Rollback();
  109. cmd.Connection.Close();
  110. return false;
  111. }
  112. }
  113. /// <summary>
  114. /// 删除用户对应页面权限
  115. /// </summary>
  116. /// <param name="id"></param>
  117. /// <returns></returns>
  118. public bool DelGroupsTaskAssignment(int DIId, int CTId, int UId)
  119. {
  120. 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)
  121. return true;
  122. return false;
  123. }
  124. }
  125. }