public static bool?Show(ref FilterStringModel fsModel) { if (fsModel == null) { fsModel = new FilterStringModel(); } var window = new FilterStringWindow(fsModel); window.ShowDialog(); fsModel.IsEnabled = window.FilterResult == true; return(window.FilterResult); }
public FilterStringWindow(FilterStringModel fsModel) { InitializeComponent(); if (fsModel == null) { throw new ArgumentNullException(nameof(fsModel)); } this.FilterStringModel = fsModel; if (fsModel.Keys != null) { foreach (var key in fsModel.Keys) { txbMain.Text += key + Environment.NewLine; } } //rtbFullMatch.IsChecked = fsModel.MatchWay == StringMatchWay.FullMatch; chbMatchCase.IsChecked = fsModel.MatchCase; }
private IEnumerable <object> FilterStringRow(IEnumerable <object> rows, FilterStringModel fsModel, Func <object, string> fieldFunc) { if (fsModel?.MatchWay == StringMatchWay.AnyKey) { var keys = fsModel.Keys; if (keys.Length > 0) { rows = rows.Where(r => keys.Any(key => !string.IsNullOrEmpty(key) && fieldFunc(r)?.IndexOf(key, fsModel.MatchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) != -1) ); } } else if (fsModel?.MatchWay == StringMatchWay.FullMatch) { if (fsModel.Keys?.Length > 0) { rows = rows.Where(r => fsModel.Keys.Contains(fieldFunc(r))); } } return(rows); }