Ejemplo n.º 1
0
        private static void setPermission(BaseUser baseUser, ref ToolStrip toolStrip, ToolStripItemPermission toolStripPermission)
        {
            for (int i = 0; i < toolStrip.Items.Count ; i++)
            {
                // 1. get Menu Item
                ToolStripItem toolStripMenuItem = toolStrip.Items[i] as ToolStripItem;
                // 2. Set permission
                setPermission(baseUser, ref toolStripMenuItem, toolStripPermission);
                // 3. Set permission for child

            }
        }
Ejemplo n.º 2
0
 private static void setPermission(BaseUser baseUser, ref ToolStripItem toolStripMenuItem, ToolStripItemPermission toolStripPermission)
 {
     // 1. get Menu Item
     // 2. Check role of user
     if (toolStripMenuItem == null)
         return;
     bool hasPermission = toolStripPermission.HasPermission(toolStripMenuItem.Name, baseUser);
     // 3. Process menu presentation base on user's role.
     if (hasPermission)
     {
         toolStripMenuItem.Enabled = true;
         toolStripMenuItem.Visible = true;
     }
     else
     {
         switch (toolStripPermission.DeniedAction)
         {
             case MenuItemPermission.DISABLED:
                 toolStripMenuItem.Enabled = false;
                 break;
             case MenuItemPermission.INVISIBLE:
                 toolStripMenuItem.Visible = false;
                 break;
             case MenuItemPermission.POPUP:
                 break;
             case MenuItemPermission.NORMAL:
                 break;
         }
     }
 }
Ejemplo n.º 3
0
 public static void setPermission(Form mainForm,ClientInfo clientInfo,ref ToolStrip toolStrip,ToolStripItemPermission toolStripPermission)
 {
     setPermission(clientInfo.LoggedUser,ref toolStrip,toolStripPermission);
 }
Ejemplo n.º 4
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();

            }
        }