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:
parent
dcfffe934f
commit
ef54992069
|
@ -138,6 +138,21 @@
|
|||
Content="生成导入模板数据"
|
||||
FontSize="14"
|
||||
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>
|
||||
</Grid>
|
||||
<TabControl x:Name="DataTabControl" Grid.Row="1">
|
||||
|
@ -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"
|
||||
|
|
|
@ -50,6 +50,7 @@ public partial class MainWindow : Window
|
|||
ViewModel.Data = [];
|
||||
ViewModel.StuffedData = [];
|
||||
ViewModel.ExportData = [];
|
||||
ViewModel.SearchedData = [];
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新列
|
||||
|
@ -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<string> e)
|
||||
{
|
||||
Trace.WriteLine(e.Info.ToString());
|
||||
ViewModel.SearchByWireName(e.Info);
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ public partial class MainViewModel : INotifyPropertyChanged
|
|||
private ObservableCollection<StuffedDataModel> stuffedData;
|
||||
private ObservableCollection<ExportModel> exportData;
|
||||
private ObservableCollection<DataGridColumn> dataColumns;
|
||||
private ObservableCollection<StuffedDataModel> searchedData;
|
||||
public ObservableCollection<ReportModel> 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
|
||||
{
|
||||
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;
|
||||
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<List<StuffedDataModel>>([.. stuffedDatas]);
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue