lixiaojun
2024-10-29 cc89c6b8112cfccd270951a9177c6ac0e5307d79
Desktop/HStation.DeskTop.Xhs.Main/GuideMain.cs
@@ -2,6 +2,11 @@
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;
@@ -58,10 +63,12 @@
                return cp;
            }
        }
        //icon
        readonly NotifyIcon _app = null;
        private readonly NotifyIcon _app = null;
        #region TileNavPane
        private void tileNavPane_ElementClick(object sender, NavElementEventArgs e)
        {
            var tagObj = e.Element.Tag;
@@ -80,31 +87,42 @@
            {
                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}");
@@ -127,29 +145,133 @@
                    {
                        nb.Appearance.BackColor = Color.SteelBlue;
                        nb.Appearance.ForeColor = Color.White;
                    }
                    else
                    {
                        nb.Appearance.BackColor = Color.White;
                        nb.Appearance.ForeColor = Color.Black;
                    }
                }
            }
        }
        #endregion
        #endregion TileNavPane
        //用水器具
        private void barBtnWaterUtensil_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
        /// 项目管理
        /// </summary>
        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);*/
            }
        }
        /// <summary>
        /// 泵管理
        /// </summary>
        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);
            }
        }
        /// <summary>
        /// 类型管理
        /// </summary>
        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);
            }
        }
        /// <summary>
        /// 分类管理
        /// </summary>
        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);
            }
        }
        /// <summary>
        /// 属性管理
        /// </summary>
        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);*/
            }
        }
        /// <summary>
@@ -157,17 +279,15 @@
        /// </summary>
        private void barBtnPart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
       /// <summary>
       /// 系统类型
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        /// <summary>
        /// 系统类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnSystemType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
@@ -175,7 +295,6 @@
        /// </summary>
        private void barBtnFacilities_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
@@ -185,7 +304,6 @@
        /// <param name="e"></param>
        private void barBtnBuilding_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
@@ -195,7 +313,6 @@
        /// <param name="e"></param>
        private void barBtnBuildingType_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
@@ -205,27 +322,36 @@
        /// <param name="e"></param>
        private void barBtnSupplier_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
        /// 用户管理
        /// 员工管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);
            }
        }
        /// <summary>
        /// 权限管理
        /// 权限管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void barBtnAuthority_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
@@ -233,18 +359,186 @@
        /// </summary>
        private void barBtnSystemLog_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
        }
        /// <summary>
        ///
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);
            }
        }
    }
}