using System; using System.Collections.Generic; using System.Linq; using System.Text; using Models; using System.Data.SqlClient; using System.Data; namespace DAL { /// /// 系统菜单数据访问类 /// public class SystemMenuService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new SystemMenu(), "SystemMenu", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 SystemMenu excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List SystemMenuList = excuteSql(sql, param); //判断集合是否为空 if (SystemMenuList == null || SystemMenuList.Count == 0) //返回null return null; //返回单个对象 return SystemMenuList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public SystemMenu GetSystemMenuByID(int id) { //调用获取单个对象的方法 return excuteType("select * from SystemMenu where Id = @id", new SqlParameter("@id", id)); } /// /// 根据条件获取全部 /// /// /// public List 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)); } /// /// 根据条件获取全部 /// /// /// public SystemMenu GetSystemMenuByPageName(string pageName) { string sql = "select * from SystemMenu where PageName = @PageName"; return excuteType(sql, new SqlParameter("@PageName", pageName)); } /// /// 根据条件获取全部 /// /// /// public List 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)); } /// /// 新增 /// /// 对象 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; } /// /// 编辑 /// /// /// 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; } /// /// 更新状态 /// /// /// /// 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; } } }