using DevExpress.Xpo.Helpers; using Yw.Hydro; namespace Yw.WinFrmUI { public partial class SetHydroMonitorDockingListCtrl : DevExpress.XtraEditors.XtraUserControl { public SetHydroMonitorDockingListCtrl() { InitializeComponent(); this.gridView1.SetNormalEditView(30); this.colRelation.OptionsColumn.AllowEdit = false; this.colPropName.OptionsColumn.AllowEdit = false; this.colUnitName.OptionsColumn.AllowEdit = false; } private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息 private Yw.Model.HydroVisualInfo _visual = null;//构件 private List _allMonitorList = null;//所有监测列表 private List _allMonitorValueList = null;//所有监测值列表 private HydroCalcuResult _calcuResult = null;//计算结果 private BindingList _allBindingList = null;//所有绑定列表 /// /// 绑定数据 /// public void SetBindingData ( Yw.Model.HydroModelInfo hydroInfo, Yw.Model.HydroVisualInfo visual, List allMonitorList, List allMonitorValueList, HydroCalcuResult calcuResult ) { _hydroInfo = hydroInfo; _visual = visual; _allMonitorList = allMonitorList; _allMonitorValueList = allMonitorValueList; _calcuResult = calcuResult; _allBindingList = new BindingList(); if (hydroInfo != null) { if (visual != null) { var allCalcuResultDict = calcuResult?.GetVisualDict(); var propList = HydroMonitorPropHelper.GetPropList(visual.Catalog); var sortCode = allMonitorList == null || allMonitorList.Count < 1 ? 0 : allMonitorList.Max(x => x.SortCode); foreach (var prop in propList) { var vmo = allMonitorList? .Find(x => x.ModelID == hydroInfo.ID && x.Relation == visual.Code && x.SourceType == Yw.Hydro.eSourceType.Docking && x.PropName == prop); if (vmo == null) { sortCode++; vmo = new HydroMonitorVmo() { ID = 0, ModelID = hydroInfo.ID, Relation = visual.Code, SourceType = Yw.Hydro.eSourceType.Docking, PropName = prop, Flags = new List(), SortCode = sortCode, Description = string.Empty }; } double? propValue = null; var monitorValue = allMonitorValueList?.Find(x => x.Vmo.Relation == vmo.Relation && x.Vmo.PropName == vmo.PropName); if (monitorValue != null) { propValue = monitorValue.PropValue; } if (!propValue.HasValue) { var calcuVisualResult = allCalcuResultDict?.GetValue(visual.Code); propValue = calcuVisualResult?.GetCalcuValue(vmo.PropName); } var vm = new HydroMonitorDockingViewModel(vmo, visual, propValue); _allBindingList.Add(vm); } } } InitialFlags(); this.hydroMonitorDockingViewModelBindingSource.DataSource = _allBindingList; this.hydroMonitorDockingViewModelBindingSource.ResetBindings(false); } //初始化标签 private async void InitialFlags() { var flags = await BLLFactory.Instance.GetBySysType(Yw.Hydro.DataType.HydroMonitor); this.repositoryItemCheckedComboBoxEdit1.Items.BeginUpdate(); this.repositoryItemCheckedComboBoxEdit1.Items.Clear(); if (flags != null && flags.Count > 0) { foreach (var flag in flags) { this.repositoryItemCheckedComboBoxEdit1.Items.Add(flag.Name); } } this.repositoryItemCheckedComboBoxEdit1.Items.EndUpdate(); } /// /// 获取值列表 /// public async Task> GetValueList() { if (_hydroInfo == null) { return default; } if (_visual == null) { return default; } var checkedList = _allBindingList?.Where(x => x.Checked).ToList(); checkedList?.ForEach(x => { x.Vmo.Flags = HydroFlagsHelper.ToList(x.Flags); x.Vmo.Description = x.Description; }); var vmoList = checkedList?.Select(x => x.Vmo).ToList(); var bol = await BLLFactory.Instance.Save(_hydroInfo.ID, _visual.Code, eSourceType.Docking, vmoList); if (!bol) { TipFormHelper.ShowError("设置失败!"); return default; } TipFormHelper.ShowSucceed("设置成功!"); var monitorList = await BLLFactory.Instance.GetBySourceType(_hydroInfo.ID, _visual.Code, eSourceType.Docking); var valueList = new List(); monitorList?.ForEach(x => { double? propValue = null; var docking = checkedList.Find(t => t.Vmo.PropName == x.PropName); propValue = docking?.PropValue; var vm = new HydroMonitorValueViewModel(x, _visual, propValue); valueList.Add(vm); }); return valueList; } } }