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          : Level Settings                              Last Modified : 14-Aug-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_LevelDetails : Base.BasePage
{
    #region Global Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    DemoVersion objDemoVersion = new DemoVersion();
    cls_Common objCommon = new cls_Common();
    #endregion

    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_AreyousuretoDelete", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        try
        {
            if (this.grvLevel.Rows.Count > 0)
            {
                this.butAdd.Visible = false;
            }
            else
            {
                this.butAdd.Visible = true;
            }
            if (!IsPostBack)
            {
                int levelid = Convert.ToInt16(Request.QueryString["tid"]);
                if (levelid != 0)
                {
                    Session["levelid"] = levelid;
                    getLevelDetails();
                }
                objCommon.menu("OrgSettings", "47");
            }
            Cls_CheckUser chck = new Cls_CheckUser();
            DataSet ds = chck.checkRights(47, Convert.ToInt32(Session["userGroup_Id"]), " ");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds.Tables[0].Rows[0]["addPrv"]) == 1)
                {
                    if (this.grvLevel.Rows.Count > 0)
                    {
                        this.butAdd.Visible = false;
                    }
                    else
                    {
                        this.butAdd.Visible = true;
                    }
                }
                else
                {
                    this.butAdd.Visible = false;
                }
                if (ds.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds.Tables[0].Rows[0]["deletePrv"]) == 1)
                {
                    this.grvLevel.Columns[4].Visible = true;
                }
                else
                {
                    this.grvLevel.Columns[4].Visible = false;
                }
            }
            else
            {
                Response.Redirect("Organisation_levels.aspx");
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
    #endregion

    #region User Defined Functions
    protected void getLevelDetails()
    {
        levelsEventData selectLevel = new levelsEventData();
        DataSet dsLev = new DataSet();
        dsLev = selectLevel.selectLevelDetails(Convert.ToInt16(Session["levelid"]));
        if (dsLev.Tables[0].Rows.Count > 0)
        {
            if ((Convert.ToString(dsLev.Tables[0].Rows[0]["levelName"]) != ""))
            {
                this.lblHead.Text = Convert.ToString(dsLev.Tables[0].Rows[0]["levelName"]) + " " + rm.GetString("Caption_Details", ci);
            }
        }
        else
        {
            this.lblHead.Text = rm.GetString("btn_Add_Child_Level", ci);
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lblHeader.Text = rm.GetString("Org_Level_Settings", ci);
        butAdd.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add_Child_Level", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        grvLevel.Columns[4].HeaderText = rm.GetString("DeleteStatus", ci);
        grvLevel.Columns[2].HeaderText = rm.GetString("Child_Level", ci);
    }
    #endregion

    #region Button Click events
    protected void butAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_levelAdd.aspx?sid=" + Session.SessionID);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Session["levelid"] = null;
        Response.Redirect("Organization_levels.aspx");
    }
    #endregion

    #region GridView Events
    protected void grvLevel_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lbllev = (Label)e.Row.Cells[0].FindControl("lbllev");
            lbllev.Text = rm.GetString("btn_Delete", ci);
        }
    }
    #endregion
}
