duheng
2024-07-10 2a41fffc9f962999ba163c3b471873b6b96f05bc
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
using DevExpress.XtraEditors.Controls;
using Yw.Dto;
 
namespace HStation.WinFrmUI.Basic
{
    public partial class SysPropEditDlg : Form
    {
        public SysPropEditDlg()
        {
            InitializeComponent();
        }
 
        public class CurrentViewModel
        {
            public CurrentViewModel(SysPropHaveLogicalTreeDto rhs)
            {
                if (rhs.LogicalType == "sys-prop")
                {
                    Name = rhs.LogicalName;
                    ID = rhs.LogicalID;
                    IsHave = rhs.Have;
                }
                else
                {
                    Name = rhs.LogicalName;
                    ID = rhs.LogicalID;
                    IsHave = rhs.Have;
                }
            }
 
            public string Name { get; set; }
            public long ID { get; set; }
            public long ParentID { get; set; }
            public bool IsHave { get; set; }
        }
 
        private List<CurrentViewModel> _allBindingList = new List<CurrentViewModel>();
 
        private Yw.BLL.SysPropMapping _bll = null;
 
        private long _CatlogID;
 
        public async void SetBindingData(long ID)
        {
            _CatlogID = ID;
            _bll = new Yw.BLL.SysPropMapping();
            var PropTreeList = await _bll.GetHaveLogicalTreeList(ID);
            foreach (var item in PropTreeList)
            {
                if (item.Children.Count > 0)
                {
                    foreach (var child in item.Children)
                    {
                        CheckedListBoxItem childitem = new CheckedListBoxItem();
                        childitem.Value = child.LogicalID;
                        childitem.Description = child.LogicalName;
                        checkedListBoxControl1.Items.Add(childitem);
                        if (child.Have)
                        {
                            childitem.CheckState = CheckState.Checked;
                        }
                    }
                }
            }
        }
 
        // 完成
        private async void BtnOk_Click(object sender, EventArgs e)
        {
            List<long> IdList = new List<long>();
            foreach (var item in checkedListBoxControl1.CheckedItems)
            {
                if (item is CheckedListBoxItem checkedListBoxItem)
                {
                    var model = item as CheckedListBoxItem;
                    if (model != null)
                    {
                        var value = model.Value;
                        IdList.Add(Convert.ToInt64(model.Value));
                    }
                }
            }
            if (await _bll.Set(_CatlogID, IdList))
            {
                MessageBoxHelper.ShowSuccess("修改成功!");
            }
            else
            {
                MessageBoxHelper.ShowError("修改失败"!);
                return;
            }
            this.Close();
        }
    }
}