Exemple #1
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (IsBtnConfirmEnabled())
            {
                try
                {
                    List <TrainingGroup> selectedGroups = new List <TrainingGroup>();

                    foreach (object item in listBoxGroups.SelectedItems)
                    {
                        TrainingGroup group = (TrainingGroup)item.GetType()
                                              .GetProperty("Value")
                                              .GetValue(item, null);
                        selectedGroups.Add(group);
                    }

                    object comboBoxItem = comboBoxFitnessLvl.SelectedItem;

                    FitnessLevel fitnessLevel = (FitnessLevel)comboBoxItem
                                                .GetType().GetProperty("Value")
                                                .GetValue(comboBoxItem, null);

                    mainController.AddClient(
                        new Client(textBoxOib.Text, textBoxFirstName.Text, textBoxLastName.Text,
                                   dtpDateOfBirth.Value, textBoxPhoneNum.Text,
                                   dtpDateOfJoining.Value, fitnessLevel,
                                   textBoxNotes.Text, selectedGroups));

                    DialogResult = DialogResult.OK;
                }
                catch (IncompleteDataException)
                {
                    MessageBox.Show("Nepotpuni ili neispravni podaci", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (OibAlreadyTakenException)
                {
                    MessageBox.Show("Klijent s unesenim OIB-om već postoji", "Greška!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }