From 5e19a309af8eab0a8df9090459fbd3d8c31db3cc Mon Sep 17 00:00:00 2001 From: Roy Date: Sun, 17 Dec 2017 22:32:16 +0200 Subject: Implemented auto generated observable entities adapter extensions on build. Implemented smart filtering of DB views. --- .../Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs index 08a455c81..b6d77748e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs @@ -15,6 +15,7 @@ using Tango.MachineStudio.DB.Messages; using System.Collections.ObjectModel; using System.Reflection; using Tango.MachineStudio.Common.StudioApplication; +using System.ComponentModel; namespace Tango.MachineStudio.DB.ViewModels { @@ -289,7 +290,21 @@ namespace Tango.MachineStudio.DB.ViewModels protected virtual void OnFilterChanged(String filter) { + String viewSourceName = this.GetType().Name.Replace("ViewVM", "ViewSource"); + ICollectionView collectionView = Adapter.GetType().GetProperty(viewSourceName).GetValue(Adapter) as ICollectionView; + collectionView.Filter = (entity) => + { + return + entity. + GetType(). + GetProperties(BindingFlags.Public | BindingFlags.Instance). + Where(x => x.Name != "Deleted" && x.Name != "ID" && x.Name != "LastUpdated"). + Where(x => !x.PropertyType.IsGenericType && (x.PropertyType.IsClass || x.PropertyType == typeof(String))). + Select(prop => prop.GetValue(entity).ToString()). + ToList(). + Any(x => x.ToLower().Contains(filter.ToLower())); + }; } protected virtual void InitializeEntity(T entity) -- cgit v1.3.1