Exemple #1
0
 private void RemoveBtnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         Pet pet = PetSelectionComboBox.SelectedItem as Pet;
         if (pet.IsListed == true)
         {
             pet.IsListed = false;
             dbContext.SaveChanges();
             PetSelectionComboBox.Items.Filter = new Predicate <object>(PetIsListed);
             PetSelectionComboBox.Items.Refresh();
         }
         else
         {
             MessageBox.Show("This pet is already unlisted, use the delete function instead.");
         }
     }
     catch (Exception)
     {
         MessageBox.Show("No pet selected", "No Pet");
     }
 }
        //Remove
        private void RemoveBtnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                SubTitleText(true, "");

                Appointment appointmentRemove = AppListOfAppointments.SelectedItem as Appointment;

                appointmentRemove.Islisted = false;

                dbcontext.SaveChanges();

                AppListOfAppointments.Visibility = Visibility.Collapsed;

                AppShowUppComingAppointments(true);


                AppListOfAppointments.SelectedIndex = 0;
            }
            catch (Exception)
            {
                MessageBox.Show("No appointment selected");
            }
        }
        private void Controls_SaveBtn(object sender, RoutedEventArgs e)
        {
            while (true)
            {
                //Save function determains which entity to save based on which
                //control detail view is visible. It then saves either a new item
                //or updates the currently selected item in the datagrid if it is
                //the same as the one in the detail view.

                //Breed
                if (ControlDetailBreed.Visibility == Visibility.Visible)
                {
                    DataGrid dg = ControlsDataGrid_Breed as DataGrid;

                    if (dg.SelectedItem != ControlDetailBreed.DataContext)
                    {
                        Breed newBreed = ControlDetailBreed.DataContext as Breed;
                        newBreed.Species = ServicesBreedCmbBox.SelectedItem as Species;

                        if (String.IsNullOrEmpty(newBreed.BreedName) ||
                            String.IsNullOrWhiteSpace(newBreed.BreedName) ||
                            newBreed.Species == null)
                        {
                            MessageBox.Show("Both Breed name and Species must have a value");
                            break;
                        }

                        dbContext.Breeds.Add(newBreed);
                        ControlsDataGrid_Breed.IsEnabled = true;
                    }
                    else
                    {
                        dg.SelectedItem = ControlDetailBreed.DataContext as Breed;
                    }

                    ControlDetailBreed.IsEnabled = false;
                }

                //Species
                else if (ControlDetailSpecies.Visibility == Visibility.Visible)
                {
                    DataGrid dg = ControlsDataGrid_Species as DataGrid;

                    if (dg.SelectedItem != ControlDetailSpecies.DataContext)
                    {
                        Species newSpecies = ControlDetailSpecies.DataContext as Species;

                        if (String.IsNullOrEmpty(newSpecies.SpeciesName) ||
                            String.IsNullOrWhiteSpace(newSpecies.SpeciesName))
                        {
                            MessageBox.Show("Species name must have a value");
                            break;
                        }

                        dbContext.Species.Add(newSpecies);
                        ControlsDataGrid_Species.IsEnabled = true;
                    }
                    else
                    {
                        dg.SelectedItem = ControlDetailSpecies.DataContext as Species;
                    }

                    ControlDetailSpecies.IsEnabled = false;
                }

                //Users
                else if (ControlDetailUsers.Visibility == Visibility.Visible)
                {
                    DataGrid dg = ControlsDataGrid_Users as DataGrid;

                    if (dg.SelectedItem != ControlDetailUsers.DataContext)
                    {
                        User newUser = ControlDetailUsers.DataContext as User;

                        newUser.Password = PasswordTxtBox.Password;

                        if (String.IsNullOrEmpty(newUser.UserName) ||
                            String.IsNullOrWhiteSpace(newUser.UserName) ||
                            String.IsNullOrEmpty(newUser.Password) ||
                            String.IsNullOrWhiteSpace(newUser.Password))

                        {
                            MessageBox.Show("Both User name and password must have a value");
                            break;
                        }

                        dbContext.Users.Add(newUser);
                        ControlsDataGrid_Users.IsEnabled = true;
                    }
                    else
                    {
                        dg.SelectedItem = ControlDetailUsers.DataContext as User;
                    }

                    ControlDetailUsers.IsEnabled = false;
                    UsersBtnClick(null, null);
                }

                //Services
                else if (ControlDetailServices.Visibility == Visibility.Visible)
                {
                    DataGrid dg = ControlsDataGrid_Services as DataGrid;

                    if (dg.SelectedItem != ControlDetailServices.DataContext)
                    {
                        Service newService = ControlDetailServices.DataContext as Service;
                        newService.Species = ServicesSpeciesCmbBox.SelectedItem as Species;

                        if (String.IsNullOrEmpty(newService.ServiceType) ||
                            String.IsNullOrWhiteSpace(newService.ServiceType) ||
                            newService.Species == null)
                        {
                            MessageBox.Show("Both Service Type and Species must have a value");
                            break;
                        }

                        dbContext.Services.Add(newService);
                        ControlsDataGrid_Services.IsEnabled = true;
                    }
                    else
                    {
                        dg.SelectedItem = ControlDetailServices.DataContext as Service;
                    }

                    ControlDetailServices.IsEnabled = false;
                }

                dbContext.SaveChanges();

                ShowBottomPanelIfAdmin();
                //BottomPanelButtons.Visibility = Visibility.Visible;
                SaveAbortButtons.Visibility           = Visibility.Collapsed;
                ControlSidePanelBtn.IsEnabled         = true;
                ControlsDataGrid_Services.Visibility  = Visibility.Visible;
                ControlsMiddleRightMainGrid.IsEnabled = true;
                break;
            }
        }