📄 addexamination.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 ExaminationSystem.BLL.Domain;
using ExaminationSystem.BLL.Service;
public partial class Teacher_AddExamination : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindClassList();
BindSubjectList();
}
}
private void BindClassList()
{
ClassListBox.DataSource = new ClassService().GetAll();
ClassListBox.DataTextField = "Name";
ClassListBox.DataValueField = "ID";
ClassListBox.DataBind();
}
private void BindSubjectList()
{
SubjectDropDownList.DataSource = new SubjectService().GetAll();
SubjectDropDownList.DataTextField = "Name";
SubjectDropDownList.DataValueField = "ID";
SubjectDropDownList.DataBind();
if (SubjectDropDownList.Items.Count > 0)
SubjectDropDownList.SelectedIndex = 0;
BindStrategyList();
}
private void BindStrategyList()
{
if (SubjectDropDownList.Items.Count == 0)
return;
Subject subject = new SubjectService().GetById(long.Parse(SubjectDropDownList.SelectedValue));
StrategyDropDownList.DataSource = subject.PaperStrategys;
StrategyDropDownList.DataTextField = "Name";
StrategyDropDownList.DataValueField = "ID";
StrategyDropDownList.DataBind();
}
protected void AddExaminationButton_Click(object sender, EventArgs e)
{
string name = ExminationNameTextBox.Text;
string[] date = ExaminationDateTextBox.Text.Split(new char[] { '-' });
DateTime startTime;
DateTime endTime;
try
{
startTime = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2])
, int.Parse(StartHourTextBox.Text), int.Parse(StartMinuteTextBox.Text), 0);
endTime = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2])
, int.Parse(EndHourTextBox.Text), int.Parse(EndMinuteTextBox.Text), 0);
}
catch
{
Label1.Text = "日期格式不正确!";
return;
}
int lateMinutes = int.Parse(LateMinutesTextBox.Text);
int submitMinutes = int.Parse(SubmitMinutesTextBox.Text);
Examination exam = new Examination();
exam.Name = name;
exam.StartTime = startTime;
exam.EndTime = endTime;
exam.LateMinutes = lateMinutes;
exam.PermitSubmitMinutes = submitMinutes;
exam.PaperStrategy = new PaperStrategyService().GetById(long.Parse(StrategyDropDownList.SelectedValue));
foreach (ListItem item in AttendListBox.Items)
{
if (item.Selected == true)
{
exam.AttendClasses.Add(new ClassService().GetById(long.Parse(item.Value)));
}
}
if (exam.AttendClasses.Count == 0)
{
Label1.Text = "考试必需有班级参加!";
return;
}
new ExaminationService().Save(exam);
Label1.Text = "添加成功!";
}
protected void Button1_Click(object sender, EventArgs e)
{
AttendListBox.Items.Add(ClassListBox.SelectedItem);
}
protected void Button2_Click(object sender, EventArgs e)
{
AttendListBox.Items.Remove(AttendListBox.SelectedItem);
}
protected void SubjectDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
BindStrategyList();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -