📄 addscore.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Linq;
using System.Collections.Generic;
public partial class DesktopModules_Score_AddScore : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
///显示班级的数据
BindClassData();
BindCourseData();
if (ClassList.Items.Count > 0)
{
ClassList.SelectedIndex = 0;
BindStudentData(Int32.Parse(ClassList.Items[0].Value));
}
}
}
private void BindClassData()
{
///定义获取数据的类
ClassM gClass = new ClassM();
Table<Class> recg = gClass.GetClasss();
///设定控件的数据源
ClassList.DataSource = recg;
///设定控件的Text属性和Value属性
ClassList.DataTextField = "Desn";
ClassList.DataValueField = "ClassID";
///绑定控件的数据
ClassList.DataBind();
}
private void BindStudentData(int nClassID)
{
///定义获取数据的类
StudentM student = new StudentM();
IList<Student> recd = student.GetStudentByClass(nClassID);
///设定控件的数据源
StudentList.DataSource = recd;
///设定控件的Text属性和Value属性
StudentList.DataTextField = "Name";
StudentList.DataValueField = "StudentID";
///绑定控件的数据
StudentList.DataBind();
}
private void BindCourseData()
{
///定义获取数据的类
CourseM course = new CourseM();
Table<Course> recc = course.GetCourses();
///设定控件的数据源
CourseList.DataSource = recc;
///设定控件的Text属性和Value属性
CourseList.DataTextField = "Desn";
CourseList.DataValueField = "CourseID";
///绑定控件的数据
CourseList.DataBind();
}
protected void AddStudent_Click(object sender, EventArgs e)
{
if (StudentList.SelectedIndex <= -1)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
return;
}
Name.Text = StudentList.SelectedItem.Text;
}
protected void AddBtn_Click(object sender, EventArgs e)
{
if (CourseList.SelectedIndex <= -1)
{
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
return;
}
///如果页面输入内容合法
if (Page.IsValid == true)
{
///定义类Department
ScoreM score = new ScoreM();
try
{
///录入成绩
score.AddScore(Int32.Parse(StudentList.SelectedValue),
Int32.Parse(CourseList.SelectedValue),decimal.Parse(Mark.Text.Trim()));
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///显示添加操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET35System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n", " "));
}
}
}
protected void ReturnBtn_Click(object sender, EventArgs e)
{
///返回管理页面
Response.Redirect("~/DesktopModules/Score/ScoreManage.aspx");
}
protected void ClassList_SelectedIndexChanged(object sender, EventArgs e)
{
if (ClassList.SelectedIndex <= -1)
{
StudentList.Items.Clear();
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET35System.OPERATIONNOSELECTMESSAGE + "')</script>");
return;
}
///重新显示学生信息
BindStudentData(Int32.Parse(ClassList.SelectedValue));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -