Ejemplo n.º 1
0
        /// <summary>
        /// 点击单元格事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataGridViewCellContent_Click(object sender, DataGridViewCellEventArgs e)
        {
            //当点击'预选课'按钮时
            if (skinDataGridView1.Columns[e.ColumnIndex].Name == "colBtn_preSelect")
            {
                //获取被选中行的数据
                int    courseId    = (int)skinDataGridView1.Rows[e.RowIndex].Cells[0].Value;       //首列的数据
                string programName = skinDataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); //第7列的数据

                if (programName.Equals(educationProgram.Name) == false)                            //只允许选择与自己班级所在的培养方案相同的课程
                {
                    this.Warning("选课失败! 该课程的培养方案与您所在班级的培养方案不相同!");
                    return;
                }

                //查:表[PlanStudyCourseDao]
                PlanStudyCourseBean planStudyCourse = new PlanStudyCourseBean(courseId, 3, student.Id);
                PlanStudyCourseDao  DAO             = new PlanStudyCourseDao();
                if (DAO.FindByStuId_CourId_SemsId(planStudyCourse) != null)
                {
                    this.Warning("选课失败!您已预先过此门课,请不要重复选课!");
                    return;
                }
                //增:表[PlanStudyCourseDao]
                if (DAO.Add(planStudyCourse))
                {
                    this.Info("预选成功!");
                }
            }

            //当点击'正式选课'按钮时
            if (skinDataGridView1.Columns[e.ColumnIndex].Name == "colBtn_formalSelect")
            {
                //获取被选中行的数据
                int courseClassId = (int)skinDataGridView1.Rows[e.RowIndex].Cells[0].Value;

                //查:表[class_student]
                ClassStudentBean classStudent = new ClassStudentBean(courseClassId, student.Id);
                ClassStudentDao  DAO          = new ClassStudentDao();
                if (DAO.FindByCourseClassId_StuId(classStudent) != null)
                {
                    this.Warning("选课失败!您已正选过此门课程,请不要重复选课!");
                    return;
                }
                //增:表[class_student]
                if (DAO.Add(classStudent))
                {
                    this.Info("正式选课成功!");
                }
            }

            //当点击'撤销预选课'按钮时
            if (skinDataGridView1.Columns[e.ColumnIndex].Name == "colBtn_preDelete")
            {
                //获取被选中行的数据
                string number = skinDataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();  //第3列的数据

                //获取目标课程的课程编号
                CourseDao  courseDAO = new CourseDao();
                CourseBean course    = courseDAO.FindByNumber(new CourseBean(number, null, null, 0, 0, 0, 0, 0));

                //获取目标预选课的预选ID
                PlanStudyCourseBean planStudyCourse    = new PlanStudyCourseBean(course.Id, 3, student.Id);
                PlanStudyCourseDao  planStudyCourseDao = new PlanStudyCourseDao();
                planStudyCourse = planStudyCourseDao.FindByStuId_CourId_SemsId(planStudyCourse);

                //删除目标预选课
                planStudyCourseDao.DeleteById(planStudyCourse);

                //刷新表格
                ShowMyPlanCourse(this.skinDataGridView1);
                this.Info("已删除!");
            }
        }