105040 添加搜索和异常筛选功能

在 `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`。
This commit is contained in:
lihanbo 2024-11-08 10:16:58 +08:00
parent dcfffe934f
commit ef54992069
4 changed files with 69 additions and 5 deletions

View File

@ -138,6 +138,21 @@
Content="生成导入模板数据" Content="生成导入模板数据"
FontSize="14" FontSize="14"
Style="{StaticResource ButtonPrimary}" /> Style="{StaticResource ButtonPrimary}" />
<StackPanel Orientation="Horizontal">
<hc:SearchBar
Width="200"
Height="30"
hc:InfoElement.Placeholder="W_00961"
hc:TitleElement.Title="线名称"
IsRealTime="True"
SearchStarted="SearchBar_SearchStarted"
ShowClearButton="True" />
<ToggleButton
Width="200"
Content="只搜索异常项"
IsChecked="{Binding OnlyShowError}"
Style="{StaticResource ToggleButtonSwitch}" />
</StackPanel>
</StackPanel> </StackPanel>
</Grid> </Grid>
<TabControl x:Name="DataTabControl" Grid.Row="1"> <TabControl x:Name="DataTabControl" Grid.Row="1">
@ -169,7 +184,7 @@
ClipboardCopyMode="IncludeHeader" ClipboardCopyMode="IncludeHeader"
EnableColumnVirtualization="False" EnableColumnVirtualization="False"
EnableRowVirtualization="True" EnableRowVirtualization="True"
ItemsSource="{Binding StuffedData, IsAsync=True}" ItemsSource="{Binding SearchedData, IsAsync=True}"
ScrollViewer.CanContentScroll="True" ScrollViewer.CanContentScroll="True"
SelectionUnit="FullRow" SelectionUnit="FullRow"
VirtualizingPanel.IsContainerVirtualizable="True" VirtualizingPanel.IsContainerVirtualizable="True"

View File

@ -50,6 +50,7 @@ public partial class MainWindow : Window
ViewModel.Data = []; ViewModel.Data = [];
ViewModel.StuffedData = []; ViewModel.StuffedData = [];
ViewModel.ExportData = []; ViewModel.ExportData = [];
ViewModel.SearchedData = [];
} }
/// <summary> /// <summary>
/// 更新列 /// 更新列
@ -177,6 +178,7 @@ public partial class MainWindow : Window
ViewModel.StuffedData?.Clear(); ViewModel.StuffedData?.Clear();
stuffedData.Result.Where(it => it != null).ForEach(ViewModel.StuffedData.Add); stuffedData.Result.Where(it => it != null).ForEach(ViewModel.StuffedData.Add);
UpdateDataGridColumnsByType([.. ViewModel.DataColumns], DataGridType.Originial); UpdateDataGridColumnsByType([.. ViewModel.DataColumns], DataGridType.Originial);
ViewModel.SearchByWireName(null);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -454,4 +456,10 @@ public partial class MainWindow : Window
FlexMessageBox.Error(ex.Message); FlexMessageBox.Error(ex.Message);
} }
} }
private void SearchBar_SearchStarted(object sender, HandyControl.Data.FunctionEventArgs<string> e)
{
Trace.WriteLine(e.Info.ToString());
ViewModel.SearchByWireName(e.Info);
}
} }

View File

@ -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() public StuffedDataModel()
{ {

View File

@ -26,6 +26,7 @@ public partial class MainViewModel : INotifyPropertyChanged
private ObservableCollection<StuffedDataModel> stuffedData; private ObservableCollection<StuffedDataModel> stuffedData;
private ObservableCollection<ExportModel> exportData; private ObservableCollection<ExportModel> exportData;
private ObservableCollection<DataGridColumn> dataColumns; private ObservableCollection<DataGridColumn> dataColumns;
private ObservableCollection<StuffedDataModel> searchedData;
public ObservableCollection<ReportModel> Data public ObservableCollection<ReportModel> Data
{ {
get => data; get => data;
@ -56,6 +57,16 @@ public partial class MainViewModel : INotifyPropertyChanged
} }
} }
public ObservableCollection<StuffedDataModel> SearchedData
{
get => searchedData;
set
{
searchedData = value;
OnPropertyChanged(nameof(SearchedData));
}
}
public ObservableCollection<DataGridColumn> DataColumns public ObservableCollection<DataGridColumn> DataColumns
{ {
get => dataColumns; get => dataColumns;
@ -127,6 +138,20 @@ public partial class MainViewModel : INotifyPropertyChanged
} }
} }
private bool _onlyShowError;
/// <summary>
/// 机构名称
/// </summary>
public bool OnlyShowError
{
get => _onlyShowError;
set
{
_onlyShowError = value;
OnPropertyChanged(nameof(OnlyShowError));
}
}
private WireFlagType _flagType; private WireFlagType _flagType;
public WireFlagType FlagType public WireFlagType FlagType
{ {
@ -297,6 +322,7 @@ public partial class MainViewModel : INotifyPropertyChanged
//IsUseDiscoloration = isL1 && isL2 && isL3 && isPe; //IsUseDiscoloration = isL1 && isL2 && isL3 && isPe;
//Trace.WriteLine($"isAllCE: {isAllCe}"); //Trace.WriteLine($"isAllCE: {isAllCe}");
//Trace.WriteLine($"isSDIProject: {isL1 && isL2 && isL3 && isPe}"); //Trace.WriteLine($"isSDIProject: {isL1 && isL2 && isL3 && isPe}");
return await Task.FromResult<List<StuffedDataModel>>([.. stuffedDatas]); return await Task.FromResult<List<StuffedDataModel>>([.. stuffedDatas]);
} }
/// <summary> /// <summary>
@ -493,5 +519,22 @@ public partial class MainViewModel : INotifyPropertyChanged
dataList.ForEach(ExportData.Add); 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);
}
}
} }