using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 12-Aug-2007
* Module          : Organisation Levels                               Last Modified : 19-Aug-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_OrganisationLevels : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    cls_Common objCommon = new cls_Common();
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        CultureInfo ci;
        // session checking
        base.Page_Load(sender, e);
        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 (source_Language == "Resources.Resource_AR")
        {
            tvLevel.LineImagesFolder = "../dist/img/TreeLineImage_RTL";
        }
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        if (!Page.IsPostBack)
        {
            getNodes();
            base.CheckPages(6);
            objCommon.menu("OrgSettings", "6");
        }
    }
    #endregion
    #region UserDefinedFunctions
    public void getNodes()
    {
        try
        {
            org_levelsEventData levl = new org_levelsEventData();
            DataSet dsLev = new DataSet();
            dsLev = levl.selectLevels();
            int count;
            for (count = 0; count < dsLev.Tables[0].Rows.Count; count++)
            {
                TreeNode root = new TreeNode();
                if (Convert.ToInt16(dsLev.Tables[0].Rows[count]["parentlevelid"]) == 0)
                {
                    DropDownList dd = new DropDownList();
                    dd.DataTextField = Convert.ToString(dsLev.Tables[0].Rows[count]["levelName"]);
                    dd.DataBind();
                    root.Text = Convert.ToString(dsLev.Tables[0].Rows[count]["levelName"]);
                    root.Value = Convert.ToString(dsLev.Tables[0].Rows[count]["levelid"]);
                    root.NavigateUrl = "TA_UI_Master_LevelDetails.aspx?tid=" + Convert.ToString(dsLev.Tables[0].Rows[count]["levelid"]) + "&sid=" + Session.SessionID;
                    getChildNodes(root, Convert.ToInt16(dsLev.Tables[0].Rows[count]["levelid"]));
                    this.tvLevel.Nodes.Add(root);
                }
            }
            dsLev.Dispose();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
    public void getChildNodes(TreeNode parent, Int16 menuNo)
    {
        org_levelsEventData levl = new org_levelsEventData();
        DataSet dsLev1 = new DataSet();
        dsLev1 = levl.selectLevels();
        TreeNode childNode;
        int rowCount = 0, kloop = 0;
        for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
        {
            if (Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["parentLevelId"]) == menuNo)
            {
                rowCount += 1;
            }
        }
        if (rowCount != 0)
        {
            for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
            {
                if (Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["parentLevelId"]) == menuNo)
                {
                    childNode = new TreeNode();
                    childNode.Text = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["levelName"]);
                    childNode.Value = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["levelid"]);
                    childNode.NavigateUrl = "TA_UI_Master_LevelDetails.aspx?tid=" + Convert.ToString(dsLev1.Tables[0].Rows[kloop]["levelid"]) + "&sid=" + Session.SessionID;
                    parent.ChildNodes.Add(childNode);
                    getChildNodes(childNode, Convert.ToInt16(dsLev1.Tables[0].Rows[kloop]["levelid"]));
                }
            }
        }
        dsLev1.Dispose();
    }
    protected void tvLevel_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    {
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Menu_Masters_OrgLevels", ci);
    }
    #endregion
}