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 CompetenceService
{
///
/// 查询所有
///
/// sql语句
/// 可变参数数组
/// 返回集合
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new Competence(), "Competence", sql, CommandType.Text, param);
}
///
/// 获取单个对象
///
/// sql语句
/// 可变参数数组
/// 返回空或者单个对象
Competence excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List cList = excuteSql(sql, param);
//判断集合是否为空
if (cList == null || cList.Count == 0)
//返回null
return null;
//返回单个对象
return cList[0];
}
///
/// 根据编号查询对象信息
///
/// 对象编号
/// 返回空或者单个对象信息
public Competence GetCompetenceByID(int id)
{
//调用获取单个对象的方法
return excuteType("select * from Competence where Id = @id", new SqlParameter("@id", id));
}
///
/// 查询所有
///
///
///
public List GetAll(int Stable)
{
return excuteSql("select * from Competence where STable = @STable", new SqlParameter("@STable", Stable));
}
///
/// 查询单个对象
///
///
///
public Competence GetAll(int uid,int sid ,int Stable)
{
return excuteType("select * from Competence where UId = @UId and SId = @SId and STable = @STable", new SqlParameter("@UId", uid),new SqlParameter("@SId", sid),new SqlParameter("@STable", Stable));
}
///
/// 增加
///
///
public bool AddCompetence(Competence c)
{
string sql = "insert into Competence values(@Uid,@Sid,@STable)";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@Uid",c.Uid),
new SqlParameter("@Sid",c.Sid),
new SqlParameter("@STable",c.STable)
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
///
/// 删除用户对应页面权限
///
///
///
public bool DelCompetence(int uid, int STable)
{
if (SqlHelper.ExecuteNonQuery("delete Competence where Uid =@Uid and STable = @STable", CommandType.Text, new SqlParameter("@Uid", uid), new SqlParameter("@STable",STable)) > 0)
return true;
return false;
}
///
/// 删除用户对应页面权限
///
///
///
///
public bool DelCompetenceBySid(int sid,int STable)
{
if (SqlHelper.ExecuteNonQuery("delete Competence where Sid =@Sid and STable = @STable", CommandType.Text, new SqlParameter("@Sid", sid), new SqlParameter("@STable",STable)) > 0)
return true;
return false;
}
///
/// 删除用户对应页面权限
///
///
///
///
public bool DelCompetenceByUIdAndSIdAndSTable(int uid,int sid,int stable)
{
if (SqlHelper.ExecuteNonQuery("delete Competence where UId =@UId and SId = @SId and STable=@STable", CommandType.Text, new SqlParameter("@UId", uid), new SqlParameter("@SId", sid), new SqlParameter("@STable", stable)) > 0)
return true;
return false;
}
}
}