ningshuxia
2025-03-21 7af1565cf5af77397453a3ea6ad516ac9be371f8
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
using DevExpress.Utils;
using DevExpress.XtraCharts;
using System.Windows.Media.Imaging;
 
namespace PBS.WinFrmUI.Hydro
{
    public partial class FacilityTreeListCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public FacilityTreeListCtrl()
        {
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.layoutControl1.SetupLayoutControl();
        }
 
        /// <summary>
        /// 选择项目事件
        /// </summary>
        public event Action<FacilityVmo> SelectFacilityEvent;
 
        /// <summary>
        /// 刷新数据事件
        /// </summary>
        public event Action RefreshDataEvent;
          
 
        private List<FacilityTreeViewModel> _allBindingList = new();
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData(List<FacilityVmo> allFacilityList)
        {
            _allBindingList = new List<FacilityTreeViewModel>();
            if (allFacilityList != null)
            {
                foreach (var item in allFacilityList)
                {
                    if (await IsHaveInp(item.ID))
                    {
                        var vm = new FacilityTreeViewModel(item, true);
                        _allBindingList.Add(vm);
                    }
                    else
                    {
                        var vm = new FacilityTreeViewModel(item, false);
                        _allBindingList.Add(vm);
                    }
                }
            }
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.ForceInitialize();
            this.treeList1.ExpandAll();
        }
 
        //查找模板是否存在模型
        private async Task<bool> IsHaveInp(long FacilityID)
        {
             
            return true;
        }
 
        /// <summary>
        /// 设置默认
        /// </summary>
        public void SetFocused()
        {
            if (_allBindingList == null)
            {
                return;
            }
            var vm = _allBindingList.FirstOrDefault();
            if (vm != null)
            {
                this.treeList1.FocusedNode = this.treeList1.FindNodeByKeyID(vm.ID);
            }
        }
 
        /// <summary>
        /// 设置聚焦
        /// </summary>
        public void SetFocused(long ID)
        {
            if (_allBindingList == null)
            {
                return;
            }
            this.treeList1.FocusedNode = this.treeList1.FindNodeByKeyID(ID);
        }
 
        ///// <summary>
        ///// 添加模型模板
        ///// </summary>
        //public void AddFacility()
        //{
        //    if (_allBindingList == null)
        //    {
        //        return;
        //    }
        //    var dlg = new AddFacilityDlg();
        //    dlg.SetBindingData();
        //    dlg.ReloadDataEvent += (rhs) =>
        //    {
        //        var vm = new FacilityTreeViewModel(rhs, true);
        //        _allBindingList.Add(vm);  
        //        this.treeList1.RefreshDataSource();
        //        SetFocused(vm.ID);
        //        TipFormHelper.ShowSucceed("模型模板添加成功!");
        //    };
        //    dlg.ShowDialog();
        //}
 
        ///// <summary>
        ///// 更新模型模板
        ///// </summary>
        //public void UpdateFacility()
        //{
        //    if (_allBindingList == null)
        //    {
        //        return;
        //    }
        //    var vm = this.treeList1.GetFocusedRow() as FacilityTreeViewModel;
        //    if (vm == null)
        //    {
        //        return;
        //    }
 
        //    var dlg = new EditFacilityDlg();
        //    dlg.SetBindingData(vm.Facility);
        //    dlg.ReloadDataEvent += (rhs) =>
        //    {
        //        vm.Name = rhs.Name;
        //        vm.Description=rhs.Description;
        //        vm.Facility = rhs;
        //        this.treeList1.RefreshNode(this.treeList1.FocusedNode);
        //        TipFormHelper.ShowSucceed("模型模板更新成功!"); 
        //    };
        //    dlg.ShowDialog();
        //}
 
 
        ///// <summary>
        ///// 保存模型模板
        ///// </summary>
        //public async void SaveFacility(PBS.Vmo.FacilityVmo vmo)
        //{
        //    if (_allBindingList == null)
        //    {
        //        return  ;
        //    } 
        //    var vm = _allBindingList.Find(x => x.ID == vmo.ID);
        //    if (vm == null)
        //    {
        //        return   ;
        //    } 
 
        //    var bol = await BLLFactory<PBS.BLL.Facility>.Instance.Update(vmo);
        //    if (!bol)
        //    {
        //        TipFormHelper.ShowError("保存失败!");
        //        return  ;
        //    }
        //    vm.Name = vmo.Name;
        //    vm.Description = vmo.Description;   
        //    vm.Facility = await BLLFactory<PBS.BLL.Facility>.Instance.GetByID(vmo.ID);
        //    this.treeList1.RefreshNode(this.treeList1.FocusedNode);
        //    TipFormHelper.ShowSucceed("模型模板保存成功!");
        //}
 
        ///// <summary>
        ///// 删除模型模板
        ///// </summary> 
        //public async void DeleteFacility()
        //{
        //    var bol = XtraMessageBox.Show("请问是否删除当前模型模板?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes;
        //    if (!bol)
        //    {
        //        return;
        //    }
        //    var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
        //    if (vm == null)
        //    {
        //        TipFormHelper.ShowWarn("请选择数据行!");
        //        return;
        //    }
 
        //    // 需增加删除模型模板映射设施的逻辑
        //    //....
 
        //    if (!await BLLFactory<PBS.BLL.Facility>.Instance.DeleteByID(vm.ID))
        //    {
        //        TipFormHelper.ShowError("模型模板删除失败,请重试!");
        //        return;
        //    }
 
        //    TipFormHelper.ShowSucceed("模型模板删除成功!");
 
        //    _allBindingList.Remove(vm);
        //    this.treeList1.RefreshDataSource();
        //}
 
        //全部展开
        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();
        }
 
        //检索(menu)
        private void barBtnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.treeList1.IsFindPanelVisible==false)
                this.treeList1.ShowFindPanel();
            else
                this.treeList1.HideFindPanel();
        }
 
        //树线
        private void barCkTreeLine_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.treeList1.OptionsView.ShowTreeLines = this.barCkTreeLine.Checked ? DefaultBoolean.True : DefaultBoolean.False;
        }
 
        //聚焦节点改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            var vm = this.treeList1.GetDataRecordByNode(e.Node) as FacilityTreeViewModel; 
            this.SelectFacilityEvent?.Invoke(vm?.Facility);
        }
         
 
        //刷新
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.RefreshDataEvent?.Invoke();
        }
 
        
    }
}