📄 projclass.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// projClass 的摘要说明
/// </summary>
public class projClass
{
public projClass()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public int getUsers(string stuId, string userPwd)
//判断用户名和密码是否正确,不过没有使用,后来用得是下面的getUser.(里面用到存储过程)
//cost:武海涛
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand thisCommand = new SqlCommand("select stuId from student where stuId='" + stuId + "'and stuPwd='" + userPwd + "'", myConnection);
myConnection.Open();
SqlDataReader thisReader = thisCommand.ExecuteReader();
int count = 0;
if (thisReader.Read())
{
count = 1;
}
thisReader.Close();
myConnection.Close();
return count;
}
public int ifStuExist(string stuId)
//判断是否存在此学生!
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_selectAsId", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@stuId", SqlDbType.VarChar, 15).Value = stuId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
thisReader.Close();
return 1;
}
else
thisReader.Close();
return 0;
}
public int ifCourseExist(string courseId, string courseName)
//判断是否存在此课程!
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_course_ifExist", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@courseId", SqlDbType.VarChar, 20).Value = courseId;
myCommand.Parameters.Add("@courseName", SqlDbType.VarChar, 20).Value = courseName;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
thisReader.Close();
return 1;
}
else
thisReader.Close();
return 0;
}
public int ifteacherExist(string teacherId)
//判断是否存在此课程!
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 15).Value = teacherId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
thisReader.Close();
return 1;
}
else
thisReader.Close();
return 0;
}
public int ifTeacherExist(string teacherId)
//判断是否存在此教师
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 15).Value = teacherId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
thisReader.Close();
return 1;
}
else
thisReader.Close();
return 0;
}
public int getUser(string stuId, string stuPwd)
//判断用户名和密码是否正确
//cost:武海涛
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_select", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@stuId", SqlDbType.VarChar, 15).Value = stuId;
myCommand.Parameters.Add("@stuPwd", SqlDbType.VarChar, 10).Value = stuPwd;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
//int count=0;//count=0说明用户名不存在
if (thisReader.Read())
{
return 1;
}
thisReader.Close();
myConnection.Close();
return 0;
}
public DataSet getStuInfoAsId(string stuId)
//根据学生的学号来查找学生
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_selectAsId", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@stuId", SqlDbType.VarChar, 15).Value = stuId;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds, "stuInfo");
myConnection.Close();
return ds;
}
public DataSet getStuInfoAsStatus(int stuStatus)
//根据学生的状态查找学生记录
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_selectAsStatus", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@stuStatus", SqlDbType.Int).Value = stuStatus;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds, "stuInfo");
myConnection.Close();
return ds;
}
public int getAdmin(string adminId, string adminPwd)
//判断用户名和密码是否正确
//cost:武海涛
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_administrator_select", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@adminId", SqlDbType.VarChar, 15).Value = adminId;
myCommand.Parameters.Add("@adminPwd", SqlDbType.VarChar, 10).Value = adminPwd;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
int count = 0;
if (thisReader.Read())
{
count = 1;
}
thisReader.Close();
myConnection.Close();
return count;
}
public int getTeacher(string teacherId, string teacherPwd)
//判断用户名和密码是否正确
//cost:武海涛
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_select", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 15).Value = teacherId;
myCommand.Parameters.Add("@teacherPwd", SqlDbType.VarChar, 10).Value = teacherPwd;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
int count = 0;
if (thisReader.Read())
{
count = 1;
}
thisReader.Close();
myConnection.Close();
return count;
}
public string getUserName(string stuId)
//从数据库中取得学生的姓名
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_selectName", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@stuId", SqlDbType.VarChar, 15).Value = stuId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
return thisReader[0].ToString();
}
else
return "none";
}
public string getTeacherName(string teacherId)
//从数据库中取得教师的姓名
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 15).Value = teacherId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
return thisReader[2].ToString();
}
else
return "none";
}
public string getTeacherCourseId(string teacherId)
//从数据库中取得教师的所教的科目ID
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 15).Value = teacherId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
return thisReader[3].ToString();
}
else
return "none";
}
public string getTeacherIdAsCourseId(string courseId)
//根据courseId取出老师姓名
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectAsCourseId", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@courseId", SqlDbType.VarChar, 20).Value = courseId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
return thisReader[0].ToString();
}
else
return "none";
}
public bool getIfTest(string courseId)
//判断该科目是否可以考试
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_course_isTest_select", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@courseId", SqlDbType.VarChar, 20).Value = courseId;
myConnection.Open();
SqlDataReader thisReader = myCommand.ExecuteReader();
if (thisReader.Read())
{
return thisReader.GetBoolean(0);
}
else
return false;
}
public DataSet getCourses()
//从数据库的course表中取得课程信息,从而绑定到页面的dropdownlist中
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_course_selectCourses", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds);
myConnection.Close();
return ds;
}
public DataSet getTest(string course)
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_test_selectAsCourse", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@testCourse", SqlDbType.VarChar, 20).Value = course;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds, "testInfo");
myConnection.Close();
return ds;
}
public DataSet getQuestionAndAns(string course)
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_test_select_questionAndAns", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@testCourse", SqlDbType.VarChar, 20).Value = course;
myConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
adapter.Fill(ds);
myConnection.Close();
return ds;
}
public DataSet getStuInfo()
//取得学生的信息
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_student_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
// SqlDataReader thisReader=myCommand.ExecuteReader();
//return thisReader;
SqlDataAdapter da = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
da.Fill(ds, "stuInfo");
myConnection.Close();
return ds;
}
public DataSet getTeacherInfo(string teacherId)
//取得学生的信息
{
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
SqlCommand myCommand = new SqlCommand("sp_teacher_selectInfo", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@teacherId", SqlDbType.VarChar, 10).Value = teacherId;
myConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
da.Fill(ds, "teacherInfo");
myConnection.Close();
return ds;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -