using System;
using System.Collections.Generic;
using System.Text;
using System.Data;//
using System.Data.SqlClient;//
public class TestQuestions
{
private SqlHelper s = null;
public TestQuestions()
{
s = new SqlHelper();
}
/// <summary>
/// 插入题目
/// </summary>
/// <param name="questionsclass">问题分类</param>
/// <param name="quesstions">问题题目</param>
/// <param name="answer1">答案1(正确答案)</param>
/// <param name="answer2">答案2</param>
/// <param name="answer3">答案3</param>
/// <param name="answer4">答案4</param>
/// <returns></returns>
public bool Insert(string questionsclass, string questions, string answer1, string answer2, string answer3, string answer4)
{
bool flag = false;
string sql = @"insert into t_testquestions values(@questionsclass,@questions,@answer1,@answer2,@answer3,@answer4)";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@questionsclass", questionsclass),
new SqlParameter("@questions", questions),
new SqlParameter("@answer1", answer1),
new SqlParameter("@answer2", answer2),
new SqlParameter("@answer3", answer3),
new SqlParameter("@answer4", answer4)
};
int res = s.ExecuteNonQuery(sql, paras);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 该方法取出所有题目(按题目分类排序)
/// </summary>
/// <param name="classid">题库id</param>
/// <returns>返回DataTable</returns>
public DataTable SelectAll_test(string classid)
{
string sql = @"select * from t_testquestions where questionsclassid="+classid;
DataTable dt = s.ExecuteQuery(sql);
return dt;
}
/// <summary>
/// 该方法删除一条题目
/// </summary>
/// <param name="id">题目的id</param>
/// <returns></returns>
public bool Delete(string id)
{
bool flag = false;
string sql = @"delete t_testquestions where id=@id";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@id", id)
};
int res = s.ExecuteNonQuery(sql, paras);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 该方法更新指定id的题目
/// </summary>
/// <param name="id">题目的id</param>
/// <param name="questionsclass">问题分类</param>
/// <param name="quesstions">问题题目</param>
/// <param name="answer1">答案1(正确答案)</param>
/// <param name="answer2">答案2</param>
/// <param name="answer3">答案3</param>
/// <param name="answer4">答案4</param>
/// <returns>成功返回真</returns>
public bool update(string id,string questionsclass, string questions, string answer1, string answer2, string answer3, string answer4)
{
bool flag = false;
string sql = @"update t_testquestions set [questionsclass]=@questionsclass,[questions]=@questions,[answer1]=@answer1,[answer2]=@answer2,[answer3]=@answer3,[answer4]=@answer4 where id=@id";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@id", id),
new SqlParameter("@questionsclass", questionsclass),
new SqlParameter("@questions", questions),
new SqlParameter("@answer1", answer1),
new SqlParameter("@answer2", answer2),
new SqlParameter("@answer3", answer3),
new SqlParameter("@answer4", answer4)
};
int res = s.ExecuteNonQuery(sql, paras);
if (res > 0)
{
flag = true;
}
return flag;
}
public string idToQuestions(string id)
{
string sql = @"select * from t_testquestions where id=" + id;
DataTable dt = s.ExecuteQuery(sql);
return dt.Rows[0][2].ToString();
}
//---类别管理
/// <summary>
/// 该方法取出所有题库分类
/// </summary>
/// <returns>返回DataTable</returns>
public DataTable SelectAll_class()
{
string sql = @"select * from t_questionsclass ";
DataTable dt = s.ExecuteQuery(sql);
return dt;
}
/// <summary>
/// 刚方法添加题库
/// </summary>
/// <param name="name">题库名</param>
/// <returns>成功返回真</returns>
public bool Insert_Class(string name)
{
bool flag = false;
if (!IsExists_class(name))
{
string sql = @"insert into t_questionsclass values('" + name + "')";
int res = s.ExecuteNonQuery(sql);
if (res > 0)
{
flag = true;
}
}
return flag;
}
/// <summary>
/// 该方法删除一个题库
/// </summary>
/// <param name="id">题库id</param>
/// <returns></returns>
public bool Delete_class(string id)
{
bool flag = false;
string sql = @"delete t_questionsclass where id=@id";
SqlParameter[] paras = new SqlParameter[] {
new SqlParameter("@id", id)
};
int res = s.ExecuteNonQuery(sql, paras);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 该方法判断传入题库名是否存在
/// </summary>
/// <param name="name">题库名</param>
/// <returns>存在返回true,不存在返回false</returns>
public bool IsExists_class(string name)
{
bool flag = false;
string sql = "select * from t_questionsclass where [classname]='" + name + "'";
DataTable dt = s.ExecuteQuery(sql);
if (dt.Rows.Count > 0)
{
flag = true;
}
return flag;
}
}
请发表评论