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 _allBindingList = null; private Lazy _bllBimfaceFile = new(() => new Yw.BLL.BimfaceFile()); private Lazy _bllBimfaceFileRelation = new(() => new BLL.BimfaceFileRelation()); //加载数据 private async Task LoadData() { var allBimfaceFileList = await _bllBimfaceFile.Value.GetAll(); var allBimfaceFileRelationList = await _bllBimfaceFileRelation.Value.GetAll(); _allBindingList = new List(); 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); } /// ///初始化数据 /// public override async void InitialDataSource() { base.InitialDataSource(); await LoadData(); } /// /// 刷新数据 /// 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(); } /// /// 注册事件 /// public override void RegistEvents() { base.RegistEvents(); //PageDataSync.DataOperationEvent += SyncBimFileData; //PageDataSync.DataOperationEvent += SyncBimFileMapperData; } /// /// 取消注册事件 /// public override void UnRegistEvents() { base.UnRegistEvents(); //PageDataSync.DataOperationEvent -= SyncBimFileData; // PageDataSync.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(); 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 } }