Skip to content

Commit

Permalink
Merge pull request #42 from dotob/punker76-refilter-projektlist
Browse files Browse the repository at this point in the history
re-filter projekt search list after changing gb number
  • Loading branch information
punker76 committed Apr 1, 2014
2 parents 9457bd1 + 63a0ae8 commit 11c27f4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
3 changes: 3 additions & 0 deletions MONI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
38 changes: 26 additions & 12 deletions MONI/ViewModels/PNSearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ public class PNSearchViewModel : ViewModelBase
private string searchText;
private ICommand cancelCommand;
private Dictionary<string, string> pnHash;
private int gbNumber;

public PNSearchViewModel(string projectNumberFiles, int gbNumber)
{
this.Results = new QuickFillObservableCollection<ProjectNumber>();
this.ProjectNumbers = new List<ProjectNumber>();
Task.Factory.StartNew(() => this.ReadPNFile(projectNumberFiles, Convert.ToInt32(gbNumber/10)));
this.ProjectNumbersToSearch = new List<ProjectNumber>();
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) {
Expand All @@ -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<ProjectNumber> ProjectNumbers { get; set; }
private List<ProjectNumber> ProjectNumbers { get; set; }
private List<ProjectNumber> ProjectNumbersToSearch { get; set; }

public bool ShowPNSearch {
get { return this.showPnSearch; }
Expand All @@ -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();
}
}

Expand All @@ -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; }
}
Expand Down

0 comments on commit 11c27f4

Please sign in to comment.