using DevExpress.Drawing;
using DevExpress.Utils.Svg;
using DevExpress.XtraBars.Docking;
using DevExpress.XtraBars.Docking2010.Views;
using Yw.Vmo;
using Yw.WinFrmUI.Page;
namespace HStation.WinFrmUI
{
public partial class XhsProjectSimulationMgrPage : Yw.WinFrmUI.DocumentPage
{
public XhsProjectSimulationMgrPage()
{
InitializeComponent();
this.PageTitle.Caption = "水力模拟";
this.PageTitle.HeaderSvgImage = this.svgImg32[0];
this.PageTitle.SvgImageSize = new Size(24, 24);
this.simulationFunctionMgrCtrl1.ShowProjectSiteInfoEvent += XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteInfoEvent;
this.simulationFunctionMgrCtrl1.ShowProjectSiteSimulationEvent += XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSimulationEvent;
this.simulationFunctionMgrCtrl1.ShowProjectSiteWorkingEvent += XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteWorkingEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteWorkingUpdateEvent += XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingUpdateEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteWorkingRemoveEvent += XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingRemoveEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteWorkingCheckedEvent += XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingCheckedEvent;
this.simulationFunctionMgrCtrl1.CreateProjectSiteSchemeEvent += XhsProjectSimulationFunctionMgrCtrl1_CreateProjectSiteSchemeEvent;
this.simulationFunctionMgrCtrl1.ShowProjectSiteSchemeEvent += XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSchemeEvent;
this.simulationFunctionMgrCtrl1.ShowProjectSiteSchemeWorkingEvent += XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSchemeWorkingEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteSchemeWorkingCheckedEvent += SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingCheckedEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteSchemeWorkingUpdateEvent += SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingUpdateEvent;
this.simulationFunctionMgrCtrl1.ProjectSiteSchemeWorkingRemoveEvent += SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingRemoveEvent;
}
private XhsProjectVmo _project = null;//项目
private object _locker = new object();//锁定对象
///
/// 初始化数据源
///
public override async void InitialDataSource()
{
base.InitialDataSource();
if (_project == null)
{
return;
}
await this.simulationFunctionMgrCtrl1.SetBindingData(_project);
}
///
/// 绑定数据
///
public async Task SetBindingData(long projectId)
{
_project = await BLLFactory.Instance.GetByID(projectId);
SetBindingData(_project);
}
///
/// 设置数据
///
public void SetBindingData(XhsProjectVmo project)
{
if (project == null)
{
return;
}
_project = project;
this.PageTitle.Caption = $"{_project.Name}\r\n项目模拟";
}
#region 功能面板
//显示项目站概况事件
private void XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteInfoEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, SvgImage svgImage)
{
lock (_locker)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Info,
};
if (!IsExistPage(guid, true))
{
var page = new XhsProjectSimulationInfoPage();
page.PageTitle.HeaderSvgImage = svgImage;
page.SetBindingData(project, projectSite, hydroInfo);
CreatePage(page, guid);
}
}
}
//显示项目站水力模拟事件
private void XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSimulationEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, Dictionary allWorkingCheckedListDict, SvgImage svgImage)
{
lock (_locker)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Simulation,
TagName = projectSite.ID.ToString()
};
if (!IsExistPage(guid, true))
{
var page = new XhsProjectSimulationCorePage();
page.PageTitle.HeaderSvgImage = svgImage;
page.AppendWorkingEvent += (working) =>
{
this.simulationFunctionMgrCtrl1.AppendWorking(working);
};
page.SetBindingData(project, projectSite, hydroInfo, allWorkingCheckedListDict);
CreatePage(page, guid);
}
}
}
//显示项目站工况事件
private void XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteWorkingEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, HydroWorkingVmo working, SvgImage svgImage)
{
lock (_locker)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Working,
TagName = working.ID.ToString()
};
if (!IsExistPage(guid, true))
{
var page = new XhsProjectSimulationWorkingPage();
page.UpdateWorkingEvent += (rhs) =>
{
this.simulationFunctionMgrCtrl1.UpdateWorking(rhs);
};
page.RemoveWorkingEvent += (rhs) =>
{
this.simulationFunctionMgrCtrl1.RemoveWorking(rhs);
};
page.PageTitle.HeaderSvgImage = svgImage;
page.SetBindingData(project, projectSite, hydroInfo, working);
CreatePage(page, guid);
}
}
}
//项目站工况更新事件
private void XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingUpdateEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, HydroWorkingVmo working)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Simulation,
TagName = projectSite.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationCorePage;
if (ctrl == null)
{
return;
}
ctrl.UpdateWorkingCheckedList(working);
}
//项目站工况移除事件
private void XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingRemoveEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, HydroWorkingVmo working)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Simulation,
TagName = projectSite.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationCorePage;
if (ctrl == null)
{
return;
}
ctrl.RemoveWorkingCheckedList(working);
}
//项目站工况选择改变事件
private void XhsProjectSimulationFunctionMgrCtrl1_ProjectSiteWorkingCheckedEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, HydroWorkingVmo working, bool hasChecked)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Simulation,
TagName = projectSite.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationCorePage;
if (ctrl == null)
{
return;
}
ctrl.UpdateWorkingCheckedList(working, hasChecked);
}
//项目站方案创建事件
private void XhsProjectSimulationFunctionMgrCtrl1_CreateProjectSiteSchemeEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo, SvgImage svgImage)
{
WaitFormHelper.ShowWaitForm(this.FindForm(), "正在加载模型,请稍侯...");
var dlg = new AddXhsSchemeDlg();
dlg.Shown += delegate { WaitFormHelper.HideWaitForm(this.FindForm()); };
dlg.ReloadDataEvent += (rhs) =>
{
this.simulationFunctionMgrCtrl1.AppendScheme(rhs);
};
dlg.SetBindingData(project, projectSite, hydroInfo);
dlg.ShowDialog();
}
//显示项目站方案事件
private void XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSchemeEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, XhsSchemeVmo scheme, Yw.Model.HydroModelInfo hydroInfo, Dictionary dict, SvgImage svgImage)
{
lock (_locker)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Scheme,
TagName = scheme.ID.ToString()
};
if (!IsExistPage(guid, true))
{
var page = new XhsProjectSimulationSchemePage();
page.PageTitle.HeaderSvgImage = svgImage;
page.AppendWorkingEvent += (working) =>
{
this.simulationFunctionMgrCtrl1.AppendSchemeWorking(scheme, working);
};
page.SetBindingData(project, projectSite, scheme, hydroInfo, dict);
CreatePage(page, guid);
}
}
}
//显示项目站方案工况事件
private void XhsProjectSimulationFunctionMgrCtrl1_ShowProjectSiteSchemeWorkingEvent
(XhsProjectVmo project, XhsProjectSiteVmo projectSite, XhsSchemeVmo scheme, Yw.Model.HydroModelInfo hydroInfo, HydroWorkingVmo working, SvgImage svgImage)
{
lock (_locker)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Working,
TagName = working.ID.ToString()
};
if (!IsExistPage(guid, true))
{
var page = new XhsProjectSimulationWorkingPage();
page.PageTitle.HeaderSvgImage = svgImage;
page.UpdateWorkingEvent += (rhs) =>
{
this.simulationFunctionMgrCtrl1.UpdateSchemeWorking(scheme, rhs);
};
page.RemoveWorkingEvent += (rhs) =>
{
this.simulationFunctionMgrCtrl1.RemoveSchemeWorking(scheme, rhs);
};
page.SetBindingData(project, projectSite, scheme, hydroInfo, working);
CreatePage(page, guid);
}
}
}
//项目站方案工况选择改变事件
private void SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingCheckedEvent(XhsSchemeVmo scheme, HydroWorkingVmo working, bool hasChecked)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Scheme,
TagName = scheme.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationSchemePage;
if (ctrl == null)
{
return;
}
ctrl.UpdateWorkingCheckedList(working, hasChecked);
}
//项目站方案工况更新事件
private void SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingUpdateEvent(XhsSchemeVmo scheme, HydroWorkingVmo working)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Scheme,
TagName = scheme.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationSchemePage;
if (ctrl == null)
{
return;
}
}
//项目站方案工况移除事件
private void SimulationFunctionMgrCtrl1_ProjectSiteSchemeWorkingRemoveEvent(XhsSchemeVmo scheme, HydroWorkingVmo working)
{
var guid = new PageGuid()
{
Modular = this.PageGuid.Modular,
MoudingType = eMoudingType.Tab,
Function = SimulationFunctionHelper.Scheme,
TagName = scheme.ID.ToString()
};
var page = FindPage(guid);
if (page == null)
{
return;
}
var ctrl = page as XhsProjectSimulationSchemePage;
if (ctrl == null)
{
return;
}
}
#endregion
#region TabbedView 相关事件处理程序
//选中
private void tabbedView1_DocumentSelected(object sender, DocumentEventArgs e)
{
if (e.Document == null)
return;
var surfaceGuid = e.Document.Tag as PageGuid;
if (surfaceGuid == null)
return;
}
//添加
private void tabbedView1_DocumentAdded(object sender, DocumentEventArgs e)
{
}
//激活
private void tabbedView1_DocumentActivated(object sender, DocumentEventArgs e)
{
var page = e.Document.Control as DocumentPage;
if (page == null)
return;
}
//正在关闭Document
private void tabbedView1_DocumentClosing(object sender, DocumentCancelEventArgs e)
{
var page = e.Document.Control as DocumentPage;
if (page == null)
{
return;
}
if (!page.CanClose())
{
e.Cancel = true;
return;
}
page.UnRegistEvents();
}
//关闭 此时控件已经为空
private void tabbedView1_DocumentClosed(object sender, DocumentEventArgs e)
{
}
#endregion
#region Page
//是否存在Page
private new bool IsExistPage(PageGuid pguid, bool isActivePage)
{
if (pguid == null)
{
return false;
}
if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
{
foreach (DockPanel panel in this.dockManager1.Panels)
{
if (panel.Tag != null)
{
if (panel.Tag is PageGuid)
{
if ((panel.Tag as PageGuid).ToString() == pguid.ToString())
{
if (isActivePage)
{
panel.Show();
}
return true;
}
}
}
}
}
if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
{
foreach (BaseDocument doc in this.tabbedView1.Documents)
{
if (doc.Tag != null)
{
if (doc.Tag is PageGuid)
{
if ((doc.Tag as PageGuid).ToString() == pguid.ToString())
{
if (isActivePage)
{
this.tabbedView1.Controller.Activate(doc);
}
return true;
}
}
}
}
}
return false;
}
//更新数据
private new void RefreshPageData(PageGuid pguid)
{
if (pguid == null)
{
return;
}
if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
{
var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (panel != null)
{
if (panel.ControlContainer.Controls.Count > 0)
{
var page = panel.ControlContainer.Controls[0] as DocumentPage;
if (page != null)
{
page.RefreshData();
}
}
return;
}
}
if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
{
var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (doc != null)
{
var page = doc.Control as DocumentPage;
if (page != null)
{
page.RefreshData();
}
return;
}
}
}
//更新PageTitle
private new void UpdatePageTitle(PageGuid pguid, PageTitle title)
{
if (pguid == null || title == null)
return;
if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
{
var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (panel != null)
{
panel.Text = title.Caption;
panel.ImageOptions.Image = title.HeaderImage;
panel.ImageOptions.SvgImage = title.HeaderSvgImage;
panel.ImageOptions.SvgImageSize = title.SvgImageSize;
if (panel.ControlContainer.Controls.Count > 0)
{
var page = panel.ControlContainer.Controls[0] as DocumentPage;
if (page != null)
{
page.PageTitle = title;
}
}
return;
}
}
if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
{
var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (doc != null)
{
doc.Caption = title.Caption;
doc.ImageOptions.Image = title.HeaderImage;
doc.ImageOptions.SvgImage = title.HeaderSvgImage;
doc.ImageOptions.SvgImageSize = title.SvgImageSize;
var page = doc.Control as DocumentPage;
if (page != null)
{
page.PageTitle = title;
}
return;
}
}
}
//创建Page
private new bool CreatePage(DocumentPage page, PageGuid pguid)
{
if (page == null || pguid == null)
{
return false;
}
page.PageGuid = pguid;
page.Dock = DockStyle.Fill;
page.IsExistPageEvent += IsExistPage;
page.CreatePageEvent += CreatePage;
page.RefreshPageDataEvent += RefreshPageData;
page.UpdatePageTitleEvent += UpdatePageTitle;
page.ClosePageEvent += ClosePage;
page.RegistEvents();
switch (pguid.MoudingType)
{
case eMoudingType.Dock:
{
this.dockManager1.BeginUpdate();
DockPanel docPnl = null;
if (pguid.DockType == eDockType.Left)
{
docPnl = this.dockManager1.AddPanel(DockingStyle.Left);
}
else if (pguid.DockType == eDockType.Right)
{
docPnl = this.dockManager1.AddPanel(DockingStyle.Right);
}
docPnl.Footer = Directory.GetCurrentDirectory();
if (page.PageTitle != null)
{
docPnl.Text = page.PageTitle.Caption;
docPnl.ImageOptions.Image = page.PageTitle.HeaderImage;
docPnl.ImageOptions.SvgImage = page.PageTitle.HeaderSvgImage;
docPnl.ImageOptions.SvgImageSize = page.PageTitle.SvgImageSize;
docPnl.Options.ShowCloseButton = page.PageTitle.AllowClose;
}
docPnl.ControlContainer.Controls.Add(page);
docPnl.Tag = pguid;
this.dockManager1.EndUpdate();
docPnl.Show();
}
break;
case eMoudingType.Tab:
{
this.tabbedView1.BeginUpdate();
var doc = this.tabbedView1.AddDocument(page);
doc.Footer = Directory.GetCurrentDirectory();
if (page.PageTitle != null)
{
doc.Caption = page.PageTitle.Caption;
doc.ImageOptions.Image = page.PageTitle.HeaderImage;
doc.ImageOptions.SvgImage = page.PageTitle.HeaderSvgImage;
doc.ImageOptions.SvgImageSize = page.PageTitle.SvgImageSize;
doc.Properties.AllowClose = page.PageTitle.AllowClose ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False;
}
doc.Tag = pguid;
this.tabbedView1.EndUpdate();
this.tabbedView1.Controller.Activate(doc);
}
break;
default: break;
}
page.InitialDataSource();
return true;
}
//关闭Page
private new void ClosePage(PageGuid pguid)
{
switch (pguid.MoudingType)
{
case eMoudingType.Dock:
{
if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
{
var panel = this.dockManager1.Panels.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (panel != null)
{
if (panel.Visibility != DockVisibility.Hidden)
panel.Close();//会触发正在关闭和关闭事件
//this.dockManager1.RemovePanel(panel);//不会触发正在关闭和关闭事件
}
}
}
break;
case eMoudingType.Tab:
{
if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
{
var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString());
if (doc != null)
{
this.tabbedView1.Controller.Close(doc);//会触发正在关闭和关闭事件
}
}
}
break;
default: break;
}
}
//查询Page
private DocumentPage FindPage(PageGuid pguid)
{
if (pguid == null)
{
return default;
}
if (this.dockManager1.Panels != null && this.dockManager1.Panels.Count > 0)
{
foreach (DockPanel panel in this.dockManager1.Panels)
{
if (panel.Tag != null)
{
if (panel.Tag is PageGuid)
{
if ((panel.Tag as PageGuid).ToString() == pguid.ToString())
{
return panel.ControlContainer.Controls[0] as DocumentPage;
}
}
}
}
}
if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0)
{
foreach (BaseDocument doc in this.tabbedView1.Documents)
{
if (doc.Tag != null)
{
if (doc.Tag is PageGuid)
{
if ((doc.Tag as PageGuid).ToString() == pguid.ToString())
{
return doc.Control as DocumentPage;
}
}
}
}
}
return default;
}
#endregion
}
}