public MainViewModel() { Application.Current.MainWindow.Closing += MainWindow_Closing; Application.Current.MainWindow.Closed += MainWindow_Closed; try { _ctx = new UnitOfWork(new IsisContext()); Workspaces = new ObservableCollection<WorkspaceViewModel> { new BerekenModuleViewModel(_ctx), new PrestatieBeheerViewModel(_ctx), new KlantenBeheerViewModel(_ctx), new PersoneelBeheerViewModel(_ctx), new ParameterBeheerViewModel(_ctx) }; SelectedWorkspace = Workspaces.First(); } catch (Exception ex) { MessageBoxService messageService = new MessageBoxService(); messageService.ShowMessageBox("ERROR"); //Hack: The first Messagebox closes automatically //TODO: Add possiblity to restore database from backup! messageService.ShowErrorBox("Er heeft zich een probleem voorgedaan bij het ophalen van de data \n\nError: " + ex.Message); logger.Error("Loading Database (startup)", ex); Application.Current.Shutdown(-1); } }
public virtual bool Leave(bool changes = false, bool errors = false) { if(Ctx.HasChanges() || changes) { MessageBoxService messageService = new MessageBoxService(); var result = messageService.AskForConfirmation("Er zijn nog onopgeslagen wijzigingen.\nWilt u deze wijzingen nog opslaan?", Header); if (result == MessageBoxResult.Yes) { //Check if there are validation errors!!! try { if (errors) throw new Exception("There is a specific validation error"); Ctx.Complete(); } catch { messageService.ShowMessageBox("Er bevinden zich nog fouten in de data! Kan dit niet opslaan!"); return false; } } else if (result == MessageBoxResult.No) { Ctx.DiscardChanges(); } else { return false; } } return true; }
//TODO Obrázek týmu public void Delete() { //TODO Are you sure? //TODO Mazání MessageBoxService.ShowMessageBox("Tým byl smazán.", "Úspěch"); GoBack(); }
public void Save() { if (name == null) { MessageBoxService.ShowErrorMessageBox(new Exception("Invalid team name")); } else { //TODO Save MessageBoxService.ShowMessageBox("Nastavení týmu bylo aktualizováno.", "Uloženo."); GoBack(); } }
private void handleEditEmployees(object sender, RoutedEventArgs eventArgs) { try { var gridRows = GetDataGridRows(EmployeeDetailsDataGrid); DataGridRow selectedRow = GetSelectedRow(gridRows); if (selectedRow == null) { MessageBoxService.ShowMessageBox("Select a row to edit.", "Edit info", MessageBoxButton.OK, MessageBoxImage.Information); } else { EditEmployeeDetailsPopupControl.editRowPopup.IsOpen = true; EditEmployeeDetailsPopupControl.DataContext = _employeeViewModel; ClosePopup(sender, eventArgs); } } catch { } }
public void Login() { var user = AppRepository.UsersRepository.FindUserByEmail(Email); string encodedPassword = Password; //TODO Encode password if (user == null) { MessageBoxService.ShowErrorMessageBox(new Exception("Invalid user")); } else if (encodedPassword != user.Password) { MessageBoxService.ShowMessageBox("Invalid password"); } else { AppRepository.UsersRepository.UpdateLastLogin(user.ID, DateTime.Now); var model = IoC.Get <MainPageViewModel>(); EventAggregator.PublishOnUIThread(new ShowViewModelMessage(model)); } }
public void Register() { if (Password != RepeatPassword) { MessageBoxService.ShowMessageBox("Zadaná hesla nesouhlasí", "Chyba validace"); return; } string encryptedPassword = Password; var newUser = new User() { Email = Email, Name = FirstName, Password = encryptedPassword, Surname = surname }; AppRepository.UsersRepository.CreateUser(newUser); MessageBoxService.ShowMessageBox("Registrace proběhla v pořádku.", "Děkujeme"); GoBack(); }
public void Save() { if (!DatumViewModel.HasDates) { MessageBoxService messageService = new MessageBoxService(); messageService.ShowMessageBox("Je hebt nog geen datum gekozen!"); return; } try { //Add prestatie + dates to DB if (ButtonToevoegenContent == "Toevoegen") { //Add date(s) to DB Ctx.Datums.AddRange(DatumViewModel.NewDates); //Add prestatie to DB (parameter needs to be last date) CurrentView.Save(DatumViewModel.NewDates.Last().Date); #region Legacy code ////Add Dates to DB //foreach (var d in DatumViewModel.NewDates) //{ // d.Id = CurrentView.AddPrestatie.Id; // context.Datum.Add(d); // //EF is retarded and thinks that I readded the Strijkers to the db, while I didn't. // //I Just use them as foreign relantionschip, I can't just use the id, because I need the name // //Manually said this is not true // //https://msdn.microsoft.com/en-us/magazine/dn166926.aspx // //This link explains it! // if (d.Strijker1 != null) // context.Entry(d.Strijker1).State = EntityState.Unchanged; // if (d.Strijker2 != null) // context.Entry(d.Strijker2).State = EntityState.Unchanged; // if (d.Strijker3 != null) // context.Entry(d.Strijker3).State = EntityState.Unchanged; // if (d.Strijker4 != null) // context.Entry(d.Strijker4).State = EntityState.Unchanged; // if (d.Strijker5 != null) // context.Entry(d.Strijker5).State = EntityState.Unchanged; //} #endregion } //Update (edit) last prestatie + dates else { CurrentView.UpdateLast(); ButtonBerekenContent = "Berekenen"; ButtonToevoegenContent = "Toevoegen"; ButtonChangeContent = "Laatste prestatie aanpassen"; } //Save changes to DB Ctx.Complete(); } catch (Exception ex) { Ctx.DiscardChanges(); MessageBoxService messageService = new MessageBoxService(); messageService.ShowErrorBox("Er heeft zich een probleem voorgedaan bij het opslaan van een prestatie \n\nError: " + ex.Message); } //Re init CurrentView => Make new Prestatie, ... CurrentView.Init(); DatumViewModel.Init(); }
public void Print() { MessageBoxService messageService = new MessageBoxService(); if (Ctx.TijdPrestaties.Any()) { //Get all previous TijdPrestaties of the selected klant var tempPrestatie = Ctx.TijdPrestaties.GetLatestPrestatie(SelectedKlant); if (tempPrestatie == null) { messageService.ShowMessageBox("Deze klant heeft geen vorige prestaties, u kunt niets printen"); } else { PrintWindow print = new PrintWindow(); print.ShowPrintPreview(tempPrestatie); } } else { messageService.ShowMessageBox("Er bevinden zich nog geen prestaties in de databank, u kunt niets printen"); } }
public void Edit() { if (SelectedKlant == null) { MessageBoxService messageBoxService = new MessageBoxService(); messageBoxService.ShowMessageBox("Je hebt nog geen klant gekozen!"); return; } if (ButtonToevoegenContent == "Toevoegen") { //TODO: Denk hier nog eens over na... try { CurrentView.EditLast(DatumViewModel); ButtonBerekenContent = "Herberekenen"; ButtonToevoegenContent = "Aanpassen"; ButtonChangeContent = "Annuleren"; } catch (Exception e) { MessageBoxService messageService = new MessageBoxService(); messageService.ShowMessageBox(e.Message); } } else { ButtonBerekenContent = "Berekenen"; ButtonToevoegenContent = "Toevoegen"; ButtonChangeContent = "Laatste prestatie aanpassen"; CurrentView.Cancel(); DatumViewModel.Init(); } }
public void Bereken() { if (SelectedKlant == null) { MessageBoxService messageBoxService = new MessageBoxService(); messageBoxService.ShowMessageBox("Je hebt nog geen klant gekozen!"); return; } CurrentView.Bereken(); }
public void Add() { var duplicate = ViewSource.View.Cast<Datum>().FirstOrDefault(d => d.Date.Date == AddDatum.Date.Date); if (duplicate == null) { //Add new date to a new prestatie if (_id == 0) NewDates.Add(AddDatum); //Add new date to an existing prestatie else { AddDatum.PrestatieId = _id; _ctx.Datums.Add(AddDatum); } AddDatum = new Datum { Date = DateTime.Now }; } else { MessageBoxService messageBoxService = new MessageBoxService(); messageBoxService.ShowMessageBox("Deze datum is al toegevoegd!"); } }