Esempio n. 1
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            String  dni    = infoIdLabel.Text;
            Student alumno = businessControl.findStudentByID(dni);
            String  idAl   = alumno.Id;

            int enId = Int32.Parse(idEnrollmentTextBox.Text);

            Enrollment enrr = new Enrollment();

            enrr.EnrollmentDate   = cursoImAnadir.StartDateTime;
            enrr.CancellationDate = cursoImAnadir.EndTime;
            enrr.UniquePayment    = true;
            enrr.TaughtCourse     = tc;

            if (idEnrollmentTextBox.TextLength == 0 || idEnrollmentTextBox.TextLength == 0)
            {
                MessageBox.Show("Debe rellenar la casilla", "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation
                                );
            }
            else
            {
                foreach (Enrollment en in tc.Enrollments)
                {
                    if (en.TaughtCourse.Id == enrr.Id)
                    {
                        DialogResult errorAsig = MessageBox.Show(this, "El ID introducido ya se está usando", "Error",
                                                                 MessageBoxButtons.OK,
                                                                 MessageBoxIcon.Error);
                        return;
                    }
                }
                try
                {
                    enrr = new Enrollment(enId, cursoImAnadir.StartDateTime, cursoImAnadir.EndTime, true, estudianteAnadir, cursoImAnadir);
                    businessControl.addEnrollment(enrr);
                    businessControl.assignStudentToTaughtCourse(idAl, enrr);
                }
                catch (BusinessLogicException ex)
                {
                    DialogResult errorAsignar = MessageBox.Show(this, ex.Message, "Error",
                                                                MessageBoxButtons.OK,
                                                                MessageBoxIcon.Error);
                    return;
                }

                /*foreach (Enrollment en in tc.Enrollments) // la lista de Enrollments es Count = 0
                 * {
                 *  if (en.Student.Id == idAl)
                 *  {
                 *      DialogResult errorAsig = MessageBox.Show(this, "El alumno ya pertenece a este curso", "Error",
                 *      MessageBoxButtons.OK,
                 *      MessageBoxIcon.Error);
                 *      return;
                 *  }
                 * }
                 * try
                 * {
                 *  //businessControl.addEnrollment(enrr);
                 *  businessControl.assignStudentToTaughtCourse(idAl, enrr);
                 * }
                 * catch (BusinessLogicException ex)
                 * {
                 *  DialogResult errorAsignar = MessageBox.Show(this, ex.Message, "Error",
                 *  MessageBoxButtons.OK,
                 *  MessageBoxIcon.Error);
                 *  return;
                 * }*/
            }
            DialogResult exitoRotundo = MessageBox.Show(this, "Inscripción completa", "Inscripción realizada correctamente",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Asterisk
                                                        );

            this.Close();
            //this.Close();
        }