123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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 SetDataTypeService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- public List<SetDataType> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<SetDataType>.excuteSql(new SetDataType(), "SetDataType", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- SetDataType excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<SetDataType> setDataTypeList = excuteSql(sql, param);
- //判断集合是否为空
- if (setDataTypeList == null || setDataTypeList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return setDataTypeList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public SetDataType GetSetDataTypeByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SetDataType where Id = @id", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 根据名称查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public SetDataType GetSetDataTypeByName(string Name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SetDataType where Name = @Name", new SqlParameter("@Name", Name));
- }
- /// <summary>
- /// 获取全部
- /// </summary>
- /// <returns></returns>
- public List<SetDataType> GetAll()
- {
- return excuteSql("select * from SetDataType");
- }
- /// <summary>
- /// 根据多个id查询多条数据
- /// </summary>
- /// <returns></returns>
- public List<SetDataType> GetAllByIds(string[] Ids)
- {
- string strId = "";
- if (Ids.Length > 0)
- for (int i = 0; i < Ids.Length; i++)
- if (i == Ids.Length-1) strId += Ids[i].ToString();
- else strId += Ids[i].ToString() + ",";
- return excuteSql("select * from SetDataType where id IN (" + strId + ");");
- }
- /// <summary>
- /// 获取已启用的数据
- /// </summary>
- /// <returns></returns>
- public List<SetDataType> GetAllByIsEnable()
- {
- return excuteSql("select * from SetDataType where IsEnable = 1");
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="sdt">对象</param>
- public bool AddSetDataType(SetDataType sdt)
- {
- if (SqlHelper.ExecuteNonQuery("insert into SetDataType values(@Name,@IsEnable)", CommandType.Text, new SqlParameter("@Name",sdt.Name),new SqlParameter("@IsEnable",sdt.IsEnable)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 更新状态
- /// </summary>
- /// <param name="isEnable"></param>
- /// <returns></returns>
- public bool UpdateState(int isEnable, int id)
- {
- if (SqlHelper.ExecuteNonQuery("update SetDataType set IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@IsEnable", isEnable), new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- public bool EditSetDataType(SetDataType sdt)
- {
- if (SqlHelper.ExecuteNonQuery("update SetDataType set Name = @Name ,IsEnable = @IsEnable where Id = @Id", CommandType.Text, new SqlParameter("@Name", sdt.Name), new SqlParameter("@IsEnable", sdt.IsEnable), new SqlParameter("@Id",sdt.Id)) > 0)
- return true;
- return false;
- }
- }
- }
|