/// <summary> /// Validate lost info data /// </summary> private void VerifyLost() { if (IsLostCheckbox.IsChecked.Value) { if (!AnimalLostDateDatePicker.SelectedDate.HasValue) { MessageBox.Show("Data ucieczki nie jest wybrana!", "Uwaga", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (Animal.LostInfo == null) { Animal.LostInfo = new Lost() { Date = AnimalLostDateDatePicker.SelectedDate.Value, Description = AnimalLostDescriptionTextBox.Text }; } else { Animal.LostInfo.Date = AnimalLostDateDatePicker.SelectedDate.Value; Animal.LostInfo.Description = AnimalLostDescriptionTextBox.Text; } } else if (!IsLostCheckbox.IsChecked.Value && Animal.LostInfo != null) { AnimalsManager.RemoveLost(Animal.LostInfo); } }
/// <summary> /// Validate death info data /// </summary> private void VerifyDeath() { if (IsAliveCheckbox.IsChecked.Value) { if (!AnimalDeathDateDatePicker.SelectedDate.HasValue) { MessageBox.Show("Data śmierci nie jest wybrana!", "Uwaga", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (Animal.DeathInfo == null) { Animal.DeathInfo = new Death() { Date = AnimalDeathDateDatePicker.SelectedDate.Value, Description = AnimalDeathDescriptionTextBox.Text }; } else { Animal.DeathInfo.Date = AnimalDeathDateDatePicker.SelectedDate.Value; Animal.DeathInfo.Description = AnimalDeathDescriptionTextBox.Text; } } else if (!IsAliveCheckbox.IsChecked.Value && Animal.DeathInfo != null) { AnimalsManager.RemoveDeath(Animal.DeathInfo); } }
/// <summary> /// Details windows loaded event - prepare data and components /// </summary> /// <param name="sender">Window object</param> /// <param name="e">Event arguments</param> private void InformationWindow_Loaded(object sender, RoutedEventArgs e) { AnimalTypeComboBox.ItemsSource = Enum.GetValues(typeof(AnimalType)).Cast <AnimalType>(); AnimalTab.DataContext = Animal; AdoptiveTab.DataContext = Animal.Adoptive; DeathTab.DataContext = Animal.DeathInfo; LostTab.DataContext = Animal.LostInfo; VaccinationTab.DataContext = new Vaccination(); IsAliveCheckbox.IsChecked = (Animal.DeathInfo != null); IsLostCheckbox.IsChecked = (Animal.LostInfo != null); IsAdoptedCheckbox.IsChecked = (Animal.Adoptive != null); AdoptivesComboBox.ItemsSource = new ObservableCollection <Adoptive>(AnimalsManager.GetAllAdoptivesInAlphabeticalOrder()); AdoptivesComboBox.SelectedItem = Animal.Adoptive; AnimalBirthDateDatePicker.DisplayDateStart = DateTime.MinValue; AnimalBirthDateDatePicker.DisplayDateEnd = DateTime.Today; AnimalJoinDateDatePicker.DisplayDateStart = DateTime.MinValue; AnimalJoinDateDatePicker.DisplayDateEnd = DateTime.Today; AnimalDeathDateDatePicker.DisplayDateStart = DateTime.MinValue; AnimalDeathDateDatePicker.DisplayDateEnd = DateTime.Today; AnimalLostDateDatePicker.DisplayDateStart = DateTime.MinValue; AnimalLostDateDatePicker.DisplayDateEnd = DateTime.Today; }
void Awake() { if (instance == null) { instance = this; } }
/// <summary> /// Animals window constructor - initialize managers and loads animals to datagrid /// </summary> /// <param name="user">Entity of logged in user</param> public AnimalsWindow(User user) { InitializeComponent(); User = user; AnimalsManager = new AnimalsManager(); ExpiringVaccinationsManager = new ExpiringVaccinationsManager(); Animals = AnimalsManager.Load(); AnimalsGrid.ItemsSource = Animals; MessageBox.Show($"Witaj {User.Name} {User.Surname}", "Powodzenie", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Details window constructor for edit mode /// </summary> /// <param name="animalsManager">Animals manager object</param> /// <param name="animal">Animal entity choosen to edit</param> public DetailsWindow(AnimalsManager animalsManager, Animal animal) { AnimalsManager = animalsManager; Animal = animal; Mode = Mode.Edit; InitializeComponent(); SaveButton.Content = "Zapisz zmiany"; VaccinationsDataGrid.ItemsSource = new ObservableCollection <Vaccination>(AnimalsManager.GetAnimalVaccinations().Where(vacc => vacc.Animal.ID == Animal.ID)); }
/// <summary> /// Details window constructor for add mode /// </summary> /// <param name="animalsManager">Animals manager object</param> public DetailsWindow(AnimalsManager animalsManager) { InitializeComponent(); AnimalsManager = animalsManager; Animal = new Animal() { BirthDate = new DateTime(DateTime.Now.Year, 1, 1), JoinDate = DateTime.Today }; Mode = Mode.Add; SaveButton.Content = "Dodaj"; VaccinationsDataGrid.ItemsSource = new ObservableCollection <Vaccination>(); }
/// <summary> /// Delete button click event handler /// </summary> /// <param name="sender">Clicked button object</param> /// <param name="e">Event arguments</param> private void DeleteButton_Click(object sender, RoutedEventArgs e) { if (AnimalsGrid.SelectedItem != null && !AnimalsGrid.SelectedItem.ToString().Contains("Placeholder")) { Animal animal = (Animal)AnimalsGrid.SelectedItem; if (MessageBox.Show("Czy na pewno chcesz usunąć to zwierzę z bazy? Operacja jest NIEODWRACALNA!", "Uwaga", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { AnimalsManager.RemoveAnimal(animal); AnimalsManager.SaveChanges(); MessageBox.Show("Pomyślnie usunięto zwierze", "Powodzenie", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Najpierw wybierz zwierzę do usunięcia!", "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } }
public AnimalsController() { _animalsManager = new AnimalsManager(); _homesManager = new HomesManager(); var conf = new MapperConfiguration(cfg => { cfg.CreateMap <AnimalModel, ElementViewModel>(); cfg.CreateMap <HomeModel, ElementViewModel>(); cfg.CreateMap <AnimalModel, AnimalViewModel>(); cfg.CreateMap <HomeModel, HomeViewModel>(); cfg.CreateMap <AnimalViewModel, AnimalModel>(); cfg.CreateMap <HomeViewModel, HomeModel>(); }); _mapper = new Mapper(conf); }
private void Awake() { instance = this; }
/// <summary> /// Saves changes click event - does validations for add/edit mode /// </summary> /// <param name="sender">Clicked button object</param> /// <param name="e">Event arguments</param> private void SaveButton_Click(object sender, RoutedEventArgs e) { if (Mode == Mode.Add) { try { if (AdoptiveTelephoneTextBox.Text.Any(c => !Char.IsDigit(c))) { MessageBox.Show("Numer telefonu zawiera inne znaki niż cyfry!", "Uwaga", MessageBoxButton.OK, MessageBoxImage.Warning); return; } int? flatNumber = null; string s_flatNumber = AdoptiveFlatNumberTextBox.Text; if (!String.IsNullOrEmpty(s_flatNumber)) { if (s_flatNumber.Any(c => !Char.IsDigit(c))) { MessageBox.Show("Numer klatki zawiera inne znaki niż cyfry!", "Uwaga", MessageBoxButton.OK, MessageBoxImage.Warning); return; } else { flatNumber = Int32.Parse(s_flatNumber); } } if (IsAdoptedCheckbox.IsChecked.Value && Animal.Adoptive == null) { Animal.Adoptive = new Adoptive() { Name = AdoptiveNameTextBox.Text, Surname = AdoptiveSurnameTextBox.Text, Email = AdoptiveEmailTextBox.Text, Telephone = Int32.Parse(AdoptiveTelephoneTextBox.Text), City = AdoptiveCityTextBox.Text, Street = AdoptiveStreetTextBox.Text, PostalCode = AdoptivePostalCodeTextBox.Text, HouseNumber = Int32.Parse(AdoptiveHouseNumberTextBox.Text), FlatNumber = flatNumber, }; } Animal.Vaccinations = GetVaccinations(); VerifyDeath(); VerifyLost(); var addedAnimal = AnimalsManager.AddNewAnimal(Animal.Name, Animal.Type, Animal.BirthDate, Animal.JoinDate, Animal.Vaccinations, Animal.Chip, Animal.Description, Animal.State, Animal.Treatments, Animal.Adoptive, Animal.DeathInfo, Animal.LostInfo); MessageBox.Show("Nowe zwierze dodane!", "Powodzenie", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } } else if (Mode == Mode.Edit) { try { Animal.Vaccinations = GetVaccinations(); VerifyDeath(); VerifyLost(); AnimalsManager.UpdateAnimal(Animal); MessageBox.Show("Edycja powiodła się!", "Powodzenie", MessageBoxButton.OK, MessageBoxImage.Information); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Błąd", MessageBoxButton.OK, MessageBoxImage.Error); } } }
void Awake() { Instance = this; }