123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- 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 SystemMenuService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<SystemMenu> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<SystemMenu>.excuteSql(new SystemMenu(), "SystemMenu", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- SystemMenu excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<SystemMenu> SystemMenuList = excuteSql(sql, param);
- //判断集合是否为空
- if (SystemMenuList == null || SystemMenuList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return SystemMenuList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public SystemMenu GetSystemMenuByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SystemMenu where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据条件获取全部
- /// </summary>
- /// <param name="mid"></param>
- /// <returns></returns>
- public List<SystemMenu> GetAll(string mid)
- {
- string sql = "select * from SystemMenu where IsDel = 0";
- if (mid != "全部")
- sql += " and Mid = @Mid";
- sql += " order by id asc";
- return excuteSql(sql, new SqlParameter("@Mid", mid));
- }
- /// <summary>
- /// 根据条件获取全部
- /// </summary>
- /// <param name="pageName"></param>
- /// <returns></returns>
- public SystemMenu GetSystemMenuByPageName(string pageName)
- {
- string sql = "select * from SystemMenu where PageName = @PageName";
- return excuteType(sql, new SqlParameter("@PageName", pageName));
- }
- /// <summary>
- /// 根据条件获取全部
- /// </summary>
- /// <param name="mid"></param>
- /// <returns></returns>
- public List<SystemMenu> GetAll(string mid, int isEnable)
- {
- string sql = "select * from SystemMenu where IsDel = 0 and IsEnable = @IsEnable";
- if (mid != "全部")
- sql += " and Mid = @Mid";
- sql += " order by id asc";
- return excuteSql(sql, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Mid", mid));
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="sdt">对象</param>
- public bool AddSystemMenu(SystemMenu sm)
- {
- string sql = "insert into SystemMenu values(@Name,@ShowName,@PageName,@Mnid,@Ico,@Width,@Height,@IsEnable,@Mid,@IsShow,@IsDel)";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@Name",sm.Name),
- new SqlParameter("@ShowName",sm.ShowName),
- new SqlParameter("@PageName",sm.PageName),
- new SqlParameter("@Mnid",sm.Mnid),
- new SqlParameter("@Ico",sm.Ico),
- new SqlParameter("@Width",sm.Width),
- new SqlParameter("@Height",sm.Height),
- new SqlParameter("@IsEnable",sm.IsEnable),
- new SqlParameter("@Mid",sm.Mid),
- new SqlParameter("@IsShow",sm.IsShow),
- new SqlParameter("@IsDel",sm.IsDel)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- public bool EditSystemMenu(SystemMenu sm)
- {
- 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";
- SqlParameter[] parameter = new SqlParameter[] {
- new SqlParameter("@Name",sm.Name),
- new SqlParameter("@ShowName",sm.ShowName),
- new SqlParameter("@PageName",sm.PageName),
- new SqlParameter("@Mnid",sm.Mnid),
- new SqlParameter("@Ico",sm.Ico),
- new SqlParameter("@Width",sm.Width),
- new SqlParameter("@Height",sm.Height),
- new SqlParameter("@IsEnable",sm.IsEnable),
- new SqlParameter("@Mid",sm.Mid),
- new SqlParameter("@IsShow",sm.IsShow),
- new SqlParameter("@Id",sm.Id)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 更新状态
- /// </summary>
- /// <param name="isEnable"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool UpdateState(int isEnable, int id)
- {
- if (SqlHelper.ExecuteNonQuery("update SystemMenu set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- }
- }
|