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());
        }
        private void Row_MouseDoubleClick_ApproveDrug(object sender, MouseButtonEventArgs e)
        {
            var          data         = (DataGrid)sender;
            Notification notification = (Notification)data.SelectedValue;

            if (notification == null)
            {
                return;
            }
            var drugId = Regex.Match(notification.Text, @"\d+").Value;

            Drug drug = _drugController.Get(Int32.Parse(drugId));

            if (drug != null)
            {
                User   user   = _userController.GetLoggedUser();
                Doctor doctor = _doctorController.Get(user.Id);

                drug = _drugController.Approve(drug.Id, doctor.Id);

                if (drug != null)
                {
                    doctor.Notification.Remove(notification.Id);
                    doctor = _doctorController.Update(doctor);

                    List <Notification> notifications = new List <Notification>();

                    foreach (var notificationId in doctor.Notification)
                    {
                        notifications.Add(_notificationController.Get(notificationId));
                    }

                    notificationDataGrid.ItemsSource = notifications;
                }
            }
        }