using DevExpress.Utils.Extensions; using DevExpress.Utils.Svg; using Yw.DAL.Basic; using Yw.Vmo; namespace HStation.WinFrmUI { public partial class XhsProjectSimulationFunctionCtrl : DevExpress.XtraEditors.XtraUserControl { public XhsProjectSimulationFunctionCtrl() { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); } /// /// 显示项目站信息事件 /// public event Action ShowProjectSiteInfoEvent; /// /// 显示项目站模拟事件 /// public event Action, SvgImage> ShowProjectSiteSimulationEvent; /// /// 显示项目站工况事件 /// public event Action ShowProjectSiteWorkingEvent; /// /// 项目站工况选择改变事件 /// public event Action ProjectSiteWorkingCheckedEvent; /// /// 显示项目站方案事件 /// public event Action ShowProjectSiteSchemeEvent; /// /// 显示项目站方案工况事件 /// public event Action ShowProjectSiteSchemeWorkingEvent; /// /// 项目站方案工况选择工况事件 /// public event Action ProjectSiteSchemeWorkingCheckedEvent; /// /// 创建项目站方案事件 /// public event Action CreateProjectSiteSchemeEvent; /// /// 比对项目工况事件 /// public event Action CompareProjectWorkingEvent; private XhsProjectVmo _project = null;//项目 private XhsProjectSiteVmo _projectSite = null;//项目站 private Yw.Model.HydroModelInfo _hydroInfo = null;//模型信息 private Dictionary _allWorkingCheckedListDict = null;//所有工况选择列表字典 private Dictionary _allSchemeHydroInfoDict = null;//所有方案水力信息列表 private Dictionary> _allSchemeWorkingCheckedListDict = null;//所有方案工况选择列表字典 /// /// 绑定数据 /// public async Task SetBindingData(XhsProjectVmo project) { if (project == null) { return; } _project = project; var overlay = this.ShowOverlay(); _projectSite = await BLLFactory.Instance.GetDefaultByProjectID(_project.ID); var relation = await BLLFactory.Instance .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation); if (relation == null) { return; } var allWorkingList = await BLLFactory.Instance.GetByModelID(relation.ModelID); if (allWorkingList != null && allWorkingList.Count > 0) { _allWorkingCheckedListDict = new Dictionary(); foreach (var working in allWorkingList) { _allWorkingCheckedListDict.Add(working, false); AppendWorking(working); } } var allSchemeList = await BLLFactory.Instance.GetBySiteID(_projectSite.ID); if (allSchemeList != null && allSchemeList.Count > 0) { _allSchemeWorkingCheckedListDict = new Dictionary>(); foreach (var scheme in allSchemeList) { AppendScheme(scheme); var schemeRelation = await BLLFactory.Instance .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsScheme, scheme.ID, HStation.Xhs.Purpose.Simulation); if (schemeRelation != null) { var allSchemeWorkingList = await BLLFactory.Instance.GetByModelID(schemeRelation.ModelID); if (allSchemeWorkingList != null && allSchemeWorkingList.Count > 0) { _allSchemeWorkingCheckedListDict.Add(scheme, new Dictionary()); foreach (var schemeWorking in allSchemeWorkingList) { _allSchemeWorkingCheckedListDict[scheme].Add(schemeWorking, false); AppendSchemeWorking(scheme, schemeWorking); } } } } } overlay.Close(); } #region 获取水力信息 /// /// 获取水力信息 /// UseCache 是否使用缓存 /// public async Task GetHydroInfo(bool useCache) { if (!useCache) { _hydroInfo = await GetHydroInfo(); if (_hydroInfo == null) { return null; } } if (_hydroInfo == null) { _hydroInfo = await GetHydroInfo(); } return _hydroInfo; } //获取水力信息 private async Task GetHydroInfo() { if (_project == null) { return default; } if (_projectSite == null) { return default; } var relation = await BLLFactory.Instance .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation); if (relation == null) { return null; } var hydroInfo = await BLLFactory.Instance.GetByID(relation.ModelID); return hydroInfo; } #endregion #region 获取方案水力信息 /// /// 获取方案水力信息 /// UseCache 是否使用缓存 /// public async Task GetSchemeHydroInfo(XhsSchemeVmo scheme, bool useCache) { if (_project == null) { return default; } if (_projectSite == null) { return default; } if (scheme == null) { return default; } if (!useCache) { var hydroInfo = await GetSchemeHydroInfo(scheme); if (hydroInfo == null) { return null; } if (_allSchemeHydroInfoDict == null) { _allSchemeHydroInfoDict = new Dictionary(); } if (_allSchemeHydroInfoDict.ContainsKey(scheme)) { _allSchemeHydroInfoDict[scheme] = hydroInfo; } else { _allSchemeHydroInfoDict.Add(scheme, hydroInfo); } return hydroInfo; } if (_allSchemeHydroInfoDict == null) { _allSchemeHydroInfoDict = new Dictionary(); } if (!_allSchemeHydroInfoDict.ContainsKey(scheme)) { var hydroInfo = await GetSchemeHydroInfo(scheme); _allSchemeHydroInfoDict.Add(scheme, hydroInfo); return hydroInfo; } return _allSchemeHydroInfoDict[scheme]; } //获取方案水力信息 private async Task GetSchemeHydroInfo(XhsSchemeVmo scheme) { if (_project == null) { return default; } if (_projectSite == null) { return default; } if (scheme == null) { return default; } var relation = await BLLFactory.Instance .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsScheme, scheme.ID, HStation.Xhs.Purpose.Simulation); if (relation == null) { return default; } var hydroInfo = await BLLFactory.Instance.GetByID(relation.ModelID); return hydroInfo; } #endregion /// /// 添加工况 /// public void AppendWorking(Yw.Vmo.HydroWorkingVmo working) { if (_project == null) { return; } if (_projectSite == null) { return; } if (working == null) { return; } this.elementProjectSiteSimulation.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; var ckEdit = new CheckEdit(); ckEdit.Properties.AutoWidth = true; ckEdit.Properties.Caption = string.Empty; ckEdit.CheckedChanged += async (sender, e) => { if (_allWorkingCheckedListDict == null) { _allWorkingCheckedListDict = new Dictionary(); } if (_allWorkingCheckedListDict.ContainsKey(working)) { _allWorkingCheckedListDict[working] = ckEdit.Checked; } else { _allWorkingCheckedListDict.Add(working, ckEdit.Checked); } var hydroInfo = await GetHydroInfo(true); this.ProjectSiteWorkingCheckedEvent?.Invoke(_project, _projectSite, hydroInfo, working, ckEdit.Checked); }; this.accordionControl1.Controls.Add(ckEdit); var elementWorking = new DevExpress.XtraBars.Navigation.AccordionControlElement(); elementWorking.HeaderControl = ckEdit; elementWorking.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; elementWorking.Text = working.Name; elementWorking.Tag = working; elementWorking.Click += async (sender, e) => { var hydroInfo = await GetHydroInfo(true); this.ShowProjectSiteWorkingEvent?.Invoke(_project, _projectSite, hydroInfo, working, this.svgImg32[4]); }; this.elementProjectSiteSimulation.Elements.Add(elementWorking); } /// /// 添加方案 /// public void AppendScheme(XhsSchemeVmo scheme) { if (scheme == null) { return; } this.elementSchemeList.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; var elementScheme = new DevExpress.XtraBars.Navigation.AccordionControlElement(); elementScheme.Text = scheme.Name; elementScheme.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; elementScheme.ImageOptions.ImageIndex = 3; elementScheme.Tag = scheme; elementScheme.Click += (sender, e) => { if (_project == null) { return; } if (_projectSite == null) { return; } this.ShowProjectSiteSchemeEvent?.Invoke(_project, _projectSite, scheme, this.svgImg32[3]); }; this.elementSchemeList.Elements.Add(elementScheme); } /// /// 添加方案工况 /// public void AppendSchemeWorking(XhsSchemeVmo scheme, Yw.Vmo.HydroWorkingVmo working) { if (_project == null) { return; } if (_projectSite == null) { return; } if (scheme == null) { return; } if (working == null) { return; } var elementScheme = this.elementSchemeList.Elements.FirstOrDefault(x => x.Tag is XhsSchemeVmo && (x.Tag as XhsSchemeVmo).ID == scheme.ID); if (elementScheme == null) { return; } elementScheme.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; var ckEdit = new CheckEdit(); ckEdit.Properties.AutoWidth = true; ckEdit.Properties.Caption = string.Empty; ckEdit.CheckedChanged += (sender, e) => { this.ProjectSiteSchemeWorkingCheckedEvent?.Invoke(scheme, working, ckEdit.Checked); }; this.accordionControl1.Controls.Add(ckEdit); var elementWorking = new DevExpress.XtraBars.Navigation.AccordionControlElement(); elementWorking.HeaderControl = ckEdit; elementWorking.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; elementWorking.Text = working.Name; elementWorking.Tag = working; elementWorking.Click += (sender, e) => { if (_project == null) { return; } if (_projectSite == null) { return; } }; elementScheme.Elements.Add(elementWorking); } //元素点击事件 private void accordionControl1_ElementClick(object sender, DevExpress.XtraBars.Navigation.ElementClickEventArgs e) { } //项目站概况 private async void elementProjectSiteInfo_Click(object sender, EventArgs e) { if (_project == null) { return; } if (_projectSite == null) { return; } var hydroInfo = await GetHydroInfo(true); if (hydroInfo == null) { return; } this.ShowProjectSiteInfoEvent?.Invoke(_project, _projectSite, hydroInfo, this.svgImg32[0]); } //项目站水力模拟 private async void elementProjectSiteSimulation_Click(object sender, EventArgs e) { if (_project == null) { return; } if (_projectSite == null) { return; } var hydroInfo = await GetHydroInfo(true); if (hydroInfo == null) { return; } this.ShowProjectSiteSimulationEvent?.Invoke(_project, _projectSite, hydroInfo, _allWorkingCheckedListDict, this.svgImg32[1]); } //创建项目站方案 private void btnCreateProjectSiteScheme_Click(object sender, EventArgs e) { if (_project == null) { return; } if (_projectSite == null) { return; } this.CreateProjectSiteSchemeEvent?.Invoke(_project, _projectSite, this.svgImg32[3]); } //工况对比 private void btnCompareWorking_Click(object sender, EventArgs e) { this.CompareProjectWorkingEvent?.Invoke(this.svgImg32[5]); } } }