public ActionResult DeleteMenu(FormCollection form)
        {
            using (Trainee15Entities db = new Trainee15Entities())
            {
                ExtendedMenu menu = new ExtendedMenu();

                try
                {
                    // Checkbox is the attribute name.
                    // Returns values of the boxes that have been checked as csv.
                    string[] checkboxes = form["checkbox"].Split(',');
                    foreach (var menuID in checkboxes)
                    {
                        int  iMenuID    = Int32.Parse(menuID);
                        Menu deleteMenu = db.Menus.SingleOrDefault(x => x.menuID == iMenuID);
                        db.Menus.Remove(deleteMenu);
                        db.SaveChanges();
                    }
                    menu.menuList       = db.Menus.ToList();
                    menu.menuTableList  = new List <Menu>();
                    TempData["Message"] = "One or more user has been successfully deleted!";
                    return(View("MenuMaintenance", menu));
                }
                catch (Exception e) // Catch exception when no item from table was selected.
                {
                    menu.menuList       = db.Menus.ToList();
                    menu.menuTableList  = new List <Menu>();
                    TempData["Message"] = "Error: No item was selected from table.";
                    return(View("MenuMaintenance", menu));
                }
            }
        }
 public ActionResult AddMenu()
 {
     using (Trainee15Entities db = new Trainee15Entities())
     {
         ExtendedMenu menu = new ExtendedMenu();
         menu.menuList = db.Menus.SqlQuery("SELECT * FROM Menu m1 INNER JOIN Menu m2 ON m1.menuID = m2.menuID WHERE m1.menuNo LIKE '00%' AND LEN(m2.MenuNo) = 3").ToList();
         return(View(menu));
     }
 }
 // Menu Maintenance landing page.
 public ActionResult MenuMaintenance(ExtendedMenu menus)
 {
     using (Trainee15Entities db = new Trainee15Entities())
     {
         menus.menuList      = db.Menus.ToList();
         menus.menuTableList = new List <Menu>();
         return(View("../MenuMaintenance/MenuMaintenance", menus));
     }
 }
 // Menu Maintenance landing page.
 public ActionResult MenuMaintenance(ExtendedMenu menus)
 {
     using (Trainee15Entities db = new Trainee15Entities())
     {
         // Query database first to get data for dropdown list.
         menus.menuList      = db.Menus.ToList();
         menus.menuTableList = new List <Menu>();
         return(View(menus));
     }
 }
        public ActionResult QueryMenu(FormCollection form)
        {
            using (Trainee15Entities db = new Trainee15Entities())
            {
                var menuID   = form["selectMenu"];
                var title    = form["selectTitle"];
                var linkType = form["selectLinkType"];
                // Status is of type string from front-end.
                // bStatus is used to check database.
                var status = form["selectStatus"];

                var queryMenu = db.Menus.AsQueryable();
                if (menuID != "")
                {
                    int iMenuID = int.Parse(menuID);
                    queryMenu = queryMenu.Where(x => x.menuID == iMenuID);
                }
                if (title != "")
                {
                    queryMenu = queryMenu.Where(x => x.title == title);
                }
                if (linkType != "")
                {
                    queryMenu = queryMenu.Where(x => x.linkType == linkType);
                }
                if (status != "")
                {
                    bool bStatus = bool.Parse(status);
                    queryMenu = queryMenu.Where(x => x.status == bStatus);
                }

                ExtendedMenu query = new ExtendedMenu();
                query.menuList      = db.Menus.ToList();
                query.menuTableList = queryMenu.ToList();

                return(View("MenuMaintenance", query));
            }
        }
        public ActionResult ModifyMenu(FormCollection form)
        {
            using (Trainee15Entities db = new Trainee15Entities())
            {
                ExtendedMenu modify = new ExtendedMenu();
                modify.menuList      = db.Menus.ToList();
                modify.menuTableList = new List <Menu>();

                try
                {
                    // Checkbox is the attribute name.
                    // Returns values of the boxes that have been checked as csv.
                    string[] checkboxes = form["checkbox"].Split(',');
                    if (checkboxes.Length != 1) // More than 1 checkbox selected.
                    {
                        TempData["Message"] = "Error: Can only select one from table to modify.";
                        return(View("MenuMaintenance", modify));
                    }
                    else
                    {
                        int iMenuID = int.Parse(checkboxes[0]);
                        modify.menu     = db.Menus.SingleOrDefault(x => x.menuID == iMenuID);
                        modify.menuList = db.Menus.SqlQuery("SELECT * FROM Menu m1 INNER JOIN Menu m2 ON m1.menuID = m2.menuID WHERE m1.menuNo LIKE '00%' AND LEN(m2.MenuNo) = 3").ToList();

                        if (modify.menu.menuNo.Length > 3)
                        {
                            modify.subMenuNo = modify.menu.menuNo.Remove(3);
                        }
                        return(View("ModifyMenu", modify));
                    }
                }
                catch (Exception e) // Catch exception when no item from table was selected.
                {
                    TempData["Message"] = "Error: No item was selected from table.";
                    return(View("MenuMaintenance", modify));
                }
            }
        }
        public ActionResult AddMenu(FormCollection form)
        {
            using (Trainee15Entities db = new Trainee15Entities())
            {
                var level    = form["selectLinkType"];
                var title    = form["title"];
                var linkType = form["selectLinkType"];
                var subMenu  = form["selectSubMenu"];
                var linkUrl  = form["linkUrl"];
                var status   = form["selectStatus"];

                Menu menu = new Menu();
                // Determine the new menu number.
                if (linkType == "1")
                {
                    menu.linkType = "Menu";
                    // Get new main menu number.
                    menu.menuNo = MenuNo(form["selectLinkType"], form["selectSubMenu"]);
                }

                if (linkType == "2")
                {
                    if (subMenu != null)
                    {
                        menu.linkType = "Program";
                        // Get new sub menu number.
                        menu.menuNo = MenuNo(form["selectLinkType"], form["selectSubMenu"]);
                    }
                    else
                    {
                        TempData["Message"] = "Error: Sub-menu category was not selected.";
                        return(View("MenuMaintenance", "SystemSetup"));
                    }
                }

                menu.level = int.Parse(level);
                menu.title = title;

                if (linkUrl != null) // Optional
                {
                    menu.linkUrl = linkUrl;
                }
                else
                {
                    menu.linkUrl = "";
                }

                menu.status = false;
                if (status == "1")
                {
                    menu.status = true;
                }
                db.Menus.Add(menu);
                db.SaveChanges();

                ExtendedMenu menus = new ExtendedMenu();
                menus.menuList      = db.Menus.ToList();
                menus.menuTableList = new List <Menu>();
                return(View("MenuMaintenance", menus));
            }
        }
        // To modify and update the menu table.
        public ActionResult ModifyMenuDatabase(FormCollection form)
        {
            using (Trainee15Entities db = new Trainee15Entities())
            {
                // Menu object to store and update database.
                Menu         updateMenu = new Menu();
                ExtendedMenu menus      = new ExtendedMenu();

                int menuID = int.Parse(form["menuID"]);
                // Get data from database and assign it to object.
                updateMenu = db.Menus.SingleOrDefault(x => x.menuID == menuID);

                if (form["selectLinkType"] == "1")     //Main Menu
                {
                    if (updateMenu.linkType != "Menu") // Checks if menu isn't already a menu.
                    {
                        updateMenu.linkType = "Menu";
                        // Update menu number if changed from sub menu to main menu.
                        updateMenu.menuNo = MenuNo(form["selectLinkType"], form["selectSubMenu"]);
                    }
                }
                if (form["selectLinkType"] == "2") // Sub Menu
                {
                    if (form["selectSubMenu"] != null)
                    {
                        if (updateMenu.linkType != "Program") // Checks if menu isn't already sub menu.
                        {
                            updateMenu.linkType = "Program";
                            // Update menu number if changed from main menu to sub menu.
                            updateMenu.menuNo = MenuNo(form["selectLinkType"], form["selectSubMenu"]);
                        }
                        else // If the menu is already a program.
                        {
                            // Compare the menu category from database to the selected menu category.
                            if (string.CompareOrdinal(updateMenu.menuNo, 0, form["selectSubMenu"], 0, 3) != 0)
                            {
                                // Update menu number if menu changed to a different menu category.
                                updateMenu.menuNo = MenuNo(form["selectLinkType"], form["selectSubMenu"]);
                            }
                        }
                    }
                    else
                    {
                        menus.menuList      = db.Menus.ToList();
                        menus.menuTableList = new List <Menu>();
                        TempData["Message"] = "Error: Sub-menu category was not selected.";
                        return(View("MenuMaintenance", menus));
                    }
                }

                updateMenu.level = int.Parse(form["selectLinkType"]);
                updateMenu.title = form["title"];
                if (form["linkUrl"] != null) // Optional
                {
                    updateMenu.linkUrl = form["linkUrl"];
                }
                else
                {
                    updateMenu.linkUrl = "";
                }
                updateMenu.status = false;
                if (form["selectStatus"] == "1")
                {
                    updateMenu.status = true;
                }
                db.SaveChanges();

                menus.menuList      = db.Menus.ToList();
                menus.menuTableList = new List <Menu>();
                TempData["Message"] = "Menu updated.";
                return(View("MenuMaintenance", menus));
            }
        }
Exemple #9
0
    public static bool settingsMenu()
    {
        int width = 100;
            int height = 170;
            int left;
            if (curMenu != ExtendedMenu.None)
                left = (Screen.width - width*2 - 10)/2;
            else
                left = (Screen.width - width)/2;

            int top = (Screen.height - height)/2;

            GUILayout.BeginArea(new Rect(left,top,width,height),GUI.skin.GetStyle("box"));
                GUILayout.Box("Settings");
                GUILayout.Space(10);

                if (GUILayout.Button("Quality")){
                    if (curMenu == Settings_GUI.ExtendedMenu.Quality)
                        curMenu = Settings_GUI.ExtendedMenu.None;
                    else
                        curMenu = Settings_GUI.ExtendedMenu.Quality;
                }

                if (GUILayout.Button("Resolution")){
                    if (curMenu == ExtendedMenu.Res)
                        curMenu = ExtendedMenu.None;
                    else
                        curMenu = ExtendedMenu.Res;
                }
                fullscreen = Screen.fullScreen;
                fullscreen = GUILayout.Toggle(fullscreen,"Fullscreen");
                if (fullscreen != Screen.fullScreen)
                    Screen.fullScreen = fullscreen;

                GUILayout.Space(10);
                if (GUILayout.Button("Back")) {
                    return true;
                }

            GUILayout.EndArea();

        if (curMenu == ExtendedMenu.Res){
            GUILayout.BeginArea(new	Rect(left + width + 10,top+20,width,height-20));
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

                Resolution[] resolutions = Screen.resolutions;
                GUIContent[] list = new GUIContent[resolutions.Length];
                for(int i = 0; i < resolutions.Length; i++){
                    if (resolutions[i].Equals(Screen.currentResolution))
                        curResIndx = i;
                    list[i] = new GUIContent(resolutions[i].width.ToString() + "x" +
                                         resolutions[i].height.ToString());
                }
                int prev = curResIndx;
                curResIndx = GUILayout.SelectionGrid(curResIndx,list,1);
                if (curResIndx != prev){
                    curMenu = ExtendedMenu.None;
                    Resolution res = resolutions[curResIndx];
                    Screen.SetResolution(res.width,res.height,fullscreen);
                }

            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }

        if (curMenu == Settings_GUI.ExtendedMenu.Quality){
            GUILayout.BeginArea(new	Rect(left + width + 10,top+20,width,height-20));
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

                GUIContent[] list = {
                    new GUIContent("Fastest"),
                    new GUIContent("Fast"),
                    new GUIContent("Simple"),
                    new GUIContent("Good"),
                    new GUIContent("Beautiful"),
                    new GUIContent("Fantastic")};
                int curQuality = (int) QualitySettings.currentLevel;
                int tmp = GUILayout.SelectionGrid(curQuality,list,1);

                if (tmp != curQuality)
                    QualitySettings.currentLevel = (QualityLevel) tmp;

            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }
        return false;
    }