123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 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 SetDataService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- public List<SetData> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<SetData>.excuteSql(new SetData(), "SetData", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- SetData excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<SetData> setDataList = excuteSql(sql, param);
- //判断集合是否为空
- if (setDataList == null || setDataList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return setDataList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public SetData GetSetDataByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SetData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// c按字查询 电码
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public SetData GetSetDataByNameCode(string NameCode)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SetData where Name = @NameCode and STid = 47 and IsDel = 0", new SqlParameter("@NameCode", NameCode));
- }
- /// <summary>
- /// 获取信用卡账单类型费用
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetAllTocreditCard()
- {
- return excuteSql("select * from setData where sTid=16 and isdel = 0");
- }
- /// <summary>
- /// 获取全部
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetAll()
- {
- return excuteSql("select * from SetData where IsDel = 0");
- }
- /// <summary>
- /// 根据name范围获取数据
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetByLvl(string lvl)
- {
- return excuteSql("select * from SetData where IsDel = 0 and STid=42 and Name in (" + lvl + ")");
- }
- /// <summary>
- /// 根据对应外键获取数据
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetAll(int STid)
- {
- return excuteSql("select * from SetData where IsDel = 0 And STid = @STid and Name <> '其他款项' order by Name asc", new SqlParameter("@STid", STid));
- }
- /// <summary>
- /// 根据对应外键获取数据
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetAllOrderByRemark(int STid)
- {
- return excuteSql("select * from SetData where IsDel = 0 And STid = @STid and Name <> '其他款项' order by Remark", new SqlParameter("@STid", STid));
- }
- /// <summary>
- /// 根据条件查询条件获取 - 分页
- /// </summary>
- /// <param name="pageIndex"></param>
- /// <param name="sumPage"></param>
- /// <param name="totalRecord"></param>
- /// <param name="dataType"></param>
- /// <returns></returns>
- public List<SetData> GetAll(int pageIndex, out int sumPage, out int totalRecord, string dataType, string name)
- {
- string sqlwhere = "STid = " + dataType + " and IsDel = 0";
- if (!string.IsNullOrEmpty(name))
- sqlwhere += " and Name like '%" + name + "%'";
- return PageBase<SetData>.excutePageSql(new SetData(), "SetData", "SetData", "*", "id desc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="sdt">对象</param>
- public bool AddSetData(SetData sd)
- {
- if (SqlHelper.ExecuteNonQuery("insert into SetData values(@Name,@Remark,@STid,@IsDel)", CommandType.Text, new SqlParameter("@Name", sd.Name), new SqlParameter("@Remark", sd.Remark), new SqlParameter("@STid", sd.STid), new SqlParameter("@IsDel", sd.IsDel)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 更新状态
- /// </summary>
- /// <param name="isEnable"></param>
- /// <returns></returns>
- public bool UpdateState(int isEnable, int id)
- {
- if (SqlHelper.ExecuteNonQuery("update SetData 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 EditSetData(SetData sd)
- {
- if (SqlHelper.ExecuteNonQuery("update SetData set Name = @Name ,Remark = @Remark ,STid = @STid where Id = @Id", CommandType.Text, new SqlParameter("@Name", sd.Name), new SqlParameter("@Remark", sd.Remark), new SqlParameter("STid", sd.STid), new SqlParameter("@Id", sd.Id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelSetData(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update SetData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 根据名称查询
- /// </summary>
- /// <param name="p"></param>
- /// <returns></returns>
- public SetData GetAll(string Name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from SetData where Name = @Name and IsDel = 0", new SqlParameter("@Name", Name));
- }
-
- /// <summary>
- /// 根据多个STid查询多条数据
- /// </summary>
- /// <returns></returns>
- public List<SetData> GetAllBySTids(string[] STids)
- {
- string strId = "";
- if (STids.Length > 0)
- for (int i = 0; i < STids.Length; i++)
- if (i == STids.Length - 1) strId += STids[i].ToString();
- else strId += STids[i].ToString() + ",";
- return excuteSql("select * from SetData where IsDel = 0 and STid IN (" + strId + ");");
- }
- }
- }
|