using Yw.Hydro; namespace HStation.WinFrmUI { /// /// 监测值辅助类 /// public class SimulationMonitorValueHelper { /// /// /// public SimulationMonitorValueHelper ( SimulationVisualListHelper visualListHelper, SimulationMonitorHelper monitorHelper, SimulationCalcuResultHelper calcuResultHelper ) { _visualListHelper = visualListHelper; _monitorHelper = monitorHelper; _calcuResultHelper = calcuResultHelper; _calcuResultHelper.InitialEvent += async () => await Update(); } private readonly SimulationVisualListHelper _visualListHelper = null;//可见列表辅助类 private readonly SimulationMonitorHelper _monitorHelper = null;//监测点辅助类 private readonly SimulationCalcuResultHelper _calcuResultHelper = null;//计算结果辅助类 private List _allList = null;//所有监测值列表 /// /// 获取所有 /// public async Task> GetAll() { if (_allList == null) { _allList = new List(); var allVisualDict = _visualListHelper.GetVisualDict(); if (allVisualDict != null && allVisualDict.Count > 0) { var allMonitorList = await _monitorHelper.GetAll(); if (allMonitorList != null && allMonitorList.Count > 0) { foreach (var monitor in allMonitorList) { if (allVisualDict.ContainsKey(monitor.Parter)) { var visual = allVisualDict[monitor.Parter]; double? propValue = null; var calcuVisualResult = _calcuResultHelper.GetVisual(monitor.Parter); if (calcuVisualResult != null) { propValue = calcuVisualResult.GetCalcuValue(monitor.PropName); } var vm = new HydroMonitorValueViewModel(monitor, visual, propValue); _allList.Add(vm); } } } } } return _allList; } /// /// 获取对接列表 /// public async Task> GetDockingList() { var all = await GetAll(); return all.Where(x => x.Vmo.SourceType == eSourceType.Docking).ToList(); } /// /// 获取分析列表 /// public async Task> GetAnalyseList() { var all = await GetAll(); return all.Where(x => x.Vmo.SourceType == eSourceType.Analyse).ToList(); } /// /// 更新 /// public async Task Update() { var all = await GetAll(); foreach (var item in all) { if (!item.PropValue.HasValue) { var calcuVisualResult = _calcuResultHelper.GetVisual(item.Vmo.Parter); if (calcuVisualResult != null) { var propValue = calcuVisualResult.GetCalcuValue(item.Vmo.PropName); if (propValue.HasValue) { item.PropValue = item.Vmo.GetPropValue(propValue.Value); } } } } } /// /// 更新 /// public async Task Update(string code, eSourceType sourceType, List valueList) { var all = await GetAll(); all.RemoveAll(x => x.Vmo.Parter == code && x.Vmo.SourceType == sourceType); if (valueList != null && valueList.Count > 0) { all.AddRange(valueList); } } /// /// 重置 /// public async Task Reset(List allWorkingMonitorList) { var all = await GetAll(); all.UpdateMonitorValue(allWorkingMonitorList); } /// /// 重置 /// public async void Reset(string monitorInfo) { var allMonitorValueList = await GetAll(); allMonitorValueList.UpdateMonitorValue(monitorInfo); } } }