private string resfreshInBackground() { AlgorithmDataService ads = new AlgorithmDataService(); Algorithms = ads.GetAlgorithms(_gekozenSessie); return("Done"); }
public void LoadImage() { //upload image OpenFileDialog _importAfbeelding = new OpenFileDialog(); _importAfbeelding.Title = "Select a image"; if (_importAfbeelding.ShowDialog() == true) { ImportPath = _importAfbeelding.FileName; string[] _padGesplitst = _importPath.Split('\\'); ImportNaam = _padGesplitst[(_padGesplitst.Length - 1)]; // kijk of de afbeeldingsNaam al bestaat in de database AlgorithmDataService ads = new AlgorithmDataService(); string afbeeldingBestaat = ads.ImageExists(ImportNaam); if (afbeeldingBestaat != null) { // voorstel voor een imageNaam ophalen string _allImages = ads.GetAllImages(); string _messageBoxMessage = "This image already exists. " + "\n" + "Please use a different name for your image." + "\n \n" + "These images already exists: \n " + _allImages; MessageBox.Show(_messageBoxMessage, "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { ValidationMessage = ""; string _destinationFullPath = System.AppDomain.CurrentDomain.BaseDirectory + "images\\OLL\\" + ImportNaam; DestinationPath = _destinationFullPath.Replace("\\", "/"); } } }
//*****CONSTRUCTOR***** public ResultaatWindowViewModel() { //laden data AlgorithmDataService ads = new AlgorithmDataService(); Algorithms = ads.GetAlgorithms(0); ResultaatDataService rds = new ResultaatDataService(); Resultaten = rds.GetResultaten(); // unieke datums uit de collection halen en opslaan in 'Datums' DateTime _vorigeDatum = new DateTime().Date; foreach (Resultaat Resultaat in Resultaten) { if (Resultaat.Datum.Date != _vorigeDatum) { Datums.Add(Resultaat); _vorigeDatum = Resultaat.Datum.Date; } } //koppelen commands ExitCommand = new BaseCommand(Exit); WijzigResultaatCommand = new BaseCommand(WijzigResultaat); VoegResultaatToeCommand = new BaseCommand(VoegResultaatToe); DeleteResultaatCommand = new BaseCommand(DeleteResultaat); //instantiëren DialogService als singleton _dialogService = new DialogService(); }
private void AlgorithmActief(object algorithmId) { int _algorithmId = (int)algorithmId; AlgorithmDataService ads = new AlgorithmDataService(); ads.SetAlgorithmActief(_algorithmId); // de algorithm updaten in collection 'Algorithms' refreshLastAlgorithm(_algorithmId); refreshIdList(); //om terug te kijken welke algorithms random mogen gegenereerd worden }
//dialog vensters private void OnMessageReceived(UpdateFinishedMessage message) { // altijd refreshen omdat je deze algorithms actief kan zetten en dat getoont moet worden in het overzicht (en al dan niet random gegenereerd moet worden BackWithRefresh = true; if (message.Type == UpdateFinishedMessage.MessageType.Updated) { _dialogService.CloseAlgorithmDetailDialog(); } if (message.Type == UpdateFinishedMessage.MessageType.Deleted || message.Type == UpdateFinishedMessage.MessageType.Inserted) { AlgorithmDataService ads = new AlgorithmDataService(); Algorithms = ads.GetAlgorithmsWithCategorie(); _dialogService.CloseAlgorithmDetailDialog(); } }
private string resetActiveInBackground() { //enkel degene updaten in database die momenteel niet actief zijn is performater //dan in de database alles op actief te zetten en vervolgens alle data weer op te halen foreach (var Algorithm in Algorithms) { if (!Algorithm.Actief) { AlgorithmDataService ads = new AlgorithmDataService(); ads.SetAlgorithmActief(Algorithm.Id); refreshLastAlgorithm(Algorithm.Id); } } return("Done"); }
//*****CONSTRUCTOR***** public AlgorithmWindowViewModel() { //laden data AlgorithmDataService ads = new AlgorithmDataService(); Algorithms = ads.GetAlgorithmsWithCategorie(); //koppelen commands ExitCommand = new BaseCommand(Exit); WijzigAlgorithmCommand = new BaseCommand(WijzigAlgorithm); VoegAlgorithmToeCommand = new BaseCommand(VoegAlgorithmToe); //instantiëren DialogService als singleton _dialogService = new DialogService(); //luisteren naar updates vanuit detailvenster Messenger.Default.Register <UpdateFinishedMessage>(this, OnMessageReceived); }
private void refreshLastAlgorithm(int _algorithmId) { // enkel 1 algorithm updaten (de getoonde random algorithm of de geselecteerde algorithm in OLL overzicht) foreach (var Algorithm in Algorithms) { if (Algorithm.Id == _algorithmId) { AlgorithmDataService ads = new AlgorithmDataService(); var updatedAlgorithm = ads.RefreshLastAlgorithm(_gekozenSessie, Algorithm); Algorithm.ResultaatAverage = updatedAlgorithm.ResultaatAverage; Algorithm.ResultaatBest = updatedAlgorithm.ResultaatBest; Algorithm.ResultaatWorst = updatedAlgorithm.ResultaatWorst; Algorithm.ResultaatProgress = updatedAlgorithm.ResultaatProgress; Algorithm.Actief = updatedAlgorithm.Actief; Algorithm.ActiefColor = updatedAlgorithm.ActiefColor; } } }
//*****CONSTRUCTOR***** public MainWindowViewModel() { //laden data ResultaatDataService rds = new ResultaatDataService(); _nieuweSessie = (rds.GetLastSession() + 1); _gekozenSessie = _nieuweSessie; AlgorithmDataService ads = new AlgorithmDataService(); Algorithms = ads.GetAlgorithms(_gekozenSessie); BackgroundDataService bds = new BackgroundDataService(); Backgrounds = bds.GetBackgrounds(); CreateBackgroundsMenu(); // ids van algorithms nu al opslaan voor de "generate random algorithm" , dit is nodig om de start functie uit te schakelen indien alles op "niet-actief" staat refreshIdList(); //koppelen commands TimerCommand = new BaseCommand(StartStopTimer); ResetActiveCommand = new BaseCommand(ResetActive); DeleteLastTimeCommand = new BaseCommand(DeleteLastTime); AlgorithmActiefCommand = new ParameterCommand(AlgorithmActief); EditAlgorithmsCommand = new BaseCommand(EditAlgorithms); EditCategoriesCommand = new BaseCommand(EditCategories); EditResultatenCommand = new BaseCommand(EditResultaten); AboutCommand = new BaseCommand(About); // timer + timer2(countdown) _timer.Tick += new EventHandler(timer_Tick); _timer.Interval = new TimeSpan(0, 0, 0, 0, 10); _timer2.Tick += new EventHandler(timer2_Tick); _timer2.Interval = new TimeSpan(0, 0, 0, 1, 0); //instantiëren DialogService als singleton _dialogService = new DialogService(); //luisteren naar updates vanuit detailvenster Messenger.Default.Register <UpdateFinishedMessage>(this, OnMessageReceived); }
public void DeleteAlgorithm() { // controleren of de delete knop wordt gebruikt terwijl je een nieuwe categorie aan het creeëren bent if (SelectedAlgorithm.Id == 0) { MessageBoxResult result = MessageBox.Show("It's not possible to delete a Algorithm when you are creating a new Algorithm.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBoxResult result = MessageBox.Show("When you delete a Algorithm, all Results from this Algorithm will be removed too." + "\n" + " Are you sure you want to delete this Algorithm ?", "Delete Algorithm?", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); switch (result) { case MessageBoxResult.Yes: AlgorithmDataService ads = new AlgorithmDataService(); ads.DeleteAlgorithm(SelectedAlgorithm); Messenger.Default.Send <UpdateFinishedMessage>(new UpdateFinishedMessage(UpdateFinishedMessage.MessageType.Deleted)); break; } } }
public void UpdateAlgorithm() { AlgorithmDataService ads = new AlgorithmDataService(); //haal de hoogste Nummer op in de database HoogsteGuideNummer = ads.GetHoogsteGuideNummer(); //INSERT een nieuwe algorithm if (SelectedAlgorithm.Id == 0) { //controleer of er wel een Nummer is ingevuld en of het groter is dan 0 if (SelectedAlgorithm.Nummer <= 0) { ValidationMessage = "Please fill in a Guide Number greater than 0 ."; } else { ValidationMessage = ""; // controleer of deze AlgorithmSolution of Nummer al bestaat in de database string _algorithmSolutionBestaat = ads.AlgorithmExist(SelectedAlgorithm.AlgorithmSolution); int _nummerBestaat = ads.NummerExist(SelectedAlgorithm.Nummer); if (_algorithmSolutionBestaat != null || _nummerBestaat != 0) { // message opbouwen voor validatiemessage // get bestaande nummers string _bestaandeNummers = ads.GetAllGuideNummers(); string _message = ""; if (_algorithmSolutionBestaat != null && _nummerBestaat != 0) { _message = "The Solution and Guide Number already exists."; } else { if (_algorithmSolutionBestaat != null) { _message = "The Solution already exists."; } else { _message = "The Guide Number already exists."; MessageBox.Show("This Guide Number already exists. " + "\n" + "Please use a different Number." + "\n \n" + "These numbers already exists:" + "\n" + _bestaandeNummers, "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } //validatiemessage tonen ValidationMessage = _message; } else { ValidationMessage = ""; // kijken of dat er een afbeelding geselecteerd is if (ImportNaam == "") { ValidationMessage = "Please select an image"; } else { try { File.Copy(ImportPath, this.DestinationPath, true); } catch { ImportNaam = ""; MessageBox.Show("Unable to open file.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } SelectedAlgorithm.Afbeelding = ImportNaam; ads.InsertAlgorithm(SelectedAlgorithm); ImportNaam = ""; Messenger.Default.Send <UpdateFinishedMessage>(new UpdateFinishedMessage(UpdateFinishedMessage.MessageType.Inserted)); } } } } //UPDATE bestaande Algorithm else { //controleer of er wel een Nummer is ingevuld en of het groter is dan 0 if (SelectedAlgorithm.Nummer <= 0) { ValidationMessage = "Please fill in a Guide Number greater than 0 ."; } else { ValidationMessage = ""; // controleer of deze AlgorithmSolution of Nummer al bestaat in de database EN controleren of deze ook is aangepast string _algorithmSolutionBestaat = ads.AlgorithmExist(SelectedAlgorithm.AlgorithmSolution); int _nummerBestaat = ads.NummerExist(SelectedAlgorithm.Nummer); if ((_algorithmSolutionBestaat != null && SelectedAlgorithm.AlgorithmSolution != VorigeSolution) || (_nummerBestaat != 0 && SelectedAlgorithm.Nummer != VorigeGuideNumber)) { // haal bestaande nummers op string _bestaandeNummers = ads.GetAllGuideNummers(); // message opbouwen voor validatiemessage string _message = ""; if ((_algorithmSolutionBestaat != null && _nummerBestaat != 0) && (SelectedAlgorithm.Nummer != VorigeGuideNumber && SelectedAlgorithm.AlgorithmSolution != VorigeSolution)) { _message = "The Solution and Guide Number already exists."; } else { if (_algorithmSolutionBestaat != null && (SelectedAlgorithm.AlgorithmSolution != VorigeSolution)) { _message = "The Solution already exists."; } if (_nummerBestaat != 0 && (SelectedAlgorithm.Nummer != VorigeGuideNumber)) { _message = "The Guide Number already exists."; MessageBox.Show("This Guide Number already exists. " + "\n" + "Please use a different Number." + "\n \n" + "These numbers already exists:" + "\n" + _bestaandeNummers, "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } //validatiemessage tonen ValidationMessage = _message; } else { ValidationMessage = ""; // "Actief" als bool opslaan if (IsSelectedTrue) { SelectedAlgorithm.Actief = true; } else { SelectedAlgorithm.Actief = false; } // de categorieId opslaan aan de hand van de categorieNaam foreach (var Categorie in Categories) { if (SelectedCategorie.Naam == Categorie.Naam) { SelectedAlgorithm.CategorieId = Categorie.Id; SelectedAlgorithm.CategorieNaam = Categorie.Naam; } } // de algorithm updaten in de database ads.UpdateAlgorithm(SelectedAlgorithm); Messenger.Default.Send <UpdateFinishedMessage>(new UpdateFinishedMessage(UpdateFinishedMessage.MessageType.Updated)); } } } }