private void Update_Click(object sender, System.Windows.RoutedEventArgs e) { if (PhotographerListBox.SelectedItem != null && _photographerListViewModel.ValidBirthday && _photographerListViewModel.ValidFirstName && _photographerListViewModel.ValidSurname) { PhotographerViewModel vm = (PhotographerViewModel)PhotographerListBox.SelectedItem; if (BirthdayBox.SelectedDate <= DateTime.Today) { vm.Birthday = BirthdayBox.SelectedDate; } if (SurnameBox.Text != "Surname" && SurnameBox.Text.Replace(" ", "").Length > 0) { vm.Surname = SurnameBox.Text; } if (FirstnameBox.Text != "First Name" && FirstnameBox.Text.Replace(" ", "").Length > 0) { vm.Name = FirstnameBox.Text; } if (_photographerListViewModel.ModifiedNotes) { vm.Notes = NotesBox.Text; } BusinessLayer.UpdatePhotographer(vm); _photographerListViewModel = new PhotographerListViewModel(BusinessLayer.GetAllPhotographers()); _photographerListViewModel.ValidBirthday = true; _photographerListViewModel.ValidFirstName = true; _photographerListViewModel.ValidSurname = true; PhotographerListBox.ItemsSource = _photographerListViewModel.PhotographerViewModels; PhotographerListBox.SelectedItem = _photographerListViewModel.PhotographerViewModels[0]; } }
public void EditPhotographer(object sender, RoutedEventArgs e) { var mdl = new PhotographerModel { FirstName = _FirstName.Text, LastName = _LastName.Text, BirthDay = _BirthDay.SelectedDate, Notes = _Notes.Text }; var vmdl = new PhotographerViewModel(mdl); if (!vmdl.IsValid) { MessageBoxEx.Show(vmdl.ValidationSummary, "Edit Photographer", MessageBoxButton.OK, MessageBoxImage.Error); } else { try { BL.Update(mdl); } catch (System.Exception) { //show error throw; } }
private void Create_Click(object sender, System.Windows.RoutedEventArgs e) { //This seems botchy, but currently you can bypass the "live" validity check with backspace, as this doesn't register as a keystroke, so we have to check it again for creation _photographerListViewModel.ValidFirstName = (SurnameBox.Text != "Surname" && SurnameBox.Text.Replace(" ", "").Length > 0); _photographerListViewModel.ValidSurname = (FirstnameBox.Text != "First Name" && FirstnameBox.Text.Replace(" ", "").Length > 0); if (_photographerListViewModel.ValidBirthday && _photographerListViewModel.ValidFirstName && _photographerListViewModel.ValidSurname) { PhotographerViewModel vm = new PhotographerViewModel(); if (BirthdayBox.SelectedDate <= DateTime.Today) { vm.Birthday = BirthdayBox.SelectedDate; } vm.Surname = SurnameBox.Text; vm.Name = FirstnameBox.Text; if (_photographerListViewModel.ModifiedNotes) { vm.Notes = NotesBox.Text; } BusinessLayer.CreatePhotographer(vm); _photographerListViewModel = new PhotographerListViewModel(BusinessLayer.GetAllPhotographers()); PhotographerListBox.ItemsSource = _photographerListViewModel.PhotographerViewModels; PhotographerListBox.SelectedItem = _photographerListViewModel.PhotographerViewModels[0]; } }
public void CreatePhotographer(object sender, RoutedEventArgs e) { var mdl = new PhotographerModel { FirstName = _FirstName.Text, LastName = _LastName.Text, Notes = _Notes.Text, BirthDay = _BirthDay.SelectedDate }; var vmdl = new PhotographerViewModel(mdl); if (vmdl.IsValid) { try { BL.Save(mdl); } catch (System.Exception) { //show error throw; } finally { Sender.UpdatePhotographerList(); Close(); } } else { MessageBox.Show(vmdl.ValidationSummary, "Add Photographer", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void SaveBtn_Clicked(object sender, RoutedEventArgs e) { var photographer = new PhotographerViewModel(); var birthday = DateTime.Now; if (DateTime.TryParse(Birthday.Text, out birthday)) { if (birthday < DateTime.Now && !string.IsNullOrWhiteSpace(FirstName.Text) && !string.IsNullOrWhiteSpace(LastName.Text) && !string.IsNullOrWhiteSpace(Notes.Text)) { photographer.BirthDay = birthday; photographer.FirstName = FirstName.Text; photographer.LastName = LastName.Text; photographer.Notes = Notes.Text; _controller.SavePhotographer(photographer); this.Close(); } else { ErrorLabel.Content = "INVALID INPUT"; } } else { ErrorLabel.Content = "INVALID INPUT"; } }
private void BtnSaveChanges_Click(object sender, RoutedEventArgs e) { if (lastSelectedViewModel != null) { if (DateTime.TryParse(Birthday.Text, out DateTime birthday)) { if (birthday < DateTime.Now && !string.IsNullOrWhiteSpace(FirstName.Text) && !string.IsNullOrWhiteSpace(LastName.Text) && !string.IsNullOrWhiteSpace(Notes.Text)) { PhotographerViewModel photographerViewModel = lastSelectedViewModel; photographerViewModel.FirstName = FirstName.Text; photographerViewModel.LastName = LastName.Text; photographerViewModel.BirthDay = DateTime.Parse(Birthday.Text); photographerViewModel.Notes = Notes.Text; _controller.UpdatePhotographer(photographerViewModel); } else { ErrorLabel.Content = "INVALID INPUT"; } } else { ErrorLabel.Content = "INVALID INPUT"; } } }
public MainWindow(MainWindowViewModel mainWindowViewModel, PhotographerWindowViewModel photographerWindowViewModel, PhotographerViewModel photographerViewModel) { DataContext = mainWindowViewModel; _mainWindowViewModel = mainWindowViewModel; _photographerWindowViewModel = photographerWindowViewModel; _photographerViewModel = photographerViewModel; InitializeComponent(); }
//Events void ChangePhotographer(object sender, SelectionChangedEventArgs args) { if (PhotographerListBox.SelectedItem != null) { PhotographerViewModel photographer = (PhotographerViewModel)PhotographerListBox.SelectedItem; FirstnameBox.Text = photographer.Name ?? "First Name"; SurnameBox.Text = photographer.Surname ?? "Surname"; BirthdayBox.SelectedDate = photographer.Birthday; NotesBox.Text = photographer.Notes ?? "Notes"; } }
/// <summary> /// add photographer to list view model /// </summary> /// <param name="p"></param> public void Add(PhotographerModel p) { if (p == null) { return; } PhotographerViewModel pvm = new PhotographerViewModel(p); _List.Add(pvm); CurrentIndex = Count - 1; OnPropertyChanged("List"); OnPropertyChanged("Count"); }
/// <summary> /// save photographer changes to database /// check if model is valid and undo updates if not valid /// </summary> /// <param name="currentPhotographer"></param> internal void CurrentPhotographerChanged(IPhotographerViewModel currentPhotographer) { PhotographerViewModel pvm = (PhotographerViewModel)currentPhotographer; if (!pvm.IsValid) { Error(pvm.ValidationSummary); pvm.UndoUpdate(); return; } Save(pvm.PhotographerModel); }
private void PhotographerBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (PhotographerBox.SelectedItem != null) { var PhotographerModel = (PhotographerViewModel)PhotographerBox.SelectedItem; lastSelectedViewModel = PhotographerModel; FirstName.Text = PhotographerModel.FirstName; LastName.Text = PhotographerModel.LastName; Birthday.Text = PhotographerModel.BirthDay.ToString(); Notes.Text = PhotographerModel.Notes; } ErrorLabel.Content = ""; }
public PictureViewModel(PictureModel mdl) { this.mdl = mdl; _camera = new CameraViewModel(); _iptc = new IPTCViewModel(); EXIFModel em = new EXIFModel(); em.Make = "Hi"; em.ISOValue = 30; em.Flash = true; _exif = new EXIFViewModel(em); _picTitle = ""; _photographer = new PhotographerViewModel(new PhotographerModel()); }
/// /// Creates a new Photographer /// public static void CreatePhotographer(PhotographerViewModel vm) { SqlCommand command; command = DbHelper.CreateCommand("INSERT INTO PHOTOGRAPHERS " + "(Name, Surname, Birthday, Notes)" + " VALUES (@name, @surname, @birthday, @notes)"); command.Parameters.AddWithValue("@surname", vm.Surname); command.Parameters.AddWithValue("@name", vm.Name); command.Parameters.AddWithValue("@birthday", vm.Birthday ?? (object)DBNull.Value); command.Parameters.AddWithValue("@notes", vm.Notes ?? (object)DBNull.Value); command.ExecuteNonQuery(); }
/// /// Updates a specific Photographer /// public static void UpdatePhotographer(PhotographerViewModel vm) { SqlCommand command; command = DbHelper.CreateCommand("UPDATE PHOTOGRAPHERS SET " + "Name = @name," + "Surname = @surname," + "Birthday = @birthday," + "Notes = @notes" + " WHERE Id = @id"); command.Parameters.AddWithValue("@id", vm.Id); command.Parameters.AddWithValue("@surname", vm.Surname); command.Parameters.AddWithValue("@name", vm.Name); command.Parameters.AddWithValue("@birthday", vm.Birthday ?? (object)DBNull.Value); command.Parameters.AddWithValue("@notes", vm.Notes ?? (object)DBNull.Value); command.ExecuteNonQuery(); }
/// <summary> /// Ladet die Photographers aus dem Configfile /// </summary> /// <returns></returns> private List <PhotographerViewModel> loadPhotographers() { BusinessLayer bl = new BusinessLayer(); bl.Sync(); var models = bl.GetPhotographers(); List <PhotographerViewModel> list = new List <PhotographerViewModel>(); if (models != null) { foreach (PhotographerModel model in models) { var photographerViewModel = new PhotographerViewModel(model); list.Add(photographerViewModel); } } //shit pfad string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Mausi\Desktop\SWE-PRUEFUNG\PicDB\photographers.config"); PhotographerModel p; PhotographerViewModel pvm; foreach (string line in lines) { string[] element = line.Split(';'); p = new PhotographerModel(); p.FirstName = element[0]; p.LastName = element[1]; p.Notes = element[3]; pvm = new PhotographerViewModel(p); list.Add(pvm); } return(list); }
/// /// Creates a new Photographer in the Database /// public static void CreatePhotographer(PhotographerViewModel vm) { DataAccessLayer.CreatePhotographer(vm); }