namespace HydroUI
|
{
|
public partial class FormFilter : XtraForm
|
{
|
public List<Func<IBaseViewModel, bool>> rules = new List<Func<IBaseViewModel, bool>>();
|
public TagList Tags=new TagList();
|
public List<MapObjectType> Types=new List<MapObjectType>();
|
public FormFilter(TagList tags)
|
{
|
InitializeComponent();
|
// Generate buttons based on tags
|
foreach (var tag in tags)
|
{
|
Button button = new Button();
|
button.Text = tag;
|
button.Tag = false;
|
button.Click += (sender, e) =>
|
{
|
//bool Enabled = !button.BackColor.Equals(Color.Gray);
|
bool Enabled=bool.Parse(button.Tag.ToString());
|
if (Enabled)
|
{
|
button.Tag=false;
|
button.BackColor = Color.White;
|
Tags.Remove(tag);
|
}
|
else
|
{
|
button.Tag = true;
|
button.BackColor = Color.SkyBlue;
|
Tags.Add(tag);
|
}
|
};
|
flowLayoutPanel1.Controls.Add(button);
|
}
|
this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
|
}
|
|
private void FormFilter_Load(object sender, EventArgs e)
|
{
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
{
|
this.DialogResult=DialogResult.OK;
|
}
|
|
private void button2_Click(object sender, EventArgs e)
|
{
|
this.DialogResult=DialogResult.Cancel;
|
}
|
|
private void button_add_Click(object sender, EventArgs e)
|
{
|
rules.Add(o =>
|
{
|
//查找属性显示名称DisplayName为comboBox_type.text的属性
|
var propertyDescriptor = TypeDescriptor.GetProperties(o)[comboBox_type.Text];
|
if (propertyDescriptor == null) return false;
|
//获取属性的值
|
var value = propertyDescriptor.GetValue(o);
|
//根据combobox_opt的选项,对value和textBox_value.Text进行比较
|
switch (comboBox_opt.Text)
|
{
|
case "等于":
|
return value.ToString() == textBox_value.Text;
|
case "不等于":
|
return value.ToString() != textBox_value.Text;
|
case "大于":
|
return double.Parse(value.ToString()) > double.Parse(textBox_value.Text);
|
case "小于":
|
return double.Parse(value.ToString()) < double.Parse(textBox_value.Text);
|
case "大于等于":
|
return double.Parse(value.ToString()) >= double.Parse(textBox_value.Text);
|
case "小于等于":
|
return double.Parse(value.ToString()) <= double.Parse(textBox_value.Text);
|
case "包含":
|
return value.ToString().Contains(textBox_value.Text);
|
case "不包含":
|
return !value.ToString().Contains(textBox_value.Text);
|
default:
|
return false;
|
}
|
|
});
|
//在listbox中显示添加的规则
|
listBox1.Items.Add(comboBox_type.Text + comboBox_opt.Text + textBox_value.Text);
|
}
|
|
private void button_minus_Click(object sender, EventArgs e)
|
{
|
//在listbox中删除选中的规则,同时在rules中删除对应的规则
|
if (listBox1.SelectedIndex >= 0)
|
{
|
rules.RemoveAt(listBox1.SelectedIndex);
|
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
|
}
|
}
|
}
|
}
|