CompetenceService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 CompetenceService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<Competence> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<Competence>.excuteSql(new Competence(), "Competence", 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. Competence excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<Competence> cList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (cList == null || cList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return cList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public Competence GetCompetenceByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from Competence where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 查询所有
  54. /// </summary>
  55. /// <param name="Stable"></param>
  56. /// <returns></returns>
  57. public List<Competence> GetAll(int Stable)
  58. {
  59. return excuteSql("select * from Competence where STable = @STable", new SqlParameter("@STable", Stable));
  60. }
  61. /// <summary>
  62. /// 查询单个对象
  63. /// </summary>
  64. /// <param name="Stable"></param>
  65. /// <returns></returns>
  66. public Competence GetAll(int uid,int sid ,int Stable)
  67. {
  68. return excuteType("select * from Competence where UId = @UId and SId = @SId and STable = @STable", new SqlParameter("@UId", uid),new SqlParameter("@SId", sid),new SqlParameter("@STable", Stable));
  69. }
  70. /// <summary>
  71. /// 增加
  72. /// </summary>
  73. /// <param name="c"></param>
  74. public bool AddCompetence(Competence c)
  75. {
  76. string sql = "insert into Competence values(@Uid,@Sid,@STable)";
  77. SqlParameter[] parameter = new SqlParameter[]{
  78. new SqlParameter("@Uid",c.Uid),
  79. new SqlParameter("@Sid",c.Sid),
  80. new SqlParameter("@STable",c.STable)
  81. };
  82. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  83. return true;
  84. return false;
  85. }
  86. /// <summary>
  87. /// 删除用户对应页面权限
  88. /// </summary>
  89. /// <param name="id"></param>
  90. /// <returns></returns>
  91. public bool DelCompetence(int uid, int STable)
  92. {
  93. if (SqlHelper.ExecuteNonQuery("delete Competence where Uid =@Uid and STable = @STable", CommandType.Text, new SqlParameter("@Uid", uid), new SqlParameter("@STable",STable)) > 0)
  94. return true;
  95. return false;
  96. }
  97. /// <summary>
  98. /// 删除用户对应页面权限
  99. /// </summary>
  100. /// <param name="sid"></param>
  101. /// <param name="STable"></param>
  102. /// <returns></returns>
  103. public bool DelCompetenceBySid(int sid,int STable)
  104. {
  105. if (SqlHelper.ExecuteNonQuery("delete Competence where Sid =@Sid and STable = @STable", CommandType.Text, new SqlParameter("@Sid", sid), new SqlParameter("@STable",STable)) > 0)
  106. return true;
  107. return false;
  108. }
  109. /// <summary>
  110. /// 删除用户对应页面权限
  111. /// </summary>
  112. /// <param name="sid"></param>
  113. /// <param name="STable"></param>
  114. /// <returns></returns>
  115. public bool DelCompetenceByUIdAndSIdAndSTable(int uid,int sid,int stable)
  116. {
  117. if (SqlHelper.ExecuteNonQuery("delete Competence where UId =@UId and SId = @SId and STable=@STable", CommandType.Text, new SqlParameter("@UId", uid), new SqlParameter("@SId", sid), new SqlParameter("@STable", stable)) > 0)
  118. return true;
  119. return false;
  120. }
  121. }
  122. }