/// <summary> /// Calculate MenuItmes from DataBase and Model Config /// </summary> private void CalculateMenuItems() { // Create Parent groups Menu from ManuItemApplication Table foreach (MenuItemApplication menuItemApplication in this.MenuItemApplicationService.GetAll()) { //Continue if user don't have a role required by menuItemApplication roles if (menuItemApplication.Roles != null && menuItemApplication.Roles.Count > 0) { if (!GwinApp.Instance.user.HasOneOfRoles(menuItemApplication.Roles)) { continue; } } // Create Parent Menu Item Structures.MenuItem menuItem = new Structures.MenuItem(true); menuItem.ToolStripMenuItem.Name = "toolStripMenuItem" + menuItemApplication.Code; menuItem.ToolStripMenuItem.Size = new System.Drawing.Size(82, 20); // Title menuItem.ToolStripMenuItem.Text = (menuItemApplication.Title.Current != string.Empty) ? menuItemApplication.Title.Current : menuItem.ToolStripMenuItem.Text = menuItemApplication.Code; MenuStruct.ParentMenuItems.Add(menuItem); } // Create SubMenu MenuItems from ModelCondiguration Entities Dictionary <Type, MenuAttribute> MenuAttributes_And_Types = new GwinEntitiesManager().Get_All_Type_And_MenuAttributes(); foreach (var menuAttributes_And_Types in MenuAttributes_And_Types) { Type EntityType = null; string Title = null; string Group = null; // Determine Category of Type : Entity or Form if (menuAttributes_And_Types.Key.IsSubclassOf(typeof(Form))) { if (menuAttributes_And_Types.Value.EntityType == null) { throw new GwinException(String.Format("The property EntityType of MenuAttribute of the Form {0} is null \n it can not be null we use it to check security permission", menuAttributes_And_Types.Key)); } EntityType = menuAttributes_And_Types.Value.EntityType; ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(EntityType); Group = menuAttributes_And_Types.Value.Group; if (menuAttributes_And_Types.Value.Title != null) { Title = configEntity.Translate(menuAttributes_And_Types.Value.Title); } } else { if (menuAttributes_And_Types.Key.IsSubclassOf(typeof(BaseEntity))) { EntityType = menuAttributes_And_Types.Key; ConfigEntity configEntity = ConfigEntity.CreateConfigEntity(EntityType); Group = configEntity.Menu.Group; Title = configEntity.Menu.Title; } else { throw new GwinException(String.Format("The Type {0} does not inherit from BaseEntity or Form ", menuAttributes_And_Types.Key)); } } // Security : Continue if User dont have persmission if (!GwinApp.Instance.user.HasAccess(EntityType)) { continue; } // Create MenuItem and Save to Dictionary MenyItem Structures.MenuItem SubMenuItem = new Structures.MenuItem(false); SubMenuItem.ToolStripMenuItem.Name = menuAttributes_And_Types.Key.FullName; SubMenuItem.ToolStripMenuItem.Size = new System.Drawing.Size(82, 20); SubMenuItem.ToolStripMenuItem.Text = Title; SubMenuItem.ToolStripMenuItem.Click += ToolStripMenuItem_Click; SubMenuItem.TypeOfEntity = menuAttributes_And_Types.Key; // Find Parent if Exist Structures.MenuItem ParentMenuItem = null; if (Group != null) { string toolStripMenuItem_key = "toolStripMenuItem" + Group; ParentMenuItem = MenuStruct.ParentMenuItems.Where(m => m.ToolStripMenuItem.Name == toolStripMenuItem_key).SingleOrDefault(); // If parrent exist if (ParentMenuItem != null) { ParentMenuItem.Add(SubMenuItem); } else { // throw new GwinException(String.Format("the Parent {0} of {1} not exist ", configEntity.Menu.Group, toolStripMenuItem_key)); // Patent not exist bevause user not have permission required by Parent Menu } } else { this.MenuStruct.ParentMenuItems.Add(SubMenuItem); } } }
/// <summary> /// Create Group Box /// </summary> /// <param name="groupesBoxMainContainers"></param> private void CreateGroupesBoxes(Dictionary <string, Control> groupesBoxMainContainers, int width, int height) { // Determine a list of groupe box var listeProprite = from i in this.EntityBLO.TypeEntity.GetProperties() where i.GetCustomAttribute(typeof(EntryFormAttribute)) != null && ((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).GroupeBox != string.Empty && ((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).GroupeBox != null orderby((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).GroupeBoxOrder select((EntryFormAttribute)i.GetCustomAttribute(typeof(EntryFormAttribute))).GroupeBox; if (listeProprite.Distinct().Count() > 0) { foreach (var item in listeProprite.Distinct()) { // // CombBox // GroupBox groupeBox = new GroupBox(); groupeBox.Text = ConfigEntity.Translate(item); groupeBox.AutoSize = true; groupeBox.Size = new Size(width, height); groupeBox.Padding = new Padding(20); this.ConteneurFormulaire.Controls.Add(groupeBox); // FlowLayout FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel(); flowLayoutPanel.Dock = DockStyle.Fill; flowLayoutPanel.AutoSize = true; flowLayoutPanel.FlowDirection = FlowDirection.TopDown; groupeBox.Controls.Add(flowLayoutPanel); groupesBoxMainContainers[item] = flowLayoutPanel; // Add Group Box to List this.GroupsBoxes.Add(item, groupeBox); } } else { GroupBox groupeBox = new GroupBox(); groupeBox.Text = this.ConfigEntity.GwinEntity.SingularName; groupeBox.AutoSize = true; groupeBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); //groupeBox.Size = new Size(width, height); this.ConteneurFormulaire.Controls.Add(groupeBox); // FlowLayout FlowLayoutPanel flowLayoutPanel = new FlowLayoutPanel(); flowLayoutPanel.Dock = DockStyle.Fill; flowLayoutPanel.AutoSize = true; flowLayoutPanel.FlowDirection = FlowDirection.TopDown; flowLayoutPanel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); groupeBox.Controls.Add(flowLayoutPanel); this.ConteneurFormulaire.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); this.ConteneurFormulaire = flowLayoutPanel; } }