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