using System;
using System.Data;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                              Started Date  : 12-Aug-2007
* Module          : Organisation Levels                                    Last Modified : 20-July-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_getOrg : Base.BasePage
{
    //Adding by MAnjula.P on 07-Jan-2014 for loading designation based on organization level in employee master modify page
    EmployeeEventData objEmployee = new EmployeeEventData();
    cls_Common objcommon = new cls_Common();
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        if (!IsPostBack)
        {            
        }
        int ctr = Convert.ToInt16(Request.QueryString["ctr"]);
        if (Request.QueryString["level"] != "Select")
        {
            int levelid = Convert.ToInt16(Request.QueryString["level"]);
            //int levelno = Convert.ToInt16(Request.QueryString["levelno"]);
            Session["parentLevelId"] = levelid;
            //Assign Top Level in Session
            if (ctr == 1)
            {
                Session["TopLevel"] = levelid;
            }
            //Session["Designation"] = null;
            //Session["Reporting"] = null;
            //Session["LeaveSanc"] = null;
            setLevel1(levelid);
        }
        else
        {
            if (ctr == 1)
            {
                Session["TopLevel"] = null;
            }
            Session["parentLevelId"] = null;
            int ses = Convert.ToInt16(Request.QueryString["ses"]);
            Session["parentLevelId"] = ses;
            setLevel1(-1);
        }
    }
    /// <summary>
    /// Added by Manjula.P on 07-Jan-2014 for showing designation based on selected levels in employee master
    /// </summary>
    /// <param name="levelID"></param>
    /// <returns></returns>
    private DataSet fillDesignationddl(int levelID)
    {
        DataSet ds_designation = new DataSet();
        ds_designation = objEmployee.select_Designationdetails(levelID);
        return ds_designation;
    }
    //*****************************************************************************************************
    protected void setLevel1(int para1)
    {
        cls_master_levels class1 = new cls_master_levels();
        DataSet ds = new DataSet();
        // ds = class1.getOrgLevelUpdated(para1, Convert.ToString(Session["LevelRights"]), Convert.ToInt32(Session["parentLevelId"]), Convert.ToString(Session["UserGroupName"]));
        //Included by sashma on 27-Sep-2010
        if (Session["OrgLevels"] != null)
        {
            ds = (DataSet)Session["OrgLevels"];
        }
        DataSet dsOrgLevel = new DataSet();
        if (ds.Tables[0].Rows.Count > 0)
        {
            ds.Tables[0].DefaultView.RowFilter = "ParentId= '" + para1 + "'";
            ds.Tables[0].DefaultView.ToTable().TableName = "Org";
            //Adding by MAnjula.P on 07-Jan-2014 for loading designation based on organization level in employee master modify page Condition only
            if (ds.Tables[0].DefaultView.ToTable().Rows.Count > 0)
                dsOrgLevel.Tables.Add(ds.Tables[0].DefaultView.ToTable());
        }
        //Adding by MAnjula.P on 07-Jan-2014 for loading designation based on organization level in employee master modify page
        DataTable dtTemp = fillDesignationddl(Convert.ToInt16(Session["TopLevel"])).Tables[0];
        dtTemp.TableName = "Designation";
        dsOrgLevel.Tables.Add(dtTemp.Copy());
        int intDesignationId = 0;
        if (Session["DesignationId_modify"] != string.Empty)
            intDesignationId = Convert.ToInt32(Session["DesignationId_modify"]);
        //Checking whether the designation is changed or not
        dtTemp.DefaultView.RowFilter = "TitleId= '" + intDesignationId + "'";
        DataSet ds_Person = new DataSet();
        ds_Person = objEmployee.SelectReportingPerson(intDesignationId);
        if (ds_Person.Tables[0].Rows.Count > 0 && dtTemp.Rows.Count > 0 && dtTemp.DefaultView.ToTable().Rows.Count > 0)
        {
            DataTable dtPers = new DataTable();
            dtPers = ds_Person.Tables[0];
            dtPers.TableName = "Person";
            dsOrgLevel.Tables.Add(dtPers.Copy());
        }
        ///******************************************************************
        if (dsOrgLevel != null)
        {
            if (dsOrgLevel.Tables.Count > 0)
            {
                if (dsOrgLevel.Tables[0].Rows.Count > 0)
                {
                    Response.Clear();
                    Response.ContentType = "text/xml";
                    Response.Write(dsOrgLevel.GetXml());
                    //Response.Write(dtTemp.GetXml());
                    Response.End();
                    ds.Dispose();
                }
            }
        }
    }
}
