📄 topicsaccess.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using ExamSystem.Common.Objects;
using ExamSystem.Common.DB;
using ExamSystem.Common;
namespace ExamSystem.DataAccess.ExamAccess
{
/// <summary>
/// TopicsAccess 的摘要说明。
/// </summary>
public class TopicsAccess
{
DataBaseOperate oper;
/// <summary>
/// 实例化班级数据访问对象
/// </summary>
/// <param name="dataBaseOperate">数据连接对象</param>
public TopicsAccess(DataBaseOperate dataBaseOperate)
{
oper=dataBaseOperate;
}
/// <summary>
/// 用or方式查找
/// </summary>
/// <param name="tops">要查找的题目对象</param>
/// <param name="type">查找类型</param>
/// <returns></returns>
public DataSet selectTopicsByOr(Topics tops,SearchType type)
{
string sql="select TopicID,TopicDetil,TopicAnwser,Anwsers,Cate,TopicLevel from Topics where isDel=0";
ParamList list=new ParamList();
if(tops.TopicsID>=0)
{
sql+=" or TopicID=@TopicID";
list.AddNew("@TopicID",SqlDbType.Int,tops.TopicsID);
}
if(tops.TopicsDetil!="")
{
if(type==SearchType.Accurate)
{
sql+=" or TopicDetil=@TopicDetil";
}
else
{
sql+=" or TopicDetil like '%'+@TopicDetil+'%'";
}
list.AddNew("@TopicDetil",SqlDbType.VarChar,tops.TopicsDetil);
}
if(tops.Cate>=0)
{
sql+=" or Cate=@Cate";
list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
}
if(tops.TopicsLevel>=0)
{
sql+=" or TopicLevel=@TopicLevel";
list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
}
DataSet ds=oper.Query(sql,"Topics",list);
return ds;
}
// public void insertTops(Topics tops)
// {
// string sql="insert into Topics(TopicDetil,TopicAnwser,Anwsers,Grade,Cate,TopicLevel) values(@TopicDetil,@TopicAnwser,@Anwsers,@Grade,@Cate,@TopicLevel)";
// ParamList list=new ParamList();
// list.AddNew("@TopicDetil",SqlDbType.NVarChar,tops.TopicsDetil);
// list.AddNew("@TopicAnwser",SqlDbType.VarChar,tops.TopicsAnwser);
// list.AddNew("@Anwsers",SqlDbType.Int,tops.Anwsers);
// list.AddNew("@Grade",SqlDbType.Int,tops.Grade);
// list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
// list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
// oper.Execute(sql,list);
// }
/// <summary>
/// 用and方式查找
/// </summary>
/// <param name="tops">要查找的题目对象</param>
/// <param name="type">查找类型</param>
/// <returns></returns>
public DataSet selectTopicsByAnd(Topics tops,SearchType type)
{
string sql="select TopicID,TopicDetil,TopicAnwser,Anwsers,Cate,TopicLevel from Topics where isDel=0";
ParamList list=new ParamList();
if(tops.TopicsID>=0)
{
sql+=" and TopicID=@TopicID";
list.AddNew("@TopicID",SqlDbType.Int,tops.TopicsID);
}
if(tops.TopicsDetil!="")
{
if(type==SearchType.Accurate)
{
sql+=" and TopicDetil=@TopicDetil";
}
else
{
sql+=" and TopicDetil like '%'+@TopicDetil+'%'";
}
list.AddNew("@TopicDetil",SqlDbType.VarChar,tops.TopicsDetil);
}
if(tops.Cate>=0)
{
sql+=" and Cate=@Cate";
list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
}
if(tops.TopicsLevel>=0)
{
sql+=" and TopicLevel=@TopicLevel";
list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
}
DataSet ds=oper.Query(sql,"Topics",list);
return ds;
}
public DataSet selectTopicsID(Class cls)
{
string sql="select TopicID,TopicLevel from Topics,Class where (Topics.Cate in (select CateID from Cate where Cate.GradeID=Class.Grade)) and Topics.isDel=0";
ParamList list=new ParamList();
if(cls.ClassID>=0)
{
sql+=" and Class.ClassID=@ClassID";
list.AddNew("@ClassID",SqlDbType.Int,cls.ClassID);
}
if(cls.ClassName!="")
{
sql+=" and Class.ClassName=@ClassName";
list.AddNew("@ClassName",SqlDbType.Int,cls.ClassName);
}
DataSet ds=oper.Query(sql,"Topics",list);
return ds;
}
public DataSet selectTopicsID(Exam exam)
{
string sql="select TopicID,TopicLevel from Topics,ExamList where ExamList.ExamCate=Topics.Cate and Topics.isDel=0";
ParamList list=new ParamList();
if(exam.ExamID>=0)
{
sql+=" and ExamList.ExamID=@ExamID";
list.AddNew("@ExamID",SqlDbType.Int,exam.ExamID);
}
if(exam.ExamName!="")
{
sql+=" and ExamList.ExamName=@ExamName";
list.AddNew("@ExamName",SqlDbType.VarChar,exam.ExamName);
}
if(exam.ExamClass>=0)
{
sql+=" and ExamList.ExamClass=@ExamClass";
list.AddNew("@ExamClass",SqlDbType.Int,exam.ExamClass);
}
if(exam.ExamCate>=0)
{
sql+=" and ExamList.ExamCate=@ExamCate";
list.AddNew("@ExamCate",SqlDbType.Int,exam.ExamCate);
}
if(exam.IsEnd!=SearchBooleans.NULL)
{
sql+=" and ExamList.isEnd=@isEnd";
list.AddNew("@isEnd",SqlDbType.Bit,(int)exam.IsEnd);
}
DataSet ds=oper.Query(sql,"Exam",list);
return ds;
}
public void insertTops(Topics tops)
{
string sql="insert into Topics(TopicDetil,TopicAnwser,Anwsers,Cate,TopicLevel) values(@TopicDetil,@TopicAnwser,@Anwsers,@Cate,@TopicLevel)";
ParamList list=new ParamList();
list.AddNew("@TopicDetil",SqlDbType.NVarChar,tops.TopicsDetil);
list.AddNew("@TopicAnwser",SqlDbType.VarChar,tops.TopicsAnwser);
list.AddNew("@Anwsers",SqlDbType.Int,tops.Anwsers);
list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
oper.Execute(sql,list);
}
public void updateTopics(Topics tops)
{
string sql="update Topics set TopicDetil=@TopicDetil,TopicAnwser=@TopicAnwser,Anwsers=@Anwsers,Cate=@Cate,TopicLevel=@TopicLevel where TopicID=@TopicID";
ParamList list=new ParamList();
list.AddNew("@TopicDetil",SqlDbType.NVarChar,tops.TopicsDetil);
list.AddNew("@TopicAnwser",SqlDbType.VarChar,tops.TopicsAnwser);
list.AddNew("@Anwsers",SqlDbType.Int,tops.Anwsers);
list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
list.AddNew("@TopicID",SqlDbType.Int,tops.TopicsID);
oper.Execute(sql,list);
}
public void deleteTopics(Topics tops)
{
string sql="update Topics set isDel=1 where isDel=0";
ParamList list=new ParamList();
if(tops.TopicsID>=0)
{
sql+=" and TopicID=@TopicID";
list.AddNew("@TopicID",SqlDbType.Int,tops.TopicsID);
}
if(tops.TopicsDetil!="")
{
sql+=" and TopicDetil=@TopicDetil";
list.AddNew("@TopicDetil",SqlDbType.VarChar,tops.TopicsDetil);
}
if(tops.Cate>=0)
{
sql+=" and Cate=@Cate";
list.AddNew("@Cate",SqlDbType.Int,tops.Cate);
}
if(tops.TopicsLevel>=0)
{
sql+=" and TopicLevel=@TopicLevel";
list.AddNew("@TopicLevel",SqlDbType.Int,tops.TopicsLevel);
}
oper.Execute(sql,list);
}
public DataSet getTopicByIDs(string ids)
{
string sql="select TopicID,TopicDetil,TopicAnwser,Anwsers,Cate,TopicLevel from Topics where TopicID in("+ids+")";
return oper.Query(sql,"Topics",null);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -