using DevExpress.XtraBars; using DevExpress.XtraBars.Docking; using DevExpress.XtraBars.Docking2010.Views; using DevExpress.XtraEditors; using IStation.DataProvider.temp; using IStation.WinFormUI; using IStation.WinFormUI.Project; using IStation.WinFormUI.Scene; using IStation.WinFrmUI.Scatl; using System; using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; namespace IStation.Client { /// /// 主界面 /// public partial class MainForm : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm { #region 构造函数 public MainForm() { InitializeComponent(); this.IconOptions.Icon = WinFormUI.Properties.Resource.app; } //禁止标题扩展 protected override bool ExtendNavigationControlToFormTitle { get { return false; } } //开启界面双缓冲 解决窗体切换闪屏问题 protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } #endregion NotifyIcon _app = null; internal void InitialForm() { if (this.components == null) _app = new System.Windows.Forms.NotifyIcon(); else _app = new System.Windows.Forms.NotifyIcon(this.components); _app.Text = "Scatl"; _app.Visible = true; _app.Click += (object sender, EventArgs e) => { this.Visible = true; this.WindowState = FormWindowState.Maximized; _app.Visible = false; }; var project = new BLL.Project().QueryById(GlobalParas.ProjectId); if (project != null) { this.barStaticProjectCaption.Caption = project.Name; } } #region Form private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (XtraMessageBox.Show("是否关闭程序?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { e.Cancel = true; return; } var bll = new BLL.Project(); var project = bll.QueryById(GlobalParas.ProjectId); project.UpdateTime = DateTime.Now; bll.Update(project); } } #endregion #region TabbedView //选中 private void tabbedView1_DocumentSelected(object sender, DocumentEventArgs e) { if (e.Document == null) return; var surfaceGuid = e.Document.Tag as SurfaceGuid; if (surfaceGuid == null) return; } //激活 private void tabbedView1_DocumentActivated(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e) { } //关闭ing private void tabbedView1_DocumentClosing(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentCancelEventArgs e) { } //关闭 private void tabbedView1_DocumentClosed(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentEventArgs e) { } #endregion #region Page //是否存在Page private bool IsExistPage(SurfaceGuid sguid, bool isActivateDoc) { if (sguid == 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 SurfaceGuid) { if ((panel.Tag as SurfaceGuid).ToString() == sguid.ToString()) { if (isActivateDoc) 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 SurfaceGuid) { if ((doc.Tag as SurfaceGuid).ToString() == sguid.ToString()) { if (isActivateDoc) this.tabbedView1.Controller.Activate(doc); return true; } } } } } return false; } //更新数据 private void RefreshPageData(SurfaceGuid sguid) { if (sguid == 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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString()); if (panel != null) { if (panel.ControlContainer.Controls.Count > 0) { var page = panel.ControlContainer.Controls[0] as DocumentPage; if (page != null) { page.RefreshDataSource(); } } 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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString()); if (doc != null) { var page = doc.Control as DocumentPage; if (page != null) { page.RefreshDataSource(); } return; } } } //更新PageTitle private void UpdatePageTitle(SurfaceGuid sguid, PageTitle title) { if (sguid == 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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.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 bool CreatePage(DocumentPage page, SurfaceGuid sguid) { if (page == null || sguid == null) return false; page.SurfaceGuid = sguid; page.Dock = DockStyle.Fill; page.IsExistPageEvent += IsExistPage; page.CreatePageEvent += CreatePage; page.RefreshPageDataEvent += RefreshPageData; page.UpdatePageTitleEvent += UpdatePageTitle; page.ClosePageEvent += ClosePage; page.ResetAllPagesEvent += ResetAllPages; page.RegistEvents(); switch (sguid.DockType) { case eDockType.Dock: { this.dockManager1.BeginUpdate(); DockPanel docPnl = null; if (sguid.SubDockType == eSubDockType.Dock_Left) docPnl = this.dockManager1.AddPanel(DockingStyle.Left); else if (sguid.SubDockType == eSubDockType.Dock_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.ControlContainer.Controls.Add(page); docPnl.Tag = sguid; this.dockManager1.EndUpdate(); docPnl.Show(); } break; case eDockType.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.Tag = sguid; this.tabbedView1.EndUpdate(); this.tabbedView1.Controller.Activate(doc); } break; default: break; } page.InitialDataSource(); return true; } //关闭Page private void ClosePage(SurfaceGuid sguid) { switch (sguid.DockType) { case eDockType.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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString()); if (panel != null) { if (panel.Visibility != DockVisibility.Hidden) panel.Close();//会触发正在关闭和关闭事件 //this.dockManager1.RemovePanel(panel);//不会触发正在关闭和关闭事件 } } } break; case eDockType.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 SurfaceGuid && (x.Tag as SurfaceGuid).ToString() == sguid.ToString()); if (doc != null) { this.tabbedView1.Controller.Close(doc);//会触发正在关闭和关闭事件 } } } break; default: break; } } //查找page private DocumentPage FindPage(SurfaceGuid sguid, bool isActiveDoc) { if (sguid == null) return default; var sguid_msg = sguid.ToString(); if (this.tabbedView1.Documents != null && this.tabbedView1.Documents.Count > 0) { var doc = this.tabbedView1.Documents.ToList().Find(x => x.Tag != null && x.Tag.ToString() == sguid_msg); if (doc != null) { if (isActiveDoc) this.tabbedView1.Controller.Activate(doc); var page = doc.Control as DocumentPage; if (page != null) { return page; } return null; } } return null; } //重置所有页面 private void ResetAllPages() { this.tabbedView1.Controller.CloseAll(); /* var project = new BLL.Project().GetById(GlobalParas.ProjectId); this.nb标题.Caption = $"Scada分析-{project.Name}"; var sguid = new SurfaceGuid(); sguid.DockType = eDockType.Tab; sguid.Modular = eModular.System; sguid.Function = "最近浏览"; if (!IsExistPage(sguid, true)) { var page = new LatelyProjectOverviewPage(sguid); CreatePage(page, sguid); }*/ } #endregion private void accProjectItem_Click(object sender, EventArgs e) { var scene = SceneTempCreate.GetScene(GlobalParas.ProjectId); var bol= GeneralMonitorDataImportHelper.Import(GlobalParas.ProjectId,scene.Id,scene.DataSourcesMappers); if (!bol) { MessageBox.Show("导入失败!"); } else { MessageBox.Show("导入成功!"); } } private void barBtnExportProject_ItemClick(object sender, ItemClickEventArgs e) { ProjectHelper.OtherSaveProject(GlobalParas.ProjectId); } private void accordionControlElement2_Click(object sender, EventArgs e) { } } }