Shuxia Ning
2024-11-11 750b85dc4c5562b9c0dc9b8c463e5cc5f0ad2553
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
using Mapster;
 
namespace HStation.WinFrmUI
{
    public partial class AddXhsSchemeDlg : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public AddXhsSchemeDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.ribbon.SetFormStyle();
            this.gridView1.SetNormalView();
            this.gridView2.SetNormalView();
            this.gridView2.OptionsView.EnableAppearanceOddRow = false;   // 使能 // 和和上面绑定 同时使用有效  
            this.gridView2.OptionsView.EnableAppearanceEvenRow = false;
 
            this.gridView1.OptionsView.ShowIndicator = false;
            this.gridView2.OptionsView.ShowIndicator = false;
 
            foreach (var page in this.tabPane1.Pages)
            {
                if (page.Controls[0] is ISetSchemeParterList ctrl)
                {
                    ctrl.ShowFindPanel = false;
                    ctrl.HydroClickEvent += async (parter) =>
                    {
                        _selected_parter = parter;
                        await _bimfaceCtrl?.ZoomAndSelectComponent(_selected_parter.Code);
                    };
                    ctrl.HydroRecordChangedEvent += (record) =>
                    {
                        _set_record_list.Add(record);
                        this.setSchemeParterRecordBindingSource.ResetBindings(false);
                    };
                    ctrl.HydroChangedEvent += (parterList) =>
                    {
 
                    };
                }
            }
 
        }
 
 
        private HStation.Vmo.XhsProjectVmo _project = null;//项目
        private HStation.Vmo.XhsProjectSiteVmo _project_site = null;//项目站
        private Yw.Model.HydroModelInfo _hydro_info = null;//水力信息
        private Yw.Model.HydroModelInfo _hydro_info_init = null;//初始 水力信息
 
        private Yw.Model.HydroParterInfo _selected_parter = null; //选择构件
        private List<SetSchemeParterRecord> _set_record_list = null;
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async Task SetBindingData
            (
                HStation.Vmo.XhsProjectVmo project,
                HStation.Vmo.XhsProjectSiteVmo project_site,
                Yw.Model.HydroModelInfo hydro_info
            )
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            _project_site = project_site;
            _hydro_info_init = hydro_info;
            _set_record_list = new List<SetSchemeParterRecord>();
            if (_project_site == null)
            {
                _project_site = await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetDefaultByProjectID(_project.ID);
            }
 
            if (_hydro_info_init == null)
            {
                var hydroRelation = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance
                    .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _project_site.ID, HStation.Xhs.Purpose.Simulation);
                _hydro_info_init = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroRelation.ModelID);
            }
 
            this.setSchemeParterRecordBindingSource.DataSource = _set_record_list;
            this.setSchemeParterRecordBindingSource.ResetBindings(false);
            SetBindingData();
            ShowBimfaceCtrl();
            FastShowHidden(false);
 
            InitialSchemeType();
            await InitialFlags();
        }
 
        //初始化文件格式
        private void InitialSchemeType()
        {
            this.imgCmbSchemeType.Properties.BeginUpdate();
            this.imgCmbSchemeType.Properties.Items.Clear();
            this.imgCmbSchemeType.Properties.Items.AddEnum(typeof(HStation.Xhs.eSchemeType), false);
            this.imgCmbSchemeType.EditValue = eSchemeType.Common;
            this.imgCmbSchemeType.Properties.EndUpdate();
        }
 
        //初始化标签
        private async Task InitialFlags()
        {
            var allFlagList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Xhs.DataType.XhsScheme);
            var allFlagNameList = allFlagList?.Select(x => x.Name).ToList();
            this.setFlagsEditCtrl1.SetBindingData(allFlagNameList, null);
        }
        private void SetBindingData(List<SetSchemeParterRecord> set_record_list = null)
        {
            _hydro_info = _hydro_info_init.Adapt<Yw.Model.HydroModelInfo, Yw.Model.HydroModelInfo>();
            if (set_record_list != null && set_record_list.Any())
            {
                foreach (var item in set_record_list)
                {
                    switch (item.Catalog)
                    {
                        case Yw.Hydro.ParterCatalog.Pump:
                            {
                                var vm = item.MatchingModel as PumpMatchingViewModel;
                                var bol = AssetsMatchingParasHelper.Apply(_hydro_info, vm);
                            }
                            break;
 
                        case Yw.Hydro.ParterCatalog.Valve:
                            {
                                var vm = item.MatchingModel as ValveMatchingViewModel;
                                var bol = AssetsMatchingParasHelper.Apply(_hydro_info, vm);
                            }
                            break;
                        case Yw.Hydro.ParterCatalog.Pipe:
                            {
                                var vm = item.MatchingModel as PipeMatchingViewModel;
                                var bol = AssetsMatchingParasHelper.Apply(_hydro_info, vm);
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
 
            this.setSchemePumpListCtrl1.SetBindingData(_hydro_info);
            this.setSchemeValveListCtrl1.SetBindingData(_hydro_info);
            this.setSchemePipeListCtrl1.SetBindingData(_hydro_info);
 
        }
 
        //按钮
        private void buttonEdit_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            if (e.Button.Tag is not string tag)
            {
                return;
            }
 
            switch (tag)
            {
                case "showhide":
                    {
                        _show_hidden = !_show_hidden;
                        FastShowHidden(_show_hidden);
                    }
                    break;
                default:
                    break;
            }
        }
 
        #region Bimface
 
        //bimface控件
        private XhsProjectSimulationBimfaceCtrl _bimfaceCtrl = null;
 
        //获取 bimface 控件
        private async Task<XhsProjectSimulationBimfaceCtrl> GetBimfaceCtrl()
        {
            if (_bimfaceCtrl == null)
            {
                _bimfaceCtrl = new XhsProjectSimulationBimfaceCtrl();
                _bimfaceCtrl.Dock = DockStyle.Fill;
                await _bimfaceCtrl.InitialData(_project, _project_site, () => _hydro_info);
                _bimfaceCtrl.LoadCompletedEvent += () =>
                {
                    //view加载完成事件
                    if (_hydro_info == null)
                    {
                        return;
                    }
                };
                _bimfaceCtrl.HydroMouseLeftClickEvent += (obj) =>
                {//鼠标左键点击事件
                    if (_hydro_info == null)
                    {
                        return;
                    }
                };
            }
            return _bimfaceCtrl;
        }
 
        //显示 bimface 控件
        private async void ShowBimfaceCtrl()
        {
            var bimfaceCtrl = await GetBimfaceCtrl();
            this.sidePanel3dModel.Controls.Clear();
            this.sidePanel3dModel.Controls.Add(bimfaceCtrl);
        }
 
        private void SelectBimfaceParter()
        {
 
        }
 
        #endregion
 
        #region FastShowHidden
 
        private bool _show_hidden = false;
        private async void FastShowHidden(bool visible)
        {
            var code_list = _hydro_info.Decorators.Select(x => x.Code).ToList();
            if (code_list == null)
            {
                return;
            }
            if (visible)
            {
                await _bimfaceCtrl?.ShowComponents(code_list);
            }
            else
            {
                await _bimfaceCtrl?.HideComponents(code_list);
            }
        }
 
 
        #endregion
 
        #region GridView
 
        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var row = this.gridView1.GetRow(e.FocusedRowHandle) as SetSchemeParterRecord;
            this.setSchemeParterRecordItemBindingSource.DataSource = row?.Items;
            this.setSchemeParterRecordItemBindingSource.ResetBindings(false);
        }
 
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Column == this.colDelete)
            {
                var row = this.gridView1.GetRow(e.RowHandle) as SetSchemeParterRecord;
                _set_record_list.Remove(row);
                this.setSchemeParterRecordBindingSource.ResetBindings(false);
                SetBindingData(_set_record_list);
 
            }
        }
 
 
        #endregion
 
 
        private bool Verify()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtNo.Text))
            {
                this.dxErrorProvider1.SetError(this.txtNo, "必填项");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtName.Text))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项");
                return false;
            }
 
            return true;
        }
 
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (_hydro_info == null)
            {
                return;
            }
            if (!Verify())
            {
                return;
            }
            var bll_hydro_model = new Yw.BLL.HydroModel();
            var bll_xhs_scheme = new BLL.XhsScheme();
            var hydro_model_id = await bll_hydro_model.Copy(_hydro_info.ID);
            if (hydro_model_id > 0)
            {
                var xhs_scheme = new Vmo.XhsSchemeVmo();
                xhs_scheme.SiteID = _project_site.ID;
                xhs_scheme.NO = this.txtNo.Text.Trim();
                xhs_scheme.Name = this.txtName.Text.Trim();
                xhs_scheme.SchemeType = eSchemeType.Common;
                xhs_scheme.Paras = null;
                xhs_scheme.Flags = null;
                xhs_scheme.UseStatus = Yw.Model.eUseStatus.Enable;
 
                var xhs_scheme_id = await bll_xhs_scheme.Insert(xhs_scheme);
                if (xhs_scheme_id < 0)
                {
                    await bll_hydro_model.DeleteByID(hydro_model_id);
                    XtraMessageBox.Show("方案创建失败!");
                    return;
                }
 
 
                var hydro_relation = new Yw.Vmo.HydroModelRelationVmo();
                hydro_relation.ObjectType = HStation.Xhs.DataType.XhsScheme;
                hydro_relation.ObjectID = xhs_scheme_id;
                hydro_relation.ModelID = hydro_model_id;
                hydro_relation.Purpose = HStation.Xhs.Purpose.Simulation;
                hydro_relation.Content = null;
                hydro_relation.Description = this.memoDescription.Text.Trim();
 
                var hydro_relation_id = await BLLFactory<Yw.BLL.HydroModelRelation>.Instance.Insert(hydro_relation);
                if (hydro_relation_id < 1)
                {
                    await bll_hydro_model.DeleteByID(hydro_model_id);
                    await bll_xhs_scheme.DeleteByID(xhs_scheme_id);
                    XtraMessageBox.Show("模型依赖创建失败!");
                    return;
                }
            }
 
            TipFormHelper.Show(eTipStatus.Succeed, "创建成功!");
            this.Close();
 
        }
 
 
    }
}