using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                     Started Date  : 12-Aug-2007
* Module          : Title Master                                  Last Modified : 14-Aug-2007
* Programmer      : Arun vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Master_TA_UI_Master_TitleFirstView : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Master_Title objTitle = new cls_Master_Title();
    cls_Common objClassCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    DataSet ds_Title = new DataSet();
    int TitleId, auEmpId;
    string gstrUserGroupName = string.Empty;
    int gradeMasterExists = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language        
        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;
        // LoadStrings Function fills the Label from the Resource File
        LoadStrings(ci);
        loadcss();
        auEmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        //Set UserRights
        UserRights();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        if (gstrUserGroupName != "SuperAdmin")
        {
            lbl_DeleteStatus_Main.Visible = false;
            lbl_DeleteStatus.Visible = false;
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        btn_Modify.Focus();
        TitleId = Convert.ToInt32(Request.QueryString["TitleId"].ToString());
        LoadTitle(TitleId);
        gradeMasterExists = objClassCommon.CheckPageExistsInLicense(228);
        if (gradeMasterExists == 0)
        {
            trStatus.Style.Add("display", "none");
        }
        ////if Standar Edition set the visibility to false
        //if (Session["Edition"].ToString() == "1")
        //{
        //    trStatus.Style.Add("display", "none");
        //}
        btn_Delete.OnClientClick = "return confirm('" + rm.GetString("Alert_ConfirmDelete", ci) + "')";
        btn_Restore.OnClientClick = "return confirm('" + rm.GetString("Alert_Areyousuretorestore", ci) + "')";
        btn_PermanentDelete.OnClientClick = "return confirm('" + rm.GetString("Alert_AreyouwantDeleteRecordPermanently", ci) + "')";
        int count = objTitle.CountTitle(TitleId);
        if (count > 0)
        {
            btn_Delete.Enabled = false;
            btn_PermanentDelete.Enabled = false;
        }
        if (!IsPostBack)
        {
            objClassCommon.menu("EmployeeMaster", "17");
        }
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadTitle(int id)
    {
        ds_Title = objTitle.SelectTitleFirstDetailsById(id, gstrUserGroupName);
        if (ds_Title != null)
        {
            if (ds_Title.Tables[0].Rows.Count > 0)
            {
                lbl_OrgLevel.Text = ds_Title.Tables[0].Rows[0]["Name"].ToString();
                lbl_TitleName.Text = ds_Title.Tables[0].Rows[0]["TitleName"].ToString();
                lbl_TitleDesc.Text = ds_Title.Tables[0].Rows[0]["TitleDescription"].ToString();
                lbl_Grade.Text = ds_Title.Tables[0].Rows[0]["Grade_Name"].ToString();
                lbl_Policy.Text = ds_Title.Tables[0].Rows[0]["PolicyName"].ToString();
                lbl_DeleteStatus.Text = ds_Title.Tables[0].Rows[0]["IsDeleted"].ToString();
                if (lbl_DeleteStatus.Text == "True" || lbl_DeleteStatus.Text == rm.GetString("Grid_True", ci))
                {
                    btn_Delete.Visible = false;
                }
                else if (lbl_DeleteStatus.Text == "False" || lbl_DeleteStatus.Text == rm.GetString("Grid_False", ci))
                {
                    btn_Restore.Visible = false;
                }
                if (lbl_DeleteStatus.Text == "True")
                {
                    lbl_DeleteStatus.Text = rm.GetString("Grid_True", ci);
                }
                else if (lbl_DeleteStatus.Text == "False")
                {
                    lbl_DeleteStatus.Text = rm.GetString("Grid_False", ci);
                }
            }
            ds_Title.Dispose();
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_OrganizationLevel.Text = rm.GetString("UserGroups_OrganizationLevel", ci);
        lbl_DesignationName.Text = rm.GetString("Designation_DesignationName", ci);
        lbl_DesignationDescription.Text = rm.GetString("Designation_DesignationDesc", ci);
        lbl_GradeName.Text = rm.GetString("Grade_GradeName", ci);
        lbl_LeavePolicy.Text = rm.GetString("Employee_LeavePolicy", ci);
        lbl_HeaderDesignation.Text = rm.GetString("EmployeeMaster_Designation", ci);
        lbl_DeleteStatus_Main.Text = rm.GetString("DeleteStatus", ci);
        btn_Modify.Text = rm.GetString("btn_Modify", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(17, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Master_TitleFirstList.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Modify.Visible = true;
            }
            else
            {
                this.btn_Modify.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
                this.btn_Restore.Visible = true;
                this.btn_PermanentDelete.Visible = true;
            }
            else
            {
                this.btn_Restore.Visible = false;
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    private void loadcss()
    {
        CultureInfo ci;
        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 Standard Demo
        htmlTitle.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            //htmlTitle.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_TitleFirstModify.aspx?TitleId=" + TitleId);
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_TitleFirstList.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int count = objTitle.CountTitle(TitleId);
        if (count == 0)
        {
            objTitle.DeleteTitles(Convert.ToString(TitleId), auEmpId);
            base.MessageWithRedirect(rm.GetString("Alert_DesignationDeletedSuccessfully", ci), "TA_UI_Master_TitleFirstList.aspx");
        }
        else
        {
            base.Message(rm.GetString("Alert_DesignationCannotbeDeleted", ci));
            return;
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        int intCount = objTitle.CheckTitleName_Update(TitleId);
        if (intCount > 0)
        {
            base.Message(rm.GetString("Message_Cannot_Restore", ci));
            return;
        }
        else
        {
            objTitle.RestoreTitles(TitleId.ToString(), auEmpId);
            base.MessageWithRedirect(rm.GetString("Alert_Designationrestoredsuccessfully", ci), "TA_UI_Master_TitleFirstList.aspx");
        }
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        int count = objTitle.CountTitle(TitleId);
        if (count == 0)
        {
            objTitle.PermanentDeleteTitles(Convert.ToString(TitleId), auEmpId);
            base.MessageWithRedirect(rm.GetString("Alert_DesignationDeletedSuccessfully", ci), "TA_UI_Master_TitleFirstList.aspx");
        }
        else
        {
            base.Message(rm.GetString("Alert_DesignationCannotbeDeleted", ci));
        }
    }
    #endregion
}