tangxu
2024-03-20 7947ecd7933cc92f5d9565afb51aff6e744074c5
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using DevExpress.XtraEditors;
using System;
using System.ComponentModel;
using System.Linq;
 
namespace IStation.WinFrmUI.Basic
{
    /// <summary>
    /// 
    /// </summary>
    public partial class PumpListCtrl : XtraUserControl
    {
        public PumpListCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.treeList1.SelectImageList = ImageLib.Lib;
            this.layoutControl1.SetupLayoutControl();
        }
 
        public class CurrentViewModel
        {
            public long ID { get; set; }
            public long ParentID { get; set; }
            public string Name { get; set; }
            public string ObjectType { get; set; }
            public object Model { get; set; }
            public bool IsGroup { get; set; }
            public int ImageIndex { get; set; }
        }
 
        /// <summary>
        /// 聚焦改变事件
        /// </summary> 
        public event Action<Model.Product<Model.Pump>> FocusedChangedEvent;
 
        private BindingList<CurrentViewModel> _allBindingList = null;//所有绑定列表
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void Clear()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            this.treeList1.DataSource = _allBindingList;
            this.FocusedChangedEvent?.Invoke(null);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            WaitFrmHelper.ShowWaitForm("正在加载数据...");
            _allBindingList = new BindingList<CurrentViewModel>();
 
            var stations = new BLL.Station().GetAll();
            if (stations != null && stations.Any())
            {
                var imgIndex = ImageLib.Station;
                foreach (var station in stations)
                {
                    var vm = new CurrentViewModel()
                    {
                        ID = station.ID,
                        Name = station.Name,
                        ObjectType = IStation.ObjectType.Station,
                        Model = station,
                        IsGroup = true,
                        ImageIndex = imgIndex
                    };
                    _allBindingList.Add(vm);
                }
            }
 
            long? key = null;
            var pumps = new BLL.Product().GetAllPump();
            if (pumps != null && pumps.Any())
            {
                var first = pumps.First();
                key = first.ID;
                var imgIndex = ImageLib.Pump;
                foreach (var pump in pumps)
                {
                    var vm = new CurrentViewModel()
                    {
                        ID = pump.ID,
                        Name = pump.Name,
                        ParentID = pump.BelongID,
                        ObjectType = IStation.ObjectType.Product,
                        Model = pump,
                        IsGroup = false,
                        ImageIndex = imgIndex
                    };
                    _allBindingList.Add(vm);
                }
            }
 
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.ForceInitialize();
 
            if (key.HasValue)
            {
                this.treeList1.FocusedNode = this.treeList1.FindNodeByKeyID(key.Value);
            }
 
            WaitFrmHelper.HideWaitForm();
        }
 
 
        //全部展开
        private void barBtnExpandAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.ExpandAll();
        }
 
        //全部折叠 
        private void barBtnCollpseAll_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.CollapseAll();
        }
 
        //检索
        private void barCkSearch_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barCkSearch.Checked)
                this.treeList1.ShowFindPanel();
            else
                this.treeList1.HideFindPanel();
        }
 
        //详细信息
        private void barBtnDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            XtraMessageBox.Show("待补充!");
        }
 
        //聚焦前
        private void treeList1_BeforeFocusNode(object sender, DevExpress.XtraTreeList.BeforeFocusNodeEventArgs e)
        {
            var row = this.treeList1.GetDataRecordByNode(e.Node) as CurrentViewModel;
            if (row != null)
            {
                if (row.IsGroup)
                {
                    e.CanFocus = false;
                }
            }
        }
 
        //聚焦改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
            if (vm.IsGroup)
                return;
            var model = vm.Model as Model.Product<Model.Pump>;
            this.FocusedChangedEvent?.Invoke(model);
        }
 
 
    }
 
}