using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Additional WeeklyOff Settings               Last Modified : 14-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_AddlWeekoffView : Base.BasePage
{
    #region "VariableDeclaration"
    AddlWeekOffEventData objAddlWeekOff = new AddlWeekOffEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int intAddlWeekoffID = 0, levelId = 0, auditEmpId;
    ResourceManager rm;
    CultureInfo ci;
    string gstrUserGroupName = string.Empty;
    #endregion

    #region Page Load Events
    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;
        LoadStrings(ci);
        auditEmpId = Convert.ToInt32(Session["EmpAutoID"]);
        UserRights();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        if (gstrUserGroupName == "SuperAdmin")
        {
            btn_Restore.Visible = true;
            btn_PermanentDelete.Visible = true;
        }
        else
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
            lblDeleted.Visible = false;
            lblDeletedData.Visible = false;
        }
        btn_Delete.Attributes.Add("onclick", "return confirm('" + rm.GetString("Alert_AreYousuretodeletetheRecord", ci) + "')");
        btn_Restore.OnClientClick = "return confirm('" + rm.GetString("Alert_Areyousuretorestore", ci) + "')";
        btn_PermanentDelete.OnClientClick = "return confirm('" + rm.GetString("Alert_AreyouwantDeleteRecordPermanently", ci) + "')";
        try
        {
            intAddlWeekoffID = Convert.ToInt32(Request.QueryString["AddlWeekoff_Id"]);
            DataSet ds = new DataSet();
            ds = objAddlWeekOff.Select_AddlWeekoffdetails_view(intAddlWeekoffID, gstrUserGroupName);
            lbl_LevelName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
            ViewState["Addl_WeekOff_Day"] = ds.Tables[0].Rows[0]["Addl_WeekOff_Day"].ToString();
            ViewState["Addl_WeekOff_Week"] = ds.Tables[0].Rows[0]["Addl_WeekOff_Week"].ToString();
            switch (ds.Tables[0].Rows[0]["Addl_WeekOff_Day"].ToString())
            {
                case "Sunday":
                    lbl_Day.Text = rm.GetString("Sunday", ci);
                    break;
                case "Monday":
                    lbl_Day.Text = rm.GetString("Monday", ci);
                    break;
                case "Tuesday":
                    lbl_Day.Text = rm.GetString("Tuesday", ci);
                    break;
                case "Wednesday":
                    lbl_Day.Text = rm.GetString("Wednesday", ci);
                    break;
                case "Thursday":
                    lbl_Day.Text = rm.GetString("Thursday", ci);
                    break;
                case "Friday":
                    lbl_Day.Text = rm.GetString("Friday", ci);
                    break;
                case "Saturday":
                    lbl_Day.Text = rm.GetString("Saturday", ci);
                    break;
            }
            switch (ds.Tables[0].Rows[0]["Addl_WeekOff_Week"].ToString())
            {
                case "First Week":
                    lbl_Week.Text = rm.GetString("FirstWeek", ci);
                    break;
                case "Second Week":
                    lbl_Week.Text = rm.GetString("SecondWeek", ci);
                    break;
                case "Third Week":
                    lbl_Week.Text = rm.GetString("ThirdWeek", ci);
                    break;
                case "Fourth Week":
                    lbl_Week.Text = rm.GetString("FourthWeek", ci);
                    break;
                case "Fifth Week":
                    lbl_Week.Text = rm.GetString("FifthWeek", ci);
                    break;
            }
            levelId = Convert.ToInt16(ds.Tables[0].Rows[0]["LevelId"]);
            if (ds.Tables[0].Rows[0]["Isdeleted"].ToString() != "")
            {
                lblDeletedData.Text = ds.Tables[0].Rows[0]["Isdeleted"].ToString();
                if (lblDeletedData.Text == "True" || lblDeletedData.Text == rm.GetString("Grid_True", ci))
                {
                    btn_Delete.Visible = false;
                }
                else if (lblDeletedData.Text == "False" || lblDeletedData.Text == rm.GetString("Grid_False", ci))
                {
                    btn_Restore.Visible = false;
                }
                if (lblDeletedData.Text == "True")
                {
                    lblDeletedData.Text = rm.GetString("Grid_True", ci);
                }
                else if (lblDeletedData.Text == "False")
                {
                    lblDeletedData.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
        catch
        {
        }
    }
    #endregion

    #region Button Click Events
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_AddlWeekoff_Modify.aspx?AddlWeekoff_Id=" + intAddlWeekoffID);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_AddlWeekoff.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        try
        {
            objAddlWeekOff.TemporaryDelete_AddlWeekoffInView(intAddlWeekoffID, auditEmpId);
            string str = "alert('" + rm.GetString("Alert_Deleted_Sucessfully", ci) + "');location.replace('Organization_AddlWeekoff.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        catch
        {
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        int count = objAddlWeekOff.CheckRestoreAddlWeekoff(intAddlWeekoffID, ViewState["Addl_WeekOff_Day"].ToString(), ViewState["Addl_WeekOff_Week"].ToString(), "V");
        if (count > 0)
        {
            lblError.Text = rm.GetString("Message_Cannot_Restore", ci);
            return;
        }
        objAddlWeekOff.Restore_AddlWeekoffInView(intAddlWeekoffID, auditEmpId);
        Response.Redirect("Organization_AddlWeekoff.aspx");
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        try
        {
            objAddlWeekOff.PermanentDelete_AddlWeekoffInView(intAddlWeekoffID, auditEmpId);
            string str = "alert('" + rm.GetString("Alert_Deleted_Sucessfully", ci) + "');location.replace('Organization_AddlWeekoff.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        catch
        {
        }
    }
    #endregion

    #region User Definde Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Level.Text = rm.GetString("LevelDetails_LevelName", ci);
        lbl_WeekDay.Text = rm.GetString("AdditionalWeeklyOff_SelectedWeek", ci);
        lbl_Weekoff.Text = rm.GetString("AdditionalWeeklyOff_WeeklyOffDay", ci);
        lbl_Header.Text = rm.GetString("Org_Additional_Weeklyoff", ci);
        btn_Save.Text = rm.GetString("btn_Modify", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        lblDeleted.Text = rm.GetString("DeleteStatus", ci);
    }
    private void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(49, Convert.ToInt32(Session["userGroup_Id"]), "");
            if (ds_Checkuser.Tables[0].Rows.Count > 0)
            {
                if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
                {
                    this.btn_Save.Visible = true;
                }
                else
                {
                    this.btn_Save.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;
                }
                else
                {
                    this.btn_Delete.Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
                {
                    Response.Redirect("Organization_AddlWeekoff.aspx");
                }
            }
        }
        catch
        {
        }
    }
    #endregion
}
