Ejemplo n.º 1
0
 partial void DeleteMenus(Menus instance);
Ejemplo n.º 2
0
 partial void UpdateMenus(Menus instance);
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (inputName.Enabled == false) return;

            this.selectedNode = menuTree.SelectedNode;

            DataClasses1DataContext ctx = new DataClasses1DataContext();

            switch (activeMode)
            {
                case SaveMode.edit:

                    int nodeId = Convert.ToInt32(this.selectedNode.Name);

                    try
                    {
                        Menus menu2edit = (from m in ctx.Menus where m.idMenu == nodeId select m).First();
                        menu2edit.MenuName = inputName.Text;
                        menu2edit.Description = inputDescription.Text;
                    }
                    catch (Exception) { }

                    break;
                case SaveMode.add:

                    Menus menu2add = new Menus();

                    try
                    {
                        if (menuTree.SelectedNode == null)
                        {// add root menu ...

                            menu2add.idParentMenu = null;

                            menu2add.MenuType = MENU_LEVEL0;

                            int? lastMenu = menusDB.FindAll(i => i.idParentMenu == null).Max(i => i.MenuOrder);

                            if (lastMenu == null)
                                menu2add.MenuOrder = 1;
                            else
                                menu2add.MenuOrder = lastMenu + 1;
                        }
                        else
                        {
                            Menus selectedNode = menusDB.Find(i => i.idMenu == Convert.ToInt32(menuTree.SelectedNode.Name));

                            if (selectedNode.idParentMenu == null)
                            {
                                menu2add.idParentMenu = selectedNode.idMenu;
                                menu2add.MenuType = MENU_LEVEL1;
                            }
                            else
                            {
                                menu2add.idParentMenu = selectedNode.idMenu;
                                menu2add.MenuType = MENU_LEVEL2;
                            }
                        }

            menu2add.MenuName = inputName.Text;
            menu2add.Description = inputDescription.Text;
            ctx.Menus.InsertOnSubmit(menu2add);
                    }
                    catch (Exception) { }
                    break;
                default:
                    break;
            }

            ctx.SubmitChanges();

            loadTreeMenu();

            this.enableInputs(false);
        }
Ejemplo n.º 4
0
 partial void InsertMenus(Menus instance);
Ejemplo n.º 5
0
        private void fillNodes(Menus[] menus, TreeNode superNode)
        {
            foreach (var item in menus)
            {
                TreeNode node = new TreeNode();
                node.Name = item.idMenu.ToString();
                node.Text = item.MenuName;
                node.Tag = item;
                superNode.Nodes.Add(node);

                Menus[] subMenu = menusDB.FindAll(i => i.idParentMenu == item.idMenu).ToArray();

                if (subMenu != null && subMenu.Length != 0)
                {
                    Array.Sort(subMenu, delegate(Menus mn1, Menus mn2)
                    { return (int)(mn1.MenuOrder - mn2.MenuOrder); });

                    // ... inception :)
                    fillNodes(subMenu,node);
                }
            }
        }