lixiaojun
2024-08-15 24f31cf1f11318a0e76d31d382313d30c0ad9e1d
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
using Mapster;
 
namespace Yw.WinFrmUI
{
    public partial class BimfaceFileMgrPage : DocumentPage
    {
        public BimfaceFileMgrPage()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView1.RegistCustomDrawRowIndicator();
 
            this.PageTitle.Caption = "模型文件管理";
            this.PageTitle.HeaderSvgImage = this.svgImage32[1];
            this.PageTitle.SvgImageSize = new Size(24, 24);
        }
 
 
        private List<BimfaceFileMgrViewModel> _allBindingList = null;
        private Lazy<Yw.BLL.BimfaceFile> _bllBimfaceFile = new(() => new Yw.BLL.BimfaceFile());
        private Lazy<Yw.BLL.BimfaceFileRelation> _bllBimfaceFileRelation = new(() => new BLL.BimfaceFileRelation());
 
 
        //加载数据
        private async Task LoadData()
        {
            var allBimfaceFileList = await _bllBimfaceFile.Value.GetAll();
            var allBimfaceFileRelationList = await _bllBimfaceFileRelation.Value.GetAll();
            _allBindingList = new List<BimfaceFileMgrViewModel>();
            if (allBimfaceFileList != null && allBimfaceFileList.Count > 0)
            {
                foreach (var bimfaceFile in allBimfaceFileList)
                {
                    var hasReason = allBimfaceFileRelationList == null ? false : allBimfaceFileRelationList.Exists(x => x.BimfaceFileID == bimfaceFile.ID);
                    var vm = new BimfaceFileMgrViewModel(bimfaceFile, hasReason);
                    _allBindingList.Add(vm);
                }
            }
            this.bimfaceFileMgrViewModelBindingSource.DataSource = _allBindingList;
            this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
        }
 
 
        /// <summary>
        ///初始化数据
        /// </summary>
        public override async void InitialDataSource()
        {
            base.InitialDataSource();
            await LoadData();
        }
 
        /// <summary>
        /// 刷新数据
        /// </summary>
        public override async void RefreshData()
        {
            base.RefreshData();
 
            if (_allBindingList == null)
            {
                return;
            }
            if (_allBindingList.Exists(x => x.FileStatus == eFileStatus.Uploading || x.FileStatus == eFileStatus.Converting))
            {
                return;
            }
 
            await LoadData();
        }
 
        /// <summary>
        /// 注册事件
        /// </summary>
        public override void RegistEvents()
        {
            base.RegistEvents();
            //PageDataSync<Model.BimFile4Get>.DataOperationEvent += SyncBimFileData;
            //PageDataSync<Model.BimFileMapper4Get>.DataOperationEvent += SyncBimFileMapperData;
        }
 
        /// <summary>
        /// 取消注册事件
        /// </summary>
        public override void UnRegistEvents()
        {
            base.UnRegistEvents();
            //PageDataSync<Model.BimFile4Get>.DataOperationEvent -= SyncBimFileData;
            // PageDataSync<Model.BimFileMapper4Get>.DataOperationEvent -= SyncBimFileMapperData;
        }
 
        //添加
        private void Add()
        {
            if (_allBindingList == null)
            {
                return;
            }
            var dlg = new AddBimfaceFileDlg();
            dlg.SetBindingData();
            dlg.ReloadDataEvent += async (bimfaceFileId) =>
            {
                var bimfaceFile = await _bllBimfaceFile.Value.GetByID(bimfaceFileId);
                var hasReason = await _bllBimfaceFileRelation.Value.IsExistByBimfaceFileID(bimfaceFileId);
                var vm = new BimfaceFileMgrViewModel(bimfaceFile, hasReason);
                _allBindingList.Add(vm);
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
                XtraMessageBox.Show("添加成功!");
            };
            dlg.ShowDialog();
        }
 
        //上传
        private void Upload()
        {
            if (_allBindingList == null)
            {
                return;
            }
            var dlg = new UploadBimfaceFileDlg();
            dlg.SetBindingData();
            dlg.ReloadDataEvent += async (rhs) =>
            {
                var vm = new BimfaceFileMgrViewModel();
                vm.BimfaceId = string.Empty;
                vm.Name = rhs.FileName;
                vm.ModelType = eModelType.File;
                vm.FileStatus = eFileStatus.Uploading;
                vm.FormatType = rhs.FormatType;
                var fileInfo = new System.IO.FileInfo(rhs.FilePath);
                vm.FileSuffix = fileInfo.Extension;
                vm.FileSize = string.Format("{0}MB", System.Math.Ceiling(fileInfo.Length / 1024.0 / 1024.0));
 
                _allBindingList.Add(vm);
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
                var bimfaceId = await BimfaceHelper.UploadFile(rhs.FilePath, rhs.FileName);
 
                if (bimfaceId < 1)
                {
                    _allBindingList.Remove(vm);
                    this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
                    this.ShowAlertInfo("模型文件上传提示", $"{rhs.FileName} 上传失败!");
                    return;
                }
 
                vm.BimfaceId = bimfaceId.ToString();
                vm.FileStatus = eFileStatus.UploadSucceed;
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
 
                var addModel = vm.Adapt<BimfaceFileMgrViewModel, Yw.Dto.AddBimfaceFileInput>();
                vm.ID = await _bllBimfaceFile.Value.Insert(addModel);
                if (vm.ID < 1)
                {
                    _allBindingList.Remove(vm);
                    this.ShowAlertInfo("模型文件上传提示", $"{rhs.FileName} 保存失败!");
                }
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
            };
            dlg.ShowDialog();
        }
 
        //转换
        private async void Translate()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            if (vm.FileStatus != eFileStatus.UploadSucceed)
            {
                MessageBoxHelper.ShowInfo("此功能仅适用于上传成功状态的模型文件!");
                return;
            }
            if (vm.FormatType != eFormatType.d3)
            {
                MessageBoxHelper.ShowInfo("此功能仅适用于3D模型文件!");
                return;
            }
            if (vm.FileSuffix.ToLower() != ".rvt")
            {
                MessageBoxHelper.ShowInfo("此功能仅适用于rvt模型文件!");
                return;
            }
 
            bool updateFileStatusResult = false;
            var translateStatus = await BimfaceHelper.TranslateRvtFile(vm.BimfaceId);
            if (translateStatus == eTranslateStatus.Processing)
            {
                vm.FileStatus = eFileStatus.Converting;
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
                updateFileStatusResult = await _bllBimfaceFile.Value.UpdateFileStatus(vm.ID, (int)vm.FileStatus);
                if (!updateFileStatusResult)
                {
                    this.ShowAlertInfo("模型文件转换", $"{vm.Name}:更新文件状态失败!");
                }
 
                this.ShowAlertInfo("模型文件转换提示", "模型文件转换耗时较长,请耐心等待...");
 
                await BimfaceHelper.WaitFileTranslateStatusUntilSuccess(vm.BimfaceId, 3000);
            }
 
            vm.FileStatus = eFileStatus.ConvertSucceed;
            this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
            updateFileStatusResult = await _bllBimfaceFile.Value.UpdateFileStatus(vm.ID, (int)vm.FileStatus);
            if (!updateFileStatusResult)
            {
                this.ShowAlertInfo("模型文件转换", $"{vm.Name}:更新文件状态失败!");
            }
 
        }
 
        //编辑
        private void Edit()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            if (vm.FileStatus == eFileStatus.Uploading)
            {
                MessageBoxHelper.ShowWarning("上传中的模型文件不可编辑");
                return;
            }
            if (vm.FileStatus == eFileStatus.Converting)
            {
                MessageBoxHelper.ShowWarning("转换中的模型文件不可编辑");
                return;
            }
 
            var dlg = new EditBimfaceFileDlg();
            dlg.SetBindingData(vm);
            dlg.ReloadDataEvent += async (bimfaceFileId) =>
            {
                var dto = await _bllBimfaceFile.Value.GetByID(bimfaceFileId);
                vm.Reset(dto);
                this.gridView1.RefreshRow(this.gridView1.FocusedRowHandle);
                XtraMessageBox.Show("更新成功!");
            };
            dlg.ShowDialog();
        }
 
        //删除
        private async void Delete()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            if (vm.HasRelation)
            {
                MessageBoxHelper.ShowWarning("存在关联关系,不可删除!");
                return;
            }
            if (vm.FileStatus == eFileStatus.Uploading)
            {
                MessageBoxHelper.ShowWarning("上传中的文件不能删除!");
                return;
            }
            if (vm.FileStatus == eFileStatus.Converting)
            {
                MessageBoxHelper.ShowWarning("转换中的文件不能删除!");
                return;
            }
 
            if (MessageBoxHelper.ShowQuestion("是否确定删除?") == DialogResult.Yes)
            {
                var deleteResult = await BimfaceHelper.Delete(vm.BimfaceId);
                if (!deleteResult)
                {
                    MessageBoxHelper.ShowError("Bimface删除失败!");
                    return;
                }
                deleteResult = await _bllBimfaceFile.Value.DeleteByID(vm.ID);
                if (!deleteResult)
                {
                    MessageBoxHelper.ShowError("Bimface文件删除失败!");
                    return;
                }
                _allBindingList.Remove(vm);
                this.bimfaceFileMgrViewModelBindingSource.ResetBindings(false);
                MessageBoxHelper.ShowSuccess("删除成功!");
            }
        }
 
        //显示详细信息
        private void ShowDetail()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            MessageBoxHelper.ShowInfo("正在开发中...");
        }
 
        //本地浏览
        private async void ShowLocalView()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
 
            var guid = new PageGuid()
            {
                Modular = Yw.WinFrmUI.PageModular.Bimface,
                MoudingType = Yw.WinFrmUI.Page.eMoudingType.Tab,
                Function = Yw.WinFrmUI.PageFunction.ViewBimface3d,
                TagName = vm.ID.ToString()
            };
 
            if (!IsExistPage(guid, true))
            {
                var page = new Bimface3dViewPage();
                await page.SetBindingData(vm.ID);
                CreatePage(page, guid);
            }
        }
 
        //网页浏览
        private void ShowWebView()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            MessageBoxHelper.ShowInfo("正在开发中...");
        }
 
        //手机浏览
        private void ShowPhoneView()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            MessageBoxHelper.ShowInfo("正在开发中...");
        }
 
        //显示模型文件设置界面
        private void ShowBimFileSettings()
        {
            var vm = GetCurrentViewModel();
            if (vm == null)
            {
                return;
            }
            MessageBoxHelper.ShowInfo("正在开发中...");
        }
 
 
        //自定义显示名称
        private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
 
        }
 
        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            //var row = this.gridView1.GetRow(e.FocusedRowHandle) as BimFile4Get;
            //var enable = row == null ? false : true;
            //this.barBtnTranslate.Enabled = enable;
            //this.barBtnEdit.Enabled = enable;
            //this.barBtnDelete.Enabled = enable;
            //this.barBtnDetail.Enabled = enable;
            //this.barBtnLocal.Enabled = enable;
            //this.barBtnWeb.Enabled = enable;
            //this.barBtnPhone.Enabled = enable;
        }
 
        private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            //if (e.Column == this.colSet && e.IsGetData)
            //{
            //    var row = e.Row as BimFile4Get;
            //    if (_allGetMappers != null)
            //    {
            //        var mapping = _allGetMappers.Find(x => x.BimFileID == row.ID);
            //        if (mapping == null)
            //            e.Value = "否";
            //        else
            //            e.Value = "是";
            //    }
            //    else
            //        e.Value = "否";
            //}
        }
 
        private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Column == this.colDetail)
            {
                ShowDetail();
            }
        }
 
 
        #region Ribbon
 
        //添加
        private void barBtnAdminAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Add();
        }
 
        //上传
        private void barBtnUpload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Upload();
        }
 
        //转换
        private void barBtnTranslate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Translate();
        }
 
        //编辑
        private void barBtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Edit();
        }
 
        //删除
        private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Delete();
        }
 
        //详细信息
        private void barBtnDetail_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowDetail();
        }
 
        //本地视图
        private void barBtnLocal_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowLocalView();
        }
 
        //网页视图
        private void barBtnWeb_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowWebView();
        }
 
        //手机视图
        private void barBtnPhone_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowPhoneView();
        }
 
        //模型设置
        private void barBtnSetBim_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowBimFileSettings();
        }
 
        //刷新数据
        private void barBtnReloadData_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_allBindingList == null)
            {
                return;
            }
            if (_allBindingList.Exists(x => x.FileStatus == eFileStatus.Uploading || x.FileStatus == eFileStatus.Converting))
            {
                MessageBoxHelper.ShowWarning("正在上传或转换模型文件,请稍后重试!");
                return;
            }
            RefreshData();
        }
 
 
        #endregion
 
        #region 当前
 
        //获取当前视图
        private BimfaceFileMgrViewModel GetCurrentViewModel()
        {
            if (_allBindingList == null)
            {
                MessageBoxHelper.ShowError("数据初始化失败");
                return null;
            }
            if (_allBindingList.Count < 1)
            {
                MessageBoxHelper.ShowInfo("数据为空");
            }
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行");
            }
            return vm;
        }
 
        #endregion
 
 
 
 
 
    }
}