예제 #1
0
        private void Add_Button_Click(object sender, RoutedEventArgs e)
        {
            if (statusText.Text != "Work")
            {
                if (FNameInput.Text != "" && SurnameInput.Text != "" && HeightInput.Text != "" && GenderCombo.SelectedIndex != -1 && EyeColorCombo.SelectedIndex != -1 && StatusCombo.SelectedIndex != -1)
                {
                    bool   doctor = false;
                    Doctor d      = new Doctor();

                    //assinging to class
                    Person p = new Person();
                    p.SurName   = SurnameInput.Text;
                    p.GivenName = FNameInput.Text;


                    p.Height = decimal.Parse(HeightInput.Text.Replace('.', ','));

                    //combo box selections to string values.
                    ComboBoxItem GenderItem = (ComboBoxItem)GenderCombo.SelectedItem;
                    p.Gender = GenderItem.Content.ToString();

                    ComboBoxItem EyeItem = (ComboBoxItem)EyeColorCombo.SelectedItem;
                    p.EyeColor = EyeItem.Content.ToString();

                    ComboBoxItem StatusItem = (ComboBoxItem)StatusCombo.SelectedItem;
                    p.Status = StatusItem.Content.ToString();


                    //launching the addPerson method, and passing it the class person.
                    SqliteDataAccess sqlDataA = new SqliteDataAccess();
                    sqlDataA.AddPerson(p, d, doctor);

                    //reset fields.
                    SurnameInput.Text = "";
                    FNameInput.Text   = "";
                    HeightInput.Text  = "";
                    GenderCombo.Items.Clear();
                    EyeColorCombo.Items.Clear();
                    StatusCombo.Items.Clear();
                }
                else
                {
                    MessageBox.Show("Please fill required boxes!");
                }
            }
            else
            {
                if (FNameInput.Text != "" && SurnameInput.Text != "" && HeightInput.Text != "" && GenderCombo.SelectedIndex != -1 && EyeColorCombo.SelectedIndex != -1 && StatusCombo.SelectedIndex != -1)
                {
                    bool doctor = true;
                    //assinging to class
                    Person p = new Person();
                    Doctor d = new Doctor();
                    d.SurName   = SurnameInput.Text;
                    d.GivenName = FNameInput.Text;


                    d.Height = decimal.Parse(HeightInput.Text.Replace('.', ','));

                    //combo box selections to string values.
                    ComboBoxItem GenderItem = (ComboBoxItem)GenderCombo.SelectedItem;
                    d.Gender = GenderItem.Content.ToString();

                    ComboBoxItem EyeItem = (ComboBoxItem)EyeColorCombo.SelectedItem;
                    d.EyeColor = EyeItem.Content.ToString();

                    ComboBoxItem WorkItem = (ComboBoxItem)StatusCombo.SelectedItem;
                    d.work = WorkItem.Content.ToString();


                    //launching the addPerson method, and passing it the class person.
                    SqliteDataAccess sqlDataA = new SqliteDataAccess();
                    sqlDataA.AddPerson(p, d, doctor);

                    //reset fields.
                    SurnameInput.Text = "";
                    FNameInput.Text   = "";
                    HeightInput.Text  = "";
                    GenderCombo.Items.Clear();
                    EyeColorCombo.Items.Clear();
                    StatusCombo.Items.Clear();
                }
                else
                {
                    MessageBox.Show("Please fill required boxes!");
                }
            }
        }