0

I have form with menus that are created dynamically from the tables in data base . as follows

  public void FourthMenu(ToolStripMenuItem mnu, string submenu)
    {

        string Seqchild = "SELECT FRM_NAME,FourthMenuID FROM MNU_FOURTH WHERE ThirdMenuID = '" + submenu + "'";
        SqlDataAdapter dachildmnu = new SqlDataAdapter(Seqchild, conn);
        DataTable dtchild = new DataTable();
        dachildmnu.Fill(dtchild);

        foreach (DataRow dr in dtchild.Rows)
        {
            ToolStripMenuItem SSMenu2 = new ToolStripMenuItem(dr["FRM_NAME"].ToString(), null, new EventHandler(ChildClick));
            FifthMenu(SSMenu2, dr["FourthMenuID"].ToString());
            mnu.DropDownItems.Add(SSMenu2);
        }

outputa as shown in fig ..

enter image description here

Requirement is to display menus as per user . for eg if user1 has only authority to visit pages of Accounts and Finance then the menus will be displayed up to the accounts and finance only .

and if user2 has authority to visit page fourth1 , then menus will be displayed upto fourth1 but it should not display "fourth" .

how can i approach it , any article reference etc .....

Thanks in advance......

speedyraz
  • 335
  • 1
  • 5
  • 18

1 Answers1

0

You may use this type of database design, which can provide user permission level rendering.

Table 1 - Users

    Users
     {
       string Name,
       int Id,
       int RoleId
     }

Table 2- Roles

    Roles
     {
       string Name,
       int Id,
       bool HasWriteAccess
     }

Table 3 - MenuItems

    MenuItems
     {
       string Title,
       int Id,
       int RoleId
     }

So your query will be

    select * from MenuItems mi, Roles role, Users user
      where mi.RoleId = role.Id and
      user.RoleId = role.Id and
      user.Id= LoggedInUserId;

This will give menu items based on the logged in User only.

Hope it helps!!!

shashwat12
  • 168
  • 8
  • thanks ,, but will it cover multi level menus .. as you can see in pic .... – speedyraz Apr 10 '17 at 10:14
  • This was just a high level solution. In case of multi level menus, you can have a more normalized database with tables like Menus , MenuItemGroups, MenuItems each will have a role associated with it and based on the query you can fetch only the role based sub group and items. – shashwat12 Apr 10 '17 at 10:40
  • thanks .. I am trying your idea . lets see how it works .. and thanks for your suggestions ... – speedyraz Apr 10 '17 at 11:41