using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace digioz.admin
{
    public class AdminMenuItemManagement
    {
        private static PortalSettings coPortalSettings;

        public static AdminMenuItem GetAdminMenuItemFromMenuName(string psMenuName)
        {
            AdminMenuItem loAdminMenuItem = new AdminMenuItem();
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                DataTable loMenu;

                string lsSQL = "SELECT * FROM tblAdminMenu WHERE adminmenu_name='" + psMenuName + "';";

                loDB.openConnection();
                loMenu = loDB.QueryDBDataset(lsSQL);
                loDB.closeConnection();
                DataRow loDR = loMenu.Rows[0];

                loAdminMenuItem.ID = (int)loDR["adminmenu_id"];
                loAdminMenuItem.Name = (string)loDR["adminmenu_name"];
                loAdminMenuItem.Data = (string)loDR["adminmenu_data"];
            }
            return loAdminMenuItem;
        }

        public static AdminMenuItem GetAdminMenuItemFromPageID(int piPageID)
        {
            AdminMenuItem loAdminMenuItem = new AdminMenuItem();
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                DataTable loMenu;

                string lsSQL = "SELECT * FROM tblAdminMenu WHERE adminmenu_id='" + piPageID + "';";

                loDB.openConnection();
                loMenu = loDB.QueryDBDataset(lsSQL);
                loDB.closeConnection();
                DataRow loDR = loMenu.Rows[0];

                loAdminMenuItem.ID = (int)loDR["adminmenu_id"];
                loAdminMenuItem.Name = (string)loDR["adminmenu_name"];
                loAdminMenuItem.Data = (string)loDR["adminmenu_data"];
            }
            return loAdminMenuItem;
        }

        public static AdminMenuItemList GetAdminMenuItemList()
        {
            AdminMenuItemList loAdminMenuItemList = new AdminMenuItemList();
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                AdminMenuItem loAdminMenuItem;
                DataTable loMenus;

                string lsSQL = "SELECT * FROM tblAdminMenu;";

                loDB.openConnection();
                loMenus = loDB.QueryDBDataset(lsSQL);
                loDB.closeConnection();

                foreach (DataRow loDR in loMenus.Rows)
                {
                    loAdminMenuItem = new AdminMenuItem();
                    loAdminMenuItem.ID = (int)loDR["adminmenu_id"];
                    loAdminMenuItem.Name = (string)loDR["adminmenu_name"];
                    loAdminMenuItem.Data = (string)loDR["adminmenu_data"];

                    loAdminMenuItemList.Add(loAdminMenuItem);
                }
            }
            return loAdminMenuItemList;
        }
    }
}


