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 SystemFunctionService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new SystemFunction(), "SystemFunction", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 SystemFunction excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List systemFunctionList = excuteSql(sql, param); //判断集合是否为空 if (systemFunctionList == null || systemFunctionList.Count == 0) //返回null return null; //返回单个对象 return systemFunctionList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public SystemFunction GetSystemFunctionByID(int id) { //调用获取单个对象的方法 return excuteType("select * from SystemFunction where Id = @id", new SqlParameter("@id", id)); } /// /// 查询全部 /// /// public List GetAll() { return excuteSql("select * from SystemFunction order by Id asc"); } /// /// 查询全部 /// /// /// public List GetAll(int isEnable) { return excuteSql("select * from SystemFunction where IsEnable = @isEnable order by Id asc", new SqlParameter("@isEnable", isEnable)); } /// /// 新增 /// /// 对象 public bool AddSystemFunction(SystemFunction sf) { string sql = "insert into SystemFunction values(@Name,@Code,@Remark,@IsEnable)"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Name",sf.Name), new SqlParameter("@Code",sf.Code), new SqlParameter("@Remark",sf.Remark), new SqlParameter("@IsEnable",sf.IsEnable) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 编辑 /// /// /// public bool EditSystemFunction(SystemFunction sf) { string sql = "update SystemFunction set Name = @Name,Code = @Code,Remark = @Remark,IsEnable = @IsEnable where Id = @Id"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@Name",sf.Name), new SqlParameter("@Code",sf.Code), new SqlParameter("@Remark",sf.Remark), new SqlParameter("@IsEnable",sf.IsEnable), new SqlParameter("@Id",sf.Id) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 更新状态 /// /// /// /// public bool UpdateState(int isEnable, int id) { if (SqlHelper.ExecuteNonQuery("update SystemFunction set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0) return true; return false; } } }