官方网站下载拼多多app/seo推广方案
效果
调用方法
实体类(可以根据需求更换)
public class ToolStr50
{public bool isSelected { get; set; }public string toolStr1 { get; set; }public string toolStr2 { get; set; }public string toolStr3 { get; set; }public string toolStr4 { get; set; }public string toolStr5 { get; set; }public string toolStr6 { get; set; }public string toolStr7 { get; set; }public string toolStr8 { get; set; }public string toolStr9 { get; set; }public string toolStr10 { get; set; }public int toolInt1 { get; set; }public int toolInt2 { get; set; }public int toolInt3 { get; set; }public int toolInt4 { get; set; }public int toolInt5 { get; set; }public int toolInt6 { get; set; }public int toolInt7 { get; set; }public int toolInt8 { get; set; }public int toolInt9 { get; set; }public int toolInt10 { get; set; }public double toolDouble1 { get; set; }public double toolDouble2 { get; set; }public double toolDouble3 { get; set; }public double toolDouble4 { get; set; }public double toolDouble5 { get; set; }public double toolDouble6 { get; set; }public double toolDouble7 { get; set; }public double toolDouble8 { get; set; }public double toolDouble9 { get; set; }public double toolDouble10 { get; set; }public DateTime toolDate1 { get; set; }public DateTime toolDate2 { get; set; }public DateTime toolDate3 { get; set; }public DateTime toolDate4 { get; set; }public DateTime toolDate5 { get; set; }public DateTime toolDate6 { get; set; }public DateTime toolDate7 { get; set; }public DateTime toolDate8 { get; set; }public DateTime toolDate9 { get; set; }public DateTime toolDate10 { get; set; }
}
传入需要二级过滤的数据
public void ShowSecondaryFiltration(){var columnMappings = new Dictionary<string, string>{{ "采购日期", "toolStr26" },{ "采购周期", "toolInt10" },{ "采购回复交期", "toolStr31" },{ "采购说明", "toolStr53" },{ "生产订单号", "toolStr1" },{ "来源单号", "toolStr2" },{ "采购订单号", "toolStr3" },{ "行号", "toolInt1" },{ "料号", "toolStr4" },{ "品名", "toolStr5" },{ "规格描述", "toolStr6" },{ "现存量", "toolInt2" },{ "单位", "toolStr11" },{ "采购数量(计量)", "toolInt3" },{ "收货数量(计量)", "toolInt4" },{ "已退货数(计量)", "toolInt5" },{ "实际入库数(计量)", "toolInt6" },{ "入库单号", "toolStr16" },{ "已暂收数量(计量)", "toolInt7" },{ "最后交货日期", "toolStr18" },{ "逾期天数(负数未到期)", "toolInt8" },{ "品质异常报告日期", "toolStr19" },{ "品质问题描述", "toolStr20" },{ "处理结论", "toolStr21" },{ "未交数量(计量)", "toolInt9" },{ "交货结案日期", "toolStr23" },{ "请购日期", "toolStr24" },{ "PMC交单日期", "toolStr25" },{ "理论交期", "toolStr28" },{ "要求交期", "toolStr29" },{ "订单回传日期", "toolStr30" },{ "色板_模板_图纸提供情况", "toolStr32" },{ "异常反馈", "toolStr33" },{ "预付款比例", "toolInt11" },{ "预付款支付日期", "toolStr35" },{ "尾款比例", "toolInt12" },{ "尾款支付日期", "toolStr39" },{ "采购员", "toolStr44" },{ "请购制单人", "toolStr40" },{ "供应商名称", "toolStr46" },{ "请购单备注", "toolStr42" },{ "采购单备注", "toolStr45" },{ "可用量", "toolStr8" },{ "含税单价", "toolDouble1" },{ "含税金额", "toolDouble2" },{ "采购到货日期", "toolStr37" },{ "财务交单日期", "toolStr38" },{ "请购人", "toolStr41" },{ "采购制单人", "toolStr43" },{ "采购订单结案状态", "toolStr48" },{ "修改日期_请购", "toolStr50" },{ "修改日期_采购", "toolStr51" },{ "PMC要求交货日期", "toolStr52" }};var traceWindow = new TraceTableSecondaryFiltration(columnMappings, OdlIbo);traceWindow.QueryConditions = _queryConditions;if (traceWindow.ShowDialog() == true) // 检查对话框的结果{var filteredIbo = traceWindow.FilteredData;_queryConditions = traceWindow.QueryConditions;Ibo = filteredIbo;// 使用 filteredIbo 进行后续处理}if (_queryConditions.Count == 0){SelectInfo();}//更新总条数和总金额InfoCount = "数据汇总:" + Ibo.Count.ToString() + "条";decimal total = Ibo.Sum(x => Convert.ToDecimal(x.toolStr10)); // 假设 TaxInclusiveSum 是 double 类型 total = decimal.Round(total, 4);//TaxinclusiveSum = "合计含税金额:" + total.ToString();}
窗体页面TraceTableSecondaryFiltration.xaml
<Window x:Class="GMWPF.Views.ModuleMenu.Purchase.PurchaseModle1.ChildWindow.TraceTableSecondaryFiltration"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:GMWPF.Views.ModuleMenu.Purchase.PurchaseModle1.ChildWindow"mc:Ignorable="d"Title="TraceTableSecondaryFiltration" Height="450" Width="800"WindowStartupLocation="CenterScreen"><Grid Margin="10" Name="myDynamicGrid"><Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/><RowDefinition Height="*"/><!-- 让表格占用剩余空间 --></Grid.RowDefinitions><TextBlock Text="字段名称" Margin="49,34,655,0" VerticalAlignment="Top" Grid.Row="0"/><!-- <ComboBox Name="FieldNameComboBox" Margin="25,5,640,0" VerticalAlignment="Top" ItemsSource="{Binding FieldNames}" SelectedItem="{Binding SelectedFieldName, Mode=TwoWay}" SelectionChanged="FieldNameComboBox_SelectionChanged"Grid.Row="1"/>--><ComboBox Name="FieldNameComboBox" Margin="25,5,640,0" VerticalAlignment="Top" IsEditable="True"IsTextSearchEnabled="False"PreviewTextInput="FieldNameComboBox_PreviewTextInput"ItemsSource="{Binding FieldNames}" SelectedItem="{Binding SelectedFieldName, Mode=TwoWay}" SelectionChanged="FieldNameComboBox_SelectionChanged"Grid.Row="1"/><TextBlock Text="条件" Margin="227,34,495,0" VerticalAlignment="Top" Grid.Row="0"/><ComboBox Name="ConditionComboBox" Margin="184,5,471,0" VerticalAlignment="Top" ItemsSource="{Binding Conditions}" SelectedItem="{Binding SelectedCondition}" Grid.Row="1"/><TextBlock Text="条件值" Margin="402,34,320,0" VerticalAlignment="Top" Grid.Row="0"/><!-- <ComboBox Name="ValueComboBox" Margin="357,5,275,0" VerticalAlignment="Top" ItemsSource="{Binding ConditionValues}" SelectedItem="{Binding SelectedConditionValue}" Grid.Row="1"/>--><ComboBox Name="ValueComboBox" Margin="357,5,275,0" VerticalAlignment="Top" IsEditable="True"IsTextSearchEnabled="False"Text="{Binding InputValue, Mode=TwoWay}"PreviewTextInput="ConditionComboBox_PreviewTextInput"SelectionChanged="ConditionComboBox_SelectionChanged"ItemsSource="{Binding ConditionValues}" SelectedItem="{Binding SelectedConditionValue}" Grid.Row="1"/><TextBlock Text="关系" Margin="564,34,168,0" VerticalAlignment="Top" Grid.Row="0"/><ComboBox Name="RelationComboBox" Margin="532,5,154,0" VerticalAlignment="Top" ItemsSource="{Binding RelationValues}" SelectedItem="{Binding SelectedRelationValue}" SelectionChanged="RelationComboBox_SelectionChanged"Grid.Row="1"/><Button Content="添加" Command="{Binding AddQueryConditionCommand}" Margin="637,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="27" Grid.Row="1"/><Button Content="查询" Command="{Binding QueryCommand}" Margin="697,5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Height="27" Grid.Row="1"/><DataGrid Name="ConditionDataGrid" Grid.Row="2" Margin="10,10,10,0" BorderThickness="1"Height="300"AutoGenerateColumns="False" ItemsSource="{Binding QueryConditions}"><DataGrid.Columns><!-- <DataGridTemplateColumn Width="200" Header="字段名称"><DataGridTemplateColumn.CellTemplate><DataTemplate><ComboBox Name="FieldNameComboBox" Margin="25,5,640,0" VerticalAlignment="Top" ItemsSource="{Binding FieldNames}" SelectedItem="{Binding SelectedFieldName}" SelectionChanged="FieldNameComboBox_SelectionChanged"Grid.Row="1"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTemplateColumn.HeaderStyle></DataGridTemplateColumn>--><DataGridTextColumn Width="200" Header="字段名称" Binding="{Binding FieldName}"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="VerticalAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTextColumn.HeaderStyle></DataGridTextColumn><DataGridTextColumn Width="100" Header="条件" Binding="{Binding Condition}"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="VerticalAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTextColumn.HeaderStyle></DataGridTextColumn><DataGridTextColumn Width="200" Header="条件值" Binding="{Binding ConditionValue}"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="VerticalAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTextColumn.HeaderStyle></DataGridTextColumn><DataGridTextColumn Width="100" Header="关系" Binding="{Binding RelationValue}"><DataGridTextColumn.ElementStyle><Style TargetType="TextBlock"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="VerticalAlignment" Value="Center"/></Style></DataGridTextColumn.ElementStyle><DataGridTextColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTextColumn.HeaderStyle></DataGridTextColumn><DataGridTemplateColumn Width="200" Header="操作"><DataGridTemplateColumn.CellTemplate><DataTemplate><Button Content="删除" Width="80" Command="{Binding DataContext.DeleteConditionCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"CommandParameter="{Binding}"/></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.HeaderStyle><Style TargetType="DataGridColumnHeader"><Setter Property="HorizontalContentAlignment" Value="Center"/></Style></DataGridTemplateColumn.HeaderStyle></DataGridTemplateColumn></DataGrid.Columns></DataGrid></Grid>
</Window>
窗体实现类TraceTableSecondaryFiltration.xaml.cs
这里在进行数据对比时对数据进行了类型转换,因为string类型的对比会出现
“4”>“20”的情况
using CommunityToolkit.Mvvm.Input;
using SQLSugarDB.Model.Public;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Expression = System.Linq.Expressions.Expression;
namespace GMWPF.Views.ModuleMenu.Purchase.PurchaseModle1.ChildWindow
{public partial class TraceTableSecondaryFiltration : Window, INotifyPropertyChanged{public List<ToolStr50> FilteredData { get; private set; }private string _inputValue;//条件值下拉框中手动输入的值public string InputValue{get { return _inputValue; }set{if (_inputValue != value){_inputValue = value;OnPropertyChanged(nameof(InputValue));}}}private Dictionary<string, string> _columnMappings;//所有的列和对应Toolstr属性的映射关系private List<ToolStr50> _Ibo;//所有的数据private List<string> _fieldNames = new List<string>(); // 字段名public List<string> FieldNames{get { return _fieldNames; }set{_fieldNames = value;OnPropertyChanged(nameof(FieldNames));}}private string _selectedFieldName;public string SelectedFieldName{get { return _selectedFieldName; }set{_selectedFieldName = value;}}private ObservableCollection<string> _conditions = new ObservableCollection<string>(); // 条件public ObservableCollection<string> Conditions{get { return _conditions; }set{_conditions = value;OnPropertyChanged(nameof(Conditions));}}private string _selectedCondition;public string SelectedCondition{get { return _selectedCondition; }set{_selectedCondition = value;}}private ObservableCollection<string> _conditionValues = new ObservableCollection<string>(); // 条件值public ObservableCollection<string> ConditionValues{get { return _conditionValues; }set{_conditionValues = value;OnPropertyChanged(nameof(ConditionValues)); // 通知 UI 更新}}private string _selectedConditionValue;public string SelectedConditionValue{get { return _selectedConditionValue; }set{_selectedConditionValue = value;}}private ObservableCollection<string> _relationValues = new ObservableCollection<string>(); // 关系public ObservableCollection<string> RelationValues{get { return _relationValues; }set{_relationValues = value;}}private string _selectedRelationValue;public string SelectedRelationValue{get { return _selectedRelationValue; }set{_selectedRelationValue = value;}}private ObservableCollection<SecondQueryCondition> _queryConditions = new ObservableCollection<SecondQueryCondition>();public event PropertyChangedEventHandler PropertyChanged;public ObservableCollection<SecondQueryCondition> QueryConditions{get => _queryConditions;set{_queryConditions = value;}}public List<String> FieldNamesValueBackUp;//所有字段名 备份原始数据public ObservableCollection<String> ConditionValueBackUp;//字段名对应的数据 备份原始数据public TraceTableSecondaryFiltration(Dictionary<string, string> columnMappings, List<ToolStr50> Ibo){_columnMappings = columnMappings;_Ibo = Ibo;InitializeComponent();DataContext = this; // 设置数据上下文为当前窗口//将columnMappings所有的key拿出来放进List<string> _fieldNames中_fieldNames = new List<string>(_columnMappings.Keys);FieldNamesValueBackUp = _fieldNames;Conditions.Add("大于");Conditions.Add("大于等于");Conditions.Add("小于");Conditions.Add("小于等于");Conditions.Add("等于");Conditions.Add("不等于");Conditions.Add("包含");RelationValues.Add("并且");RelationValues.Add("或者");//给所有的下拉框的值备份起来//设定个默认值//SelectedRelationValue = "并且";}private void ConditionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e){// 当用户选择了已有的项时,更新 InputValue 为所选项的值if (ValueComboBox.SelectedItem != null){InputValue = ValueComboBox.SelectedItem.ToString();}else{// 如果没有选中任何项,保持 Text 的自定义输入InputValue = ValueComboBox.Text;}}//监听下拉框输入数据进行模糊查询private void ConditionComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e){var comboBox = sender as ComboBox;var view = (CollectionView)CollectionViewSource.GetDefaultView(comboBox.ItemsSource);if (view != null){string text = comboBox.Text;if (string.IsNullOrEmpty(text)){ConditionValues = ConditionValueBackUp;_conditionValues = ConditionValueBackUp;}else{ConditionValues = new ObservableCollection<string>(ConditionValueBackUp.Where(p => p.Contains(text)));//ConditionValues = ConditionValueBackUp.Where(p => p.Contains(text)).ToList();}}}//监听下拉框输入数据进行模糊查询private void FieldNameComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e){var comboBox = sender as ComboBox;var view = (CollectionView)CollectionViewSource.GetDefaultView(comboBox.ItemsSource);if (view != null){string text = comboBox.Text;if (string.IsNullOrEmpty(text)){FieldNames = FieldNamesValueBackUp;_fieldNames = FieldNamesValueBackUp;}else{FieldNames = FieldNamesValueBackUp.Where(p => p.Contains(text)).ToList();}}}// 处理 ComboBox 的 SelectionChanged 事件private void RelationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e){try {// 获取选中的项string selectedValue = RelationComboBox.SelectedItem as string;// 如果选中的值不为空,进行操作// 如果其他属性有空值则不清空if (!string.IsNullOrEmpty(selectedValue)&& !(string.IsNullOrEmpty(_selectedFieldName) ||string.IsNullOrEmpty(_selectedCondition) ||string.IsNullOrEmpty(_selectedConditionValue) ||string.IsNullOrEmpty(_selectedRelationValue))){AddQueryCondition();//添加到查询条件列表中}}catch(Exception ex){MessageBox.Show(ex.Message);}}[RelayCommand]public void AddQueryCondition(){try {// 检查是否有空值或空字符串if (string.IsNullOrEmpty(_selectedFieldName) ||string.IsNullOrEmpty(_selectedCondition) ||string.IsNullOrEmpty(_selectedRelationValue) ||(string.IsNullOrEmpty(_selectedConditionValue) &&string.IsNullOrEmpty(InputValue))){return; // 如果有空值,直接返回}// 创建并添加 SecondQueryCondition 对象到 QueryConditions 列表QueryConditions.Add(new SecondQueryCondition(QueryConditions.Count + 1, _selectedFieldName, _selectedCondition, string.IsNullOrEmpty(_selectedConditionValue)?InputValue: _selectedConditionValue, _selectedRelationValue));//清空查询条件RelationComboBox.SelectedItem = null; // 清空 ComboBox 的选中项ValueComboBox.SelectedItem = null;ConditionComboBox.SelectedItem = null;FieldNameComboBox.SelectedItem = null;}catch(Exception ex){MessageBox.Show(ex.Message);}}private void FieldNameComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e){try {ConditionValues.Clear();_columnMappings.TryGetValue(_selectedFieldName, out string property);if (_Ibo == null){return;}foreach (var item in _Ibo){string propertyValue = item.GetType().GetProperty(property)?.GetValue(item)?.ToString();if (!string.IsNullOrEmpty(propertyValue) && !ConditionValues.Contains(propertyValue)){ConditionValues.Add(propertyValue);}}ConditionValueBackUp = ConditionValues;} catch (Exception ex){return;}}[RelayCommand]public void DeleteCondition(SecondQueryCondition secondQueryCondition){QueryConditions.Remove(secondQueryCondition);}[RelayCommand]public void Query(){var parameter = Expression.Parameter(typeof(ToolStr50), "p");Expression finalExpression = null;foreach (var queryCondition in QueryConditions){if (_columnMappings.TryGetValue(queryCondition.FieldName, out string property)){var member = Expression.Property(parameter, property);var conditionValue = Expression.Constant(queryCondition.ConditionValue, typeof(string));Expression comparison;// 尝试解析为 int, double, DateTimeif (int.TryParse(queryCondition.ConditionValue, out int intValue)){var intMember = Expression.Convert(member, typeof(int));var intConditionValue = Expression.Constant(intValue, typeof(int));comparison = GetIntegerComparison(queryCondition.Condition, intMember, intConditionValue);}else if (double.TryParse(queryCondition.ConditionValue, out double doubleValue)){var doubleMember = Expression.Convert(member, typeof(double));var doubleConditionValue = Expression.Constant(doubleValue, typeof(double));comparison = GetDoubleComparison(queryCondition.Condition, doubleMember, doubleConditionValue);}//如果日期类型无法对比直接注释掉,按照string类型对比//else if (DateTime.TryParse(queryCondition.ConditionValue, out DateTime dateTimeValue))//{// var dateTimeMember = Expression.Convert(member, typeof(DateTime));// var dateTimeConditionValue = Expression.Constant(dateTimeValue, typeof(DateTime));// comparison = GetDateTimeComparison(queryCondition.Condition, dateTimeMember, dateTimeConditionValue);//}else{// 如果无法转换,继续使用字符串比较comparison = GetStringComparison(queryCondition.Condition, member, conditionValue);}// 组合条件if (finalExpression == null){finalExpression = comparison;}else{if (queryCondition.RelationValue.Equals("并且")){finalExpression = Expression.AndAlso(finalExpression, comparison); // 使用 AndAlso 组合条件}if (queryCondition.RelationValue.Equals("或者")){finalExpression = Expression.Or(finalExpression, comparison); // 使用 Or 组合条件}}}}// 生成最终的 Lambda 表达式if (finalExpression != null){var lambda = Expression.Lambda<Func<ToolStr50, bool>>(finalExpression, parameter);FilteredData = _Ibo.Where(lambda.Compile()).ToList();this.DialogResult = true; // 可选: 设置窗口的结果this.Close(); // 关闭窗口}else //没有查询条件查全部{FilteredData = _Ibo;this.DialogResult = true; // 可选: 设置窗口的结果this.Close(); // 关闭窗口}}private Expression GetIntegerComparison(string condition, Expression member, Expression conditionValue){return condition switch{"大于" => Expression.GreaterThan(member, conditionValue),"大于等于" => Expression.GreaterThanOrEqual(member, conditionValue),"小于" => Expression.LessThan(member, conditionValue),"小于等于" => Expression.LessThanOrEqual(member, conditionValue),"等于" => Expression.Equal(member, conditionValue),"不等于" => Expression.NotEqual(member, conditionValue),_ => throw new NotSupportedException($"不支持的条件: {condition}")};}private Expression GetDoubleComparison(string condition, Expression member, Expression conditionValue){return condition switch{"大于" => Expression.GreaterThan(member, conditionValue),"大于等于" => Expression.GreaterThanOrEqual(member, conditionValue),"小于" => Expression.LessThan(member, conditionValue),"小于等于" => Expression.LessThanOrEqual(member, conditionValue),"等于" => Expression.Equal(member, conditionValue),"不等于" => Expression.NotEqual(member, conditionValue),_ => throw new NotSupportedException($"不支持的条件: {condition}")};}private Expression GetDateTimeComparison(string condition, Expression member, Expression conditionValue){return condition switch{"大于" => Expression.GreaterThan(member, conditionValue),"大于等于" => Expression.GreaterThanOrEqual(member, conditionValue),"小于" => Expression.LessThan(member, conditionValue),"小于等于" => Expression.LessThanOrEqual(member, conditionValue),"等于" => Expression.Equal(member, conditionValue),"不等于" => Expression.NotEqual(member, conditionValue),_ => throw new NotSupportedException($"不支持的条件: {condition}")};}private Expression GetStringComparison(string condition, Expression member, Expression conditionValue){// 比较两个字符串时,我们需要使用 string.Compare 方法var compareMethod = typeof(string).GetMethod("Compare", new[] { typeof(string), typeof(string) });return condition switch{// 等于"等于" => Expression.Equal(member, conditionValue),// 不等于"不等于" => Expression.NotEqual(member, conditionValue),// 大于"大于" => Expression.GreaterThan(Expression.Call(null, compareMethod, member, conditionValue),Expression.Constant(0)),// 小于"小于" => Expression.LessThan(Expression.Call(null, compareMethod, member, conditionValue),Expression.Constant(0)),// 大于等于"大于等于" => Expression.GreaterThanOrEqual(Expression.Call(null, compareMethod, member, conditionValue),Expression.Constant(0)),// 小于等于"小于等于" => Expression.LessThanOrEqual(Expression.Call(null, compareMethod, member, conditionValue),Expression.Constant(0)),// 包含"包含" => Expression.Call(member,typeof(string).GetMethod("Contains", new[] { typeof(string) }),conditionValue),_ => throw new NotSupportedException($"不支持的条件: {condition}")};}// 触发属性更新通知的方法protected virtual void OnPropertyChanged(string propertyName){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}// 模糊查询方法public void UpdateFieldNames(string searchText){FieldNames = _fieldNames.Where(p => p.Contains(searchText)).ToList();}}
}
动态生成的lambda表达式:
模糊查询的逻辑
在下拉框输入字段后会显示服务要求的字段
代码体现
<TextBlock Text="字段名称" Margin="49,34,655,0" VerticalAlignment="Top" Grid.Row="0"/><ComboBox Name="FieldNameComboBox" Margin="25,5,640,0" VerticalAlignment="Top" IsEditable="True"IsTextSearchEnabled="False"PreviewTextInput="FieldNameComboBox_PreviewTextInput"ItemsSource="{Binding FieldNames}" SelectedItem="{Binding SelectedFieldName, Mode=TwoWay}" SelectionChanged="FieldNameComboBox_SelectionChanged"Grid.Row="1"/>
1.IsEditable="True"控制 ComboBox 是否可以编辑。设置为 True 时,用户可以直接在 ComboBox 中输入文本;设置为 False 时,用户只能从下拉列表中选择项,而不能直接输入。2.IsTextSearchEnabled="False"控制是否启用文本搜索功能。在启用时,用户输入的文本将用来在列表项中进行搜索。如果设置为 False,则禁用此功能。3.PreviewTextInput="FieldNameComboBox_PreviewTextInput"这是 ComboBox 的事件处理器,当用户在 ComboBox 中输入文本时触发。PreviewTextInput 是一个 预处理 事件,在文本输入之前触发,可以用来在用户输入时进行拦截或处理(例如输入验证)。事件处理方法是 FieldNameComboBox_PreviewTextInput,这是在代码后面定义的一个方法,它会处理此事件。例如,可能会检查用户输入是否符合某些规则。
// 监听 ComboBox 输入事件进行模糊查询
private void FieldNameComboBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{// 将 sender 强制转换为 ComboBox 控件var comboBox = sender as ComboBox;// 获取 ComboBox 的数据源,并转换为可操作的集合视图(CollectionView)var view = (CollectionView)CollectionViewSource.GetDefaultView(comboBox.ItemsSource);// 如果视图不为空,则进行后续处理if (view != null){// 获取 ComboBox 中当前输入的文本string text = comboBox.Text;// 如果输入文本为空,恢复备份的所有项if (string.IsNullOrEmpty(text)){// 恢复 FieldNames 为原始备份的值FieldNames = FieldNamesValueBackUp;_fieldNames = FieldNamesValueBackUp;}else{// 否则,使用输入文本进行模糊查询,筛选出包含该文本的项FieldNames = FieldNamesValueBackUp.Where(p => p.Contains(text)).ToList();}}
}
相关文章:

c# 动态lambda实现二级过滤(支持多种参数类型和模糊查询)
效果 调用方法 实体类(可以根据需求更换) public class ToolStr50 {public bool isSelected { get; set; }public string toolStr1 { get; set; }public string toolStr2 { get; set; }public string toolStr3 { get; set; }public string toolStr4 { …...

第J5周:DenseNet+SE-Net实战
🍨 本文为🔗365天深度学习训练营 中的学习记录博客🍖 原作者:K同学啊 任务: ●1. 在DenseNet系列算法中插入SE-Net通道注意力机制,并完成猴痘病识别 ●2. 改进思路是否可以迁移到其他地方呢 ●3. 测试集acc…...

Intern大模型训练营(五):书生大模型全链路开源体系笔记
观看视频,可以比较详细地了解到书生大模型全链路开源体系。 其中有几个印象比较深的点: 这张图讲述了书生浦语大模型开源的发展史,同时与主流的llama和Chatgpt模型进行比较,可以看出在参数上,InterLM在努力追赶甚至超…...

聚观早报 | 比亚迪腾势D9登陆泰国;苹果 iOS 18.2 将发布
聚观早报每日整理最值得关注的行业重点事件,帮助大家及时了解最新行业动态,每日读报,就读聚观365资讯简报。 整理丨Cutie 11月5日消息 比亚迪腾势D9登陆泰国 苹果 iOS 18.2 将发布 真我GT7 Pro防尘防水细节 小米15 Ultra最快明年登场 …...

微信小程序开发,诗词鉴赏app,诗词搜索实现(三)
微信小程序开发,诗词鉴赏app(一): https://blog.csdn.net/jky_yihuangxing/article/details/143501681微信小程序开发,诗词鉴赏app,诗词推荐实现(二):https://blog.csdn.net/jky_yih…...

Kotlin 协程使用及其详解
Kotlin协程,好用,但是上限挺高的,我一直感觉自己就处于会用,知其然不知其所以然的地步。 做点小总结,比较浅显。后面自己再继续补充吧。 一、什么是协程? Kotlin 协程是一种轻量级的并发编程方式&#x…...

计算机组成原理--三章四章
这里写目录标题 第三章:存储系统3.1 存储系统基本概念引入存储器的层次结构简介产品 存储器的分类按层次分类按照介质分类按照存取方式分类按照信息的可更改性按照信息的可保护性 存储器的性能指标存储容量单位成本存储速度 总结 3.2主存储器的基本组成半导体元器件…...

单片机工程使用链接优化-flto找不到定义_链接静态库
IDE: CLion HOST: Windows 11 MinGW:x86_64-14.2.0-release-posix-seh-ucrt-rt_v12-rev0 GCC: arm-gnu-toolchain-13.3.rel1-mingw-w64-i686-arm-none-eabi 示例工程:https://github.com/ichliebedich-DaCapo/STM…...

UniTask/Unity的PlayerLoopTiming触发顺序
开始尝试在项目中使用UniTask,发现其中的UniTask.Yield确实很好用,还可以传入PlayerLoopTiming来更细致的调整代码时机,不过平常在Mono中接触的只有Awake,Start,Update等常用Timing,其他的就没怎么接触了&a…...

【报错记录】Steam迁移(移动)游戏报:移动以下应用的内容失败:XXX: 磁盘写入错误
前言 由于黑神话悟空,导致我的2TB的SSD系统盘快满了,我又买了一块4TB的SSD用来存放游戏,我就打算把之前C盘里的游戏移动到D盘,结果Steam移动游戏居然报错了,报的还是“磁盘写入错误”,如下图所示ÿ…...

C 语言学习-04【结构化程序设计】
1、单分支结构语句 用单分支结构进行奇偶判断: #include <stdio.h>int main() {int num;printf("Please enter an integer: ");scanf("%d", &num);if (num % 2 ! 0) {printf("%d is odd! \n", num);}if (num % 2 0) {prin…...

机器视觉:轮廓匹配算法原理
轮廓匹配的模板变量主要包括模板图像(Template)和待检测图像(Source Image) 在轮廓匹配中,模板变量主要包括一下几个关键部分: 模板图像(Template):这是进行匹配的…...

动力商城-02 环境搭建
1.父工程必须满足:1.1删除src目录 1.2pom 2.依赖继承 //里面的依赖,后代无条件继承<dependencies></dependencies>//里面的依赖,后代想要继承,得自己声明需要使用,可以不写版本号,自动继承&l…...

【react】Redux基础用法
1. Redux基础用法 Redux 是一个用于 JavaScript 应用的状态管理库,它不依赖于任何 UI库,但常用于与 React 框架配合使用。它提供了一种集中式的状态管理方式,将应用的所有状态保存在一个单一的全局 Store(存储)中&…...

使用Python分析股票价格数据并计算移动平均线的实用指南
使用Python分析股票价格数据并计算移动平均线的实用指南 在金融市场中,移动平均线(Moving Average, MA)是一种常用的技术分析工具,用于平滑价格数据,帮助投资者识别趋势。本文将详细介绍如何使用Python分析股票价格数据,并计算移动平均线。我们将通过一个实际的案例来演…...

如何解决FPS低的问题?代码优化方法有哪些?
如果你是一名游戏开发者,或者对电脑性能有所追求的用户,那么你一定遇到过帧率(FPS)低的问题。帧率低会导致游戏卡顿、画面不流畅等问题,极大地影响了用户体验。本文将从代码层面探讨FPS低的原因,并提供一些…...

QT信号和槽与自定义的信号和槽
QT信号和槽与自定义的信号和槽 1.概述 这篇文章介绍下QT信号和槽的入门知识,通过一个案例介绍如何创建信号和槽,并调用他们。 2.信号和槽使用 下面通过点击按钮关闭窗口的案例介绍如何使用信号和槽。 创建按钮 在widget.cpp文件中创建按钮代码如下 …...

LC:二分查找——杂记
文章目录 268. 丢失的数字162. 寻找峰值 268. 丢失的数字 LC将此题归类为二分查找,并且为简单题,下面记一下自己对这道题目的思考。 题目链接:268.丢失的数字 第一次看到这个题目,虽然标注的为简单,但肯定不能直接排…...

GA/T1400视图库平台EasyCVR多品牌摄像机视频平台前端监控摄像头镜头的基础知识
在现代安全监控系统中,摄像机镜头作为捕捉图像的关键组件,其选择和应用直接影响到监控图像的质量和系统的整体性能。随着技术的发展,摄像机镜头的种类和功能也在不断扩展,以适应各种复杂的监控环境和需求。对于相机成像来讲&#…...

【C++】踏上C++的学习之旅(六):深入“类和对象“世界,掌握编程的黄金法则(一)
文章目录 前言1. "面向过程"和"面向对象"的碰撞1.1 面向过程1.2 面向对象 2. "类"的引入3. "类"的定义3.1 🍉语法展示:3.2 "类"的两种定义方式3.3 "类"的命名规则 4. 类的访问限定符以及封…...

【物联网技术】ESP8266 WIFI模块在STA模式下作为TCP客户端上电自动进入透传数据模式
前言:讲解如何在ESP8266 WIFI模块在STA模式下作为TCP客户端与网络调试助手(TCP服务器)上电自动进入透传数据模式,而不需重新再发指令配置进入透传模式。 演示视频: ESP8266 WIFI模块在STA模式下作为TCP客户端上电自动进入透传数据模式 wifi模块在STA模式下作为TCP客户端相…...

重构代码之用委托替代继承
在代码重构中,用委托替代继承 是一种用于改善代码设计和提高灵活性的重要技术。它的核心思想是,将子类与父类的直接继承关系转换为委托关系,即子类不再直接继承父类,而是通过持有父类的实例来访问所需的功能。 一、为什么需要用委…...

软件设计师下午题UML15分
一、涉及到的图及对应关系 二、例题 1.用例图和类图的例题 解析及答案 2.状态图和类图的例题 3.通信图和类图例题 例题...

css background-image背景图片轮播
1、CSS背景样式有以下几种: 背景颜色(background-color):设置元素的背景颜色。背景图片(background-image):设置元素的背景图片。背景重复(background-repeat)ÿ…...

java---认识异常(详解)
还有大家来到权权的博客~欢迎大家对我的博客提出意见哦,有错误会及时改进的~点击进入我的博客主页 目录 一、异常的概念及体系结构1.1 异常的概念1.2 异常的体系结构1.3异常的分类 二、异常的处理2.1防御式编程2.2 异常的抛出2.3 异常的捕获2.3.1异常声明throws2.3.…...

Linux基础学习笔记
Linux基础学习笔记 Linux目录结构: 具体的目录结构: /bin [重点] (/usr/bin 、 /usr/local/bin) • 是Binary的缩写, 这个目录存放着最经常使用的命令 /home [重点] • 存放普通用户的主目录,在Linux中每个用户都有一个自己的目录,一…...

自动泊车端到端算法 ParkingE2E 介绍
01 算法介绍 自主泊车是智能驾驶领域中的一项关键任务。传统的泊车算法通常使用基于规则的方案来实现。因为算法设计复杂,这些方法在复杂泊车场景中的有效性较低。 相比之下,基于神经网络的方法往往比基于规则的方法更加直观和多功能。通过收集大量专家…...

《手写Spring渐进式源码实践》实践笔记(第十七章 数据类型转换)
文章目录 第十七章 数据类型转换工厂设计实现背景技术背景Spring数据转换实现方式类型转换器(Converter)接口设计实现 业务背景 目标设计实现代码结构类图实现步骤 测试事先准备属性配置文件转换器工厂Bean测试用例测试结果: 总结 第十七章 数…...

W3C HTML 活动
关于W3C(万维网联盟)的HTML活动,我们可以从HTML的不同版本的发展历程中了解其主要的活跃时期和贡献。 HTML 2.0:这个版本的HTML是由Internet工程工作小组(IETF)的HTML工作组于1996年开发的。它是HTML的早期…...

机器学习—为什么我们需要激活函数
如果我们使用神经网络中每个神经元的线性激活函数,回想一下这个需求预测示例,如果对所有节点使用线性激活函数,在这个神经网络中,事实证明,这个大神经网络将变得与线性回归没有什么不同,所以这将挫败使用神…...