Browse Source

Added config search function, updated SystemConfigView.xmal and SystemConfigViewModel.cs .

intern02 1 year ago
parent
commit
dc8303196b

+ 194 - 6
Venus/Venus_MainPages/ViewModels/SystemConfigViewModel.cs

@@ -3,24 +3,41 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Input;
+using Aitex.Core.RT.SCCore;
+using ControlzEx.Standard;
+using FabConnect.SecsGemInterface.Application.Objects.ObjectService;
 using MECF.Framework.Common.DataCenter;
 using MECF.Framework.Common.Equipment;
 using MECF.Framework.Common.OperationCenter;
+using MECF.Framework.Common.Schedulers;
 using Prism.Commands;
 using Prism.Mvvm;
 using Venus_MainPages.Unity;
+using Venus_MainPages.Views;
 //using  Venus_MainPages.Unity.SystemConfig;
 
 namespace Venus_MainPages.ViewModels
 {
-    public class SystemConfigViewModel:BindableBase
+    public class SystemConfigViewModel : BindableBase
     {
         #region 私有字段
         private List<ConfigNode> _ConfigNodes = new List<ConfigNode>();
         private List<ConfigItem> _configItems = null;
+        private List<String> _SearchResultCollection = null;
         string _CurrentNodeName = string.Empty;
+        private Visibility _Visibility = new Visibility();
+        private string[] _InstalledModules = null;
+        private string _SearchText;
+        List<string> searchResultListHistory = new List<string>();
 
+        public string SearchText
+        {
+            get { return _SearchText; }
+            set { _SearchText = value; RaisePropertyChanged("SearchText"); }
+        }
         #endregion
 
         #region 属性
@@ -29,11 +46,21 @@ namespace Venus_MainPages.ViewModels
             get { return _ConfigNodes; }
             set { _ConfigNodes = value; RaisePropertyChanged("ConfigNodes"); }
         }
+        public List<String> SearchResultCollection
+        {
+            get { return _SearchResultCollection; }
+            set { _SearchResultCollection = value; RaisePropertyChanged("SearchResultCollection"); }
+        }
         public List<ConfigItem> ConfigItems
         {
             get { return _configItems; }
             set { _configItems = value; RaisePropertyChanged("ConfigItems"); }
         }
+        public Visibility SearchListBoxShow
+        {
+            get { return _Visibility; }
+            set { _Visibility = value; RaisePropertyChanged("SearchListBoxShow"); }
+        }
 
         #region 命令
 
@@ -50,10 +77,21 @@ namespace Venus_MainPages.ViewModels
         private DelegateCommand<object> _SetValueCommand;
         public DelegateCommand<object> SetValueCommand =>
             _SetValueCommand ?? (_SetValueCommand = new DelegateCommand<object>(SetValue));
-          
+        private DelegateCommand<object> _SearchTextChangedCommand;
+        public DelegateCommand<object> SearchTextChangedCommand =>
+            _SearchTextChangedCommand ?? (_SearchTextChangedCommand = new DelegateCommand<object>(SearchTextChanged));
+
+        private DelegateCommand<object> _ListBoxSelectSearchResultCommand;
+        public DelegateCommand<object> ListBoxSelectSearchResultCommand =>
+            _ListBoxSelectSearchResultCommand ?? (_ListBoxSelectSearchResultCommand = new DelegateCommand<object>(SelectSearchResult));
+
+
+
+
         #endregion
         public SystemConfigViewModel()
         {
+            SearchListBoxShow = Visibility.Hidden;
             ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
 
         }
@@ -65,12 +103,162 @@ namespace Venus_MainPages.ViewModels
         //    ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
         //}
 
+        //输入关键字
+        private void SearchTextChanged(object searchConfigItem)
+        {
+            List<string> searchResultList = new List<string>();
+            //如果输入框为空,不显示提示词,并展开左侧栏
+            if (string.IsNullOrEmpty((string)searchConfigItem))
+            {
+                ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
+                SearchListBoxShow = Visibility.Hidden;
+            }
+            else
+            {
+                ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
+                var itemslist = ConfigNodes.SelectMany(m => m.Items).ToList();
+                if (SearchText != null)
+                {
+                    SearchListBoxShow = Visibility.Visible;
+                    //根节点
+                    string searchResult = null;
+                    _InstalledModules = QueryDataClient.Instance.Service.GetConfig($"System.InstalledModules").ToString().Split(',');
+                    foreach (var ConfigNodesItems in ConfigNodes)
+                    {
+                        if (!_InstalledModules.Contains(ConfigNodesItems.Name) && ConfigNodesItems.Name != "System" && ConfigNodesItems.Name != "Recipe" && ConfigNodesItems.Name != "Scheduler")
+                        {
+                            ConfigNodesItems.IsShow = false;
+                            continue;
+                        }
+                        //根节点搜索
+                        if (ConfigNodesItems.Name.Contains(SearchText))
+                        {
+                            ConfigNodesItems.IsShow = true;//展开根节点
+                            _CurrentNodeName = SearchText;//TreeView节点
+                            searchResult = _CurrentNodeName;
+                            GetDataOfConfigItems();
+                        }
+                        else
+                        {
+                            ConfigNodesItems.IsShow = false;
+                            //二级节点搜索
+                            foreach (var SubNodesItems in ConfigNodesItems.SubNodes)
+                            {
+                                if (SubNodesItems.Name.ToLower().Contains(SearchText.ToLower()))
+                                {
+                                    ConfigNodesItems.IsShow = true;
+                                    SubNodesItems.IsShow = true;
+                                    _CurrentNodeName = String.Format("{0}{1}{2}", ConfigNodesItems.Name, ".", SubNodesItems.Name);
+                                    searchResult = _CurrentNodeName;
+                                    GetDataOfConfigItems();
+                                }
+                                else
+                                {
+                                    SubNodesItems.IsShow = false;
+
+                                    //叶子节点搜索
+                                    foreach (var Items in SubNodesItems.Items)
+                                    {
+                                        var searchResult1 = SubNodesItems.Items.FindAll(e => e.Name.ToLower().Contains(SearchText.ToLower()));
+                                        if (Items.Name.ToLower().Contains(SearchText.ToLower()))
+                                        {
+                                            ConfigNodesItems.IsShow = true;
+                                            SubNodesItems.IsShow = true;
+                                            _CurrentNodeName = String.Format("{0}{1}{2}{3}{4}", ConfigNodesItems.Name, ".", SubNodesItems.Name, ".", Items.Name);
+                                            searchResult = _CurrentNodeName;
+                                            GetDataOfConfigItems();
+                                            searchResultList.Add(_CurrentNodeName);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                        var searchResult2 = ConfigNodesItems.Items.FindAll(e => e.Name.ToLower().Contains(SearchText.ToLower()));
+                        if (searchResult2.Count != 0)
+                        {
+                            ConfigNodesItems.IsShow = true;
+                            _CurrentNodeName = SearchText;//TreeView节点
+                            searchResultList.Add(ConfigNodesItems.Name + "." + searchResult2[0].Name);
+                            searchResult = _CurrentNodeName;
+                            GetDataOfConfigItems();
+                        }
+                        //查询为空
+                        if (searchResult == null)
+                        {
+                            ConfigItems = null;
+                        }
+
+                    }
+                }
+                SearchResultCollection = searchResultList;
+                if (searchResultList.Count > 0)
+                {
+                    searchResultListHistory = searchResultList;
+
+                }
+            }
+        }
+        //选择选中项
+        private void SelectSearchResult(object slectItem)
+        {
+            SearchResultCollection = searchResultListHistory;
+            ConfigNodes = SystemConfigProvider.Instance.GetConfigTree().SubNodes;
+            if (slectItem != null)
+            {
+                SearchText = slectItem.ToString();
+                string[] searchResult = SearchText.Split('.');
+                List<ConfigItem> ConfigItem = new List<ConfigItem>();
+                //根节点下ConfigItems
+                if (searchResult.Length == 2)
+                {
+                    ConfigNodes.ForEach(e => e.IsShow = false);
+                    ConfigNode targetmodule = ConfigNodes.Find(e => e.Name.ToLower() == searchResult[0].ToLower());
+                    targetmodule.IsShow = true;
+                    targetmodule.SubNodes.ForEach(e => e.IsShow = false);
+                    _CurrentNodeName = string.IsNullOrEmpty(targetmodule.Path) ? targetmodule.Name : $"{targetmodule.Path}.{targetmodule.Name}";
+                    ConfigItems = targetmodule.Items.FindAll(e => e.Name.ToLower() == searchResult[1].ToLower());
+                    GetDataOfConfigItems();
+
+                }
+                //二级节点下ConfigItems
+                if (searchResult.Length == 3)
+                {
+                    ConfigNodes.ForEach(e => e.IsShow = false);
+                    ConfigNode targetmodule = ConfigNodes.Find(e => e.Name.ToLower() == searchResult[0].ToLower());
+                    targetmodule.IsShow = true;
+                    targetmodule.SubNodes.ForEach(e => e.IsShow = false);
+                    ConfigNode submodule = targetmodule.SubNodes.Find(e => e.Name.ToLower() == searchResult[1].ToLower());
+                    submodule.IsShow = true;
+                    _CurrentNodeName = string.IsNullOrEmpty(submodule.Path) ? submodule.Name : $"{submodule.Path}.{submodule.Name}";
+                    ConfigItems = submodule.Items.FindAll(e => e.Name.ToLower() == searchResult[2].ToLower());
+                    submodule.Items.FindAll(e => e.Name.ToLower() != searchResult[2].ToLower()).ForEach(e => e.Visible = false);
+                    GetDataOfConfigItems();
+                }
+
+            }
+
+        }
         private void TreeViewSelectedItemChanged(object node)
         {
-           var   node2 = (ConfigNode)node;
+            var node2 = (ConfigNode)node;
             _CurrentNodeName = string.IsNullOrEmpty(node2.Path) ? node2.Name : $"{node2.Path}.{node2.Name}";
-            ConfigItems = node2.Items;
-
+            string[] searchResult = null;
+            if (SearchText == "" || SearchText == null)
+            {
+                ConfigItems = node2.Items;
+            }
+            else
+            {
+                searchResult = SearchText.Split('.');
+                if (searchResult.Length == 2)
+                {
+                    ConfigItems = node2.Items.FindAll(e => e.Name.ToLower() == searchResult[1].ToLower());
+                }
+                if (searchResult.Length == 3)
+                {
+                    ConfigItems = node2.Items.FindAll(e => e.Name.ToLower() == searchResult[2].ToLower());
+                }
+            }
             GetDataOfConfigItems();
         }
 
@@ -178,6 +366,6 @@ namespace Venus_MainPages.ViewModels
 
             ConfigItems.ForEach(item => SetValue(item));
         }
-        
+
     }
 }

+ 141 - 0
Venus/Venus_MainPages/Views/SystemConfigView.xaml

@@ -100,6 +100,7 @@
         <Grid.ColumnDefinitions>
             <ColumnDefinition MinWidth="300" Width="Auto"/>
             <ColumnDefinition/>
+            <ColumnDefinition/>
         </Grid.ColumnDefinitions>
 
         <Border BorderBrush="{DynamicResource Table_BD}" BorderThickness="1" Background="{DynamicResource Table_BG_Content}" Padding="5,1">
@@ -224,6 +225,146 @@
                 </DataGrid.Columns>
             </DataGrid>
         </Grid>
+        <Grid Grid.Column="2"  Margin="5,0,0,0">
+
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="auto"/>
+                <ColumnDefinition Width="auto"/>
+                <ColumnDefinition Width="*" />
+            </Grid.ColumnDefinitions>
+            <Grid.RowDefinitions>
+                <RowDefinition Height="auto"/>
+                <RowDefinition Height="auto"/>
+            </Grid.RowDefinitions>
+            <TextBox x:Name="SearchTextBox" Grid.Column="0" BorderBrush="{DynamicResource Table_BG_FirstTitle}" BorderThickness="1" Background="White" Width="370"
+                             HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" VerticalAlignment="Stretch" VerticalContentAlignment="Center" Height="25"
+                             Text="{Binding SearchText ,Delay=0, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
+                <i:Interaction.Triggers>
+                    <i:EventTrigger EventName="TextChanged">
+                        <i:InvokeCommandAction Command="{Binding SearchTextChangedCommand}" CommandParameter="{Binding Path=Text, ElementName=SearchTextBox}"/>
+                    </i:EventTrigger>
+                </i:Interaction.Triggers>
+            </TextBox>
+            <!--<Button Grid.Column="1" Content="Search" Width="80" Height="25" Margin="5,0,0,0" Command="{Binding SearchCommand}" CommandParameter="{Binding Path=Text, ElementName=SearchTextBox}"></Button>-->
+
+            <Border Grid.Row="1" BorderBrush="{DynamicResource Table_BD}" BorderThickness="1" Background="{DynamicResource Table_BG_Content}" Padding="5,1" Visibility="{Binding SearchListBoxShow}">
+                <Grid>
+                    <ListBox x:Name="PART_LIST_SEARCH" Margin="5" ItemsSource="{Binding SearchResultCollection}" Width="350"
+                           VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling"
+                                     ScrollViewer.HorizontalScrollBarVisibility="Auto" MaxHeight="215">
+                        <i:Interaction.Triggers>
+                            <i:EventTrigger EventName="SelectionChanged">
+                                <i:InvokeCommandAction Command="{Binding ListBoxSelectSearchResultCommand}" CommandParameter="{Binding Path=SelectedItem, ElementName=PART_LIST_SEARCH}"/>
+                            </i:EventTrigger>
+                        </i:Interaction.Triggers>
+                        <ListBox.ItemTemplate>
+                            <DataTemplate>
+                                <Label Content="{Binding}"></Label>
+                            </DataTemplate>
+                        </ListBox.ItemTemplate>
+                        <ListBox.ItemContainerStyle>
+                            <Style TargetType="{x:Type ListBoxItem}">
+                                <Setter Property="Background" Value="Transparent"></Setter>
+                                <Setter Property="Padding" Value="0" />
+                                <Setter Property="BorderThickness" Value="0 0 0 1" />
+                                <Setter Property="BorderBrush" Value="Gray" />
+                            </Style>
+                        </ListBox.ItemContainerStyle>
+                    </ListBox>
+                </Grid>
+            </Border>
+
+            <Popup x:Name="PART_Popup"
+                AllowsTransparency="true"
+                PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
+                Placement="Bottom"
+                StaysOpen="True">
+
+                <Border Grid.Row="1" BorderBrush="{DynamicResource Table_BD}" BorderThickness="1" Background="{DynamicResource Table_BG_Content}" Padding="5,1">
+                    <ListBox x:Name="PART_LIST_SEARCH1" Margin="5" ItemsSource="{Binding SearchResultCollection}" Width="350"
+                       VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling"
+                                 ScrollViewer.HorizontalScrollBarVisibility="Auto" MaxHeight="215">
+                        <i:Interaction.Triggers>
+                            <i:EventTrigger EventName="SelectionChanged">
+                                <i:InvokeCommandAction Command="{Binding ListBoxSelectSearchResultCommand}" CommandParameter="{Binding Path=SelectedItem, ElementName=PART_LIST_SEARCH1}"/>
+                            </i:EventTrigger>
+                        </i:Interaction.Triggers>
+                        <ListBox.ItemTemplate>
+                            <DataTemplate>
+                                <Label Content="{Binding}"></Label>
+                            </DataTemplate>
+                        </ListBox.ItemTemplate>
+                        <ListBox.ItemContainerStyle>
+                            <Style TargetType="{x:Type ListBoxItem}">
+                                <Setter Property="Background" Value="Transparent"></Setter>
+                                <Setter Property="Padding" Value="0" />
+                                <Setter Property="BorderThickness" Value="0 0 0 1" />
+                                <Setter Property="BorderBrush" Value="Gray" />
+
+                                <Setter Property="Template">
+                                    <Setter.Value>
+                                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
+                                            <Border x:Name="Bd"
+                                            Height="38"
+                                            Margin="0,0,0,4"
+                                            BorderThickness="0"
+                                            Background="{TemplateBinding Background}"
+                                            SnapsToDevicePixels="true">
+                                                <ContentPresenter HorizontalAlignment="Stretch"
+                                                Margin="14,0,0,0"
+                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
+                                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
+                                            </Border>
+                                            <ControlTemplate.Triggers>
+
+                                                <Trigger Property="IsMouseOver"
+                                                 Value="True">
+                                                    <Setter TargetName="Bd"
+                                                    Property="BorderBrush"
+                                                    Value="Chartreuse" />
+                                                    <Setter TargetName="Bd"
+                                                    Property="Background"
+                                                    Value="Chartreuse" />
+                                                    <Setter Property="Foreground"
+                                                    Value="White" />
+                                                </Trigger>
+                                                <Trigger Property="IsSelected"
+                                                    Value="true">
+                                                    <Setter Property="Background"
+                                                     TargetName="Bd"
+                                                     Value="Blue" />
+                                                    <Setter Property="Foreground"
+                                                     Value="White" />
+                                                </Trigger>
+                                                <MultiTrigger>
+                                                    <MultiTrigger.Conditions>
+                                                        <Condition Property="IsSelected"
+                                                                                               Value="true" />
+                                                        <Condition Property="Selector.IsSelectionActive"
+                                                                                               Value="false" />
+                                                    </MultiTrigger.Conditions>
+                                                    <Setter Property="Background"
+                                                                                        TargetName="Bd"
+                                                                                        Value="{DynamicResource BgColorLeftTreeRowSelected}" />
+                                                    <Setter Property="Foreground"
+                                                                                        Value="{DynamicResource ForegroundSelect}" />
+                                                </MultiTrigger>
+                                                <Trigger Property="IsEnabled"
+                                                                                     Value="false">
+                                                    <Setter Property="Foreground"
+                                                                                        Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
+                                                </Trigger>
+                                            </ControlTemplate.Triggers>
+                                        </ControlTemplate>
+                                    </Setter.Value>
+                                </Setter>
+                            </Style>
+                        </ListBox.ItemContainerStyle>
+                    </ListBox>
+                </Border>
+
+            </Popup>
+        </Grid>
 
     </Grid>
 </UserControl>