📄 st_grade_query.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace STGROUP
{
/// <summary>
/// ST_grade_query 的摘要说明。
/// </summary>
public class ST_grade_query : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button st_btn_ok;
protected System.Web.UI.WebControls.DataGrid st_dtg_grade;
protected System.Web.UI.WebControls.TextBox st_tbx_course;
protected System.Web.UI.WebControls.Label st_lbl_must;
protected System.Web.UI.WebControls.Label st_lbl_sort;
string st_sqlstr;
protected System.Web.UI.WebControls.TextBox st_tbx_term;
protected System.Web.UI.WebControls.Button st_btn_look;SqlConnection st_conn;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string st_connstr= ConfigurationSettings.AppSettings["st_dbconn"];
st_conn=new SqlConnection(st_connstr);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.st_btn_ok.Click += new System.EventHandler(this.st_btn_ok_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void st_btn_ok_Click(object sender, System.EventArgs e)
{
//当课程名称为空时,执行下面代码
if(st_tbx_course.Text=="")
{
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()+"'";
}
//当课程名称非空时,执行下面代码
else
{
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()+"'";
}
st_conn.Open();
SqlDataAdapter st_da=new SqlDataAdapter(st_sqlstr,st_conn);
DataSet st_ds=new DataSet();
st_da.Fill(st_ds);
st_dtg_grade.DataSource=st_ds;
st_dtg_grade.DataBind();
st_conn.Close();
//在Label中显示信息
display();
}
//选出必修课总学分和选修课总学分显示在Label中
public void display()
{
//选出非选修课总学分,条件是必须及格
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";
SqlCommand st_comm=new SqlCommand(st_sqlstr,st_conn);
st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_id"].Value=Session["User_id"].ToString();
st_conn.Open();
SqlDataReader dr=st_comm.ExecuteReader();
if(dr.Read())
{
st_lbl_sort.Text="本学期选修课的总学分为:"+dr[0].ToString();
}
else
{
st_lbl_sort.Text="本学期选修课的总学分为:0";
}
st_conn.Close();
//选出选修课总学分,条件是必须及格
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";
st_comm=new SqlCommand(st_sqlstr,st_conn);
st_comm.Parameters.Add(new SqlParameter("@Student_id",SqlDbType.VarChar,50));
st_comm.Parameters["@Student_id"].Value=Session["User_id"].ToString();
st_conn.Open();
dr=st_comm.ExecuteReader();
if(dr.Read())
{
st_lbl_must.Text="本学期必修课的总学分为:"+dr[0].ToString();
}
else
{
st_lbl_must.Text="本学期必修课的总学分为:0";
}
st_conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -