Shuxia Ning
2024-12-19 ba67a904276b104f2c9f35c3bba0fb4928a6bae0
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,29 @@
            }
            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();
            }
        }
@@ -148,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))
@@ -170,33 +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;
                        default: break;
                    }
                    e.Appearance.ForeColor = HydroPropStatusHelper.GetColor(propStatus.PropStatus);
                }
            }
        }
@@ -256,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;
@@ -381,7 +396,8 @@
                    {
                        vm.Vmo.Flags = flags;
                        vm.Flags = Yw.Untity.FlagsHelper.ToString(flags);
                        UpdateRows();
                        this.propertyGridControl1.UpdateRows();
                        this.propertyGridControl1.RefreshEditor();
                        this.PropertyValueChangedEvent?.Invoke(vm);
                    };
                    dlg.ShowDialog();