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_AddlWeekoff_Modify : Base.BasePage
{
    #region Variable declaration
    AddlWeekOffEventData objAddlWeekOff = new AddlWeekOffEventData();
    ResourceManager rm;
    CultureInfo ci;
    int intAddlWeekofID = 0, LevelID, auditEmpId;
    string strAddlWeekOffDay = "";
    string strAddlWeekOffWeek = "";
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    #endregion

    #region Page Load Event
    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();
        try
        {
            intAddlWeekofID = Convert.ToInt32(Request.QueryString["AddlWeekoff_Id"]);
            GC.Collect();
            if (!IsPostBack)
            {
                FillAddlWeekoffDetails();
                ddl_Day.Focus();
            }
        }
        catch
        {
        }
        btn_Save.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;";
    }
    #endregion

    #region Button Click Events
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        strAddlWeekOffDay = ddl_Day.SelectedItem.Value;
        strAddlWeekOffWeek = ddl_Week.SelectedItem.Value;
        int count = 0;
        LevelID = (int)Session["parentLevelId"];
        Session["parentLevelId"] = null;
        if (LevelID == 0)
        {
            lbl_Error.Text = rm.GetString("Alert_Selectallorganizationlevels", ci); ;
            return;
        }
        count = objAddlWeekOff.CheckAddlWeekoff_Update(intAddlWeekofID, LevelID, strAddlWeekOffDay, strAddlWeekOffWeek);
        if (count == 0)
        {
            objAddlWeekOff.Update_AddlWeekoffDetails(intAddlWeekofID, LevelID, strAddlWeekOffDay, strAddlWeekOffWeek, auditEmpId);
            string str = "alert('" + rm.GetString("Additional_WeekOff_AddedSuccess") + "');location.replace('Organization_AddlWeekoffView.aspx?AddlWeekoff_Id=" + intAddlWeekofID + "');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        else
        {
            string strAlert = rm.GetString("AdditionalWeeklyOff_Already_Exists", ci);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", "alert('" + strAlert + "');", true);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_AddlWeekoff.aspx");
    }
    #endregion

    #region User Defined Functions
    private void FillAddlWeekoffDetails()
    {
        DataSet ds_AddlWeekoff = new DataSet();
        ds_AddlWeekoff = objAddlWeekOff.Select_AddlWeekoffdetails_Modify(intAddlWeekofID);
        if (ds_AddlWeekoff.Tables[0].Rows.Count > 0)
        {
            Session["parentLevelId_modify"] = ds_AddlWeekoff.Tables[0].Rows[0]["LevelId_Id"].ToString();
        }
        ddl_Day.SelectedIndex = ddl_Day.Items.IndexOf(ddl_Day.Items.FindByValue(ds_AddlWeekoff.Tables[0].Rows[0]["Addl_WeekOff_Day"].ToString()));
        ddl_Week.SelectedIndex = ddl_Week.Items.IndexOf(ddl_Week.Items.FindByValue(ds_AddlWeekoff.Tables[0].Rows[0]["Addl_WeekOff_Week"].ToString()));
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_man.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_selectedweek.Text = rm.GetString("AdditionalWeeklyOff_WeeklyOffDay", ci);
        lbl_Weekof.Text = rm.GetString("AdditionalWeeklyOff_SelectedWeek", ci);
        lbl_Header.Text = rm.GetString("Org_Additional_Weeklyoff", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("ReqField_SelectDay", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("ReqField_SelectWeek", ci);
        btn_Save.Text = rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        ddl_Day.Items[0].Text = rm.GetString("Select", ci);
        ddl_Day.Items[1].Text = rm.GetString("Sunday", ci);
        ddl_Day.Items[2].Text = rm.GetString("Monday", ci);
        ddl_Day.Items[3].Text = rm.GetString("Tuesday", ci);
        ddl_Day.Items[4].Text = rm.GetString("Wednesday", ci);
        ddl_Day.Items[5].Text = rm.GetString("Thursday", ci);
        ddl_Day.Items[6].Text = rm.GetString("Friday", ci);
        ddl_Day.Items[7].Text = rm.GetString("Saturday", ci);
        ddl_Week.Items[0].Text = rm.GetString("Select", ci);
        ddl_Week.Items[1].Text = rm.GetString("FirstWeek", ci);
        ddl_Week.Items[2].Text = rm.GetString("SecondWeek", ci);
        ddl_Week.Items[3].Text = rm.GetString("ThirdWeek", ci);
        ddl_Week.Items[4].Text = rm.GetString("FourthWeek", ci);
        ddl_Week.Items[5].Text = rm.GetString("FifthWeek", ci);
    }
    public 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"]) == 0)
                {
                    Response.Redirect("OrganizationLandingPage.aspx");
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    #endregion
}
