using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Masters_TA_UI_Master_APIList : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    MultiLingualEventData objMultiLingualEventData = new MultiLingualEventData();
    DataSet ds_MultiLingual = new DataSet();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string source_Language;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
        if (!Page.IsPostBack)
        {
            base.CheckPages(330);
            objCommon.menu("Configuration", "330");
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        string str = Session["SiteMapProvider"].ToString();
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        UserRights();

        //if (!IsPostBack)
        //{
        //    LoadStrings(ci);
        //    //Call to a function to implement the UserRights
        //    UserRights();
        //    fillLanguage();
        //    setActiveLanguage(Convert.ToInt32(Session["EmpAutoID"]));
        //    //ddlLanguage.Focus();
        //    //string strSetAlert = "";
        //    //strSetAlert = strSetAlert + "<script language='javascript'>";
        //    //strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_SelectLanguage") + "','" + rm.GetString("Alert_Selectedlanguagealreadycurrentlanguage") + "','" + rm.GetString("Alert_AreyousurechangeLanguage") + "');";
        //    //strSetAlert = strSetAlert + "</script>";
        //    //Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        //    //btn_Save.OnClientClick = "javascript:return MultiLingualValidation();";
        //}
        BindEmployeeData();

    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("SystemSettings_APIMaster", ci);
        //btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        //lbl_Language.Text = rm.GetString("SystemSettings_APIMaster", ci);
        //ddlLanguage.Items[0].Text = rm.GetString("Select", ci);
        ////lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
    }

    private void BindEmployeeData()
    {
        DataTable dt = new DataTable();

        // Define columns
        dt.Columns.Add("API Parameter", typeof(string));
        dt.Columns.Add("Type", typeof(string));
        dt.Columns.Add("Length", typeof(int));
        dt.Columns.Add("Mandatory", typeof(string));

        // Add rows from the given data
        dt.Rows.Add("EmpFirstName", "nvarchar", 100, "Mandatory");
        dt.Rows.Add("EmployeeMiddleName", "nvarchar", 100, "");
        dt.Rows.Add("EmployeeLastName", "nvarchar", 100, "");
        dt.Rows.Add("FatherName", "nvarchar", 100, "");
        dt.Rows.Add("MotherName", "nvarchar", 100, "");
        dt.Rows.Add("DateofBirth", "datetime", 8, "");
        dt.Rows.Add("DateofBirth_Record", "datetime", 8, "");
        dt.Rows.Add("BloodGroup", "nvarchar", 20, "");
        dt.Rows.Add("OfficialMailID", "nvarchar", 200, "");
        dt.Rows.Add("ContactAddress", "nvarchar", 510, "");
        dt.Rows.Add("PermanentAddress", "nvarchar", 510, "");
        dt.Rows.Add("PhoneNumber", "nvarchar", 100, "");
        dt.Rows.Add("MobileNumber", "nvarchar", 100, "");
        dt.Rows.Add("Gender", "nvarchar", 20, "Mandatory");
        dt.Rows.Add("MaritalStatus", "nvarchar", 20, "");
        dt.Rows.Add("Nationality", "nvarchar", 100, "");
        dt.Rows.Add("ReligionName", "int", 4, "");
        dt.Rows.Add("PersonalMailID", "nvarchar", 200, "");
        dt.Rows.Add("PassportNo", "nvarchar", 100, "");
        dt.Rows.Add("PassportExpiryDate", "datetime", 8, "");
        dt.Rows.Add("VisaNo", "nvarchar", 100, "");
        dt.Rows.Add("VisaExpiryDate", "datetime", 8, "");
        dt.Rows.Add("EmployeeCardID", "nvarchar", 30, "Mandatory");
        dt.Rows.Add("SwipeCardNo", "nvarchar", 30, "Mandatory");
        dt.Rows.Add("DateOfJoining", "datetime", 8, "Mandatory");
        dt.Rows.Add("QualificationJoiningTime", "nvarchar", 100, "");
        dt.Rows.Add("QualificationDuringEmployment", "nvarchar", 100, "");
        dt.Rows.Add("CompOff_Eligible", "bit", 1, "");
        dt.Rows.Add("OT_Eligible", "bit", 1, "");
        dt.Rows.Add("ESI_Eligible", "bit", 1, "");
        dt.Rows.Add("Hostel", "bit", 1, "");
        dt.Rows.Add("Designation", "nvarchar", 20, "Mandatory");
        dt.Rows.Add("GradeName", "nvarchar", 20, "Mandatory");
        dt.Rows.Add("GradeNo", "int", 1, "Mandatory");
        dt.Rows.Add("EmployeeType", "nvarchar", 20, "Mandatory");
        dt.Rows.Add("EmployeeCategory", "nvarchar", 20, "Mandatory");
        dt.Rows.Add("BasicSalary", "nvarchar", 20, "");
        dt.Rows.Add("OrganizationLevel1", "nvarchar", 50, "Mandatory");
        dt.Rows.Add("OrganizationLevel2", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel3", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel4", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel5", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel6", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel7", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel8", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel9", "nvarchar", 50, "");
        dt.Rows.Add("OrganizationLevel10", "nvarchar", 50, "");
        dt.Rows.Add("isFlag", "bit", 1, "Mandatory");

        // Generate table dynamically
        GenerateTable(dt);
    }

    private void GenerateTable(DataTable dt)
    {
        // Create table header row
        TableRow headerRow = new TableRow();

        foreach (DataColumn column in dt.Columns)
        {
            TableHeaderCell headerCell = new TableHeaderCell
            {
                Text = column.ColumnName,
                CssClass = "header"
            };
            headerRow.Cells.Add(headerCell);
        }

        tblEmployee.Rows.Add(headerRow);

        // Add rows to the table
        foreach (DataRow row in dt.Rows)
        {
            TableRow tableRow = new TableRow();

            foreach (var item in row.ItemArray)
            {
                TableCell tableCell = new TableCell { Text = item.ToString() };
                tableRow.Cells.Add(tableCell);
            }

            tblEmployee.Rows.Add(tableRow);
        }
    }


    protected void GenerateMenu()
    {
        CultureInfo ci;
        Session["TopMenu"] = "";
        Session["MasterLeftMenu"] = "";
        Session["OrgLeftMenu"] = "";
        Session["ReportLeftMenu"] = "";
        Session["SystemLeftMenu"] = "";
        Session["TransLeftMenu"] = "";
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        string strType = string.Empty;
        if (Session["Demo"] != null)
        {
            if (Session["Demo"].ToString() == "Standard")
            {
                strType = "Standard";
            }
        }
        //Top Menu
        cls_Common getmenu = new cls_Common();
        DataSet ds = new DataSet();
        Session["TopMenu"] = "<table border='0' cellpadding=0 cellspacing=0><tr><td width'10'>&nbsp;</td>";
        if (Convert.ToInt16(Session["userGroup_Id"]) != 0)
        {
            ds = getmenu.getUserMenu(0, Convert.ToInt16(Session["userGroup_Id"]), strType);
            for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
            {
                String txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
                Session["TopMenu"] += "<td align='center'><a href='../" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a></td>";
                Session["TopMenu"] += "<td width='15' align='center'>|</td>";
            }
        }
        Session["TopMenu"] += "</tr></table>";
        ds.Clear();
        ds.Dispose();
        //End of Top Menu
        //Master Left menu
        ds = getmenu.getUserMenu(1, Convert.ToInt16(Session["userGroup_Id"]), strType);
        Session["MasterLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_Masters", ci) + "</span>";
        for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        {
            string txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
            Session["MasterLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        }
        ds.Clear();
        ds.Dispose();
        //End of Master Left Menu
        //Transaction left menu
        ds = getmenu.getUserMenu(2, Convert.ToInt16(Session["userGroup_Id"]), strType);
        Session["TransLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_Transactions", ci) + "</span>";
        for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        {
            string txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
            Session["TransLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        }
        ds.Clear();
        ds.Dispose();
        //End of Transaction Left Menu
        //Report left menu
        ds = getmenu.getUserMenu(3, Convert.ToInt16(Session["userGroup_Id"]), strType);
        Session["ReportLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_Reports", ci) + "</span>";
        for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        {
            string txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
            Session["ReportLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        }
        ds.Clear();
        ds.Dispose();
        //End of Report Left Menu
        //Org setting left menu
        ds = getmenu.getUserMenu(4, Convert.ToInt16(Session["userGroup_Id"]), strType);
        Session["OrgLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_Org_Settings", ci) + "</span>";
        for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        {
            string txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
            Session["OrgLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        }
        ds.Clear();
        ds.Dispose();
        //End of Org Setting Left MEnu
        //Sys Setting left menu            
        ds = getmenu.getUserMenu(5, Convert.ToInt16(Session["userGroup_Id"]), strType);
        Session["SystemLeftMenu"] = "<span class='LeftMenuHeader'>" + rm.GetString("Menu_System_Settings", ci) + "</span>";
        for (int iloop = 0; iloop <= ds.Tables[0].Rows.Count - 1; iloop++)
        {
            string txt = Convert.ToString(ds.Tables[0].Rows[iloop]["displayName"]);
            Session["SystemLeftMenu"] += "<a class='leftMenu' href='" + ds.Tables[0].Rows[iloop]["path"] + "' title='" + rm.GetString(txt, ci) + " '>" + rm.GetString(txt, ci) + " </a>";
        }
        ds.Clear();
        ds.Dispose();
        //End of Sys Setting Left Menu
    }
    private void getActiveLanguage()
    {
        ds_MultiLingual = objMultiLingualEventData.GetActiveLanguageDetails();
        Session["Session_ActiveLanguage"] = "";
        source_Language = "Resources." + Convert.ToString(ds_MultiLingual.Tables[0].Rows[0]["Resource_File_Name"]);
        Session["Session_ActiveLanguage"] = source_Language;
        //get the culture info to set the language
        CultureInfo ci;
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
    }
    /// <summary>
    /// Fill Language Details in dropdown list ddlLanguage
    /// </summary>
    private void fillLanguage()
    {
        //ds_MultiLingual = objMultiLingualEventData.GetLanguageDetails();
        //ddlLanguage.DataSource = ds_MultiLingual;
        //ddlLanguage.DataTextField = "Language_Name";
        //ddlLanguage.DataValueField = "Language_Id";
        //ddlLanguage.DataBind();
        //ddlLanguage.Items.Insert(0, rm.GetString("Select", ci));
        //ds_MultiLingual.Clear();
        //foreach (ListItem item in ddlLanguage.Items)
        //{
        //    item.Attributes.Add("title", item.Text);
        //}
    }
    /// <summary>
    /// set Active Language
    /// </summary>
    private void setActiveLanguage(int EmpID)
    {
        ds_MultiLingual = objMultiLingualEventData.GetEmployeeLingual(EmpID);
        //if (ds_MultiLingual.Tables.Count > 0)
        //{
        //    if (ds_MultiLingual.Tables[0].Rows.Count > 0)
        //    {
        //        ddlLanguage.SelectedValue = Convert.ToString(ds_MultiLingual.Tables[0].Rows[0]["Language_Id"]);
        //        hdnLanguage.Value = ddlLanguage.SelectedIndex.ToString();
        //    }
        //    else
        //    {
        //        ddlLanguage.SelectedValue = "1";
        //        hdnLanguage.Value = "2";
        //    }
        //}
        //else
        //{
        //    ddlLanguage.SelectedValue = "1";
        //    hdnLanguage.Value = "2";
        //}
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(75, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
    }
    #endregion
}