public void LoadDynamicMenu(string username, string PCC)
        {
            List <Rol> rolList = RolesBL.GetRolesByUser(username, PCC);

            roles = Array.ConvertAll <Rol, string>(rolList.ToArray(), delegate(Rol from) { return(from.RoleName.ToString()); });
            //roles = Roles.GetRolesForUser(username);
            //roles = new string[] { "admin", "" };
            List <ApplicationObjects> applicationObjects = MyCTS.Forms.UI.DataAccess.Security.GetMenuData();
            List <ApplicationObjects> parentObjects      = GetParents(applicationObjects);

            foreach (ApplicationObjects item in parentObjects)
            {
                ToolStripMenuItemExtended menu = new ToolStripMenuItemExtended();

                menu.Name     = item.Name;
                menu.Text     = item.Text;
                menu.Value    = item.ID.ToString();
                menu.Width    = 55;
                menu.AutoSize = false;
                this.Items.Add(menu);
                AddChild(applicationObjects, (ToolStripMenuItemExtended)this.Items[this.Items.Count - 1]);
            }
        }
        private void AddChild(List <ApplicationObjects> applicationObjects, ToolStripMenuItemExtended menuItem)
        {
            List <ApplicationObjects> childObjects = GetChilds(applicationObjects, menuItem.Value);
            ToolStripSeparator        separator    = null;

            foreach (ApplicationObjects objects in childObjects)
            {
                ToolStripMenuItemExtended item = new ToolStripMenuItemExtended();
                if (objects.Text.Equals("-"))
                {
                    separator = new ToolStripSeparator();
                    menuItem.DropDownItems.Add(separator);
                }
                else
                {
                    if (roles != null && !string.IsNullOrEmpty(objects.Roles))
                    {
                        if (!IsAllowed(objects.Roles))
                        {
                            continue;
                        }
                    }

                    item.Name  = objects.Name;
                    item.Text  = objects.Text;
                    item.Value = objects.ID.ToString();

                    if (objects.Checked)
                    {
                        item.Checked      = true;
                        item.CheckOnClick = true;
                    }
                    try
                    {
                        if (!string.IsNullOrEmpty(objects.ImageName))
                        {
                            Image img = GetImageFromResource(objects.ImageName.ToLower());
                            if (img != null)
                            {
                                item.Image = img;
                            }
                        }
                    }
                    catch {}

                    string[] arrKeys = objects.ShortCut.Split(new char[] { ',' });
                    if (arrKeys.Length == 1)
                    {
                        if (!(string.IsNullOrEmpty(arrKeys[0])))
                        {
                            TypeConverter conv = TypeDescriptor.GetConverter(typeof(Keys));
                            Keys          key  = (Keys)conv.ConvertFromString(arrKeys[0]);
                            item.ShortcutKeys = key;
                        }
                    }
                    else
                    {
                        TypeConverter conv = TypeDescriptor.GetConverter(typeof(Keys));
                        //if (arrKeys[1].ToUpper().Trim().Equals("SUPR"))
                        //    arrKeys[1] = "Delete";

                        Keys key = (Keys)conv.ConvertFromString(arrKeys[0]) | (Keys)conv.ConvertFromString(arrKeys[1]);
                        item.ShortcutKeys = key;
                    }

                    menuItem.DropDownItems.Add(item);

                    if (!string.IsNullOrEmpty(objects.EventName))
                    {
                        FindEventsByName(item, this.Form, true, "MenuItemOn", objects.EventName);
                    }

                    AddChild(applicationObjects, (ToolStripMenuItemExtended)menuItem.DropDownItems[menuItem.DropDownItems.Count - 1]);
                }
            }
        }