From ef54992069c6b0a720c03542a5d057fd4854b377 Mon Sep 17 00:00:00 2001 From: lihanbo Date: Fri, 8 Nov 2024 10:16:58 +0800 Subject: [PATCH] =?UTF-8?q?105040=20=E6=B7=BB=E5=8A=A0=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=92=8C=E5=BC=82=E5=B8=B8=E7=AD=9B=E9=80=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `MainWindow.xaml` 中添加了 `StackPanel`,包含 `SearchBar` 和 `ToggleButton`。将 `DataGrid` 的 `ItemsSource` 从 `StuffedData` 更改为 `SearchedData`。在 `MainWindow.xaml.cs` 中初始化 `ViewModel.SearchedData`,并在数据加载完成后调用 `ViewModel.SearchByWireName(null)` 进行初始搜索。添加 `SearchBar_SearchStarted` 方法处理搜索事件,并调用 `ViewModel.SearchByWireName` 进行搜索。在 `StuffedDataModel.cs` 中删除 `INotifyPropertyChanged` 接口的实现。在 `MainViewModel.cs` 中添加 `SearchedData` 和 `OnlyShowError` 属性,以及 `SearchByWireName` 方法用于搜索和更新 `SearchedData`。 --- Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml | 17 +++++++- .../MainWindow.xaml.cs | 8 ++++ .../Models/StuffedDataModel.cs | 6 +-- .../ViewModel/MainViewModel.cs | 43 +++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml index eec58b4..954373c 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml @@ -138,6 +138,21 @@ Content="生成导入模板数据" FontSize="14" Style="{StaticResource ButtonPrimary}" /> + + + + @@ -169,7 +184,7 @@ ClipboardCopyMode="IncludeHeader" EnableColumnVirtualization="False" EnableRowVirtualization="True" - ItemsSource="{Binding StuffedData, IsAsync=True}" + ItemsSource="{Binding SearchedData, IsAsync=True}" ScrollViewer.CanContentScroll="True" SelectionUnit="FullRow" VirtualizingPanel.IsContainerVirtualizable="True" diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs index d2cb340..066e751 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/MainWindow.xaml.cs @@ -50,6 +50,7 @@ public partial class MainWindow : Window ViewModel.Data = []; ViewModel.StuffedData = []; ViewModel.ExportData = []; + ViewModel.SearchedData = []; } /// /// 更新列 @@ -177,6 +178,7 @@ public partial class MainWindow : Window ViewModel.StuffedData?.Clear(); stuffedData.Result.Where(it => it != null).ForEach(ViewModel.StuffedData.Add); UpdateDataGridColumnsByType([.. ViewModel.DataColumns], DataGridType.Originial); + ViewModel.SearchByWireName(null); } catch (Exception ex) { @@ -454,4 +456,10 @@ public partial class MainWindow : Window FlexMessageBox.Error(ex.Message); } } + + private void SearchBar_SearchStarted(object sender, HandyControl.Data.FunctionEventArgs e) + { + Trace.WriteLine(e.Info.ToString()); + ViewModel.SearchByWireName(e.Info); + } } \ No newline at end of file diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/Models/StuffedDataModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/Models/StuffedDataModel.cs index dbf1e89..727b902 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/Models/StuffedDataModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/Models/StuffedDataModel.cs @@ -1,6 +1,4 @@ -using System.ComponentModel; - -namespace Sinvo.EplanHpD.Plugin.WPFUI.Models +namespace Sinvo.EplanHpD.Plugin.WPFUI.Models { /* 线色 @@ -20,7 +18,7 @@ namespace Sinvo.EplanHpD.Plugin.WPFUI.Models 数量 */ - public class StuffedDataModel : CheckedModel, INotifyPropertyChanged + public class StuffedDataModel : CheckedModel { public StuffedDataModel() { diff --git a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs index 390d23d..96e0bd6 100644 --- a/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs +++ b/Sinvo.EplanHpD.Plugin.WPFUI/ViewModel/MainViewModel.cs @@ -26,6 +26,7 @@ public partial class MainViewModel : INotifyPropertyChanged private ObservableCollection stuffedData; private ObservableCollection exportData; private ObservableCollection dataColumns; + private ObservableCollection searchedData; public ObservableCollection Data { get => data; @@ -56,6 +57,16 @@ public partial class MainViewModel : INotifyPropertyChanged } } + public ObservableCollection SearchedData + { + get => searchedData; + set + { + searchedData = value; + OnPropertyChanged(nameof(SearchedData)); + } + } + public ObservableCollection DataColumns { get => dataColumns; @@ -127,6 +138,20 @@ public partial class MainViewModel : INotifyPropertyChanged } } + private bool _onlyShowError; + /// + /// 机构名称 + /// + public bool OnlyShowError + { + get => _onlyShowError; + set + { + _onlyShowError = value; + OnPropertyChanged(nameof(OnlyShowError)); + } + } + private WireFlagType _flagType; public WireFlagType FlagType { @@ -297,6 +322,7 @@ public partial class MainViewModel : INotifyPropertyChanged //IsUseDiscoloration = isL1 && isL2 && isL3 && isPe; //Trace.WriteLine($"isAllCE: {isAllCe}"); //Trace.WriteLine($"isSDIProject: {isL1 && isL2 && isL3 && isPe}"); + return await Task.FromResult>([.. stuffedDatas]); } /// @@ -493,5 +519,22 @@ public partial class MainViewModel : INotifyPropertyChanged dataList.ForEach(ExportData.Add); } } + public void SearchByWireName(string wireName) + { + SearchedData.Clear(); + if (string.IsNullOrEmpty(wireName)) + { + stuffedData.ForEach(SearchedData.Add); + } + else + { + stuffedData.Where(it => it.WireName.Contains(wireName) + || (it.RearTerminalModel?.Contains(wireName) ?? false) + || (it.FrontTerminalModel?.Contains(wireName) ?? false) + ) + .Where(it => it.IsError == OnlyShowError || !OnlyShowError) + .ForEach(SearchedData.Add); + } + } } \ No newline at end of file