From 63a0ae823bf61e69a355e4b2c1f6171ec6b5ad4c Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 1 Apr 2014 12:30:43 +0200 Subject: [PATCH] re-filter projekt search list after changing gb number --- MONI/ViewModels/MainViewModel.cs | 3 +++ MONI/ViewModels/PNSearchViewModel.cs | 38 +++++++++++++++++++--------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/MONI/ViewModels/MainViewModel.cs b/MONI/ViewModels/MainViewModel.cs index f23f933..5786753 100644 --- a/MONI/ViewModels/MainViewModel.cs +++ b/MONI/ViewModels/MainViewModel.cs @@ -481,6 +481,9 @@ public void StartEditingPreferences() { public void SaveEditingPreferences() { this.ProjectHitListVisibility = this.MonlistSettings.MainSettings.ShowProjectHitList ? Visibility.Visible : Visibility.Collapsed; this.PositionHitListVisibility = this.MonlistSettings.MainSettings.ShowPositionHitList ? Visibility.Visible : Visibility.Collapsed; + if (this.PNSearch != null) { + this.PNSearch.SetGBNumber(this.Settings.MainSettings.MonlistGBNumber, true); + } this.EditPreferences = null; this.WorkWeek.Reparse(); } diff --git a/MONI/ViewModels/PNSearchViewModel.cs b/MONI/ViewModels/PNSearchViewModel.cs index 0bc1439..9a8ae77 100644 --- a/MONI/ViewModels/PNSearchViewModel.cs +++ b/MONI/ViewModels/PNSearchViewModel.cs @@ -16,12 +16,23 @@ public class PNSearchViewModel : ViewModelBase private string searchText; private ICommand cancelCommand; private Dictionary pnHash; + private int gbNumber; public PNSearchViewModel(string projectNumberFiles, int gbNumber) { this.Results = new QuickFillObservableCollection(); this.ProjectNumbers = new List(); - Task.Factory.StartNew(() => this.ReadPNFile(projectNumberFiles, Convert.ToInt32(gbNumber/10))); + this.ProjectNumbersToSearch = new List(); + Task.Factory.StartNew(() => this.ReadPNFile(projectNumberFiles, gbNumber)); + } + + public void SetGBNumber(int gbNumber, bool doSearch = false) + { + this.gbNumber = gbNumber / 10; + this.ProjectNumbersToSearch = this.ProjectNumbers.Where(pn => this.gbNumber <= 0 || pn.GB == this.gbNumber).ToList(); + if (doSearch) { + this.Search(); + } } private void ReadPNFile(string pnFilePaths, int gbNumber) { @@ -31,23 +42,23 @@ private void ReadPNFile(string pnFilePaths, int gbNumber) { if (!string.IsNullOrWhiteSpace(pnFile) && File.Exists(pnFile)) { var allPnLines = File.ReadAllLines(pnFile, Encoding.Default); foreach (string line in allPnLines.Skip(1)) { - if (Convert.ToInt32(line.Substring(0, 1)) == gbNumber) - { - var pn = new ProjectNumber(); - pn.Number = line.Substring(0, 5); - pn.Description = line.Substring(14); - this.ProjectNumbers.Add(pn); - } + var pn = new ProjectNumber(); + pn.GB = Convert.ToInt32(line.Substring(0, 1)); + pn.Number = line.Substring(0, 5); + pn.Description = line.Substring(14); + this.ProjectNumbers.Add(pn); } // break after first file worked break; } } } + this.SetGBNumber(gbNumber); this.pnHash = this.ProjectNumbers.ToDictionary(pnum => pnum.Number, pnum => pnum.Description); } - protected List ProjectNumbers { get; set; } + private List ProjectNumbers { get; set; } + private List ProjectNumbersToSearch { get; set; } public bool ShowPNSearch { get { return this.showPnSearch; } @@ -66,11 +77,13 @@ public string SearchText { } private void Search() { - this.Results.Clear(); var s = this.searchText; if (!string.IsNullOrWhiteSpace(s)) { - var res = this.ProjectNumbers.Where(pn => Regex.IsMatch(pn.Number, s, RegexOptions.IgnoreCase) || Regex.IsMatch(pn.Description, s, RegexOptions.IgnoreCase)); - this.Results.Fill(res); + var res = this.ProjectNumbersToSearch + .Where(pn => Regex.IsMatch(pn.Number, s, RegexOptions.IgnoreCase) || Regex.IsMatch(pn.Description, s, RegexOptions.IgnoreCase)); + this.Results.Fill(res, true); + } else { + this.Results.Clear(); } } @@ -93,6 +106,7 @@ public ICommand CancelCommand { public class ProjectNumber { + public int GB { get; set; } public string Number { get; set; } public string Description { get; set; } }