SystemMenuService.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 SystemMenuService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<SystemMenu> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<SystemMenu>.excuteSql(new SystemMenu(), "SystemMenu", 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. SystemMenu excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<SystemMenu> SystemMenuList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (SystemMenuList == null || SystemMenuList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return SystemMenuList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public SystemMenu GetSystemMenuByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from SystemMenu where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 根据条件获取全部
  54. /// </summary>
  55. /// <param name="mid"></param>
  56. /// <returns></returns>
  57. public List<SystemMenu> GetAll(string mid)
  58. {
  59. string sql = "select * from SystemMenu where IsDel = 0";
  60. if (mid != "全部")
  61. sql += " and Mid = @Mid";
  62. sql += " order by id asc";
  63. return excuteSql(sql, new SqlParameter("@Mid", mid));
  64. }
  65. /// <summary>
  66. /// 根据条件获取全部
  67. /// </summary>
  68. /// <param name="pageName"></param>
  69. /// <returns></returns>
  70. public SystemMenu GetSystemMenuByPageName(string pageName)
  71. {
  72. string sql = "select * from SystemMenu where PageName = @PageName";
  73. return excuteType(sql, new SqlParameter("@PageName", pageName));
  74. }
  75. /// <summary>
  76. /// 根据条件获取全部
  77. /// </summary>
  78. /// <param name="mid"></param>
  79. /// <returns></returns>
  80. public List<SystemMenu> GetAll(string mid, int isEnable)
  81. {
  82. string sql = "select * from SystemMenu where IsDel = 0 and IsEnable = @IsEnable";
  83. if (mid != "全部")
  84. sql += " and Mid = @Mid";
  85. sql += " order by id asc";
  86. return excuteSql(sql, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Mid", mid));
  87. }
  88. /// <summary>
  89. /// 新增
  90. /// </summary>
  91. /// <param name="sdt">对象</param>
  92. public bool AddSystemMenu(SystemMenu sm)
  93. {
  94. string sql = "insert into SystemMenu values(@Name,@ShowName,@PageName,@Mnid,@Ico,@Width,@Height,@IsEnable,@Mid,@IsShow,@IsDel)";
  95. SqlParameter[] parameter = new SqlParameter[]{
  96. new SqlParameter("@Name",sm.Name),
  97. new SqlParameter("@ShowName",sm.ShowName),
  98. new SqlParameter("@PageName",sm.PageName),
  99. new SqlParameter("@Mnid",sm.Mnid),
  100. new SqlParameter("@Ico",sm.Ico),
  101. new SqlParameter("@Width",sm.Width),
  102. new SqlParameter("@Height",sm.Height),
  103. new SqlParameter("@IsEnable",sm.IsEnable),
  104. new SqlParameter("@Mid",sm.Mid),
  105. new SqlParameter("@IsShow",sm.IsShow),
  106. new SqlParameter("@IsDel",sm.IsDel)
  107. };
  108. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  109. return true;
  110. return false;
  111. }
  112. /// <summary>
  113. /// 编辑
  114. /// </summary>
  115. /// <param name="sdt"></param>
  116. /// <returns></returns>
  117. public bool EditSystemMenu(SystemMenu sm)
  118. {
  119. string sql = "update SystemMenu set Name = @Name,ShowName = @ShowName,PageName = @PageName,Mnid = @Mnid,Ico = @Ico,Width = @Width,Height = @Height,IsEnable = @IsEnable,Mid = @Mid,IsShow = @IsShow where Id = @Id";
  120. SqlParameter[] parameter = new SqlParameter[] {
  121. new SqlParameter("@Name",sm.Name),
  122. new SqlParameter("@ShowName",sm.ShowName),
  123. new SqlParameter("@PageName",sm.PageName),
  124. new SqlParameter("@Mnid",sm.Mnid),
  125. new SqlParameter("@Ico",sm.Ico),
  126. new SqlParameter("@Width",sm.Width),
  127. new SqlParameter("@Height",sm.Height),
  128. new SqlParameter("@IsEnable",sm.IsEnable),
  129. new SqlParameter("@Mid",sm.Mid),
  130. new SqlParameter("@IsShow",sm.IsShow),
  131. new SqlParameter("@Id",sm.Id)
  132. };
  133. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  134. return true;
  135. return false;
  136. }
  137. /// <summary>
  138. /// 更新状态
  139. /// </summary>
  140. /// <param name="isEnable"></param>
  141. /// <param name="id"></param>
  142. /// <returns></returns>
  143. public bool UpdateState(int isEnable, int id)
  144. {
  145. if (SqlHelper.ExecuteNonQuery("update SystemMenu set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
  146. return true;
  147. return false;
  148. }
  149. }
  150. }