Exemplo n.º 1
0
        private void button_Copy_Click(object sender, RoutedEventArgs e)
        {
            DrugView _drug = new DrugView();

            _drug.Id   = Int32.Parse(idLabel.Content.ToString());
            _drug      = new DrugView(_drugController.Get(_drug.Id));
            _drug.Name = nameTextBox.Text;

            if (quantityTextBox.Text.Length == 0)
            {
                _drug.Count = 0;
            }
            else
            {
                string s = quantityTextBox.Text;
                int    x = 0;
                int    ux;
                if (int.TryParse(s, out ux))
                {
                    x = int.Parse(s);
                }
                _drug.Count = x;
            }

            Drug drug = _drugController.Get(_drug.Id);

            drug    = _drug.Convert();
            drug.Id = _drug.Id;
            _drugController.Update(drug);

            if (drug.Approved)
            {
                foreach (var drugView in DrugPage.DrugList)
                {
                    if (drugView.Id == drug.Id)
                    {
                        DrugPage.DrugList.Remove(drugView);
                        break;
                    }
                }
                DrugPage.DrugList.Add(_drug);
            }
            else
            {
                foreach (var drugView in DrugPage.DrugListUnapproved)
                {
                    if (drugView.Id == drug.Id)
                    {
                        DrugPage.DrugListUnapproved.Remove(drugView);
                        break;
                    }
                }
                DrugPage.DrugListUnapproved.Add(_drug);
            }

            System.Windows.MessageBox.Show("Uspešno ste sačuvali informacije.");
            NavigationService.Navigate(new Page());
        }
Exemplo n.º 2
0
        private void button_Copy_Click(object sender, RoutedEventArgs e)
        {
            if (nameTextBox.Text.Length == 0)
            {
                System.Windows.MessageBox.Show("Unesite adekvatno ime leka.");
                return;
            }

            if (_drugController.GetByName(nameTextBox.Text) != null)
            {
                System.Windows.MessageBox.Show("Ime leka vec postoji.");
                return;
            }

            DrugView newDrug = new DrugView();

            newDrug.Name     = nameTextBox.Text;
            newDrug.Approved = false;

            foreach (var alternativeDrug in dataGridAlternativeDrug.ItemsSource)
            {
                newDrug.alternativeDrug.Add(((DrugView)alternativeDrug).Id);
            }

            int count = 0;

            bool success = Int32.TryParse(quantityTextBox.Text, out count);

            if (success)
            {
                if (doctorDataGrid.SelectedItems.Count < 2)
                {
                    MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Molimo vas unesite bar 2 lekara");
                    return;
                }
                newDrug.Count = count;

                Drug drug = new Drug();
                drug             = newDrug.Convert();
                drug.SimilarDrug = newDrug.alternativeDrug;
                newDrug.Id       = drug.Id;

                DrugPage.DrugListUnapproved.Add(newDrug);

                List <Doctor> doctors = new List <Doctor>();

                System.Collections.IList selectedDoctors = (System.Collections.IList)doctorDataGrid.SelectedItems;

                foreach (var doctor in selectedDoctors)
                {
                    DoctorView dw = (DoctorView)doctor;
                    doctors.Add(_doctorController.Get((int)dw.Id));
                }

                foreach (var doctor in doctors)
                {
                    drug.ApprovedByDoctor.Add(doctor.Id);
                    doctor.drugsToApprove.Add(drug.Id);

                    _doctorController.Update(doctor);

                    _doctorController.AddNewDrugNotification(doctor.Id, drug.Id);
                }

                _drugController.Add(drug);

                System.Windows.MessageBox.Show("Uspešno ste sačuvali informacije.");
                var page = new Page();
                NavigationService.Navigate(page);
            }
            else
            {
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Molimo vas unesite pravilno informacije o leku.");
            }
        }