using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
public partial class Masters_TA_UI_Master_ReligionModify : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ReligionMaster objReligion = new ReligionMaster();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    DataSet ds_Religion = new DataSet();
    int gintReligionId;
    string gstrUserGroupName = string.Empty;
    int EmployeeID = 0;
    #endregion
    #region "Page Load"
    /// <summary>
    /// When page is loaded
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    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"]);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        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);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        //Set UserRights
        UserRights();
        loadcss();
        gintReligionId = Convert.ToInt32(Request.QueryString["ReligionId"].ToString());
        if (gstrUserGroupName != "SuperAdmin")
        {
            lbl_Status.Visible = false;
            lbl_RecordStatus.Visible = false;
            //btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        if (!IsPostBack)
        {
            LoadReligionType(gintReligionId);
            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) + "')";
            objCommon.menu("EmployeeMaster", "229");
        }
        btn_Modify.Focus();
        int count = objReligion.CheckReligionReferance(gintReligionId);
        if (count > 0)
        {
            btn_Delete.Enabled = false;
            btn_PermanentDelete.Enabled = false;
        }
    }
    #endregion
    #region "User Defined Function"
    /// <summary>
    /// To load label names
    /// </summary>
    /// <param name="ci"></param>
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lbl_Religion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lbl_Des.Text = rm.GetString("Caption_ReligionName", ci);
        lbl_Status.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_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
    }
    /// <summary>
    ///Function Sets User Rights 
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(229, 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_ReligionList.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_PermanentDelete.Visible = true;
                //this.btn_Restore.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
                //this.btn_Restore.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
        htmlReligin.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
        {
            //htmlReligin.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";
        }
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="Religionid"></param>
    private void LoadReligionType(int Religionid)
    {
        ds_Religion = objReligion.SelectReligionDetailsById(Religionid, gstrUserGroupName);
        if (ds_Religion.Tables[0].Rows.Count > 0)
        {
            lbl_Religionname.Text = ds_Religion.Tables[0].Rows[0]["Name"].ToString();
            lbl_ReligionDescription.Text = ds_Religion.Tables[0].Rows[0]["Description"].ToString();
            lbl_RecordStatus.Text = ds_Religion.Tables[0].Rows[0]["IsDeleted"].ToString();
            if (lbl_RecordStatus.Text == "True" || lbl_RecordStatus.Text == rm.GetString("Grid_True", ci))
            {
                btn_Delete.Visible = false;
            }
            else if (lbl_RecordStatus.Text == "False" || lbl_RecordStatus.Text == rm.GetString("Grid_False", ci))
            {
                //btn_Restore.Visible = false;
            }
            if (lbl_RecordStatus.Text == "True")
            {
                lbl_RecordStatus.Text = rm.GetString("Grid_True", ci);
            }
            else if (lbl_RecordStatus.Text == "False")
            {
                lbl_RecordStatus.Text = rm.GetString("Grid_False", ci);
            }
        }
    }
    #endregion
    #region "Button Events"
    /// <summary>
    /// Modify function
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ReligionModify.aspx?Id=" + gintReligionId);
    }
    /// <summary>
    /// Cancel function
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ReligionList.aspx");
    }
    /// <summary>
    /// Delete function
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int intReferranceCount = objReligion.CheckReligionReferance(gintReligionId);
        // set enable status to delete check box
        if (intReferranceCount > 0)
        {
            base.Message(rm.GetString("Alert_Cannot_Delete_this_Record_It_is_Already_mapped", ci));
        }
        else if (intReferranceCount == 0)
        {
            objReligion.Delete_ReligionTypes(Convert.ToString(gintReligionId), EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Religiondeletedsuccessfully", ci), "TA_UI_Master_ReligionList.aspx");
        }
    }
    /// <summary>
    /// Permanent delete function
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        int count = objReligion.CheckReligionReferance(gintReligionId);
        if (count == 0)
        {
            objReligion.PermanentDeletereligionTypes(Convert.ToString(gintReligionId), EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Religiondeletedsuccessfully", ci), "TA_UI_Master_ReligionList.aspx");
        }
        else
        {
            base.Message(rm.GetString("Alert_Cannot_Delete_this_Record_It_is_Already_mapped", ci));
        }
    }
    #endregion
}
