Exemple #1
0
        public AddMedicament(Medicament medicament, Human human)
        {
            InitializeComponent();
            ComboBoxMedicament.Items.Add("Tablets");
            ComboBoxMedicament.Items.Add("Spray");
            ComboBoxMedicament.Items.Add("Syrup");
            ComboBoxMedicament.Items.Add("Suspension");
            ComboBoxMedicament.Items.Add("Ampoule");

            ComboBoxCountName.Items.Add("tabl");
            ComboBoxCountName.Items.Add("time(s)");
            ComboBoxCountName.Items.Add("ml");
            ComboBoxCountName.Items.Add("mg");
            ComboBoxCountName.Items.Add("piece(s)");

            for (int i = 1; i < 25; i++)
            {
                ComboBoxTimesOfADay.Items.Add(i);
            }

            ComboBoxPeople.Items.Add(human.Name);
            ComboBoxPeople.SelectedIndex = 0;
            ComboBoxPeople.IsEnabled     = false;

            TextBoxTitle.Text = medicament.Title;

            ComboBoxMedicament.SelectedItem = medicament.Name;

            TextBoxCountMedicament.Text = medicament.Num.ToString();

            ComboBoxCountName.SelectedItem = medicament.UnitOfPreparation.ToString();

            DatePickerStartDate.SelectedDate = medicament.StartDate;

            switch (medicament.OfAdmission)
            {
            case FrequencyOfAdmission.EveryDay:
                EveryDay.IsChecked = true;
                break;

            case FrequencyOfAdmission.OnCertainDays:
                OnCertainDays.IsChecked = true;
                foreach (var item in listBoxOnCertainDays.Items)
                {
                    foreach (var day in medicament.Days)
                    {
                        if (((CheckBox)item).Content.ToString() == day.ToString())
                        {
                            ((CheckBox)item).IsChecked = true;
                        }
                    }
                }
                break;

            case FrequencyOfAdmission.DailyInterval:
                DailyInterval.IsChecked   = true;
                textBoxDailyInterval.Text = medicament.DaysOfDailyInterval.ToString();
                break;
            }

            TextBoxDuring.Text = medicament.DurationOfAdmission.ToString();

            ComboBoxTimesOfADay.SelectedItem = medicament.TimesADay;

            TextBoxNotes.Text = medicament.Notes;
            _medicament       = medicament;
            _human            = human;
        }
Exemple #2
0
        private void ButtonDone_Click(object sender, RoutedEventArgs e)
        {
            if (_medicament == null)
            {
                Human humanFind = null;
                try
                {
                    foreach (var human in _people)
                    {
                        if (ComboBoxPeople.SelectedItem.ToString() == human.Name)
                        {
                            humanFind = human;
                            break;
                        }
                    }
                    if (humanFind != null)
                    {
                        Medicament newMedicament = new Medicament(ComboBoxMedicament.SelectedItem.ToString());
                        newMedicament.Title               = TextBoxTitle.Text;
                        newMedicament.Notes               = TextBoxNotes.Text;
                        newMedicament.Num                 = Int32.Parse(TextBoxCountMedicament.Text);
                        newMedicament.StartDate           = (DateTime)DatePickerStartDate.SelectedDate;
                        newMedicament.DurationOfAdmission = Int32.Parse(TextBoxDuring.Text);
                        newMedicament.UnitOfPreparation   = UnitOfPreparation.Pieces;
                        newMedicament.OfAdmission         = _frequencyOfAdmission;
                        newMedicament.TimesADay           = Int32.Parse(ComboBoxTimesOfADay.SelectedItem.ToString());
                        switch (newMedicament.OfAdmission)
                        {
                        case FrequencyOfAdmission.EveryDay:
                            break;

                        case FrequencyOfAdmission.OnCertainDays:
                            if (listBoxOnCertainDays != null)
                            {
                                int i = 0;
                                foreach (var item in listBoxOnCertainDays.Items)
                                {
                                    if ((bool)((CheckBox)item).IsChecked)
                                    {
                                        newMedicament.Days.Add((CertainDays)i);
                                    }
                                    i++;
                                }
                            }
                            break;

                        case FrequencyOfAdmission.DailyInterval:
                            if (textBoxDailyInterval != null)
                            {
                                newMedicament.DaysOfDailyInterval = Int32.Parse(textBoxDailyInterval.Text);
                            }
                            break;
                        }
                        humanFind.AddMedicament(newMedicament);
                        _isEdited = false;
                        this.Close();
                    }
                }
                catch (Exception exception)
                {
                    new ToastPopUp("Error!", exception.Message + "\nPlease, fill the fields!", NotificationType.Error).Show();
                }
            }
            else
            {
                SaveChanges();
            }
        }