duheng
2025-03-28 9be9ba4e159969fb5e32648c2c34e912ccc3ae6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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);
            }
        }
    }
}