using DevExpress.Utils.Svg; using DevExpress.XtraBars.Docking; using DevExpress.XtraBars.Docking2010.Views; using DevExpress.XtraBars.Navigation; using DevExpress.XtraEditors; using HStation.WinFrmUI; using HStation.WinFrmUI.Assets; using HStation.WinFrmUI.Basic; using HStation.WinFrmUI.Dict; using PBS.WinFrmUI; using PBS.WinFrmUI.Box; using PBS.WinFrmUI.DataAnalysis; using PBS.WinFrmUI.Hydro; using PBS.WinFrmUI.WE; using Yw.WinFrmUI; using Yw.WinFrmUI.Page; namespace PBS.Desktop { public partial class MainForm : XtraForm { public MainForm() { InitializeComponent(); InitializeStyle(); InitializeEvents(); InitializeMenus(); } protected override FormShowMode ShowMode { get { return FormShowMode.AfterInitialization; } } #region Initialize private void InitializeStyle() { this.nbMinimize.SuperTip = new DevExpress.Utils.SuperToolTip(); this.nbMinimize.SuperTip.Items.Add(new DevExpress.Utils.ToolTipItem() { Text = "最小化" }); this.nbRestore.SuperTip = new DevExpress.Utils.SuperToolTip(); this.nbRestore.SuperTip.Items.Add(new DevExpress.Utils.ToolTipItem() { Text = "恢复" }); this.nbClose.SuperTip = new DevExpress.Utils.SuperToolTip(); this.nbClose.SuperTip.Items.Add(new DevExpress.Utils.ToolTipItem() { Text = "关闭" }); this.accordionControl.GroupHeight = 40; this.accordionControl.ItemHeight = 40; this.accordionControl.Appearance.Group.Default.Font = new Font("微软雅黑", 10.5f); this.accordionControl.Appearance.Item.Default.Font = new Font("微软雅黑", 10.5f); this.accordionControl.AllowItemSelection = true; this.accordionControl.AllowHtmlText = true; this.accordionControl.HtmlTemplates.HamburgerHeaderPanel.Template = @"
"; this.accordionControl.HtmlTemplates.HamburgerHeaderPanel.Styles = @".hamburger-header-background {background-color: #ffffff; height: 100%;width: 100%;}"; this.tabbedView1.Appearance.BackColor = Color.White; this.tabbedView1.AppearancePage.Header.BackColor = Color.White; this.tabbedView1.AppearancePage.Header.BorderColor = Color.White; this.tabbedView1.AppearancePage.Header.ForeColor = SystemColors.Highlight; this.tabbedView1.AppearancePage.Header.Options.UseBackColor = true; this.tabbedView1.AppearancePage.Header.Options.UseBorderColor = true; this.tabbedView1.AppearancePage.Header.Options.UseForeColor = true; this.tabbedView1.AppearancePage.HeaderSelected.FontStyleDelta = FontStyle.Bold; this.tabbedView1.AppearancePage.HeaderSelected.ForeColor = SystemColors.HotTrack; this.tabbedView1.AppearancePage.HeaderSelected.Options.UseFont = true; this.tabbedView1.AppearancePage.HeaderSelected.Options.UseForeColor = true; this.tabbedView1.DocumentProperties.AllowGlyphSkinning = true; this.tabbedView1.DocumentProperties.ShowPinButton = false; this.tabbedView1.Style = DevExpress.XtraBars.Docking2010.Views.DockingViewStyle.Light; this.tabbedView1.DocumentGroupProperties.ShowDocumentSelectorButton = false; //this.tabbedView1.DocumentGroupProperties.ShowTabHeader = false; } private void InitializeEvents() { this.Load += MainForm_Load; this.Shown += MainForm_Shown; this.FormClosing += MainForm_FormClosing; this.FormClosed += MainForm_FormClosed; this.Resize += MainForm_Resize; this.tileNavPane.ElementClick += TileNavPane_ElementClick; this.tileNavPane.MouseDown += TileNavPane_MouseDown; this.nbMinimize.ElementClick += NbMinimize_ElementClick; this.nbRestore.ElementClick += NbRestore_ElementClick; this.nbClose.ElementClick += NbClose_ElementClick; this.tabbedView1.DocumentSelected += TabbedView1_DocumentSelected; this.tabbedView1.DocumentAdded += TabbedView1_DocumentAdded; this.tabbedView1.DocumentActivated += TabbedView1_DocumentActivated; this.tabbedView1.DocumentClosed += TabbedView1_DocumentClosed; } private void InitializeMenus() { _menuTempSvg= svgImgDefault[0]; var menus = new List(); menus.Add(GetHomeMenus()); menus.Add(GetHardwareMgrMenus()); menus.Add(GetDataAnalysisMgrMenus()); menus.Add(GetDataMgrMenus()); menus.Add(GetAuthorityMgrMenus()); var list = new List(); foreach (var menu in menus) { var ele = ConvertControlElement(menu); ele.Height = 60; list.Add(ele); } this.navigationGroup.Elements.AddRange(list.ToArray()); } #region Menus 硬编码 private SvgImage _menuTempSvg =null; private readonly Size _menuModularSvgSize = new(24, 24); private readonly Size _menuSvgSize = new(18, 18); #region HomeMenus private AccordionElement GetHomeMenus() { var modular = "Home"; var group = GetElementGroup("主页", svgImgModular[0], _menuModularSvgSize); group.Elements.Add(GetElementItem("地图信息", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new HomePbsProjectPage()); })); group.Elements.Add(GetModelMenus(modular)); group.Elements.Add(GetModelAnalysisMenus(modular)); return group; } #region ModelMenus private AccordionElement GetModelMenus(string modular) { var group = GetElementGroup("模型管理", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("水力场景", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { TipFormHelper.ShowInfo("功能待开发!"); })); group.Elements.Add(GetElementItem("模型模版", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ModelTemplatePage()); })); group.Elements.Add(GetElementItem("快速建模", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ModelTemplatePage()); })); group.Elements.Add(GetElementItem("模型编辑", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ModelEditPage()); })); return group; } #endregion #region ModelAnalysisMenus private AccordionElement GetModelAnalysisMenus(string modular) { var group = GetElementGroup("模型分析", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("系统曲线", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new SystemCurvePage()); })); group.Elements.Add(GetElementItem("水量预测", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { TipFormHelper.ShowInfo("功能待开发!"); })); group.Elements.Add(GetElementItem("运行评估", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { TipFormHelper.ShowInfo("功能待开发!"); })); return group; } #endregion #endregion #region HardwareMgrMenus private AccordionElement GetHardwareMgrMenus() { var modular = "HardwareMgr"; var group = GetElementGroup("硬件管理", svgImgModular[1], _menuModularSvgSize); group.Elements.Add(GetElementItem("硬件详情", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new IBoxInfoMgr()); })); group.Elements.Add(GetHardwareMonitorMenus(modular)); group.Elements.Add(GetHardwareConfigMenus(modular)); return group; } #region HardwareMonitorMenus private AccordionElement GetHardwareMonitorMenus(string modular) { var list = new List(); var group = GetElementGroup("监测分析", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("实时监测", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new MonitorMgr()); })); group.Elements.Add(GetElementItem("能耗分析", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AnalysisMgr()); })); return group; } #endregion #region HardwareConfigMenus private AccordionElement GetHardwareConfigMenus(string modular) { var list = new List(); var group = GetElementGroup("配置管理", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("基础信息", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new BasicInfoMgr()); })); group.Elements.Add(GetElementItem("协议配置", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ProtocolMgr()); })); group.Elements.Add(GetElementItem("监测配置", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new MonitorConfigurationMgr()); })); group.Elements.Add(GetElementItem("数据处理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new DataFilter()); })); group.Elements.Add(GetElementItem("参数配置", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ParameterMgr()); })); group.Elements.Add(GetElementItem("日志管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new LogManagentMgr()); })); return group; } #endregion #endregion #region DataAnalysisMgrMenus private AccordionElement GetDataAnalysisMgrMenus() { var modular = "DataAnalysisMgr"; var group = GetElementGroup("数据分析", svgImgModular[2], _menuModularSvgSize); group.Elements.Add(GetElementItem("能耗分析", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new EnergyAnalysis()); })); group.Elements.Add(GetElementItem("流量压力比对分析", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new FlowPressAnalysis()); })); group.Elements.Add(GetElementItem("末端压力分析", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new EndPressAnalysis()); })); return group; } #endregion #region DataMgrMenus private AccordionElement GetDataMgrMenus() { var modular = "DataMgr"; var group = GetElementGroup("数据管理", svgImgModular[3], _menuModularSvgSize); group.Elements.Add(GetPlaceMenus(modular)); group.Elements.Add(GetWEMenus(modular)); group.Elements.Add(GetAssetsMenus(modular)); group.Elements.Add(GetSystemConfigMenus(modular)); return group; } #region PlaceMenus private AccordionElement GetPlaceMenus(string modular) { var list = new List(); var group = GetElementGroup("场所管理", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("区域", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new DivisionMainPage()); })); group.Elements.Add(GetElementItem("场所", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new PlaceMgrPage()); })); group.Elements.Add(GetElementItem("设施", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new FacilityMgrPage()); })); return group; } #endregion #region WEMenus private AccordionElement GetWEMenus(string modular) { var group = GetElementGroup("当量管理", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("用水器具", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new WaterUtensilMainPage()); })); group.Elements.Add(GetElementItem("用水当量", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new WaterWEMgr()); })); return group; } #endregion #region AssetsMenus private AccordionElement GetAssetsMenus(string modular) { var group = GetElementGroup("产品管理", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("厂商", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsManufacturerMainPage()); })); group.Elements.Add(GetAssetsCouplingMenus(modular)); group.Elements.Add(GetAssetsEmitterMenus(modular)); group.Elements.Add(GetAssetsInstrumentMenus(modular)); group.Elements.Add(GetAssetsResistanceMenus(modular)); group.Elements.Add(GetAssetsWaterSupplySourceMenus(modular)); group.Elements.Add(GetAssetsWaterSupplyMenus(modular)); group.Elements.Add(GetAssetsNetworkMenus(modular)); return group; } private AccordionElement GetAssetsCouplingMenus(string modular) { var group = GetElementGroup("连接件", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("闷头", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsBluntheadMgrPage()); })); group.Elements.Add(GetElementItem("弯头", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsElbowMgrPage()); })); group.Elements.Add(GetElementItem("三通", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsThreelinkMgrPage()); })); group.Elements.Add(GetElementItem("四通", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsFourlinkMgrPage()); })); return group; } private AccordionElement GetAssetsEmitterMenus(string modular) { var group = GetElementGroup("扩散器", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("喷头", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsSprinklerMgrPage()); })); group.Elements.Add(GetElementItem("消火栓", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsHydrantMgrPage()); })); group.Elements.Add(GetElementItem("冷却塔", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsCoolingMgrPage()); })); return group; } private AccordionElement GetAssetsInstrumentMenus(string modular) { var group = GetElementGroup("仪器仪表", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("水表", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsMeterMgrPage()); })); group.Elements.Add(GetElementItem("压力表", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsPressmeterMgrPage()); })); group.Elements.Add(GetElementItem("流量计", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsFlowmeterMgrPage()); })); return group; } private AccordionElement GetAssetsResistanceMenus(string modular) { var group = GetElementGroup("阻件", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("换热器", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsExchangerMgrPage()); })); group.Elements.Add(GetElementItem("压缩机", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsCompressorMgrPage()); })); return group; } private AccordionElement GetAssetsWaterSupplySourceMenus(string modular) { var group = GetElementGroup("供水水源", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("水池", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsTankMgrPage()); })); return group; } private AccordionElement GetAssetsWaterSupplyMenus(string modular) { var group = GetElementGroup("供水装置", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("水泵", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new PumpProductMainPage()); })); group.Elements.Add(GetElementItem("成套设备", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new PackageManageMainPage()); })); return group; } private AccordionElement GetAssetsNetworkMenus(string modular) { var group = GetElementGroup("管网设施", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("管道", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsPipeMgrPage()); })); group.Elements.Add(GetElementItem("阀门", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsValveMgrPage()); })); group.Elements.Add(GetElementItem("过渡件", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new AssetsTranslationMgrPage()); })); return group; } #endregion #region SystemConfigMenus private AccordionElement GetSystemConfigMenus(string modular) { var group = GetElementGroup("系统配置", _menuTempSvg, _menuSvgSize); group.Elements.Add(GetElementItem("类型管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new SysTypeManageMainPanel()); })); group.Elements.Add(GetElementItem("分类管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new SysCatalogManageMainPanel()); })); group.Elements.Add(GetElementItem("属性管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new SysPropManageMainPanel()); })); group.Elements.Add(GetElementItem("标签管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new SysFlagManageMainPanel()); })); group.Elements.Add(GetElementItem("字典类型", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new DictManageMainPanel()); })); group.Elements.Add(GetElementItem("电费配置", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new ElecPriceMgr()); })); group.Elements.Add(GetElementItem("供水设备", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new WaterEquipmentMgr()); })); return group; } #endregion #endregion #region AuthorityMgrMenus private AccordionElement GetAuthorityMgrMenus() { var modular = "AuthorityMgr"; var group = GetElementGroup("权限管理", svgImgModular[4], _menuModularSvgSize); group.Elements.Add(GetElementItem("用户管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new UserMgrPage()); })); group.Elements.Add(GetElementItem("角色管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new RoleMgrPage()); })); group.Elements.Add(GetElementItem("菜单管理", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new MenuMgrPage()); })); group.Elements.Add(GetElementItem("角色菜单", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new RoleProjectMenuPage()); })); group.Elements.Add(GetElementItem("用户日志", modular, _menuTempSvg, _menuSvgSize, (caption, guid, svg, svgSize) => { ElementClickEvent(caption, guid, svg, svgSize, new UserLoginLogPage()); })); group.Elements.Add(GetElementItem("个人中心", modular, _menuTempSvg, _menuSvgSize, () => { var dlg = new PersonalCenterDlg(); dlg.ShowDialog(); })); return group; } #endregion #region Convert private AccordionElement GetElementGroup(string caption, SvgImage svg, Size svgSize, bool allowGlyphSkinning = true) { var ele = new AccordionElement(); ele.Id = Guid.NewGuid().ToString(); ele.Caption = caption; ele.SvgImage = svg; ele.SvgImageSize = svgSize; ele.AllowGlyphSkinning = allowGlyphSkinning; ele.Elements = new List(); return ele; } private AccordionElement GetElementItem(string caption, string modular, SvgImage svg, Size svgSize, Action action, bool isNormallyOpen = false, bool allowGlyphSkinning = true) { var id = Guid.NewGuid().ToString(); var guid = new PageGuid() { Modular = modular, Function = caption + id, MoudingType = eMoudingType.Tab, }; var ele = new AccordionElement(); ele.Id = id; ele.Click += delegate { action(caption, guid, svg, svgSize); }; ele.PageGuid = guid; ele.Caption = caption; ele.SvgImage = svg; ele.SvgImageSize = svgSize; ele.IsNormallyOpen = isNormallyOpen; ele.AllowGlyphSkinning = allowGlyphSkinning; return ele; } private AccordionElement GetElementItem(string caption, string modular, SvgImage svg, Size svgSize, Action action, bool allowGlyphSkinning = true) { var id = Guid.NewGuid().ToString(); var ele = new AccordionElement(); ele.Id = id; ele.Click += delegate { action(); }; ele.Caption = caption; ele.SvgImage = svg; ele.SvgImageSize = svgSize; ele.IsNormallyOpen = false; ele.AllowGlyphSkinning = allowGlyphSkinning; return ele; } private void ElementClickEvent(string caption, PageGuid guid, SvgImage svg, Size svgSize, DocumentPage page) { if (!IsExistPage(guid, true)) { page.PageGuid = guid; page.PageTitle.Caption = caption; page.PageTitle.HeaderSvgImage = svg; page.PageTitle.SvgImageSize = svgSize; CreatePage(page, guid); } } //获取模块元素 private DevExpress.XtraBars.Navigation.AccordionControlElement ConvertControlElement(AccordionElement ele) { var controlElement = new DevExpress.XtraBars.Navigation.AccordionControlElement(); controlElement.Name = ele.Id; controlElement.Text = ele.Caption; controlElement.Image = ele.Image; controlElement.ImageOptions.SvgImage = ele.SvgImage; controlElement.ImageOptions.SvgImageSize = ele.SvgImageSize; controlElement.AllowGlyphSkinning = ele.AllowGlyphSkinning ? DevExpress.Utils.DefaultBoolean.True : DevExpress.Utils.DefaultBoolean.False; controlElement.Tag = ele; controlElement.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; controlElement.Click += delegate { ele.Click?.Invoke(); }; controlElement.Enabled = ele.Enable; ele.EnableChangedEvent += (bol) => { controlElement.Enabled = bol; }; if (ele.Elements != null && ele.Elements.Count > 0) { controlElement.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; foreach (var item in ele.Elements) { controlElement.Elements.Add(ConvertControlElement(item)); } var tip = new DevExpress.Utils.ToolTipItem(); tip.AllowHtmlText = DevExpress.Utils.DefaultBoolean.True; tip.Text = $"{ele.Caption}"; controlElement.SuperTip = new(); controlElement.SuperTip.Items.Add(tip); } return controlElement; } #endregion #endregion #endregion #region MainForm //界面记载事件 private void MainForm_Load(object sender, EventArgs e) { } //界面显示事件 private void MainForm_Shown(object sender, EventArgs e) { } //界面正在退出时确认 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) { } #endregion #region TileNavPane //移动窗体 private void TileNavPane_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks >= 2) { this.WindowState = this.WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized; } else { var hitInfo = this.tileNavPane.CalcHitInfo(e.Location); if (hitInfo.InButton) return; this.DragMove(); } } //功能点击事件 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.tabbedView1.ActiveDocument != null) //{ // pguid = this.tabbedView1.ActiveDocument.Tag as PageGuid; //} } // 最小化窗体 private void NbMinimize_ElementClick(object sender, NavElementEventArgs e) { this.WindowState = FormWindowState.Minimized; } // 还原窗体 private void NbRestore_ElementClick(object sender, NavElementEventArgs e) { this.WindowState = this.WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized; } // 关闭窗体 private void NbClose_ElementClick(object sender, NavElementEventArgs e) { this.Close(); } #endregion #region TabbedView //选中 private void TabbedView1_DocumentSelected(object sender, DocumentEventArgs e) { //if (e.Document == null) // return; //var pguid = e.Document.Tag as PageGuid; //if (pguid == null) // return; } //添加 private void TabbedView1_DocumentAdded(object sender, DocumentEventArgs e) { //if (this.tabbedView1.Documents.Count > 1) //{ // if (!this.tabbedView1.DocumentGroupProperties.ShowTabHeader) // { // } //} } //激活 private void TabbedView1_DocumentActivated(object sender, DocumentEventArgs e) { //var page = e.Document.Control as DocumentPage; //if (page == null) //{ // return; //} } //关闭 此时控件已经为空 private void TabbedView1_DocumentClosed(object sender, DocumentEventArgs e) { } #endregion #region DocumentPage //是否存在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.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 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 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 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 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; } } #endregion } }