温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:某大学学生管理系统(毕业设计)源码
当前文件:
StudentsInfo/ST_grade_query.aspx.cs,打开代码结构图
StudentsInfo/ST_grade_query.aspx.cs,打开代码结构图1using System; 2
using System.Collections; 3
using System.ComponentModel; 4
using System.Data; 5
using System.Data.SqlClient; 6
using System.Drawing; 7
using System.Web; 8
using System.Web.SessionState; 9
using System.Web.UI; 10
using System.Web.UI.WebControls; 11
using System.Web.UI.HtmlControls; 12
using System.Configuration; 13
14
namespace STGROUP 15
{ 16
/// <summary> 17
/// ST_grade_query 的摘要说明。 18
/// </summary> 19
public class ST_grade_query : System.Web.UI.Page 20
{ 21
protected System.Web.UI.WebControls.Button st_btn_ok; 22
protected System.Web.UI.WebControls.DataGrid st_dtg_grade; 23
protected System.Web.UI.WebControls.TextBox st_tbx_course; 24
protected System.Web.UI.WebControls.Label st_lbl_must; 25
protected System.Web.UI.WebControls.Label st_lbl_sort; 26
string st_sqlstr; 27
protected System.Web.UI.WebControls.TextBox st_tbx_term; 28
protected System.Web.UI.WebControls.Button st_btn_look;SqlConnection st_conn; 29
private void Page_Load(object sender, System.EventArgs e) 30
{ 31
// 在此处放置用户代码以初始化页面 32
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"]; 33
st_conn=new SqlConnection(st_connstr); 34
} 35
36
Web Form Designer generated code 57
58
59
60
private void st_btn_ok_Click(object sender, System.EventArgs e) 61
{ 62
63
//当课程名称为空时,执行下面代码 64
if(st_tbx_course.Text=="") 65
{ 66
st_sqlstr="select ST_course.ST_Course_name,ST_student_course.ST_Course_id,ST_Course_year,ST_Student_grade,ST_Course_credit,ST_Course_kind from ST_student_course,ST_course where ST_Course_year='"+st_tbx_term.Text+"' and ST_student_course.ST_Course_id=ST_course.ST_Course_id and ST_Student_id='"+Session["User_id"].ToString()+"'"; 67
68
} 69
//当课程名称非空时,执行下面代码 70
else 71
{ 72
st_sqlstr="select ST_course.ST_Course_name,ST_student_course.ST_Course_id,ST_Course_year,ST_Student_grade,ST_Course_credit,ST_Course_kind from ST_student_course,ST_course where ST_Course_year='"+st_tbx_term.Text+"'and ST_course.ST_Course_id=ST_student_course.ST_Course_id and ST_course.ST_Course_name='"+st_tbx_course.Text+"'and ST_Student_id='"+Session["User_id"].ToString()+"'"; 73
} 74
st_conn.Open(); 75
SqlDataAdapter st_da=new SqlDataAdapter(st_sqlstr,st_conn); 76
DataSet st_ds=new DataSet(); 77
st_da.Fill(st_ds); 78
st_dtg_grade.DataSource=st_ds; 79
st_dtg_grade.DataBind(); 80
st_conn.Close(); 81
//在Label中显示信息 82
display(); 83
} 84
//选出必修课总学分和选修课总学分显示在Label中 85
public void display() 86
{ 87
//选出非选修课总学分,条件是必须及格 88
st_sqlstr="select SUM(ST_Course_credit) from ST_course,ST_student_course where ST_Course_year='"+st_tbx_term.Text+"' and ST_Student_id=@Student_id and ST_student_course.ST_Course_id=ST_course.ST_Course_id and ST_Course_kind=2 and ST_Student_grade>=60"; 89
SqlCommand st_comm=new SqlCommand(st_sqlstr,st_conn); 90
st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50)); 91
st_comm.Parameters["@Student_id"].Value=Session["User_id"].ToString(); 92
st_conn.Open(); 93
SqlDataReader dr=st_comm.ExecuteReader(); 94
if(dr.Read()) 95
{ 96
st_lbl_sort.Text="本学期选修课的总学分为:"+dr[0].ToString(); 97
} 98
else 99
{ 100
st_lbl_sort.Text="本学期选修课的总学分为:0"; 101
} 102
st_conn.Close(); 103
//选出选修课总学分,条件是必须及格 104
st_sqlstr="select SUM(ST_Course_credit) from ST_course,ST_student_course where ST_Course_year='"+st_tbx_term.Text+"' and ST_Student_id=@Student_id and ST_student_course.ST_Course_id=ST_course.ST_Course_id and ST_Course_kind<2 and ST_Student_grade>=60"; 105
st_comm=new SqlCommand(st_sqlstr,st_conn); 106
st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50)); 107
st_comm.Parameters["@Student_id"].Value=Session["User_id"].ToString(); 108
st_conn.Open(); 109
dr=st_comm.ExecuteReader(); 110
if(dr.Read()) 111
{ 112
st_lbl_must.Text="本学期必修课的总学分为:"+dr[0].ToString(); 113
} 114
else 115
{ 116
st_lbl_must.Text="本学期必修课的总学分为:0"; 117
} 118
st_conn.Close(); 119
} 120
121
} 122
} 123





}