lixiaojun
2024-11-06 278e94cb1b045288d1205f36b67f60cb5224754c
WinFrmUI/Yw.WinFrmUI.Hydro.Core/05-property/HydroParterPropertyCtrl.cs
@@ -15,6 +15,8 @@
        {
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.barBtnChangeLink.Visibility = BarItemVisibility.Never;
            this.barBtnView.Visibility = BarItemVisibility.Never;
            SetDescriptionVisible(false);//默认设置属性描述面板不显示
        }
@@ -39,13 +41,9 @@
        /// </summary>
        public event Func<HydroParterViewModel, string, bool> SetPatternEvent;
        /// <summary>
        /// 属性值正在改变事件
        /// </summary>
        public event Func<HydroParterViewModel, bool> PropertyValueChangingEvent;
        /// <summary>
        /// 属性值发生改变事件
        /// </summary>
        public event Func<HydroParterViewModel, bool> PropertyValueChangedEvent;
        public event Action<HydroParterViewModel> PropertyValueChangedEvent;
        /// <summary>
        /// 强调连接组件事件
        /// 第一个参数为本身Code
@@ -53,17 +51,15 @@
        /// </summary>
        public event Action<string, string> BlinkLinkParterEvent;
        //获取水力信息方法
        private Func<Yw.Model.HydroModelInfo> _hydroInfoFunc = null;
        /// <summary>
        /// 初始化数据
        /// 查看构件事件
        /// </summary>
        public void InitialData(Func<Yw.Model.HydroModelInfo> hydroInfoFunc)
        {
            _hydroInfoFunc = hydroInfoFunc;
        }
        public event Action<HydroParterViewModel> ViewParterEvent;
        /// <summary>
        /// 绑定对象
@@ -72,13 +68,18 @@
        {
            get
            {
                return this.propertyGridControl1.SelectedObject as HydroParterViewModel;
                var vm = this.propertyGridControl1.SelectedObject as HydroParterViewModel;
                return vm;
            }
            set
            {
                this.barBtnChangeLink.Visibility = value is HydroLinkViewModel ? BarItemVisibility.Always : BarItemVisibility.Never;
                this.barBtnView.Visibility = value == null ? BarItemVisibility.Never : BarItemVisibility.Always;
                this.propertyGridControl1.SelectedObject = value;
            }
        }
        /// <summary>
        /// 重新从数据源中读取数据,外观恢复刚开始加载的样子
@@ -99,6 +100,10 @@
        //获取行的视图对象
        private HydroParterViewModel GetPropertyViewModel(DevExpress.XtraVerticalGrid.Rows.BaseRow row)
        {
            if (row == null)
            {
                return default;
            }
            if (row.Level <= 1)
            {
                return this.SelectedObject;
@@ -124,25 +129,7 @@
        //自定义属性Header缩进
        private void propertyGridControl1_CustomDrawRowHeaderIndent(object sender, CustomDrawRowHeaderIndentEventArgs e)
        {
            //字段名称
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            if (string.IsNullOrEmpty(fieldName))
            {
                return;
            }
            //属性描述器
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            if (descriptor != null)
            {
                var displayAttri = (DisplayAttribute)descriptor.Attributes[typeof(DisplayAttribute)];
                if (displayAttri != null && !string.IsNullOrEmpty(displayAttri.Name))
                {
                    //e.Appearance.BackColor = Color.Red;
                }
            }
        }
        //自定义属性Header显示
@@ -164,104 +151,42 @@
                if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName))
                {
                    e.Caption = displayNameAttri.DisplayName;
                    // e.Appearance.BackColor = Color.White;
                    //e.Appearance.ForeColor = Color.Red;
                    // e.Properties.Row.AppearanceHeader.BackColor = Color.White;
                    //e.Properties.Row.AppearanceHeader.ForeColor = Color.Red;
                    //e.Handled = true;
                }
                var displayAttri = (DisplayAttribute)descriptor.Attributes[typeof(DisplayAttribute)];
                if (displayAttri != null && !string.IsNullOrEmpty(displayAttri.Name))
                {
                    //e.Appearance.BackColor = Color.Blue;
                    //e.Appearance.ForeColor = Color.Red;
                    e.Info.Appearance.ForeColor = Color.Red;
                    //e.Info.Appearance.BackColor = Color.Blue;
                    // e.Info.AllowGlyphSkinning = true;
                    // e.Info.AllowColoring = true;
                    // e.Info.AllowSingleRowHeader = true;
                    //e.Info.BackAppearance.ForeColor = Color.Red;
                    //e.Info.BackAppearance.BackColor = Color.Blue;
                    //e.Info.ImageIndex = 0;
                    // e.Info.Appearance.BorderColor = Color.Yellow;
                    // e.Appearance.BackColor = Color.Yellow;
                    //e.Row.Properties.ImageOptions.ImageIndex = 0;
                    //e.Row.Properties.ImageOptions.ImageIndex = 1;
                    e.Row.Properties.ToolTip = "测试用的";
                    //this.propertyGridControl1.OptionsView.LevelIndent = 10;
                }
            }
            if (e.Row.IsFocused)
            //颜色
            var vm = GetPropertyViewModel(e.Row);
            if (vm != null)
            {
                //e.Info.Appearance.BackColor = Color.FromArgb(0, 122, 204);
                var propStatus = vm.GetPropStatus(fieldName);
                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.BackColor = Color.Blue;
            //e.Appearance.ForeColor = Color.Red;
            //e.AllowGlyphSkinning = true;
            // e.Row.AppearanceHeader.ForeColor = Color.Red;
            //e.Row.AppearanceHeader.BackColor = Color.Blue;
            // e.Row.AppearanceCell.BackColor = Color.Green;
            // e.Row.AppearanceCell.ForeColor = Color.Yellow;
            //行字段名称
            //var rowFieldName = this.propertyGridControl1.FocusedRow.Properties.FieldName.Split(new char[] { '.' }).Last();
            //if (string.IsNullOrEmpty(rowFieldName))
            //{
            //    e.Handled = false;
            //    return;
            //}
            //if (e.Row is not DevExpress.XtraVerticalGrid.Rows.BaseRow)
            //{
            //    e.Handled = false;
            //    return;
            //}
            //var vm = GetPropertyViewModel(e.Row);
            //var propStatus = vm.GetPropStatus(rowFieldName);
            //if (propStatus == null)
            //{
            //    e.Handled = false;
            //    return;
            //}
            //switch (propStatus.PropStatus)
            //{
            //    case Yw.Hydro.ePropStatus.Error:
            //        {
            //            e.Row.AppearanceHeader.ForeColor = Color.White;
            //            e.Row.AppearanceHeader.BackColor = Color.Red;
            //        }
            //        break;
            //    case Yw.Hydro.ePropStatus.Normal:
            //        {
            //            e.Row.AppearanceHeader.ForeColor = Color.Black;
            //            e.Row.AppearanceHeader.BackColor = Color.White;
            //        }
            //        break;
            //    case Yw.Hydro.ePropStatus.Lack:
            //        {
            //            e.Row.AppearanceHeader.ForeColor = Color.White;
            //            e.Row.AppearanceHeader.BackColor = Color.Green;
            //        }
            //        break;
            //    case Yw.Hydro.ePropStatus.Abnormal:
            //        {
            //            e.Row.AppearanceHeader.ForeColor = Color.White;
            //            e.Row.AppearanceHeader.BackColor = Color.Orange;
            //        }
            //        break;
            //    default: break;
            //}
            //e.Handled = true;
        }
        //自定义属性值显示
@@ -298,7 +223,6 @@
            }
        }
        //属性编辑框的显示与取消
        private void propertyGridControl1_ShowingEditor(object sender, CancelEventArgs e)
        {
@@ -323,63 +247,21 @@
            }
        }
        //行标题,描述,编辑框
        //编辑框
        private void propertyGridControl1_CustomRecordCellEdit(object sender, GetCustomRowCellEditEventArgs e)
        {
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            if (string.IsNullOrEmpty(fieldName))
            {
                return;
            }
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            var rowTypeFullName = e.Row.Properties.RowType.FullName;
            var vm = GetPropertyViewModel(e.Row);
            #region 属性显示名称和描述
            //名称
            var displayNameAttri = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
            if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName))
            if (vm == null)
            {
                e.Row.Properties.Caption = displayNameAttri.DisplayName;
                return;
            }
            var propStatus = vm.GetPropStatus(fieldName);
            if (propStatus != null)
            {
                var sb = new StringBuilder();
                sb.AppendLine($"状态:{propStatus.PropStatus.GetDisplayText()}");
                sb.AppendLine($"信息:{propStatus.StatusInfo}");
                e.Row.Properties.ToolTip = sb.ToString();
            }
            //备注
            //if (e.Row.Properties.Value == null)
            //{
            //    e.Row.Properties.ToolTip = string.Empty;
            //}
            //else
            //{
            //    if (e.Row.Properties.RowType.IsEnum)
            //    {
            //        e.Row.Properties.ToolTip = ((Enum)(e.Row.Properties.Value)).GetDisplayText();
            //    }
            //    else if (e.Row.Properties.RowType.FullName == typeof(DateTime).FullName)
            //    {
            //        e.Row.Properties.ToolTip = ((DateTime)e.Row.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss");
            //    }
            //    else if (e.Row.Properties.RowType.FullName == typeof(Image).FullName)
            //    {
            //        e.Row.Properties.ToolTip = string.Empty;
            //    }
            //    else
            //    {
            //        e.Row.Properties.ToolTip = e.Row.Properties.Value.ToString();
            //    }
            //}
            #endregion
            #region bool
@@ -437,11 +319,6 @@
                    {
                        return;
                    }
                    var hydroInfo = _hydroInfoFunc?.Invoke();
                    if (hydroInfo == null)
                    {
                        return;
                    }
                    var vm = GetPropertyViewModel(e.Row);
                    if (vm == null)
                    {
@@ -467,12 +344,11 @@
                buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
                buttonEdit.ButtonClick += delegate
                {
                    var hydroInfo = _hydroInfoFunc?.Invoke();
                    if (hydroInfo == null)
                    var vm = GetPropertyViewModel(e.Row);
                    if (vm == null)
                    {
                        return;
                    }
                    var vm = GetPropertyViewModel(e.Row);
                    switch (curvePropAttri.CurveType)
                    {
                        case HydroCurve.Tank:
@@ -504,23 +380,23 @@
                                if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, HydroCurve.PumpQH))
                                {
                                    var pumpViewModel = vm as HydroPumpViewModel;
                                    var curveQh = hydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQH);
                                    var curveQh = vm.HydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQH);
                                    var dlg = new SetHydroCurveDlg();
                                    dlg.ReloadDataEvent += (curveInfo) =>
                                    {
                                        if (hydroInfo.Curves == null)
                                        if (vm.HydroInfo.Curves == null)
                                        {
                                            hydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                            vm.HydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                        }
                                        if (curveQh != null)
                                        {
                                            hydroInfo.Curves.Remove(curveQh);
                                            vm.HydroInfo.Curves.Remove(curveQh);
                                        }
                                        hydroInfo.Curves.Add(curveInfo);
                                        vm.HydroInfo.Curves.Add(curveInfo);
                                        pumpViewModel.CurveQH = curveInfo.Code;
                                        UpdateRows();
                                    };
                                    dlg.SetBindingData(hydroInfo, curveQh, curvePropAttri.CurveType);
                                    dlg.SetBindingData(vm.HydroInfo, curveQh, curvePropAttri.CurveType);
                                    dlg.ShowDialog();
                                }
                            }
@@ -530,23 +406,23 @@
                                if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePropAttri.CurveType))
                                {
                                    var pumpViewModel = vm as HydroPumpViewModel;
                                    var curveQp = hydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQP);
                                    var curveQp = vm.HydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQP);
                                    var dlg = new SetHydroCurveDlg();
                                    dlg.ReloadDataEvent += (curveInfo) =>
                                    {
                                        if (hydroInfo.Curves == null)
                                        if (vm.HydroInfo.Curves == null)
                                        {
                                            hydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                            vm.HydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                        }
                                        if (curveQp != null)
                                        {
                                            hydroInfo.Curves.Remove(curveQp);
                                            vm.HydroInfo.Curves.Remove(curveQp);
                                        }
                                        hydroInfo.Curves.Add(curveInfo);
                                        vm.HydroInfo.Curves.Add(curveInfo);
                                        pumpViewModel.CurveQP = curveInfo.Code;
                                        UpdateRows();
                                    };
                                    dlg.SetBindingData(hydroInfo, curveQp, curvePropAttri.CurveType);
                                    dlg.SetBindingData(vm.HydroInfo, curveQp, curvePropAttri.CurveType);
                                    dlg.ShowDialog();
                                }
                            }
@@ -554,23 +430,23 @@
                        case HydroCurve.PumpQE:
                            {
                                var pumpViewModel = vm as HydroPumpViewModel;
                                var curveQe = hydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQE);
                                var curveQe = vm.HydroInfo.Curves?.Find(x => x.Code == pumpViewModel.CurveQE);
                                var dlg = new SetHydroCurveDlg();
                                dlg.ReloadDataEvent += (curveInfo) =>
                                {
                                    if (hydroInfo.Curves == null)
                                    if (vm.HydroInfo.Curves == null)
                                    {
                                        hydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                        vm.HydroInfo.Curves = new List<Model.HydroCurveInfo>();
                                    }
                                    if (curveQe != null)
                                    {
                                        hydroInfo.Curves.Remove(curveQe);
                                        vm.HydroInfo.Curves.Remove(curveQe);
                                    }
                                    hydroInfo.Curves.Add(curveInfo);
                                    vm.HydroInfo.Curves.Add(curveInfo);
                                    pumpViewModel.CurveQE = curveInfo.Code;
                                    UpdateRows();
                                };
                                dlg.SetBindingData(hydroInfo, curveQe, curvePropAttri.CurveType);
                                dlg.SetBindingData(vm.HydroInfo, curveQe, curvePropAttri.CurveType);
                                dlg.ShowDialog();
                            }
                            break;
@@ -607,11 +483,6 @@
                buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
                buttonEdit.ButtonClick += delegate
                {
                    var hydroInfo = _hydroInfoFunc?.Invoke();
                    if (hydroInfo == null)
                    {
                        return;
                    }
                    var vm = GetPropertyViewModel(e.Row);
                    switch (patternProAttri.PatternType)
                    {
@@ -675,11 +546,6 @@
                    buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor;
                    buttonEdit.ButtonClick += delegate
                    {
                        var hydroInfo = _hydroInfoFunc?.Invoke();
                        if (hydroInfo == null)
                        {
                            return;
                        }
                        var vm = GetPropertyViewModel(e.Row);
                        this.BlinkLinkParterEvent?.Invoke(vm.Code, e.Row.Properties.Value.ToString());
                    };
@@ -692,45 +558,35 @@
        }
        //属性值正在改变
        void propertyGridControl1_CellValueChanging(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            var propertyViewModel = GetPropertyViewModel(e.Row);
            this.PropertyValueChangingEvent?.Invoke(propertyViewModel);
        }
        //属性值改变
        void propertyGridControl1_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        private void propertyGridControl1_CellValueChanged(object sender, DevExpress.XtraVerticalGrid.Events.CellValueChangedEventArgs e)
        {
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            var propertyViewModel = GetPropertyViewModel(e.Row);
            this.PropertyValueChangedEvent?.Invoke(propertyViewModel);
            if (this.PropertyValueChangedEvent == null || !this.PropertyValueChangedEvent.Invoke(propertyViewModel))
            if (string.IsNullOrEmpty(fieldName))
            {
                var hydroInfo = _hydroInfoFunc?.Invoke();
                if (hydroInfo == null)
                {
                    return;
                }
                var allParterList = hydroInfo.GetAllParters();
                var parter = allParterList?.Find(x => x.ID == propertyViewModel.ID);
                if (parter == null)
                {
                    return;
                }
                parter.UpdateProperty(allParterList, propertyViewModel);
                return;
            }
            UpdateRows();
            var vm = GetPropertyViewModel(e.Row);
            if (vm == null)
            {
                return;
            }
            vm.UpdateVmoProperty();
            this.PropertyValueChangedEvent?.Invoke(vm);
        }
        // 描述
        private void barBtnHelp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        //改变连接节点
        private void barBtnChangeLink_ItemClick(object sender, ItemClickEventArgs e)
        {
            var visible = this.splitterItem1.Visibility == LayoutVisibility.Always ? false : true;
            SetDescriptionVisible(visible);
            var link = this.SelectedObject as HydroLinkViewModel;
            if (link != null)
            {
                var tempCode = link.StartCode;
                link.StartCode = link.EndCode;
                link.EndCode = tempCode;
                link.UpdateVmoProperty();
                this.propertyGridControl1.UpdateRows();
            }
        }
        //全部展开
@@ -745,11 +601,69 @@
            this.propertyGridControl1.CollapseAllRows();
        }
        //查看
        private void barBtnView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var vm = this.SelectedObject;
            if (vm == null)
            {
                return;
            }
            this.ViewParterEvent?.Invoke(vm);
        }
        // 描述
        private void barBtnHelp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var visible = this.splitterItem1.Visibility == LayoutVisibility.Always ? false : true;
            SetDescriptionVisible(visible);
        }
        //聚焦行改变
        private void propertyGridControl1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e)
        {
            //e.Row.AppearanceHeader.BackColor = Color.FromArgb(0, 122, 204);
            // e.Row.AppearanceHeader.ForeColor = Color.White;
            if (e.Row == null)
            {
                return;
            }
            //字段名称
            var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last();
            if (string.IsNullOrEmpty(fieldName))
            {
                return;
            }
            var vm = GetPropertyViewModel(e.Row);
            if (vm == null)
            {
                return;
            }
            string caption = string.Empty;
            string descrition = string.Empty;
            //属性描述器
            var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row);
            if (descriptor != null)
            {
                //名称
                var displayNameAttri = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
                if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName))
                {
                    caption = displayNameAttri.DisplayName;
                }
                //描述
                var descritionAttri = (DescriptionAttribute)descriptor.Attributes[typeof(DescriptionAttribute)];
                if (descritionAttri != null)
                {
                    descrition = descritionAttri.Description;
                }
            }
            var propStatus = vm.GetPropStatus(fieldName);
            this.hydroParterPropertyDescriptionCtrl1.SetBindingData(caption, descrition, propStatus);
        }