using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
public partial class UserControls_TA_uc_OrgLevel_Filter_Modify : System.Web.UI.UserControl
{
    cls_Common objCommon = new cls_Common();
    ResourceManager rm;
    CultureInfo ci;
    protected void Page_Load(object sender, EventArgs e)
    {
        //get the culture info to set the language               
        string strSourceLanguage;
        strSourceLanguage = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(strSourceLanguage, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (!IsPostBack)
        {
            //Session["parentLevelId"] = null;
        }
        getLev();
    }
    private void getLev()
    {
        cls_master_levels totLev = new cls_master_levels();
        int tot = 0;
        int maxId;
        //tot = totLev.getNoLevel();
        maxId = totLev.getMaxLevel();
        string IDs = "";
        string orgIds = "";
        string IDsName = "";
        string IDsName1 = "";
        int intialVal = 0;
        DataSet ds_ParentLevels = new DataSet();
        DataSet ds_maxLevel = new DataSet();
        //int LevelID = Convert.ToInt16(Session["orgLevelid"]);
        int LevelID = Convert.ToInt16(Session["parentLevelId_modify"]);
        ///Added by Manjula.P on 08-Jan-2014 for getting designation assign
        int DesignationId = 0;
        int PFESI_ID = 0;
        int ReportingTo = 0;
        int Authority = 0;
        if (Convert.ToString(Session["DesignationId_modify"]) != string.Empty)
            DesignationId = Convert.ToInt32(Session["DesignationId_modify"]);

        if(Convert.ToString(Session["PFESI_modify"])!=string.Empty)
        {
            PFESI_ID = Convert.ToInt32(Session["PFESI_modify"]);
        }

        if (Convert.ToString(Session["Reporting_To_modify"]) != string.Empty)
            ReportingTo = Convert.ToInt32(Session["Reporting_To_modify"]);
        if (Convert.ToString(Session["Leave_Sanc_Authority_modify"]) != string.Empty)
            Authority = Convert.ToInt32(Session["Leave_Sanc_Authority_modify"]);
        //*****************************************************************
        //objCommon.GetParentLevels_FromLevelID(LevelID);
        objCommon.GetParentLevels_FromLevelID(maxId);
        ds_ParentLevels = objCommon.GetParentLevels();
        if (ds_ParentLevels.Tables[0].Rows.Count > 0)
        {
            tot = ds_ParentLevels.Tables[0].Rows.Count;
        }
        else
        {
        }
        foreach (DataRow dr in ds_ParentLevels.Tables[0].Rows)
        {
            if (IDs == "")
            {
                IDs = dr[0].ToString();
                IDsName = "'" + dr[1].ToString().Replace("'", "\\'") + "'";
                IDsName1 = dr[1].ToString();
                //this.lblTitle.Text = IDsName1;
                intialVal = Convert.ToInt16(IDs);
            }
            else
            {
                IDs = IDs + "," + dr[0].ToString();
                //IDsName = IDsName + "," + "'" + dr[1].ToString() + "'";
                IDsName = IDsName + "," + "'" + dr[1].ToString().Replace("'", "\\'") + "'";
            }
        }
        //getting parent of the selected organizationlevel
        //int orgID = Convert.ToInt16(Session["parentLevelId"]);
        int orgID = Convert.ToInt16(Session["parentLevelId_modify"]);
        if (orgID == null || orgID == 0)
        {
            //start
            string strLevelID = Convert.ToString(Session["LevelRights"]);
            string str = strLevelID;
            char[] comma = { ',' };
            string[] str1 = str.Split(comma);
            //sb.Remove(0,sb.Length);
            int Max = 0;
            int temp = 0;
            foreach (string st in str1)
            {
                if (st != "" && Convert.ToInt32(st) > Max)
                {
                    Max = Convert.ToInt32(st);
                }
            }
            //end
            orgID = Max;
        }
        org_levelsEventData getOrg = new org_levelsEventData();
        getOrg.GetOrgParentLevels_FromID(orgID);
        DataSet ds_getOrg = new DataSet();
        ds_getOrg = getOrg.GetOrgParentLevels();
        foreach (DataRow dr1 in ds_getOrg.Tables[0].Rows)
        {
            if (orgIds == "")
            {
                orgIds = dr1[0].ToString();
            }
            else
            {
                orgIds = orgIds + "," + dr1[0].ToString();
            }
            //end
        }
        this.Page.RegisterStartupScript("AjaxCall", "<script>var orgArray=new Array( " + orgIds + ",0); var OrgDesignationId=" + DesignationId + "; var orgPFESI="+PFESI_ID+"; var ReportingTo=" + ReportingTo + "; var AthorityTo=" + Authority + "; var totLevels =" + (Convert.ToInt16(tot)) + ";var levelArray=new Array(" + IDs + "); var levelNameArray = new Array(" + IDsName + "); chckLevel1_getOrg(0,0,'" + rm.GetString("Select", ci) + "');</script>");
    }
}
