Пример #1
0
        /// <summary>
        /// 修改学生信息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pData_OnStudentModify(object sender, EventArgsStudent e)
        {
            TreeNode tn = treeView1.SelectedNode;

            if (tn == null)
            {
                return;
            }
            //学生的系和班级没有更改,修改表格中的内容
            if (tn.Text == e.NewClassName || tn.Text == e.NewDepName || tn.Text == "全部")
            {
                DataGridViewRow row = dataGridView1.Rows[this.rowindex];
                row.Cells["StuName"].Value     = e.NewStuobj.Name;
                row.Cells["StuAge"].Value      = e.NewStuobj.Age;
                row.Cells["StuSex"].Value      = e.NewStuobj.Sex.ToString();
                row.Cells["StuChinese"].Value  = e.NewStuobj.Chinese;
                row.Cells["StuEnglish"].Value  = e.NewStuobj.English;
                row.Cells["StuMath"].Value     = e.NewStuobj.Math;
                row.Cells["StuComputer"].Value = e.NewStuobj.Computer;
            }
            else
            {
                dataGridView1.Rows.RemoveAt(rowindex);
            }
        }
Пример #2
0
        /// <summary>
        /// 删除一个学生
        /// </summary>
        /// <param name="depname">学生所在系的名称</param>
        /// <param name="classname">学生所在班级的名称</param>
        /// <param name="stu">学生对象</param>
        /// <returns>成功:true;失败:false</returns>
        internal bool DelStudent(string depname, string classname, Student stu)
        {
            Department depobj = FindDepartmentByName(depname);

            if (depobj == null)
            {
                return(false);                //没有找到系对象,返回
            }
            clsClass clsobj = depobj.FindClassByName(classname);

            if (clsobj == null)
            {
                return(false);          //没有找到班对象,返回
            }
            if (clsobj.DelStudent(stu)) //删除成功
            {
                EventArgsStudent e = new EventArgsStudent();
                e.depobj = depobj;
                e.clsobj = clsobj;
                e.stuobj = stu;
                e.number = StudentNumber;
                ActOnStudentDel(this, e);
                return(true);
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// 增加一个学生
        /// </summary>
        /// <param name="depname">学生所在系的名称</param>
        /// <param name="classname">学生所在班级的名称</param>
        /// <param name="stu">学生对象</param>
        /// <returns></returns>
        internal bool AddStudent(string depname, string classname, Student stu)
        {
            Department depobj = FindDepartmentByName(depname);

            if (depobj == null)
            {
                return(false);
            }
            clsClass clsobj = FindClassByName(depobj, classname);

            if (clsobj == null)
            {
                return(false);
            }
            if (clsobj.AddStudent(stu)) //学生增加成功
            {
                EventArgsStudent e = new EventArgsStudent();
                e.clsobj = clsobj; e.depobj = depobj;
                e.stuobj = stu;
                e.number = StudentNumber;
                ActOnStudentAdd(this, e);
                return(true);
            }
            return(false);
        }
Пример #4
0
 private void ActOnStudentModify(object sender, EventArgsStudent e)
 {
     if (this.OnStudentModify != null)
     {
         OnStudentModify(this, e);
     }
 }
Пример #5
0
 private void ActOnStudentDel(object sender, EventArgsStudent e)
 {
     if (OnStudentDel != null)
     {
         OnStudentDel(this, e);
     }
 }
Пример #6
0
        /// <summary>
        /// 修改学生信息
        /// </summary>
        /// <param name="OldDepName">修改前所在的系名称</param>
        /// <param name="NewDepName">修改后所在的系名称</param>
        /// <param name="OldClassName">修改前所在的班级名称</param>
        /// <param name="NewClassName">修改后所在的班级名称</param>
        /// <param name="StudentID">学生的ID</param>
        /// <param name="NewStudent">新的学生对象</param>
        /// <returns>成功:true;失败:false</returns>
        internal bool ModifyStudent(string OldDepName, string NewDepName,
                                    string OldClassName, string NewClassName,
                                    string StudentID, Student NewStudent)
        {
            Department olddep;
            clsClass   oldclass;
            Student    OldStudent = FindStudentByID(StudentID, out olddep, out oldclass);
            Department newdep     = FindDepartmentByName(NewDepName);
            clsClass   newclass   = FindClassByName(newdep, NewClassName);//原来的学生对象

            //找不到相应的对象,则返回ture;
            if (olddep == null || newdep == null || oldclass == null || newclass == null || OldStudent == null)
            {
                return(false);
            }
            if (olddep == newdep)
            {
                if (oldclass == newclass) //学生所在的系和班级没有改动
                {
                    ChangeStudentInfo(OldStudent, NewStudent);
                    EventArgsStudent e = new EventArgsStudent();
                    e.OldDepName = OldDepName; e.OldClassName = OldClassName;
                    e.NewDepName = NewDepName; e.NewClassName = NewClassName;
                    e.stuobj     = OldStudent; e.NewStuobj = NewStudent;
                    e.number     = StudentNumber;
                    ActOnStudentModify(this, e);
                }
                else //系没有改动,班级发生改动
                {
                    oldclass.DelStudent(StudentID); //在原来班级中删除学生对象
                    newclass.AddStudent(NewStudent); //在新班级中添加学生
                    EventArgsStudent e = new EventArgsStudent();
                    e.OldDepName = OldDepName; e.OldClassName = OldClassName;
                    e.NewDepName = NewDepName; e.NewClassName = NewClassName;
                    e.stuobj     = OldStudent; e.NewStuobj = NewStudent;
                    e.number     = StudentNumber;
                    ActOnStudentModify(this, e);
                }
            }
            else//系发生改变
            {
                DelStudent(OldDepName, OldClassName, StudentID);//在原来的系原来的班级中删除学生对象
                AddStudent(NewDepName, NewClassName, NewStudent);//在新的系新的班级中增加学生
                EventArgsStudent e = new EventArgsStudent();
                e.OldDepName = OldDepName; e.OldClassName = OldClassName;
                e.NewDepName = NewDepName; e.NewClassName = NewClassName;
                e.stuobj     = OldStudent; e.NewStuobj = NewStudent;
                e.number     = StudentNumber;
                ActOnStudentModify(this, e);
            }
            return(true);
        }
Пример #7
0
        /// <summary>
        /// 处理删除学生事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pData_OnStudentDel(object sender, EventArgsStudent e)
        {
            TreeNode tndep = FindNodeInTree(e.depobj.Name);
            TreeNode tncls = FindNodeInTree(e.clsobj.Name);

            if (treeView1.SelectedNode == tndep || treeView1.SelectedNode == tncls ||
                treeView1.SelectedNode.Text == "全部")
            {
                int index = FindStudentInDataGridView(e.stuobj.ID);
                if (index != -1)
                {
                    dataGridView1.Rows.RemoveAt(index);
                }
                this.labelStudentNumber.Text = "学生数量:" + e.number.ToString("00");
            }
        }
Пример #8
0
        /// <summary>
        /// 处理增加学生事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pData_OnStudentAdd(object sender, EventArgsStudent e)
        {
            TreeNode depNode = FindNodeInTree(e.depobj.Name); //学生对应的系节点
            TreeNode clsNode = FindNodeInTree(e.clsobj.Name); //学生对应的班级节点

            //如果treeView当前节点是“全部”或是学生所在的系或者是学生所在的班级节点,则显示学生信息
            if (treeView1.SelectedNode != null)
            {
                if (treeView1.SelectedNode.Text == "全部" || treeView1.SelectedNode == depNode ||
                    treeView1.SelectedNode == clsNode)
                {
                    this.AddStudentInDataGridView(e.stuobj);
                }
            }
            this.labelStudentNumber.Text = "学生数量:" + e.number.ToString("00");
        }