Ejemplo n.º 1
0
        private void InsertClicked(object sender, EventArgs e)
        {
            Course             c     = new Course();
            Random             r     = new Random();
            SemesterRepository sRepo = new SemesterRepository();
            int x;

            if (this.textBoxName.Text != "" && this.comboBoxSemester.Text != "" && this.textBoxSection.Text != "" && this.comboBoxSchedule.Text != "")
            {
                if (sRepo.CheckSemester2(this.comboBoxSemester.Text))
                {
                    x = r.Next(1000, 4999);

                    if (this.radioButtonCSE.Checked)
                    {
                        c.CourseId   = "CSE" + x.ToString();
                        c.Department = "CSE";
                    }
                    else if (this.radioButtonEEE.Checked)
                    {
                        c.CourseId   = "EEE" + x.ToString();
                        c.Department = "EEE";
                    }
                    else
                    {
                        c.CourseId   = "BBA" + x.ToString();
                        c.Department = "BBA";
                    }
                    this.labelId.Text = c.CourseId;
                    c.Name            = this.textBoxName.Text.ToUpper();
                    c.Semester        = this.comboBoxSemester.Text.ToUpper();
                    c.Section         = this.textBoxSection.Text.ToUpper();

                    if (this.radioButton20.Checked)
                    {
                        c.MaxStudent = 20;
                    }
                    else if (this.radioButton30.Checked)
                    {
                        c.MaxStudent = 30;
                    }
                    else
                    {
                        c.MaxStudent = 40;
                    }
                    c.CurrentStudent = 0;

                    if (this.radioButton1Credit.Checked)
                    {
                        c.Credit = 1;
                    }
                    else
                    {
                        c.Credit = 3;
                    }
                    c.Schedule = this.comboBoxSchedule.Text.ToUpper();

                    CourseRepository cRepo = new CourseRepository();

                    if (cRepo.Insert2(c))
                    {
                        MessageBox.Show("One Course Added", "Successful");
                        this.dataGridViewCourse.DataSource = cRepo.GetAllCourses2();
                    }
                    else
                    {
                        MessageBox.Show("Fill up all the fields", "Failed");
                    }
                }
                else
                {
                    MessageBox.Show("Invalide Semester Name", "Failed");
                }
            }
        }