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
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_Levels : Base.BasePage
{
    #region Global Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string gstrUserGroupName = string.Empty;
    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);
        grvLevel.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            objCommon.menu("OrgSettings", "47");
        }
        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);
        UserRights();
        this.btn_Delete.Focus();

    }
    #endregion
    #region Button Click Events
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        levelsEventData del = new levelsEventData();
        LinkButton btn = sender as LinkButton;
        int LevelId = Convert.ToInt32(btn.CommandName);
        del.DelLev(Convert.ToString(LevelId), "D");
        string str = "alert('" + rm.GetString("Alert_Level_Settings_Deleted_Successfully", ci) + "');location.replace('Organization_levels.aspx?sid=" + Session.SessionID + "');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    protected void butAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_levelAdd.aspx?sid=" + Session.SessionID);
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        levelsEventData del = new levelsEventData();
        if (hdnSelectRow.Value != string.Empty)
        {
            del.DelLev(hdnSelectRow.Value, "D");
        }
        string str = "alert('" + rm.GetString("Alert_Level_Settings_Deleted_Successfully", ci) + "');location.replace('Organization_levels.aspx?sid=" + Session.SessionID + "');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    #endregion
    #region User Defined Functions
    private void LoadStrings(CultureInfo ci)
    {
        lblImportNote.Text = rm.GetString("Field_ImportantNote", ci);
        butAdd.Text = "&nbsp;&nbsp;" + rm.GetString("btn_AddNewLevel", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        grvLevel.Columns[1].Caption = rm.GetString("Level_Id", ci);
        grvLevel.Columns[3].Caption = rm.GetString("Parent_Id", ci);
        grvLevel.Columns[2].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grvLevel.Columns[4].Caption = rm.GetString("Grid_Edit", ci);
        lblTitle.Text = rm.GetString("Org_Level_Settings", ci);
    }
    private void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(47, Convert.ToInt32(Session["userGroup_Id"]), "");
            if (ds_Checkuser.Tables[0].Rows.Count > 0)
            {
                if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
                {
                    if (this.grvLevel.VisibleRowCount > 0)
                    {
                        this.butAdd.Visible = false;
                    }
                    else
                    {
                        this.butAdd.Visible = true;
                    }
                }
                else
                {
                    this.butAdd.Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
                {
                    this.grvLevel.Columns[0].Visible = true;
                    this.grvLevel.Columns[6].Visible = true;
                    this.btn_Delete.Visible = true;
                }
                else
                {
                    this.grvLevel.Columns[0].Visible = false;
                    this.grvLevel.Columns[6].Visible = false;
                    this.btn_Delete.Visible = false;

                }
                if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
                {
                    this.grvLevel.Columns[4].Visible = true;
                }
                else
                {
                    this.grvLevel.Columns[4].Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 0)
                {
                    //Response.Redirect("OrganizationLandingPage.aspx");
                    this.grvLevel.Columns[5].Visible = true;
                }
                else
                {
                    this.grvLevel.Columns[5].Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    protected void ObjectDataSource1_Updated(object sender, ObjectDataSourceStatusEventArgs e)
    {
        DataSet ds = new DataSet();
        ds = (DataSet)e.ReturnValue;
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows[0][0] != DBNull.Value && Convert.ToString(ds.Tables[0].Rows[0][0]) == "0")
            {
                Page.RegisterStartupScript("Alert", "<script>alert('" + rm.GetString("Alert_Level_Settings_Saved_Successfully", ci) + "');</script>");
            }
            else
            {
                Page.RegisterStartupScript("Alert", "<script>alert('" + rm.GetString("Alert_Levelnamealreadyexits", ci) + "');</script>");
            }
        }
    }
    #endregion
    #region GridView Events
    protected void grvLevel_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            LinkButton BtnDelete = grvLevel.FindRowCellTemplateControl(e.VisibleIndex, null, "btnDelete") as LinkButton;
            if (BtnDelete != null)
            {
                if (BtnDelete.Enabled == false)
                {
                    BtnDelete.OnClientClick = null;
                }
            }

        }
    }
    #endregion

}
