using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
///
/// 等级信息数据访问层
///
public class LevelService
{
///
/// 查询所有等级信息数据
///
///
///
///
///
public object GetAll(int pageIndex, out int sumPage, out int totalRecord,string Did,string Cid)
{
string sqlwhere = " Did="+Did+" and IsDel = 0 and Cid="+Cid;
return PageBase.excutePageSql(new Level(), "Level", "Level", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
}
///
/// 新增等级信息
///
/// 等级信息实体
///
public bool AddLevel(Level level)
{
string sql = "insert into Level values(@Lid,@LName,@Profit,@Rebate,@Tax,@Did,@IsDel,@Cid)";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@Lid",level.Lid),
new SqlParameter("@LName",level.LName),
new SqlParameter("@Profit",level.Profit),
new SqlParameter("@Rebate",level.Rebate),
new SqlParameter("@Tax",level.Tax),
new SqlParameter("@Did",level.Did),
new SqlParameter("@IsDel",level.IsDel),
new SqlParameter("@Cid",level.Cid)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 根据编号查询实体
///
///
///
public Level GetSetDataByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from Level where Id = @id and IsDel = 0", new SqlParameter("@id", id));
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
private Level excuteType(string sql, SqlParameter param)
{
//查询结果放入对象集合
List LevelList = excuteSql(sql, param);
//判断集合是否为空
if (LevelList == null || LevelList.Count == 0)
//返回null
return null;
//返回单个对象
return LevelList[0];
}
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new Level(), "Level", sql, CommandType.Text, param);
}
///
/// 根据id修改level表数据
///
///
///
public bool EditLevel(Level level)
{
string sql = "update Level set Lid = @Lid ,LName = @LName ,Profit = @Profit,Rebate = @Rebate,Tax = @Tax,Did = @Did,Cid=@Cid where Id = @Id";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@Lid",level.Lid),
new SqlParameter("@LName",level.LName),
new SqlParameter("@Profit",level.Profit),
new SqlParameter("@Rebate",level.Rebate),
new SqlParameter("@Tax",level.Tax),
new SqlParameter("@Did",level.Did),
new SqlParameter("@IsDel",level.IsDel),
new SqlParameter("@Id",level.Id),
new SqlParameter("@Cid",level.Cid)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除
///
///
///
public bool DelSetData(int id)
{
if (SqlHelper.ExecuteNonQuery("update Level set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
return true;
return false;
}
///
/// 根据航空公司id和等级id查询等级信息
///
///
///
public Level GetOfferByLid(int Lid,int Cid)
{
//调用获取单个对象的方法
return excuteType("select * from Level where Lid = @Lid and Cid="+Cid+" and IsDel = 0", new SqlParameter("@Lid", Lid));
}
}
}