📄 userdb.cs
字号:
}
finally
{
myConnection.Close();
}
}
#endregion
#region 删除完形填空题详细记录
public int deleteWXTKDetailInfo(string WXID)
//删除选择题记录
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_WXTKDetail_delete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@WXID", SqlDbType.Int).Value = WXID;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return 1;//删除成功
}
catch (SqlException SQLexc)
{
Console.WriteLine("SqlException:{0}", SQLexc);
return 0;//删除失败
}
finally
{
myConnection.Close();
}
}
#endregion
#region 更新完形填空题
public int updateWXTKInfo(string ID, string WXName, int pub, string ClassifyID)
//更新完形填空题信息,返回1表示更新成功,返回0则更新失败
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_WXTK_Update", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
myCommand.Parameters.Add("@WXName", SqlDbType.Text).Value = WXName;
myCommand.Parameters.Add("@pub", SqlDbType.Int).Value = pub;
myCommand.Parameters.Add("@ClassifyID", SqlDbType.VarChar, 20).Value = ClassifyID;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return 1;
}
catch (SqlException SQLexc)
{
Console.WriteLine("SqlException:{0}", SQLexc);
return 0;
}
finally
{
myConnection.Close();
}
}
#endregion
#region 获得阅读题信息
public DataSet getYDAllInfo()
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_selectAllInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
da.Fill(ds, "YDInfo");
myConnection.Close();
return ds;
}
#endregion
#region 根据ClassifyID来获取阅读题详细信息
public DataSet getYDInfoAsClassifyID(string ClassifyID)
//根据ClassifyID来获取阅读题详细信息
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_selectAsClassifyId", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterID = myCommand.Parameters.Add("@ClassifyID", SqlDbType.Int);
parameterID.Value = ClassifyID;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds, "YDInfo");
myConnection.Close();
return ds;
}
#endregion
#region 添加阅读题的信息
private const string paramYD = "YDName_IfIssue_ClassifyID_YDID";
public int AddYD(String YDName, int IfIssue, string ClassifyID, string YDID)
{
//定义数据库的Connection and Command
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_insert", myConnection);
//定义访问数据库的方式为存储过程
myCommand.CommandType = CommandType.StoredProcedure;
//创建访问数据库的参数
SqlParameter[] paramCache = SQLHelper.GetCachedParameters(paramYD);
if (paramCache == null)
{
paramCache = new SqlParameter[]{
new SqlParameter("@YDName",SqlDbType.Text),
new SqlParameter("@ClassifyID",SqlDbType.Text),
new SqlParameter("@IfIssue",SqlDbType.Int,8),
new SqlParameter("@ID",SqlDbType.Int,8),
new SqlParameter("@YDID",SqlDbType.VarChar)};
SQLHelper.CacheParameters(paramYD, paramCache);
}
SQLHelper.AddMyCommandParams(myCommand, paramCache);
paramCache[0].Value = YDName;
paramCache[1].Value = ClassifyID;
paramCache[2].Value = IfIssue;
paramCache[3].Direction = ParameterDirection.ReturnValue;
paramCache[4].Value = YDID;
try
{
//打开数据库的连接
myConnection.Open();
}
catch (Exception ex)
{
throw new GlobalDB.MyException("10001", "数据库连接失败!", ex);
}
try
{
//执行数据库的存储过程(访问数据库)
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new GlobalDB.MyException("10001", ex.Message, ex);
}
finally
{
if (myConnection.State == ConnectionState.Open)
{
//关闭数据库的连接
myConnection.Close();
}
}
return (int)paramCache[3].Value;
}
#endregion
#region 添加阅读题的完整信息
private const string paramYDDetail = "YDNumber_YDName_testAns1_testAns2_testAns3_testAns4_rightAns_testScore_YDID";
public int AddYDDetail(String YDNumber, String YDName, String testAns1, String testAns2, String testAns3, String testAns4, int rightAns, int testScore, string YDID)
{
//定义数据库的Connection and Command
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YDDetail_insert", myConnection);
//定义访问数据库的方式为存储过程
myCommand.CommandType = CommandType.StoredProcedure;
//创建访问数据库的参数
SqlParameter[] paramCache = SQLHelper.GetCachedParameters(paramYDDetail);
if (paramCache == null)
{
paramCache = new SqlParameter[]{
new SqlParameter("@YDNumber",SqlDbType.Int,8),
new SqlParameter("@YDName",SqlDbType.Text),
new SqlParameter("@testAns1",SqlDbType.Text),
new SqlParameter("@testAns2",SqlDbType.Text),
new SqlParameter("@testAns3",SqlDbType.Text),
new SqlParameter("@testAns4",SqlDbType.Text),
new SqlParameter("@rightAns",SqlDbType.Int,8),
new SqlParameter("@testScore",SqlDbType.Int,8),
new SqlParameter("@ID",SqlDbType.Int,8),
new SqlParameter("@YDID",SqlDbType.VarChar)};
SQLHelper.CacheParameters(paramYDDetail, paramCache);
}
SQLHelper.AddMyCommandParams(myCommand, paramCache);
paramCache[0].Value = YDNumber;
paramCache[1].Value = YDName;
paramCache[2].Value = testAns1;
paramCache[3].Value = testAns2;
paramCache[4].Value = testAns3;
paramCache[5].Value = testAns4;
paramCache[6].Value = rightAns;
paramCache[7].Value = testScore;
paramCache[8].Direction = ParameterDirection.ReturnValue;
paramCache[9].Value = YDID;
try
{
//打开数据库的连接
myConnection.Open();
}
catch (Exception ex)
{
throw new GlobalDB.MyException("10001", "数据库连接失败!", ex);
}
try
{
//执行数据库的存储过程(访问数据库)
myCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new GlobalDB.MyException("10001", ex.Message, ex);
}
finally
{
if (myConnection.State == ConnectionState.Open)
{
//关闭数据库的连接
myConnection.Close();
}
}
return (int)paramCache[8].Value;
}
#endregion
#region 根据阅读题ID来获取阅读题详细信息
public DataSet getYDInfoAsId(int ID)
//根据阅读题ID来获取阅读题详细信息
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_selectAsId", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter parameterID = myCommand.Parameters.Add("@ID", SqlDbType.Int);
parameterID.Value = ID;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds, "YDInfo");
myConnection.Close();
return ds;
}
#endregion
#region 更新阅读题
public int updateYDInfo(string ID, string YDName, int pub, string ClassifyID)
//更新阅读题信息,返回1表示更新成功,返回0则更新失败
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_Update", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
myCommand.Parameters.Add("@YDName", SqlDbType.Text).Value = YDName;
myCommand.Parameters.Add("@pub", SqlDbType.Int).Value = pub;
myCommand.Parameters.Add("@ClassifyID", SqlDbType.VarChar, 20).Value = ClassifyID;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return 1;
}
catch (SqlException SQLexc)
{
Console.WriteLine("SqlException:{0}", SQLexc);
return 0;
}
finally
{
myConnection.Close();
}
}
#endregion
#region 删除阅读题记录
public int deleteYDInfo(string ID)
//删除阅读题记录
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YD_delete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return 1;//删除成功
}
catch (SqlException SQLexc)
{
Console.WriteLine("SqlException:{0}", SQLexc);
return 0;//删除失败
}
finally
{
myConnection.Close();
}
}
#endregion
#region 删除阅读题详细记录
public int deleteYDDetailInfo(string YDID)
//删除阅读题详细记录
{
SqlConnection myConnection = new SqlConnection(SQLHelper.DBCONNECTIONSTRING);
SqlCommand myCommand = new SqlCommand("Pr_YDDetail_delete", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@YDID", SqlDbType.Int).Value = YDID;
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return 1;//删除成功
}
catch (SqlException SQLexc)
{
Console.WriteLine("SqlException:{0}", SQLexc);
return 0;//删除失败
}
finally
{
myConnection.Close();
}
}
#endregion
#region 判断指定的用户指定的科目是否已经考试过
public int ifCourseHasTest(string stuId, s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -