📄 student_paper.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.Common;
using System.Web.Management;
using System.Collections;
#region Student_Paper
/// <summary>
/// This object represents the properties and methods of a Student_Paper.
/// </summary>
public class Student_Paper
{
protected int _id;
protected int _candidatePaperID;
protected string _studentID = String.Empty;
protected bool _isAscertainSelect;
protected DateTime _selectDate;
public Student_Paper()
{
}
public Student_Paper(int id)
{
DbDataReader reader = DataAccess.ExecuteDataReader("usp_");
if (reader.Read())
{
this.LoadFromReader(reader);
reader.Close();
}
else
{
if (!reader.IsClosed) reader.Close();
throw new ApplicationException("Student_Paper does not exist.");
}
}
public Student_Paper(DbDataReader reader)
{
this.LoadFromReader(reader);
}
protected void LoadFromReader(DbDataReader reader)
{
if (reader != null && !reader.IsClosed)
{
_id = reader.GetInt32(0);
if (!reader.IsDBNull(1)) _candidatePaperID = reader.GetInt32(1);
if (!reader.IsDBNull(2)) _studentID = reader.GetString(2);
if (!reader.IsDBNull(3)) _isAscertainSelect = reader.GetBoolean(3);
if (!reader.IsDBNull(4)) _selectDate = reader.GetDateTime(4);
}
}
#region Public Properties
public int Id
{
get {return _id;}
}
public int CandidatePaperID
{
get {return _candidatePaperID;}
set {_candidatePaperID = value;}
}
public string StudentID
{
get {return _studentID;}
set {_studentID = value;}
}
public bool IsAscertainSelect
{
get {return _isAscertainSelect;}
set {_isAscertainSelect = value;}
}
public DateTime SelectDate
{
get {return _selectDate;}
set {_selectDate = value;}
}
#endregion
public static Student_Paper GetStudent_Paper(int id)
{
return new Student_Paper(id);
}
public static int SelectCandidatePaper(int cpid,string studentid)
{
string sql1 = "select * from Student_Paper where StudentID='" + studentid + "'";
DbDataReader ddr = DataAccess.ExecuteDataReader(sql1);
if (ddr.HasRows == true)
{
ddr.Close();
return -3;//如果已已选题,则返回-3
}
ddr.Close();
return DataAccess.ExecuteNonQuery("usp_InsertStudent_Paper", false, new object[]
{ cpid,studentid,0,System.DateTime.Now});
}
//设置论文为确定状态,此后将不可更改
public static int SetCandidatePaperAscertain(string studentid)
{
string sql = "update Student_Paper set IsAscertainSelect=1 where StudentID='" + studentid + "'";
return DataAccess.ExecuteNonQuery(sql);
}
//删除选题,并置原论文的选择标记为False
public static int DelectSelectedCandidatePaper(string studentid)
{
string sql1 = "select * from Student_Paper where StudentID='" + studentid + "'";
DbDataReader ddr = DataAccess.ExecuteDataReader(sql1);
int candidateid = -1;
bool isascertain = false;
if (ddr.HasRows == true)
{
ddr.Read();
candidateid = (int)ddr.GetValue(1);
isascertain = ddr.GetBoolean(3);
ddr.Close();
if(isascertain==true)
return -3;//如果已确定选题,将不能删除
}
ddr.Close();
string sql = "delete from Student_Paper where Studentid='" + studentid + "'";
DataAccess.ExecuteNonQuery(sql);
sql = "update CandidatePaper set IsBeSelected=0 where CandidatePaperID=" + candidateid;
return DataAccess.ExecuteNonQuery(sql);
}
//更新老师可带学生数,在删除、添加选题后,此值将要更新。
public static int UpdateTeacherInstructNum(string teacherid,int i)
{
string sql = "";
if(i==1)
sql = "update Teacher set AlreadyInstructNum=AlreadyInstructNum+1 where teacherid='" + teacherid + "'";
if(i==-1)
sql = "update Teacher set AlreadyInstructNum=AlreadyInstructNum-1 where teacherid='" + teacherid + "'";
return DataAccess.ExecuteNonQuery(sql);
}
//设置论文已选,别的人将不能再选此题
public static int SetCandidatePaperSelected(int candidatePaperID)
{
string sql = "update CandidatePaper set IsBeSelected=1 where CandidatePaperID =" + candidatePaperID;
return DataAccess.ExecuteNonQuery(sql);
}
//获得老师ID,通过学生ID
public static string GetTeacherIDByStudentID(string studentid)
{
string result = "";
string sql = " SELECT Teacher.TeacherID " +
" FROM Student INNER JOIN " +
" Student_Paper ON Student.StudentID = Student_Paper.StudentID INNER JOIN " +
" CandidatePaper ON Student_Paper.CandidatePaperID = CandidatePaper.CandidatePaperID INNER JOIN " +
" Teacher ON CandidatePaper.TeacherID = Teacher.TeacherID " +
"WHERE Student.StudentID = '" + studentid + "'";
DbDataReader ddr = DataAccess.ExecuteDataReader(sql);
if (ddr.Read())
{
result= ddr.GetString(0);
}
ddr.Close();
return result;
}
//检查老师能不能再带人
public static bool CheckTeacherCanInstruce(string teacherid)
{
string sql = "select * from teacher where AlreadyInstructNum=CanInstructNum and " +
" teacherid = '" + teacherid + "'";
DbDataReader ddr = DataAccess.ExecuteDataReader(sql);
if (ddr.HasRows == false)
{
ddr.Close();
return true;//如果查不到已带人数和可带人数匹配的记录,则表示还可以带人
}
ddr.Close();
return false;
}
//通过学生ID获得论文信息
public static ArrayList GetCandidatePaperInfoByStudentID(string studentid)
{
ArrayList al = new ArrayList();
string sql = "SELECT CandidatePaper.CandidatePaperID, Teacher.Name," +
" CandidatePaper.Description, CandidatePaper.Reference, CandidatePaper.Title, " +
" Student_Paper.IsAscertainSelect, Student_Paper.SelectDate, Student_Paper.StudentID" +
" FROM CandidatePaper INNER JOIN " +
" Student_Paper ON CandidatePaper.CandidatePaperID = Student_Paper.CandidatePaperID INNER JOIN " +
" Teacher ON CandidatePaper.TeacherID = Teacher.TeacherID" +
" WHERE Student_Paper.StudentID ='" + studentid + "'";
DbDataReader ddr = DataAccess.ExecuteDataReader(sql);
int i=0;
if(ddr.Read())
{
for (i = 0; i < ddr.FieldCount; i++)
{
al.Add(ddr.GetValue(i));
}
}
ddr.Close();
return al;
}
}
#endregion
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -