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