SystemFunctionService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 SystemFunctionService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<SystemFunction> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<SystemFunction>.excuteSql(new SystemFunction(), "SystemFunction", 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. SystemFunction excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<SystemFunction> systemFunctionList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (systemFunctionList == null || systemFunctionList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return systemFunctionList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public SystemFunction GetSystemFunctionByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from SystemFunction where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 查询全部
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<SystemFunction> GetAll()
  57. {
  58. return excuteSql("select * from SystemFunction order by Id asc");
  59. }
  60. /// <summary>
  61. /// 查询全部
  62. /// </summary>
  63. /// <param name="IsEnable"></param>
  64. /// <returns></returns>
  65. public List<SystemFunction> GetAll(int isEnable)
  66. {
  67. return excuteSql("select * from SystemFunction where IsEnable = @isEnable order by Id asc", new SqlParameter("@isEnable", isEnable));
  68. }
  69. /// <summary>
  70. /// 新增
  71. /// </summary>
  72. /// <param name="sdt">对象</param>
  73. public bool AddSystemFunction(SystemFunction sf)
  74. {
  75. string sql = "insert into SystemFunction values(@Name,@Code,@Remark,@IsEnable)";
  76. SqlParameter[] parameter = new SqlParameter[]{
  77. new SqlParameter("@Name",sf.Name),
  78. new SqlParameter("@Code",sf.Code),
  79. new SqlParameter("@Remark",sf.Remark),
  80. new SqlParameter("@IsEnable",sf.IsEnable)
  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="sdt"></param>
  90. /// <returns></returns>
  91. public bool EditSystemFunction(SystemFunction sf)
  92. {
  93. string sql = "update SystemFunction set Name = @Name,Code = @Code,Remark = @Remark,IsEnable = @IsEnable where Id = @Id";
  94. SqlParameter[] parameter = new SqlParameter[] {
  95. new SqlParameter("@Name",sf.Name),
  96. new SqlParameter("@Code",sf.Code),
  97. new SqlParameter("@Remark",sf.Remark),
  98. new SqlParameter("@IsEnable",sf.IsEnable),
  99. new SqlParameter("@Id",sf.Id)
  100. };
  101. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  102. return true;
  103. return false;
  104. }
  105. /// <summary>
  106. /// 更新状态
  107. /// </summary>
  108. /// <param name="isEnable"></param>
  109. /// <param name="id"></param>
  110. /// <returns></returns>
  111. public bool UpdateState(int isEnable, int id)
  112. {
  113. if (SqlHelper.ExecuteNonQuery("update SystemFunction set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
  114. return true;
  115. return false;
  116. }
  117. }
  118. }