⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createexam.ascx.cs

📁 学生成绩管理系统
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
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 TeachHelper.BusinessLogicLayer;
using TeachHelper.Comm;

public partial class TeachHelper_Controls_CreateExam : System.Web.UI.UserControl
{
    #region 变量

    string name;
    string teacher;
    int departmentId;
    int grade;
    int majorId;
    int classes;
    int subjectId;
    int examTypeId;
    DateTime time;
    string description;

    #endregion

    #region 事件处理

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindClasses();
            BindTeacher();

            DataSet ds = Department.GetCollect();
            this.DropDownListDepartment.DataSource = ds;
            this.DropDownListDepartment.DataTextField = "Name";
            this.DropDownListDepartment.DataValueField = "Id";
            this.DropDownListDepartment.DataBind();

            DropDownListDepartment_SelectedIndexChanged(this.DropDownListDepartment, null);
        }
    }

    protected void DropDownListDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        int departmentId = Convert.ToInt32(((DropDownList)(sender)).SelectedValue);
        DataSet ds = Major.GetCollectByDepartmentId(departmentId);
        this.DropDownListMajor.DataSource = ds;
        this.DropDownListMajor.DataTextField = "Name";
        this.DropDownListMajor.DataValueField = "Id";
        this.DropDownListMajor.DataBind();
    }

    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        CreateExam();
    }

    #endregion

    #region 私有 & 保护方法

    private void BindClasses()
    {
        List<int> listClasses = OtherData.Classes();
        this.DropDownListClasses.DataSource = listClasses;
        this.DropDownListClasses.DataBind();
    }

    private void BindTeacher()
    {
        string roleName = "科任老师";
        string[] teachersArray = Roles.GetUsersInRole(roleName);
        this.DropDownListTeacher.DataSource = teachersArray;
        this.DropDownListTeacher.DataBind();
    }

    private void CreateExam()
    {
        bool result = false;

        name = this.TextBoxName.Text;
        teacher = this.DropDownListTeacher.SelectedItem.Text.Trim();
        departmentId = Convert.ToInt32(this.DropDownListDepartment.SelectedValue);
        grade = Convert.ToInt32(this.DropDownListGrade.SelectedValue);
        majorId = Convert.ToInt32(this.DropDownListMajor.SelectedValue);
        classes = Convert.ToInt32(this.DropDownListClasses.SelectedValue);
        subjectId = Convert.ToInt32(this.DropDownListSubject.SelectedValue);
        examTypeId = Convert.ToInt32(this.DropDownListExamType.SelectedValue);
        try
        {
            time = Convert.ToDateTime(this.TextBoxTime.Text);
        }
        catch (Exception ex)
        {
            MessageBox.Show(this.Page, "时间类型错误");
            return;
        }
        description = this.TextBoxDescription.Text;

        result = Exam.Create(name, teacher, departmentId, grade, majorId, classes, subjectId, examTypeId, time, description);

        if (result)
        {
            this.LabelMessage.Text = "添加成功!";
        }
        else
        {
            this.LabelMessage.Text = "添加失败,请重试";
        }
    }

    #endregion

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -