using DevExpress.Utils.Svg; using DevExpress.XtraBars.Docking; using DevExpress.XtraBars.Navigation; using DevExpress.XtraBars.Ribbon; using DevExpress.XtraEditors; using DevExpress.XtraTab; using DevExpress.XtraTab.ViewInfo; using HStation.WinFrmUI; using HStation.WinFrmUI.Assets; using HStation.WinFrmUI.Xhs.PumpProduct; using PBS.WinFrmUI.WE; using System.Drawing.Drawing2D; using System.IO; using Yw.WinFrmUI; using Yw.WinFrmUI.Page; namespace PBS.Desktop { public partial class MainForm : RibbonForm { public MainForm() { InitializeComponent(); this.accordionControlFunction.GroupHeight = 50; this.accordionControlFunction.ItemHeight = 35; this.accordionControlFunction.Appearance.Group.Default.Font = new Font("΢ÈíÑźÚ", 10.5f); this.accordionControlFunction.Appearance.Item.Default.Font = new Font("΢ÈíÑźÚ", 9.5f); this.accordionControlFunction.AllowItemSelection = true; this.accordionControlFunction.Appearance.AccordionControl.BackColor = Color.White; this.accordionControlFunction.Appearance.AccordionControl.BorderColor = Color.White; this.accordionControlFunction.AllowHtmlText = true; this.accordionControlFunction.HtmlTemplates.HamburgerHeaderPanel.Template = @"
"; this.accordionControlFunction.HtmlTemplates.HamburgerHeaderPanel.Styles = @".hamburger-header-background {background-color: #ffffff; height: 100%;width: 100%;}"; this.xtraTabContrl.AllowGlyphSkinning = DevExpress.Utils.DefaultBoolean.True; } private HatchBrush myHatchBrush1 = new HatchBrush(HatchStyle.BackwardDiagonal, Color.LightGray, Color.AliceBlue); private void TabbedView1_CustomDrawTabHeader(object sender, DevExpress.XtraTab.TabHeaderCustomDrawEventArgs e) { e.Cache.FillRectangle(myHatchBrush1, e.Bounds); e.DefaultDrawText(); e.DefaultDrawImage(); e.DefaultDrawButtons(); e.Handled = true; } #region TileNavPane Ïà¹Ø´¦Àí //ÒÆ¶¯´°Ìå private void tileNavPane_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks >= 2) { if (this.WindowState == FormWindowState.Maximized) { this.WindowState = FormWindowState.Normal; } else { this.WindowState = FormWindowState.Maximized; } } else { var hit_info = this.tileNavPane.CalcHitInfo(e.Location); if (hit_info.InButton) { return; } this.DragMove(); } } //±êÌâµã»÷ private void nbTitle_ElementClick(object sender, NavElementEventArgs e) { } //×î´ó»¯×îС»¯´°Ìå private void nbNormal_ElementClick(object sender, NavElementEventArgs e) { if (this.WindowState == FormWindowState.Maximized) { this.WindowState = FormWindowState.Normal; } else { this.WindowState = FormWindowState.Maximized; } } //×îС»¯´°Ìå private void nbMin_ElementClick(object sender, NavElementEventArgs e) { this.WindowState = FormWindowState.Minimized; } //¹Ø±Õ´°Ìå private void nabClose_ElementClick(object sender, NavElementEventArgs e) { this.Close(); } //¹¦Äܵã»÷ʼþ private void tileNavPane_ElementClick(object sender, NavElementEventArgs e) { if (e.Element is not NavButton btn) return; if (!btn.Enabled) return; if (btn.Tag is not string tag) return; PageGuid pguid = null; if (this.xtraTabContrl.SelectedTabPage != null) { pguid = this.xtraTabContrl.SelectedTabPage.Tag as PageGuid; } SelectModular(tag, pguid); } #endregion TileNavPane Ïà¹Ø´¦Àí #region ´°Ìåʼþ //½çÃæ¼ÇÔØÊ¼þ private void MainForm_Load(object sender, EventArgs e) { } //½çÃæÏÔʾʼþ private void MainForm_Shown(object sender, EventArgs e) { //var guid = new PageGuid() //{ // Modular = "PBS", // MoudingType = eMoudingType.Tab, // Function = "Home" //}; //if (!IsExistPage(guid, true)) //{ //} SelectModular("BasicData"); } //½çÃæÕýÔÚÍ˳öʱȷÈÏ 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; } } } //½çÃæÍ˳ö private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { } //´°Ìå³ß´ç¸Ä±ä private void MainForm_Resize(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Maximized) { } else { } } #endregion ´°Ìåʼþ #region TabbedView Ïà¹ØÊ¼þ´¦Àí³ÌÐò //Ñ¡ÖÐ private void xtraTabContrl_SelectedPageChanged(object sender, TabPageChangedEventArgs e) { if (e.Page == null) return; var pguid = e.Page.Tag as PageGuid; if (pguid == null) return; SelectModular(pguid.Modular, pguid); } //¹Ø±Õ private void xtraTabContrl_CloseButtonClick(object sender, EventArgs e) { var arg = e as ClosePageButtonEventArgs; var last_index = this.xtraTabContrl.SelectedTabPageIndex - 1; this.xtraTabContrl.TabPages.Remove(arg.Page as XtraTabPage); if (last_index > 0) { this.xtraTabContrl.SelectedTabPageIndex = last_index; } } #endregion TabbedView Ïà¹ØÊ¼þ´¦Àí³ÌÐò #region Page //ÊÇ·ñ´æÔÚPage private 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.xtraTabContrl.TabPages != null && this.xtraTabContrl.TabPages.Count > 0) { foreach (XtraTabPage doc in this.xtraTabContrl.TabPages) { if (doc.Tag != null) { if (doc.Tag is PageGuid) { if ((doc.Tag as PageGuid).ToString() == pguid.ToString()) { if (isActivePage) { this.xtraTabContrl.SelectedTabPage = doc; } return true; } } } } } return false; } //¸üÐÂÊý¾Ý private 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.xtraTabContrl.TabPages != null && this.xtraTabContrl.TabPages.Count > 0) { var doc = this.xtraTabContrl.TabPages.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString()); if (doc != null) { var page = doc.Controls[0] as DocumentPage; if (page != null) { page.RefreshData(); } return; } } } //¸üÐÂPageTitle private 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.xtraTabContrl.TabPages != null && this.xtraTabContrl.TabPages.Count > 0) { var doc = this.xtraTabContrl.TabPages.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString()); if (doc != null) { doc.Text = title.Caption; doc.ImageOptions.Image = title.HeaderImage; doc.ImageOptions.SvgImage = title.HeaderSvgImage; doc.ImageOptions.SvgImageSize = title.SvgImageSize; var page = doc.Controls[0] as DocumentPage; if (page != null) { page.PageTitle = title; } return; } } } //´´½¨Page private 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: { var sel_page = new XtraTabPage(); page.Dock = DockStyle.Fill; sel_page.Controls.Add(page); this.xtraTabContrl.TabPages.Add(sel_page); if (page.PageTitle != null) { sel_page.Text = page.PageTitle.Caption; sel_page.ImageOptions.Image = page.PageTitle.HeaderImage; sel_page.ImageOptions.SvgImage = page.PageTitle.HeaderSvgImage; sel_page.ImageOptions.SvgImageSize = page.PageTitle.SvgImageSize; //doc.Properties.AllowClose = page.PageTitle.AllowClose ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False; } sel_page.Tag = pguid; this.xtraTabContrl.SelectedTabPage = sel_page; } break; default: break; } page.InitialDataSource(); return true; } //¹Ø±ÕPage private 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.xtraTabContrl.TabPages != null && this.xtraTabContrl.TabPages.Count > 0) { var doc = this.xtraTabContrl.TabPages.ToList().Find(x => x.Tag != null && x.Tag is PageGuid && (x.Tag as PageGuid).ToString() == pguid.ToString()); if (doc != null) { this.xtraTabContrl.TabPages.Remove(doc); } } } break; default: break; } } #endregion Page #region Modular private string _sel_modular = string.Empty; //Ñ¡ÔñÄ£¿é private void SelectModular(string modular, PageGuid pguid = null) { if (_sel_modular != modular) { foreach (NavButton btn in this.tileNavPane.Buttons) { if (btn.Tag == null) continue; if (btn.Tag is string tag) { if (tag == modular) { btn.Appearance.BackColor = Color.FromArgb(50, 121, 197); btn.Appearance.ForeColor = Color.White; } else { btn.Appearance.BackColor = Color.White; btn.Appearance.ForeColor = Color.Black; } } } //³õʼ¹¦ÄÜÁбí this.accordionControlFunction.Elements.Clear(); var list = GetAccordionElementList(modular); if (list != null && list.Count > 0) { foreach (var element in list) { var accEle = GetAccordionControlElement(element); this.accordionControlFunction.Elements.Add(accEle); } } _sel_modular = modular; } //Ñ¡Ôñ¹¦ÄÜ if (pguid != null) { foreach (var item in this.accordionControlFunction.Elements) { if (SelectAccordionControlElement(item, pguid)) break; } } } //»ñȡģ¿éÔªËØ private DevExpress.XtraBars.Navigation.AccordionControlElement GetAccordionControlElement(AccordionElement ele) { var dev_ele = new DevExpress.XtraBars.Navigation.AccordionControlElement(); dev_ele.Name = ele.Id; dev_ele.Text = ele.Caption; dev_ele.Image = ele.Image; dev_ele.ImageOptions.SvgImage = ele.SvgImage; dev_ele.ImageOptions.SvgImageSize = ele.SvgImageSize; dev_ele.AllowGlyphSkinning = ele.AllowGlyphSkinning ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False; dev_ele.Tag = ele; dev_ele.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; dev_ele.Click += delegate { ele.Click?.Invoke(); }; if (ele.Elements != null && ele.Elements.Count > 0) { dev_ele.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; foreach (var item in ele.Elements) { dev_ele.Elements.Add(GetAccordionControlElement(item)); } } return dev_ele; } //Ñ¡Ôñ¹¦ÄÜÔªËØ private bool SelectAccordionControlElement(DevExpress.XtraBars.Navigation.AccordionControlElement ctrl_ele, PageGuid pguid) { if (ctrl_ele == null) return false; if (pguid == null) return false; if (ctrl_ele.Tag is AccordionElement ele) { if (ele.PageGuid != null && ele.PageGuid.ToString() == pguid.ToString()) { this.accordionControlFunction.SelectedElement = ctrl_ele; if (ctrl_ele.OwnerElement != null) { ctrl_ele.OwnerElement.Expanded = true; this.accordionControlFunction.Refresh(); } return true; } else { if (ctrl_ele.Elements != null && ctrl_ele.Elements.Count > 0) { foreach (var item in ctrl_ele.Elements) { SelectAccordionControlElement(item, pguid); } } } } return false; } //»ñÈ¡ private List GetAccordionElementList(string modular) { var list = new List(); if (modular == "BasicData") { var place_mgr_ele = new AccordionElement() { Id = "place", Caption = "³¡Ëù¹ÜÀí", SvgImage = svgImgGroup32[0], SvgImageSize = new Size(24, 24), AllowGlyphSkinning = true, Elements = new List() { Get("ÐÐÕþÇøÓò",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "DistrictMgr", }, svgImgItem32[0], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page = new DocumentPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page, guid); } }), Get("³¡Ëù½¨Öþ",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "PlaceMgr", }, svgImgItem32[1], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page = new DocumentPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page, guid); } }), Get("³¡ËùÉèÊ©", new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "FacilityMgr", }, svgImgItem32[2], new Size(18, 18), (caption, guid, svg, size) => { if (!IsExistPage(guid, true)) { var page = new DocumentPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page, guid); } }) } }; var we_mgr_ele = new AccordionElement() { Id = "we", Caption = "µ±Á¿¹ÜÀí", SvgImage = svgImgGroup32[1], SvgImageSize = new Size(24, 24), AllowGlyphSkinning = true, Elements = new List() { Get("ÓÃË®Æ÷¾ß",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "WaterUtensilMgr", }, svgImgItem32[4], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page=new WaterUtensilMainPage(); CreatePage(page, guid); } }), Get("ÓÃË®µ±Á¿",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "WaterWEMgr", }, svgImgItem32[5], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page=new WaterWEMgr(); CreatePage(page, guid); } }) } }; var asset_mgr_ele = new AccordionElement() { Id = "asset", Caption = "²úÆ·¹ÜÀí", SvgImage = svgImgGroup32[2], SvgImageSize = new Size(24, 24), AllowGlyphSkinning = true, Elements = new List() { Get("³§É̹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "AssetsManufacturerMgr", }, svgImgItem32[6], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page=new AssetsManufacturerMainPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page,guid); } }), Get("Ë®±Ã¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "AssetsPumpMgr", }, svgImgItem32[7], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page=new PumpProductMainPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page,guid); } }), Get("³ÉÌ×É豸",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "AssetsKitMgr", }, svgImgItem32[8], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { var page=new PackageManageMainPage(); page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = size; CreatePage(page,guid); } }) } }; var system_config_ele = new AccordionElement() { Id = "asset", Caption = "ϵͳÅäÖÃ", SvgImage = svgImgGroup32[3], SvgImageSize = new Size(24, 24), AllowGlyphSkinning = true, Elements = new List() { Get("ÀàÐ͹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "SystemTypeMgr", }, svgImgItem32[9], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), Get("·ÖÀà¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "SystemCatalogMgr", }, svgImgItem32[10], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), Get("ÊôÐÔ¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "SystemPropMgr", }, svgImgItem32[11], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), Get("×ÖµäÀàÐÍ",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "SystemDictMgr", }, svgImgItem32[12], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), } }; var auth_config_ele = new AccordionElement() { Id = "asset", Caption = "ȨÏÞÅäÖÃ", SvgImage = svgImgGroup32[4], SvgImageSize = new Size(24, 24), AllowGlyphSkinning = true, Elements = new List() { Get("½ÇÉ«¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "RoleMgr", }, svgImgItem32[13], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), Get("Óû§¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "UserMgr", }, svgImgItem32[14], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), Get("²Ëµ¥¹ÜÀí",new PageGuid() { Modular = "BasicData", MoudingType = eMoudingType.Tab, Function = "MenuMgr", }, svgImgItem32[15], new Size(18, 18), (caption,guid,svg,size) => { if (!IsExistPage(guid, true)) { } }), } }; list.Add(place_mgr_ele); list.Add(we_mgr_ele); list.Add(asset_mgr_ele); list.Add(system_config_ele); list.Add(auth_config_ele); } return list; } private AccordionElement Get(string caption, PageGuid guid, SvgImage svg_img, Size size, Action action, bool glyph_skinning = true) { var ele = new AccordionElement(); if (guid == null) { ele.Id = Guid.NewGuid().ToString(); } else { ele.Id = guid.ToString(); ele.Click = delegate { action(caption, guid, svg_img, size); }; } ele.PageGuid = guid; ele.Caption = caption; ele.SvgImage = svg_img; ele.SvgImageSize = size; ele.AllowGlyphSkinning = glyph_skinning; return ele; } #endregion Modular } }