From 616652a5ae2deb9439ffd3cbb9d972c0a8990bc5 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期一, 09 十二月 2024 08:53:34 +0800 Subject: [PATCH] 修复属性状态 --- WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroVisualPropertyCtrl.cs | 105 ++++++++++++++++++++++++++++------------------------ 1 files changed, 57 insertions(+), 48 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroVisualPropertyCtrl.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroVisualPropertyCtrl.cs index ba185b6..6d3d926 100644 --- a/WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroVisualPropertyCtrl.cs +++ b/WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroVisualPropertyCtrl.cs @@ -59,6 +59,11 @@ /// <summary> + /// 鍏佽淇敼 + /// </summary> + public bool AllowEdit { get; set; } + + /// <summary> /// 缁戝畾瀵硅薄 /// </summary> public HydroVisualViewModel SelectedObject @@ -70,21 +75,28 @@ } set { - this.barBtnChangeLink.Visibility = value is HydroLinkViewModel ? BarItemVisibility.Always : BarItemVisibility.Never; - this.barBtnMatchingDb.Visibility = value == null ? BarItemVisibility.Never : BarItemVisibility.Always; - this.barBtnView.Visibility = value == null ? BarItemVisibility.Never : BarItemVisibility.Always; - if (value != null) - { - if (value is HydroReservoirViewModel) - { - this.barBtnMatchingDb.Visibility = BarItemVisibility.Never; - } - else if (value is HydroJunctionViewModel) - { - this.barBtnMatchingDb.Visibility = BarItemVisibility.Never; - } - } - this.propertyGridControl1.SelectedObject = value; + SetSelectedObject(value); + } + } + + //璁剧疆閫夋嫨瀵硅薄 + private void SetSelectedObject(HydroVisualViewModel vm) + { + if (this.AllowEdit) + { + this.barBtnChangeLink.Visibility = vm is HydroLinkViewModel ? BarItemVisibility.Always : BarItemVisibility.Never; + this.barBtnMatchingDb.Visibility = vm == null ? BarItemVisibility.Never : BarItemVisibility.Always; + } + else + { + this.barBtnMatchingDb.Visibility = BarItemVisibility.Never; + this.barBtnChangeLink.Visibility = BarItemVisibility.Never; + } + this.barBtnView.Visibility = vm == null ? BarItemVisibility.Never : BarItemVisibility.Always; + var selectObj = this.propertyGridControl1.SelectedObject as HydroVisualViewModel; + this.propertyGridControl1.SelectedObject = vm; + if (selectObj == vm) + { this.propertyGridControl1.UpdateRows(); } } @@ -149,10 +161,17 @@ { return; } + var realFieldName = fieldName; //灞炴�ф弿杩板櫒 var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row); if (descriptor != null) { + //鐪熷疄灞炴�у悕绉� + var realPropAttri = (HydroRealProAttribute)descriptor.Attributes[typeof(HydroRealProAttribute)]; + if (realPropAttri != null) + { + realFieldName = realPropAttri.RealPropName; + } //鍚嶇О var displayNameAttri = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)]; if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName)) @@ -171,38 +190,10 @@ var vm = GetPropertyViewModel(e.Row); if (vm != null) { - var propStatus = vm.GetPropStatus(fieldName); + var propStatus = vm.GetPropStatus(realFieldName); if (propStatus != null) { - switch (propStatus.PropStatus) - { - case Yw.Hydro.ePropStatus.Error: - { - e.Appearance.ForeColor = Color.Red; - } - break; - case Yw.Hydro.ePropStatus.Normal: - { - e.Appearance.ForeColor = Color.Black; - } - break; - case Yw.Hydro.ePropStatus.Lack: - { - e.Appearance.ForeColor = Color.Green; - } - break; - case Yw.Hydro.ePropStatus.Abnormal: - { - e.Appearance.ForeColor = Color.Orange; - } - break; - case Yw.Hydro.ePropStatus.Matching: - { - e.Appearance.ForeColor = Color.Purple; - } - break; - default: break; - } + e.Appearance.ForeColor = HydroPropStatusHelper.GetColor(propStatus.PropStatus); } } } @@ -262,10 +253,28 @@ } var descriptor = this.propertyGridControl1.GetPropertyDescriptor(this.propertyGridControl1.FocusedRow); - var showEditor = (ShowEditorAttribute)descriptor.Attributes[typeof(ShowEditorAttribute)]; - if (showEditor != null) + + if (this.AllowEdit) { - if (!showEditor.ShowEditor) + var showEditor = (ShowEditorAttribute)descriptor.Attributes[typeof(ShowEditorAttribute)]; + if (showEditor != null) + { + if (!showEditor.ShowEditor) + { + e.Cancel = true; + return; + } + } + } + else + { + var showEditorInView = (ShowEditorInViewAttribute)descriptor.Attributes[typeof(ShowEditorInViewAttribute)]; + if (showEditorInView == null) + { + e.Cancel = true; + return; + } + if (!showEditorInView.ShowEditor) { e.Cancel = true; return; -- Gitblit v1.9.3