| | |
| | | using DevExpress.XtraEditors.Controls; |
| | | using DevExpress.XtraEditors.Repository; |
| | | using DevExpress.XtraLayout.Utils; |
| | | using DevExpress.XtraRichEdit.SpellChecker; |
| | | using DevExpress.XtraVerticalGrid.Events; |
| | | using NetTaste; |
| | | using SQLitePCL; |
| | | using System.Text; |
| | | using System.Windows.Forms.VisualStyles; |
| | | using Yw.EPAnet; |
| | | |
| | | namespace Yw.WinFrmUI |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取水力信息事件 |
| | | /// 匹配db事件 |
| | | /// </summary> |
| | | public event Func<Yw.Model.HydroModelInfo> GetHydroInfoEvent; |
| | | public event Action<Yw.Model.HydroParterInfo> MatchingDbEvent; |
| | | /// <summary> |
| | | /// 选择曲线事件 |
| | | /// 查看曲线事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SelectCurveEvent; |
| | | public event Action<Yw.Model.HydroParterInfo, string> ViewCurveEvent; |
| | | /// <summary> |
| | | /// 选择模式事件 |
| | | /// 设置曲线事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SelectPatternEvent; |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SetCurveEvent; |
| | | /// <summary> |
| | | /// 设置模式事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SetPatternEvent; |
| | | /// <summary> |
| | | /// 属性值正在改变事件 |
| | | /// </summary> |
| | |
| | | /// 属性值发生改变事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, bool> PropertyValueChangedEvent; |
| | | |
| | | /// <summary> |
| | | /// 强调连接组件事件 |
| | | /// 第一个参数为本身Code |
| | | /// 第二个参数为连接Code |
| | | /// </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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 绑定对象 |
| | |
| | | set |
| | | { |
| | | this.propertyGridControl1.SelectedObject = value; |
| | | OnChanged(); |
| | | } |
| | | } |
| | | |
| | |
| | | set |
| | | { |
| | | this.propertyGridControl1.SelectedObjects = value?.ToArray(); |
| | | OnChanged(); |
| | | } |
| | | } |
| | | |
| | | |
| | | //改变触发 |
| | | protected virtual void OnChanged() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //获取行的视图对象 |
| | | private HydroParterPropertyViewModel GetPropertyViewModel(DevExpress.XtraVerticalGrid.Rows.BaseRow row) |
| | | { |
| | | if (row.Level == 1) |
| | | if (row.Level <= 1) |
| | | { |
| | | return this.SelectedObject; |
| | | } |
| | | if (row.ParentRow == null) |
| | | { |
| | | return this.SelectedObject; |
| | | } |
| | |
| | | this.layoutDescription.Visibility = this.splitterItem1.Visibility = visible; |
| | | } |
| | | |
| | | //自定义属性值显示内容 |
| | | //自定义属性Header显示 |
| | | private void propertyGridControl1_CustomDrawRowHeaderCell(object sender, CustomDrawRowHeaderCellEventArgs e) |
| | | { |
| | | //行字段名称 |
| | | //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; |
| | | } |
| | | |
| | | //自定义属性值显示 |
| | | private void propertyGridControl1_CustomDrawRowValueCell(object sender, CustomDrawRowValueCellEventArgs e) |
| | | { |
| | | //行类型全名称 |
| | | var rowTypeFullName = e.Row.Properties.RowType.FullName; |
| | | |
| | | //行字段名称 |
| | | var rowFieldName = this.propertyGridControl1.FocusedRow.Properties.FieldName.Split(new char[] { '.' }).Last(); |
| | | if (rowTypeFullName == typeof(DateTime).FullName) |
| | | { |
| | | e.CellText = ((DateTime)e.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | else |
| | | { |
| | | var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row); |
| | | var displayUnit = (DisplayUnitAttribute)descriptor.Attributes[typeof(DisplayUnitAttribute)]; |
| | | if (displayUnit != null) |
| | | var calcuPropAttri = (IsHydroCalcuProAttribute)descriptor.Attributes[typeof(IsHydroCalcuProAttribute)]; |
| | | if (calcuPropAttri != null && calcuPropAttri.CalcuPro) |
| | | { |
| | | if (e.Properties.Value == null) |
| | | { |
| | | e.CellText = "尚未计算"; |
| | | e.Appearance.ForeColor = Color.OrangeRed; |
| | | } |
| | | } |
| | | var displayUnitAttri = (DisplayUnitAttribute)descriptor.Attributes[typeof(DisplayUnitAttribute)]; |
| | | if (displayUnitAttri != null) |
| | | { |
| | | if (e.Properties.Value != null) |
| | | { |
| | | e.CellText = e.Properties.Value.ToString() + " " + displayUnit.Unit; |
| | | e.CellText = e.Properties.Value.ToString() + " " + displayUnitAttri.Unit; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //自定义属性描述 |
| | | private void propertyGridControl1_CustomPropertyDescriptors(object sender, CustomPropertyDescriptorsEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | //属性编辑框的显示与取消 |
| | |
| | | var fieldName = e.Row.Properties.FieldName.Split(new char[] { '.' }).Last(); |
| | | var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row); |
| | | var rowTypeFullName = e.Row.Properties.RowType.FullName; |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | |
| | | |
| | | #region 属性显示名称和描述 |
| | | |
| | | //名称 |
| | | var attri_caption = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)]; |
| | | if (attri_caption != null && !string.IsNullOrEmpty(attri_caption.DisplayName)) |
| | | //var displayNameAttri = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)]; |
| | | //if (displayNameAttri != null && !string.IsNullOrEmpty(displayNameAttri.DisplayName)) |
| | | //{ |
| | | // e.Row.Properties.Caption = displayNameAttri.DisplayName; |
| | | //} |
| | | |
| | | var propStatus = vm.GetPropStatus(fieldName); |
| | | if (propStatus != null) |
| | | { |
| | | e.Row.Properties.Caption = attri_caption.DisplayName; |
| | | 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(); |
| | | } |
| | | } |
| | | //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 |
| | | |
| | |
| | | buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor; |
| | | buttonEdit.ButtonClick += delegate |
| | | { |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | if (this.SelectCurveEvent == null || !this.SelectCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | var hydroInfo = _hydroInfoFunc?.Invoke(); |
| | | if (hydroInfo == null) |
| | | { |
| | | var hydroInfo = GetHydroInfoEvent?.Invoke(); |
| | | if (hydroInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | switch (curvePro.CurveType) |
| | | { |
| | | case HydroCurve.Pump: |
| | | return; |
| | | } |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | switch (curvePro.CurveType) |
| | | { |
| | | case HydroCurve.Pump: |
| | | { |
| | | var pumpInfo = hydroInfo.Pumps?.Find(x => x.Code == vm.Code); |
| | | if (pumpInfo == null) |
| | | { |
| | | |
| | | return; |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQH: |
| | | this.ViewCurveEvent?.Invoke(pumpInfo, HydroCurve.Pump); |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQH: |
| | | { |
| | | if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | { |
| | | var vmPump = vm as HydroPumpPropertyViewModel; |
| | | var curveQh = hydroInfo.Curves?.Find(x => x.Code == vmPump.CurveQH); |
| | |
| | | dlg.SetBindingData(hydroInfo, curveQh, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQP: |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQP: |
| | | { |
| | | if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | { |
| | | var vmPump = vm as HydroPumpPropertyViewModel; |
| | | var curveQp = hydroInfo.Curves?.Find(x => x.Code == vmPump.CurveQP); |
| | |
| | | dlg.SetBindingData(hydroInfo, curveQp, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQE: |
| | | } |
| | | break; |
| | | case HydroCurve.PumpQE: |
| | | { |
| | | if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | { |
| | | var vmPump = vm as HydroPumpPropertyViewModel; |
| | | var curveQe = hydroInfo.Curves?.Find(x => x.Code == vmPump.CurveQE); |
| | |
| | | dlg.SetBindingData(hydroInfo, curveQe, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | break; |
| | | case HydroCurve.Valve: |
| | | } |
| | | break; |
| | | case HydroCurve.Valve: |
| | | { |
| | | |
| | | } |
| | | break; |
| | | case HydroCurve.ValveQL: |
| | | { |
| | | if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | { |
| | | |
| | | } |
| | | break; |
| | | case HydroCurve.ValveQL: |
| | | { |
| | | |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | }; |
| | | e.RepositoryItem = buttonEdit; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 型号 |
| | | |
| | | var modelTypePro = (IsHydroModelTypeAttribute)descriptor.Attributes[typeof(IsHydroModelTypeAttribute)]; |
| | | if (modelTypePro != null) |
| | | { |
| | | var buttonEdit = new RepositoryItemButtonEdit(); |
| | | buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor; |
| | | buttonEdit.ButtonClick += delegate |
| | | { |
| | | var hydroInfo = _hydroInfoFunc?.Invoke(); |
| | | if (hydroInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | var allParterList = hydroInfo.GetAllParters(); |
| | | var parter = allParterList?.Find(x => x.Code == vm.Code); |
| | | this.MatchingDbEvent?.Invoke(parter); |
| | | }; |
| | | e.RepositoryItem = buttonEdit; |
| | | } |
| | |
| | | buttonEdit.ButtonClick += delegate |
| | | { |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | this.SelectPatternEvent?.Invoke(vm, patternPro.PatternType); |
| | | this.SetPatternEvent?.Invoke(vm, patternPro.PatternType); |
| | | }; |
| | | e.RepositoryItem = buttonEdit; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 标签 |
| | | |
| | | var flagsPro = (IsHydroFlagsProAttribute)descriptor.Attributes[typeof(IsHydroFlagsProAttribute)]; |
| | | if (flagsPro != null && flagsPro.FlagsPro) |
| | | { |
| | | var buttonEdit = new RepositoryItemButtonEdit(); |
| | | buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor; |
| | | buttonEdit.ButtonClick += async delegate |
| | | { |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | var flagVmoList = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(Yw.Hydro.DataType.HydroParter); |
| | | var dbFlagList = flagVmoList?.Select(x => x.Name).Distinct().ToList(); |
| | | var dlg = new SetFlagsDlg(); |
| | | dlg.SetBindingData(dbFlagList, Yw.Untity.FlagsHelper.ToList(vm.Flags)); |
| | | dlg.ReloadDataEvent += (flags) => |
| | | { |
| | | vm.Flags = Yw.Untity.FlagsHelper.ToString(flags); |
| | | UpdateRows(); |
| | | }; |
| | | dlg.ShowDialog(); |
| | | }; |
| | | e.RepositoryItem = buttonEdit; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 连接 |
| | | |
| | | if (e.Row.Properties.Value != null) |
| | | { |
| | | var linkCodeAttri = (IsHydroLinkCodeAttribute)descriptor.Attributes[typeof(IsHydroLinkCodeAttribute)]; |
| | | if (linkCodeAttri != null) |
| | | { |
| | | var buttonEdit = new RepositoryItemButtonEdit(); |
| | | 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()); |
| | | }; |
| | | e.RepositoryItem = buttonEdit; |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | |
| | |
| | | this.PropertyValueChangedEvent?.Invoke(propertyViewModel); |
| | | if (this.PropertyValueChangedEvent == null || !this.PropertyValueChangedEvent.Invoke(propertyViewModel)) |
| | | { |
| | | var hydroInfo = GetHydroInfoEvent?.Invoke(); |
| | | var hydroInfo = _hydroInfoFunc?.Invoke(); |
| | | if (hydroInfo == null) |
| | | { |
| | | return; |
| | |
| | | this.propertyGridControl1.CollapseAllRows(); |
| | | } |
| | | |
| | | //聚焦行改变 |
| | | private void propertyGridControl1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | private void propertyGridControl1_CustomDrawCaption(object sender, CustomDrawCaptionEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |