Esempio n. 1
0
 private static void setPermission(BaseUser user, ref ToolStripMenuItem menuItem, MenuItemPermission permission)
 {
     // 1. get Menu Item
     // 2. Check role of user
     if(menuItem == null)
         return;
     bool hasPermission = permission.HasPermission(menuItem.Name, user);
     // 3. Process menu presentation base on user's role.
     if (hasPermission)
     {
         menuItem.Enabled = true;
         menuItem.Visible = true;
     }
     else
     {
         switch (permission.DeniedAction)
         {
             case MenuItemPermission.DISABLED:
                 menuItem.Enabled = false;
                 break;
             case MenuItemPermission.INVISIBLE:
                 menuItem.Visible = false;
                 break;
             case MenuItemPermission.POPUP:
                 break;
             case MenuItemPermission.NORMAL:
                 break;
         }
     }
        for(int i = 0;i<menuItem.DropDownItems.Count;i++)
        {
        ToolStripMenuItem childMenuItem = menuItem.DropDownItems[i] as ToolStripMenuItem;
        setPermission(user,ref childMenuItem, permission);
        }
 }
Esempio n. 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="user"></param>
        /// <param name="menuStrip"></param>
        /// <param name="menuItemPermission"></param>
        public static void setPermission(BaseUser user, ref MenuStrip menuStrip, MenuItemPermission menuItemPermission)
        {
            for (int i = 0; i < menuStrip.Items.Count ; i++)
            {
                // 1. get Menu Item
                ToolStripMenuItem toolStripMenuItem = menuStrip.Items[i] as ToolStripMenuItem;
                // 2. Set permission
                setPermission(user, ref toolStripMenuItem, menuItemPermission);
                // 3. Set permission for child

            }
        }
Esempio n. 3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Stream inStream = this.GetType().Assembly.GetManifestResourceStream("ClientManagementTool.MenuPermissions.xml");

            // load menu permission
            MenuItemPermission menuItemPermission = new MenuItemPermission(MenuItemPermission.INVISIBLE);
            menuItemPermission.loadRoles(inStream);
            ClientInfo clientInfo = ClientInfo.getInstance();
            clientInfo.MenuPermissions = menuItemPermission;

            // register main form
            GlobalCache.Instance().MainForm = this;

            // check menu permission
            MenuUtility.setPermission(clientInfo.LoggedUser, ref this.menuStrip1, menuItemPermission);
            //CheckClientServer();
        }
Esempio n. 4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Stream inStream = null;
            if(ClientSetting.IsClient())
            {
                inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ClientMenuPermissions.xml");
            }
            else
            {
                if(ClientSetting.IsServer())
                {
                    inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ServerMenuPermissions.xml");
                }
                else
                {
                    inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.NAMenuPermissions.xml");
                }
            }

            // load menu permission
            MenuItemPermission menuItemPermission = new MenuItemPermission(MenuItemPermission.INVISIBLE);
            menuItemPermission.loadRoles(inStream);
            ClientInfo clientInfo = ClientInfo.getInstance();
            clientInfo.MenuPermissions = menuItemPermission;

            // register main form
            GlobalCache.Instance().MainForm = this;

            // check menu permission
            MenuUtility.setPermission(clientInfo.LoggedUser, ref this.mnuMenu, menuItemPermission);
            //CheckClientServer();
        }
Esempio n. 5
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            foreach (ToolStripItem item in toolStripClient.Items)
            {
                toolStripTexts.Add(item.Text);
            }
            Stream inStream = null;
            if(ClientSetting.IsClient())
            {

                // load menu
                inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ClientMenuPermissions.xml");
            }
            else
            {
                if(ClientSetting.IsServer())
                {
                    inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ServerMenuPermissions.xml");
                }
                else
                {
                    if(ClientSetting.IsSubStock())
                    {
                        inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.SubStockMenuPermissions.xml");
                    }
                    else
                    {
                        inStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.NAMenuPermissions.xml");
                    }

                }
            }

            // load menu permission
            MenuItemPermission menuItemPermission = new MenuItemPermission(MenuItemPermission.INVISIBLE);
            menuItemPermission.loadRoles(inStream);
            ClientInfo clientInfo = ClientInfo.getInstance();
            clientInfo.MenuPermissions = menuItemPermission;

            // register main form
            GlobalCache.Instance().MainForm = this;

            // check menu permission
            MenuUtility.setPermission(clientInfo.LoggedUser, ref this.mnuMenu, menuItemPermission);
            //CheckClientServer();
            toolStripClient.Focus();
            Stream toolStripInStream = null;
            if(ClientSetting.IsClient())
            {
                toolStripClient.Visible = true;
                // load and set permissions
                toolStripInStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ClientToolStripPermissions.xml");
                // run service in client
                consumer = new ServerServiceConsumer();
            }
            else if (ClientSetting.IsSubStock())
            {
                subStockConsumer= new SubStockConsumer();
                    // load toolstrip
                    toolStripClient.Visible = true;
                    // load and set permissions
                    toolStripInStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.SubStockToolStripPermissions.xml");

            }
            else if(ClientSetting.IsServer())
            {
                // load toolstrip
                toolStripClient.Visible = true;
                // load and set permissions
                toolStripInStream = this.GetType().Assembly.GetManifestResourceStream("AppFrameClient.ServerToolStripPermissions.xml");
                ServiceStatus.Text = "...";
            }
            else
            {
                toolStripClient.Visible = false;
            }
            if(toolStripInStream != null)
            {
                ToolStripItemPermission toolStripItemPermission = new ToolStripItemPermission(ToolStripItemPermission.INVISIBLE);
                toolStripItemPermission.loadRoles(toolStripInStream);
                GlobalCache.Instance().ClientToolStripPermission = toolStripItemPermission;
                MenuUtility.setPermission(this, clientInfo, ref this.toolStripClient, toolStripItemPermission);
            }

            if(toolStripClient.Visible == true)
            {
                RenderFunctionKeysTextToToolStrip();

            }
        }