using DevExpress.XtraBars.Docking2010.Views; using DevExpress.XtraBars.Navigation; using DevExpress.XtraBars.Ribbon; using DevExpress.XtraEditors; using HStation.WinFrmUI; using HStation.WinFrmUI.Auth; using HStation.WinFrmUI.Basic; using HStation.WinFrmUI.Organize; using HStation.WinFrmUI.Xhs.PumpProduct; using System; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; namespace HStation.Desktop { public partial class GuideMain : RibbonForm { public GuideMain() { InitializeComponent(); this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; //this.IconOptions.Icon = WinFrmUI.Properties.Resources.App; //this.nbMain.ImageOptions.Image = WinFrmUI.Properties.Resources.App.ToBitmap(); _app = new System.Windows.Forms.NotifyIcon(this.components); _app.Text = this.Text; _app.Visible = true; //_app.Icon = WinFrmUI.Properties.Resources.App; //_app.Click += (object sender, EventArgs e) => //{ // this.Visible = true; // this.WindowState = FormWindowState.Maximized; // _app.Visible = false; //}; //var guid = new SurfaceGuid() //{ // Function = "地图总览", // Modular = eModular.Model //}; //if (!IsExistPage(guid, true)) //{ // var overview = new MapMgr(); // overview.PageTitle.Caption = guid.Function; // overview.SurfaceGuid = guid; // CreatePage(overview, guid); //} this.FormClosed += (sender, e) => { System.Diagnostics.Process.GetCurrentProcess().Kill(); }; } // 开启界面双缓冲 解决窗体切换闪屏问题 protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } //icon private readonly NotifyIcon _app = null; #region TileNavPane private void tileNavPane_ElementClick(object sender, NavElementEventArgs e) { var tagObj = e.Element.Tag; if (tagObj == null || !(tagObj is string)) return; var tag = tagObj.ToString(); var hitInfo = this.tileNavPane.CalcHitInfo(MousePosition); var buttonInfo = hitInfo.ButtonInfo; if (buttonInfo == null) return; var width = buttonInfo.Location.X; var height = buttonInfo.Bounds.Y + buttonInfo.Bounds.Height; var point = new Point(width, height); switch (tag) { case "MapOverview": { } break; case "SystemConfig": { popSystemConfig.MinWidth = buttonInfo.Bounds.Width; popSystemConfig.ShowPopup(point); } break; case "SystemOrganize": { popSystemOrganize.MinWidth = buttonInfo.Bounds.Width; popSystemOrganize.ShowPopup(point); } break; case "SystemAuthority": { popSystemAuthority.MinWidth = buttonInfo.Bounds.Width; popSystemAuthority.ShowPopup(point); } break; case "Minimize": { this.WindowState = System.Windows.Forms.FormWindowState.Minimized; } break; case "Close": { this.Close(); } break; default: { XtraMessageBox.Show($"未知功能:{tag}"); } break; } } /// /// 设置NvaButton按钮背景 /// /// public void SetNvaButtonAppearance(string tag) { foreach (var btn in this.tileNavPane.Buttons) { if (btn is DevExpress.XtraBars.Navigation.NavButton nb) { if (nb.Tag != null && nb.Tag.ToString() == tag) { nb.Appearance.BackColor = Color.SteelBlue; nb.Appearance.ForeColor = Color.White; } else { nb.Appearance.BackColor = Color.White; nb.Appearance.ForeColor = Color.Black; } } } } #endregion TileNavPane //用水器具 private void barBtnWaterUtensil_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 项目管理 /// private void barBtnProject_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "项目管理", Modular = "" }; if (!IsExistPage(guid, true)) { /* var page = new XhsProjectMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid);*/ } } /// /// 泵管理 /// private void barBtnPumpManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "泵管理", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new PumpProductMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } /// /// 类型管理 /// private void barButtonTypeManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "类型管理", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new SysTypeManageMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } /// /// 分类管理 /// private void BtnCatlogManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "分类管理", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new SysCatalogManageMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } /// /// 属性管理 /// private void BtnPropManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "属性管理", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new SysPropManageMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } //角色管理 private void BarBtnRoleManage_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "角色管理", Modular = "" }; if (!IsExistPage(guid, true)) { /* var page = new MenuMgrMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid);*/ } } /// /// 分区管理 /// private void barBtnPart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 系统类型 /// /// /// private void barBtnSystemType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 设施管理 /// private void barBtnFacilities_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 建筑物 /// /// /// private void barBtnBuilding_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 建筑类型 /// /// /// private void barBtnBuildingType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 厂家管理 /// /// /// private void barBtnSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 员工管理 /// /// /// private void barBtnUser_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var guid = new PageGuid() { Function = "员工管理", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new EmployeeMgrMainPanel(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } /// /// 权限管理 /// /// /// private void barBtnAuthority_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// 日志管理 /// private void barBtnSystemLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } /// /// /// /// /// private void barBtnWaterEquivalent_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { } //是否存在Page private bool IsExistPage(PageGuid sguid, bool isActivateDoc) { if (sguid == null) return false; 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() == sguid.ToString()) { if (isActivateDoc) this.tabbedView1.Controller.Activate(doc); return true; } } } } } return false; } //更新数据 private void RefreshPageData(PageGuid sguid) { if (sguid == null) 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() == sguid.ToString()); if (doc != null) { if (doc.Control is DocumentPage page) { page.RefreshData(); } return; } } } //更新PageTitle private void UpdatePageTitle(PageGuid sguid, PageTitle title) { if (sguid == null || title == null) 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() == sguid.ToString()); if (doc != null) { doc.Caption = title.Caption; doc.ImageOptions.Image = title.HeaderImage; doc.ImageOptions.SvgImage = title.HeaderSvgImage; doc.ImageOptions.SvgImageSize = title.SvgImageSize; if (doc.Control is DocumentPage page) { page.PageTitle = title; } return; } } } //创建Page private bool CreatePage(DocumentPage page, PageGuid sguid) { if (page == null || sguid == null) return false; page.PageGuid = 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(); this.tabbedView1.BeginUpdate(); var doc = this.tabbedView1.AddDocument(page); doc.Footer = Directory.GetCurrentDirectory(); doc.Properties.AllowClose = page.AllowClose() ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False; 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; } else { doc.Caption = page.PageGuid?.Function; } doc.Tag = sguid; this.tabbedView1.EndUpdate(); this.tabbedView1.Controller.Activate(doc); this.tabbedView1.ActivateDocument(doc.Control); page.InitialDataSource(); return true; } //关闭Page private void ClosePage(PageGuid sguid) { 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() == sguid.ToString()); if (doc != null) { var page = doc.Control as DocumentPage; this.tabbedView1.Controller.Close(doc);//会触发正在关闭和关闭事件 } } } //查找page private DocumentPage FindPage(PageGuid 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); if (doc.Control is DocumentPage page) { return page; } return null; } } return null; } //重置所有页面 private void ResetAllPages() { this.tabbedView1.Controller.CloseAll(); } private void GuideMain_Load(object sender, EventArgs e) { var guid = new PageGuid() { Function = "项目总览", Modular = "" }; if (!IsExistPage(guid, true)) { var page = new HomeXhsProjectPage_Bak(); page.PageTitle.Caption = guid.Function; page.PageGuid = guid; CreatePage(page, guid); } } } }