Пример #1
0
        protected void Add_Student_Click(object sender, EventArgs e)
        {
            MessageLabel.Text = "StudentID = " + StudentID.Text + " Name = " + StudentName.Text;
            if (Page.IsValid)
            {
                bool found = false;
                foreach (var item in StudentsList)
                {
                    if (item.StudentID == int.Parse(StudentID.Text))
                    {
                        found = true;
                    }
                }
                if (found)
                {
                    MessageLabel.Text = "Record already exists.";
                }
                else
                {
                    Student newstudent = new Student(int.Parse(StudentID.Text), StudentName.Text, double.Parse(StudentCredits.Text), StudentEmergencyContact.Text);

                    StudentsList.Add(newstudent);
                    StudentListView.DataSource = StudentsList;
                    StudentListView.DataBind();
                }
            }
        }
Пример #2
0
    protected void studentdelete_Click(object sender, EventArgs e)
    {
        int    xh  = Int32.Parse((sender as Button).CommandArgument.ToString());
        string sql = "delete from tb_student where xh ='" + xh + "'";

        try
        {
            if (DBControl.delete(sql) > 0)
            {
                StudentListView.DataSource = null;
                StudentListView.DataBind();
                ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('删除成功')", true);
            }
            else
            {
                StudentListView.DataSource = null;
                StudentListView.DataBind();
                ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('该学生不存在')", true);
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('系统异常')", true);
        }
    }
Пример #3
0
    protected void studenteditsub_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(studenteditage.Text.Trim()))
        {
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('年龄不能为空!')", true);
        }
        if (Convert.ToInt32(studenteditdept.SelectedValue) == 0)
        {
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('请选择院系!')", true);
        }
        int    xh  = 0;
        int    nl  = 0;
        string xb  = null;
        string xm  = null;
        int    dno = 0;

        try
        {
            xh = Convert.ToInt32(studentedituser.Text.Trim());
            xm = studenteditname.Text.Trim();
            xb = "男";
            if (studenteditsex2.Checked)
            {
                xb = "女";
            }
            nl  = Convert.ToInt32(studenteditage.Text.Trim());
            dno = Convert.ToInt32(studenteditdept.SelectedValue);
        }
        catch (Exception)
        {
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('请在年龄中输入数字!')", true);
        }

        string sql = "update tb_student set xm='" + xm + "',xb='" + xb + "',nl='" + nl + "',dno='" + dno + "' where xh ='" + xh + "'";

        try
        {
            DBControl.update(sql);
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('编辑成功')", true);
            StudentListView.DataSource = null;
            StudentListView.DataBind();

            student_panel.Visible       = true;
            managestudent_panel.Visible = true;
            editstudent_panel.Visible   = false;
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('编辑失败')", true);
        }
    }