Shuxia Ning
2024-11-13 208ca42e1c20afafbe48d66259d553ee81eb48ed
WinFrmUI/HStation.WinFrmUI.Xhs.Core/01-home/01-project/HomeXhsProjectTreeListCtrl.cs
@@ -1,4 +1,7 @@
using DevExpress.Utils;
using HStation.Vmo;
using NetTaste;
using Yw.WinFrmUI.Page;
namespace HStation.WinFrmUI
{
@@ -9,30 +12,76 @@
            InitializeComponent();
            this.treeList1.InitialDefaultSettings();
            this.layoutControl1.SetupLayoutControl();
            this.treeList1.SelectImageList = imageCollection1;
        }
        /// <summary>
        /// 选择项目事件
        /// </summary>
        public event Action<XhsProjectStdDto> SelectProjectEvent;
        private List<HomeXhsProjectTreeViewModel> _allBindingList = null;//当前绑定列表
        public event Action<XhsProjectVmo> SelectProjectEvent;
        /// <summary>
        /// 刷新数据事件
        /// </summary>
        public event Action RefreshDataEvent;
        public event Action<long> JumpDirectEvent;
        /// <summary>
        /// 项目导入完成事件
        /// </summary>
        public event Action<ImportXhsProjectViewModel> ImportProjectCompletedEvent;
        private List<HomeXhsProjectTreeViewModel> _allBindingList = new List<HomeXhsProjectTreeViewModel>();//当前绑定列表
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(List<XhsProjectStdDto> allProjectList)
        public async void SetBindingData(List<XhsProjectVmo> allProjectList)
        {
            _allBindingList = new List<HomeXhsProjectTreeViewModel>();
            foreach (var item in allProjectList)
            if (allProjectList != null)
            {
                var vm = new HomeXhsProjectTreeViewModel(item);
                _allBindingList.Add(vm);
                foreach (var item in allProjectList)
                {
                    if (await IsHaveBimFace(item.ID))
                    {
                        var vm = new HomeXhsProjectTreeViewModel(item, true);
                        _allBindingList.Add(vm);
                    }
                    else
                    {
                        var vm = new HomeXhsProjectTreeViewModel(item, false);
                        _allBindingList.Add(vm);
                    }
                }
            }
            this.treeList1.DataSource = _allBindingList;
            this.treeList1.ForceInitialize();
            this.treeList1.ExpandAll();
        }
        //查找项目是否存在模型
        private async Task<bool> IsHaveBimFace(long ProjectID)
        {
            var projectSite = await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetDefaultByProjectID(ProjectID);
            if (projectSite == null)
            {
                return false;
            }
            var relation = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance
               .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, projectSite.ID, Yw.Bimface.Purpose.Simulation);
            if (relation == null)
            {
                return false;
            }
            var bimfaceFile = await BLLFactory<Yw.BLL.BimfaceFile>.Instance.GetByID(relation.BimfaceFileID);
            if (bimfaceFile == null)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 设置默认
@@ -89,17 +138,6 @@
            this.treeList1.OptionsView.ShowTreeLines = this.barCkTreeLine.Checked ? DefaultBoolean.True : DefaultBoolean.False;
        }
        //鼠标点击
        private void treeList1_RowCellClick(object sender, DevExpress.XtraTreeList.RowCellClickEventArgs e)
        {
            //暂时不用
            //if (e.Button == MouseButtons.Left)
            //{
            //    var vm = this.treeList1.GetDataRecordByNode(e.Node) as HomeXhsProjectTreeViewModel;
            //    this.SelectProjectEvent?.Invoke(vm.Project);
            //}
        }
        //聚焦节点改变
        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
@@ -114,8 +152,25 @@
            dlg.SetBindingData();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.ImportProjectCompletedEvent?.Invoke(dlg.ViewModel);
            }
        }
        //刷新
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.RefreshDataEvent?.Invoke();
        }
        //双击事件
        private void treeList1_DoubleClick(object sender, EventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                return;
            }
            JumpDirectEvent.Invoke(vm.Project.ID);
        }
    }
}
}