lixiaojun
2024-12-20 a7c780692ab2d8072ad4cae0fecbf851c27231d9
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
using DevExpress.XtraEditors.Controls;
using System.Collections.Generic;
using System.Windows.Forms;
using Yw.Untity;
 
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 选择Flags控件
    /// </summary>
    public partial class SelectFlagsCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SelectFlagsCtrl()
        {
            InitializeComponent();
        }
 
        //绑定数据
        public void SetBindingData(List<string> sysFlags = null, List<string> cekFlags = null)
        {
            this.clbFlags.Items.Clear();
            if (sysFlags != null)
            {
                this.clbFlags.Items.AddRange(sysFlags.ToArray());
            }
            if (cekFlags != null)
            {
                foreach (CheckedListBoxItem item in this.clbFlags.Items)
                    item.CheckState = (cekFlags.IndexOf(item.Value.ToString()) > -1) ? CheckState.Checked : CheckState.Unchecked;
 
                List<string> customFlags = null;
                if (sysFlags != null)
                    customFlags = cekFlags.FindAll(x => !sysFlags.Contains(x));
                else
                    customFlags = cekFlags;
                if (customFlags != null && customFlags.Count > 0)
                    this.CustomFlagsTextEdit.EditValue = FlagsHelper.ToString(customFlags);
            }
        }
 
        /// <summary>
        /// 验证
        /// </summary>
        public bool Valid()
        {
            //临时
            var flags = this.CustomFlagsTextEdit.Text.Trim();
            if (!string.IsNullOrEmpty(flags))
            {
                var list = FlagsHelper.ToList(flags);
                if (list == null)
                {
                    this.dxErrorProvider1.SetError(this.CustomFlagsTextEdit, "格式错误");
                    return false;
                }
            }
            return true;
        }
 
        /// <summary>
        /// 获取数据
        /// </summary>
        public List<string> GetFlags()
        {
            var list = new List<string>();
            foreach (CheckedListBoxItem item in this.clbFlags.Items)
            {
                if (item.CheckState == CheckState.Checked)
                    list.Add(item.Value.ToString());
            }
            var custom = this.CustomFlagsTextEdit.Text.Trim();
            var flags = FlagsHelper.ToList(custom);
            if (flags != null)
                list.AddRange(flags);
            if (list.Count < 1)
                return default;
            return list;
        }
    }
}