using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Leave Master                                Last Modified : 14-Aug-2007
* Programmer      : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Master_TA_UI_MasterLeaveTypeView : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    LeaveEventData objLeavetype = new LeaveEventData();
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet ds_Leave = new DataSet();
    int gintLeaveTypeId;
    string gstrUserGroupName = string.Empty;
    int EmployeeID = 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"]);
        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();
        gintLeaveTypeId = Convert.ToInt32(Request.QueryString["LeaveId"].ToString());
        int Count = objLeavetype.CheckLeaveType(gintLeaveTypeId);
        if (Count > 0)
        {
            btn_Modify.Enabled = false;
            btn_Delete.Enabled = false;
            btn_PermanentDelete.Enabled = false;
            btn_Restore.Enabled = false;
        }
        if (gstrUserGroupName != "SuperAdmin")
        {
            lbl_Status.Visible = false;
            lbl_RecordStatus.Visible = false;
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        if (!IsPostBack)
        {
            LoadLeaveType(gintLeaveTypeId);
            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("LeaveMasters", "195");
        }
        trCountFactor.Attributes.Add("style", "display:''");
        btn_Modify.Focus();
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadLeaveType(int LeaveTypeid)
    {
        ds_Leave = objLeavetype.SelectLeaveTypeDetailsById(LeaveTypeid, gstrUserGroupName);
        if (ds_Leave.Tables[0].Rows.Count > 0)
        {
            lbl_LeaveType.Text = ds_Leave.Tables[0].Rows[0]["LeaveType"].ToString();
            lbl_LeaveDescription.Text = ds_Leave.Tables[0].Rows[0]["LeaveDescription"].ToString();
            lbl_RecordStatus.Text = ds_Leave.Tables[0].Rows[0]["IsDeleted"].ToString();
            if (ds_Leave.Tables[0].Rows[0]["EmployeeCategory"].ToString() != string.Empty && ds_Leave.Tables[0].Rows[0]["EmployeeCategory"].ToString() != null)
            {
                lbl_EmpCategory.Text = ds_Leave.Tables[0].Rows[0]["EmployeeCategory"].ToString();
            }
            else if (ds_Leave.Tables[0].Rows[0]["EmployeeCategory"].ToString() == string.Empty || ds_Leave.Tables[0].Rows[0]["EmployeeCategory"].ToString() == null)
            {
                lbl_EmpCategory.Text = "All";
            }
            if (ds_Leave.Tables[0].Rows[0]["EmployeeType"].ToString() != string.Empty && ds_Leave.Tables[0].Rows[0]["EmployeeType"].ToString() != null)
            {
                lbl_EmpType.Text = ds_Leave.Tables[0].Rows[0]["EmployeeType"].ToString();
            }
            else if (ds_Leave.Tables[0].Rows[0]["EmployeeType"].ToString() == string.Empty || ds_Leave.Tables[0].Rows[0]["EmployeeType"].ToString() == null)
            {
                lbl_EmpType.Text = "All";
            }
            lbl_Gender.Text = Convert.ToString(ds_Leave.Tables[0].Rows[0]["Gender"]);
            if (ds_Leave.Tables[0].Rows[0]["Religion"].ToString() != string.Empty && ds_Leave.Tables[0].Rows[0]["Religion"].ToString() != null)
            {
                lbl_Religion.Text = ds_Leave.Tables[0].Rows[0]["Religion"].ToString();
            }
            else if (ds_Leave.Tables[0].Rows[0]["Religion"].ToString() == null || ds_Leave.Tables[0].Rows[0]["Religion"].ToString() == string.Empty)
            {
                lbl_Religion.Text = "All";
            }
            if (ds_Leave.Tables[0].Rows[0]["CountFactor"].ToString() == "True")
            {
                lblCountFactorData.Text = rm.GetString("ShiftSetting_Yes", ci);
            }
            else
            {
                lblCountFactorData.Text = rm.GetString("ShiftSetting_No", ci);
            }
            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);
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("lbl_leavetype", ci);
        lbl_Leave.Text = rm.GetString("lbl_leavetype", ci);
        lbl_Des.Text = rm.GetString("LeaveType_LeaveDesc", ci);
        lbl_Status.Text = rm.GetString("DeleteStatus", ci);
        lblCountFactor.Text = rm.GetString("lblCountFactor", 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);
        lblGender.Text = rm.GetString("EmployeeMaster_Gender", ci);
        lblReligion.Text = rm.GetString("EmployeeMaster_Religion", ci);
        lblEmpCategory.Text = rm.GetString("Master_Category", ci);
        lblEmpType.Text = rm.GetString("Master_Type", ci);
        lbl_LeaveType.Text = rm.GetString("lbl_leavetype", ci);
    }
    /// <summary>
    ///Function Sets User Rights 
    /// </summary>
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(195, 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_MasterLeaveTypeList.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
        htmlLeaveType.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
        {
            //htmlLeaveType.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)
    {
        int Count = objLeavetype.CheckLeaveType(gintLeaveTypeId);
        int Count1 = objLeavetype.CheckLeaveType_LeaveApp(gintLeaveTypeId);
        if (Count > 0 || Count1 > 0)
        {
            base.Message(rm.GetString("Master_Leave_Type_Cannot_Modify", ci));
        }
        else
        {
            Response.Redirect("TA_UI_MasterLeaveTypeModify.aspx?LeaveId=" + gintLeaveTypeId);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_MasterLeaveTypeList.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int Count = objLeavetype.CheckLeaveType(gintLeaveTypeId);
        int Count1 = objLeavetype.CheckLeaveType_LeaveApp(gintLeaveTypeId);
        if (Count > 0 || Count1 > 0)
        {
            base.Message(rm.GetString("Alert_Cannot_Delete_this_Record_It_is_Already_mapped", ci));
        }
        else
        {
            objLeavetype.Delete_LeaveTypes(Convert.ToString(gintLeaveTypeId), EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_LeaveTypedeletedsuccessfully", ci), "TA_UI_MasterLeaveTypeList.aspx");
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        string strLeaveType = lbl_LeaveType.Text.Trim().Replace("'", "''");
        int Count = objLeavetype.CheckRestoreLeaveType(gintLeaveTypeId);
        if (Count > 0)
        {
            base.Message(rm.GetString("Message_Cannot_Restore", ci));
            return;
        }
        else
        {
            objLeavetype.RestoreLeaveTypes(Convert.ToString(gintLeaveTypeId), EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_LeaveTyperestoredsuccessfully", ci), "TA_UI_MasterLeaveTypeList.aspx");
        }
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        int Count = objLeavetype.CheckLeaveType(gintLeaveTypeId);
        int Count1 = objLeavetype.CheckLeaveType_LeaveApp(gintLeaveTypeId);
        if (Count > 0 || Count1 > 0)
        {
            base.Message(rm.GetString("Message_Cannot_Delete", ci));
        }
        else
        {
            objLeavetype.PermanentDeleteLeaveTypes(Convert.ToString(gintLeaveTypeId), EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_LeaveTypedeletedsuccessfully", ci), "TA_UI_MasterLeaveTypeList.aspx");
        }
    }
    #endregion
}