⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmain.cs

📁 基于C/S的医疗卫生管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

using Qeb.Support;
using Qeb.Support.Common;
using Qeb.Support.UI;
using Qeb.Resource;
using Qeb.Control;
using Qeb.DBProxy;

namespace Qeb.GY
{
    public partial class FMain : Qeb.Control.FBase,IMainForm
    {
        public FMain()
        {
            InitializeComponent();
        }

        private void Exit(bool prompt)
        {
            this.Close();
            Application.Exit();
        }

        private void FMain_Load(object sender, EventArgs e)
        {
            this.Hide();
            if (ShowLogon())
            {
                this.Show();
                if ( !InitUI())
                {
                    this.Exit(false);
                }
            }
            else
            {
                this.Exit(false);    
            }
        }

        #region 初始化界面
        private bool InitUI()
        {
            try
            {
                this.Size = new Size(1024, 740);
                if (InitMenu() != Define.Succeed)
                {
                    return false;
                }

                lbAppName.Text = App.yyMc;
                this.SizeGripStyle = SizeGripStyle.Hide;
                //this.VerticalScroll.Visible = false;
                SetStatusStrip();
                this.lbUser.Text = "当前用户:"+App.yhMc;
                return true;
            }
            catch(Exception ex)
            {
                MessageBox.Show("初始化界面出错:" + ex.Message, MsgTitle.Error);
                return false;
            }

        }
        #endregion

        #region SetStatusStrip
        private void SetStatusStrip()
        {
            StatusStrip1.Items.Add("杭州掌幄科技有限公司版权所有");
            StatusStrip1.Items.Add(" | ");
            StatusStrip1.Items.Add("登陆时间:" + App.logonTime);
        }
        #endregion

        #region 调用登陆窗口
        private bool ShowLogon()
        {
            try
            {
                FLogon fLogon = new FLogon();

                DialogResult ret = fLogon.ShowDialog();
                fLogon.Dispose();
                if (ret == DialogResult.OK)
                    return true;
                else
                    return false;
            }
            catch(Exception ex)
            {
                MessageBox.Show("调用登陆窗口发生异常:" + ex.Message, MsgTitle.Error);
                return false;
            }
        }
        #endregion

        #region 菜单相关
        private QButton[] m_MenuBtn;
        private int m_MenuBtnStartIndex = 0;
        private int m_ShowMenuBtnCount = 8;
        private int m_MenuBtnWidth = 100;
        private int m_MenuBtnHeight = 40;

        private int InitMenu()
        {
            #region 
            try
            {
                btnRight.Location = new Point(btnLeft.Location.X + btnLeft.Width + 1 + (m_MenuBtnWidth + 1) * m_ShowMenuBtnCount, btnRight.Location.Y);
                btnRight.Size = btnLeft.Size;

                AddMenu();
                if (m_MenuBtn != null && m_MenuBtn.Length > m_ShowMenuBtnCount)
                {
                    btnRight.Visible = true;
                    btnLeft.Visible = true;
                }
                else
                {
                    btnLeft.Width = 0;
                    btnRight.Visible = false;
                    btnLeft.Visible = false;
                }

                SetMenuBtnLocation();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,MsgTitle.Error);
                return Define.Failed;
            }

            return Define.Succeed;
            #endregion
        }

        //添加菜单
        private void AddMenu()
        {
            QDataStore dsAppMenu = null;
            QDataStore dsAppMenuModule = null;

            DataTable dtAppMenu = null; 
            try
            {
                DbProxyClient proxy = new DbProxyClient();

                dsAppMenu = this.GetAppMenuData(proxy);
                //没有数据,不需要处理
                if (dsAppMenu == null || dsAppMenu.RowCount == 0)
                {
                    throw new Exception("没有取到菜单数据,不能加载加菜单,请联系信息中心!");
                }
                else
                {
                    dtAppMenu = dsAppMenu.CovertToDataTable();
                }

                dsAppMenuModule = this.GetAppMenuModuleData(proxy);

                ArrayList btnList = new ArrayList();

                //根级菜单
                dsAppMenu.SetFilter("SjCdId='0' AND MkId='0'");
                dsAppMenu.Filter();
                dsAppMenu.SetSort("PxXh ASC");
                dsAppMenu.Sort();
                string menuId = "";
                for(int i=1;i<dsAppMenu.RowCount+1;i++)
                {
                    QButton btn = new QButton();
                    //Id
                    menuId = dsAppMenu.GetItemString(i,"CdId");
                    btn.Name = "menuBtn" + menuId;
                    //文字
                    if (dsAppMenu.IsItemNull(i, "CdWz"))
                        btn.Text = "Error";
                    else
                        btn.Text = dsAppMenu.GetItemString(i,"CdWz");

                    btn.Arrow = QButton.arrow.ToDown;
                    btn.Size = new Size(m_MenuBtnWidth, m_MenuBtnHeight);
                    btn.ShowBase = QButton.showbase.No;
                    btn.clickShowContextMenu = true;

                    btn.ImageLocation = QButton.imagelocation.Left;
                    btn.ImageOffset = 4;
                    btn.MaxImageSize = new Point(28, 28);

                    //菜单图标
                    if (!dsAppMenu.IsItemNull(i,"CdTbMc"))
                    {
                        btn.Image = Resource.Resource.GetImage(dsAppMenu.GetItemString(i, "CdTbMc"));
                        if (btn.Image == null)
                        {
                            Qeb.Support.Common.AppLog.Add(new AppError("没有取到资源:" + dsAppMenu.GetItemString(i,"MenuIconName"), this.GetType()));
                        }
                    }

                    if (btn.Image == null)
                    {
                        //取默认的图片
                        btn.Image = Resource.Resource.GetImage("MenuBtn_Default");
                    }


                    ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
                    contextMenuStrip.Name = "menu" + menuId;

                    AddSubMenu(contextMenuStrip, null, dtAppMenu, dsAppMenuModule, menuId);
                    if (contextMenuStrip.Items.Count == 0)
                    {
                        //根级菜单下没有子菜单,则不显示根级菜单
                        continue;
                    }

                    btn.ContextMenuStrip = contextMenuStrip;
                    btnList.Add(btn);
                }

                m_MenuBtn = (QButton[])btnList.ToArray(typeof(QButton));
                for (int i = 0; i < m_MenuBtn.Length; i++)
                {
                    panelMenu.Controls.Add(m_MenuBtn[i]);
                }

                //缓存
                App.cache.AddObject("DataStore/YyCd", dsAppMenu, true);
            }
            finally
            {
                if (dsAppMenuModule != null)
                    dsAppMenuModule.Dispose();

                if (dtAppMenu != null)
                    dtAppMenu.Dispose();
            }
        }

        private void AddSubMenu(ContextMenuStrip contextMenuStrip, ToolStripMenuItem mItem, DataTable dtAppMenu, QDataStore dsAppMenuModule, string menuId)
        {
            DataRow[] rows = dtAppMenu.Select("SjCdId='" + menuId + "'", "PxXh");
            ToolStripItem menuItem = null;

            string menuText = "";
            string moduleId = "";
            int rowNum = -1;

            foreach (DataRow dr in rows)
            {
                //菜单文字
                menuText = dr["CdWz"].ToString();

                //同级次连续两个分隔符处理
                if (menuItem is ToolStripSeparator && menuText == "-")
                {
                    continue;
                }

                object objTag = null;
                //非末级菜单或分隔符不需要权限判断
                moduleId = dr["MkId"].ToString();
                if (moduleId == "0")
                {
                    rowNum = -1;
                    objTag = null;
                }
                else
                {
                    //判断权限
                    rowNum = dsAppMenuModule.FindRow("MkId = '" + moduleId + "'",0,dsAppMenuModule.RowCount);
                    if (rowNum < 1)
                        continue;

                    MenuTag menuTag;
                    //AssemblyName
                    if (dsAppMenuModule.IsItemNull(rowNum, "CxjMc"))
                        menuTag.assembly = "";
                    else
                        menuTag.assembly = dsAppMenuModule.GetItemString(rowNum, "CxjMc");

                    //TypeName
                    if (dsAppMenuModule.IsItemNull(rowNum, "LxMc"))
                        menuTag.typeName = "";
                    else
                        menuTag.typeName = dsAppMenuModule.GetItemString(rowNum, "LxMc");

                    //ShowModal
                    menuTag.showModal = dr["DkFs"].ToString();

                    //InvokeParm
                    if (dsAppMenuModule.IsItemNull(rowNum, "DyCs"))
                        menuTag.param = "";
                    else
                        menuTag.param = dsAppMenuModule.GetItemString(rowNum, "DyCs");

                    objTag = menuTag;
                }

                //从资源文件中取图像
                Image image = null;
                string menuIconName = dr["CdTbMc"].ToString();
                if (!string.IsNullOrEmpty(menuIconName))
                {
                    image = Resource.Resource.GetImage(menuIconName);
                    if (image == null)
                    {
                        Qeb.Support.Common.AppLog.Add(new AppError("没有取到资源:" + menuIconName, this.GetType()));
                    }
                }

                //添加菜单
                if (mItem != null)
                {
                    menuItem = mItem.DropDown.Items.Add(menuText, image);
                }
                else
                {
                    menuItem = contextMenuStrip.Items.Add(menuText, image);
                }
                menuItem.Tag = objTag;

                //非末级菜单且不是分隔符
                if (moduleId == "0")
                {
                    if (menuText != "-")
                        AddSubMenu(contextMenuStrip, (ToolStripMenuItem)menuItem, dtAppMenu, dsAppMenuModule, dr["CdId"].ToString());
                }
                else
                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -