| | |
| | | using DevExpress.XtraEditors.Repository; |
| | | using DevExpress.XtraLayout.Utils; |
| | | using DevExpress.XtraVerticalGrid.Events; |
| | | using NetTaste; |
| | | using SQLitePCL; |
| | | using System.Windows.Forms.VisualStyles; |
| | | using Yw.EPAnet; |
| | | |
| | | namespace Yw.WinFrmUI |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 选择曲线事件 |
| | | /// 匹配db事件 |
| | | /// </summary> |
| | | public event Action<HydroParterPropertyViewModel, string> SelectCurveEvent; |
| | | |
| | | public event Action<Yw.Model.HydroParterInfo> MatchingDbEvent; |
| | | /// <summary> |
| | | /// 选择模式事件 |
| | | /// 查看曲线事件 |
| | | /// </summary> |
| | | public event Action<HydroParterPropertyViewModel, string> SelectPatternEvent; |
| | | |
| | | public event Action<Yw.Model.HydroParterInfo, string> ViewCurveEvent; |
| | | /// <summary> |
| | | /// 设置曲线事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SetCurveEvent; |
| | | /// <summary> |
| | | /// 设置模式事件 |
| | | /// </summary> |
| | | public event Func<HydroParterPropertyViewModel, string, bool> SetPatternEvent; |
| | | /// <summary> |
| | | /// 属性值正在改变事件 |
| | | /// </summary> |
| | | public event Action<HydroParterPropertyViewModel> PropertyValueChangingEvent; |
| | | |
| | | public event Func<HydroParterPropertyViewModel, bool> PropertyValueChangingEvent; |
| | | /// <summary> |
| | | /// 属性值发生改变事件 |
| | | /// </summary> |
| | | public event Action<HydroParterPropertyViewModel> PropertyValueChangedEvent; |
| | | public event Func<HydroParterPropertyViewModel, bool> PropertyValueChangedEvent; |
| | | |
| | | |
| | | |
| | | //获取水力信息方法 |
| | | 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(); |
| | | } |
| | | } |
| | | |
| | | //改变触发 |
| | | protected virtual void OnChanged() |
| | | /// <summary> |
| | | /// 绑定对象列表 |
| | | /// </summary> |
| | | public List<HydroParterPropertyViewModel> SelectedObjects |
| | | { |
| | | if (this.SelectedObject == null) |
| | | get { return this.propertyGridControl1.SelectedObjects?.Select(x => x as HydroParterPropertyViewModel).ToList(); } |
| | | set |
| | | { |
| | | |
| | | } |
| | | else |
| | | { |
| | | |
| | | this.propertyGridControl1.SelectedObjects = value?.ToArray(); |
| | | } |
| | | } |
| | | |
| | |
| | | private void propertyGridControl1_CustomDrawRowValueCell(object sender, CustomDrawRowValueCellEventArgs e) |
| | | { |
| | | var rowTypeFullName = e.Row.Properties.RowType.FullName; |
| | | |
| | | if (rowTypeFullName == typeof(DateTime).FullName) |
| | | { |
| | | e.CellText = ((DateTime)e.Properties.Value).ToString("yyyy-MM-dd HH:mm:ss"); |
| | |
| | | { |
| | | if (e.Properties.Value != null) |
| | | { |
| | | e.CellText = e.Properties.Value.ToString() + displayUnit.Unit; |
| | | e.CellText = e.Properties.Value.ToString() + " " + displayUnit.Unit; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //自定义属性描述 |
| | | private void propertyGridControl1_CustomPropertyDescriptors(object sender, CustomPropertyDescriptorsEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | //属性编辑框的显示与取消 |
| | |
| | | buttonEdit.TextEditStyle = TextEditStyles.DisableTextEditor; |
| | | buttonEdit.ButtonClick += delegate |
| | | { |
| | | var hydroInfo = _hydroInfoFunc?.Invoke(); |
| | | if (hydroInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | var vm = GetPropertyViewModel(e.Row); |
| | | this.SelectCurveEvent?.Invoke(vm, curvePro.CurveType); |
| | | switch (curvePro.CurveType) |
| | | { |
| | | case HydroCurve.Pump: |
| | | { |
| | | var pumpInfo = hydroInfo.Pumps?.Find(x => x.Code == vm.Code); |
| | | if (pumpInfo == null) |
| | | { |
| | | return; |
| | | } |
| | | 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); |
| | | var dlg = new SetHydroCurveDlg(); |
| | | dlg.ReloadDataEvent += (curveInfo) => |
| | | { |
| | | if (hydroInfo.Curves == null) |
| | | { |
| | | hydroInfo.Curves = new List<Model.HydroCurveInfo>(); |
| | | } |
| | | if (curveQh != null) |
| | | { |
| | | hydroInfo.Curves.Remove(curveQh); |
| | | } |
| | | hydroInfo.Curves.Add(curveInfo); |
| | | vmPump.CurveQH = curveInfo.Code; |
| | | UpdateRows(); |
| | | }; |
| | | dlg.SetBindingData(hydroInfo, curveQh, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | } |
| | | 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); |
| | | var dlg = new SetHydroCurveDlg(); |
| | | dlg.ReloadDataEvent += (curveInfo) => |
| | | { |
| | | if (hydroInfo.Curves == null) |
| | | { |
| | | hydroInfo.Curves = new List<Model.HydroCurveInfo>(); |
| | | } |
| | | if (curveQp != null) |
| | | { |
| | | hydroInfo.Curves.Remove(curveQp); |
| | | } |
| | | hydroInfo.Curves.Add(curveInfo); |
| | | vmPump.CurveQP = curveInfo.Code; |
| | | UpdateRows(); |
| | | }; |
| | | dlg.SetBindingData(hydroInfo, curveQp, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | } |
| | | 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); |
| | | var dlg = new SetHydroCurveDlg(); |
| | | dlg.ReloadDataEvent += (curveInfo) => |
| | | { |
| | | if (hydroInfo.Curves == null) |
| | | { |
| | | hydroInfo.Curves = new List<Model.HydroCurveInfo>(); |
| | | } |
| | | if (curveQe != null) |
| | | { |
| | | hydroInfo.Curves.Remove(curveQe); |
| | | } |
| | | hydroInfo.Curves.Add(curveInfo); |
| | | vmPump.CurveQE = curveInfo.Code; |
| | | UpdateRows(); |
| | | }; |
| | | dlg.SetBindingData(hydroInfo, curveQe, curvePro.CurveType); |
| | | dlg.ShowDialog(); |
| | | } |
| | | } |
| | | break; |
| | | case HydroCurve.Valve: |
| | | { |
| | | |
| | | } |
| | | break; |
| | | case HydroCurve.ValveQL: |
| | | { |
| | | if (this.SetCurveEvent == null || !this.SetCurveEvent.Invoke(vm, curvePro.CurveType)) |
| | | { |
| | | |
| | | } |
| | | } |
| | | 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) |
| | | { |
| | | 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; |
| | | } |
| | |
| | | var descriptor = this.propertyGridControl1.GetPropertyDescriptor(e.Row); |
| | | var propertyViewModel = GetPropertyViewModel(e.Row); |
| | | this.PropertyValueChangedEvent?.Invoke(propertyViewModel); |
| | | if (this.PropertyValueChangedEvent == null || !this.PropertyValueChangedEvent.Invoke(propertyViewModel)) |
| | | { |
| | | 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); |
| | | } |
| | | UpdateRows(); |
| | | } |
| | | |
| | |
| | | this.propertyGridControl1.CollapseAllRows(); |
| | | } |
| | | |
| | | private void propertyGridControl1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |