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          : Holiday Settings                            Last Modified : 14-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_HolidaySetting : Base.BasePage
{
    #region Global Variable Declaration
    HolidaySettingsEventData objHolidaysettings = new HolidaySettingsEventData();
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet ds_HolidaySetting = new DataSet();
    int YearSettingId, count;
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objcommon = new cls_Common();
    #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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(52);
            objcommon.menu("Configuration", "52");
            LoadStrings(ci);
            btn_Add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_AreyousureChangeHolidaySettings", ci) + "');return false;";
            HolidaySettings();
            txt_GolbalHoliday.Focus();
            DataSet dsYearSettings = objYearSettingsEventData.GetActiveYearSettings();
            if (dsYearSettings.Tables[0].Rows.Count > 0)
            {
                if (dsYearSettings.Tables[0].Rows[0]["YearSetting"] != DBNull.Value)
                {
                    lbl_ActiveYear.Text = "Year : " + dsYearSettings.Tables[0].Rows[0]["YearSetting"].ToString();
                }
                if (dsYearSettings.Tables[0].Rows[0]["YearSettings_Id"] != DBNull.Value)
                {
                    hdnYearSettingId.Value = Convert.ToString(dsYearSettings.Tables[0].Rows[0]["YearSettings_Id"]);
                }
            }
            else
            {
                string strScript = "";
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_DefineYearSettinginOrganizationSettings", ci) + "');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("AlertHolidaySetting", strScript);
            }
            GetYearSetting(lbl_ActiveYear.Text);
            UserRights();
        }
    }
    #endregion
    #region User Defined Functions
    public void GetYearSetting(string ActiveYearSetting)
    {
        string sYearValue = ActiveYearSetting;
        if (sYearValue != null && sYearValue != "")
        {
            lbl_ActiveYear.Text = sYearValue;
            if (lbl_ActiveYear.Text.Contains("January"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("January", rm.GetString("January", ci));
            }
            if (lbl_ActiveYear.Text.Contains("February"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("February", rm.GetString("February", ci));
            }
            if (lbl_ActiveYear.Text.Contains("March"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("March", rm.GetString("March", ci));
            }
            if (lbl_ActiveYear.Text.Contains("April"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("April", rm.GetString("April", ci));
            }
            if (lbl_ActiveYear.Text.Contains("May"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("May", rm.GetString("May", ci));
            }
            if (lbl_ActiveYear.Text.Contains("June"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("June", rm.GetString("June", ci));
            }
            if (lbl_ActiveYear.Text.Contains("July"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("July", rm.GetString("July", ci));
            }
            if (lbl_ActiveYear.Text.Contains("August"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("August", rm.GetString("August", ci));
            }
            if (lbl_ActiveYear.Text.Contains("September"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("September", rm.GetString("September", ci));
            }
            if (lbl_ActiveYear.Text.Contains("October"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("October", rm.GetString("October", ci));
            }
            if (lbl_ActiveYear.Text.Contains("November"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("November", rm.GetString("November", ci));
            }
            if (lbl_ActiveYear.Text.Contains("December"))
            {
                lbl_ActiveYear.Text = lbl_ActiveYear.Text.Replace("December", rm.GetString("December", ci));
            }
        }
        else
        {
            lbl_ActiveYear.Text = string.Empty;
        }
    }
    private void HolidaySettings()
    {
        try
        {
            lbl_GlobalHoliday.Text = Convert.ToString(objHolidaysettings.GetNumberofGlobalHolidays());
            lbl_Yearly.Text = Convert.ToString(objHolidaysettings.GetNumberofYearlyHolidays());
            ds_HolidaySetting = objHolidaysettings.GetHolidaySettings();
            if (ds_HolidaySetting.Tables[0].Rows.Count > 0)
            {
                txt_GolbalHoliday.Text = Convert.ToString(ds_HolidaySetting.Tables[0].Rows[0]["Global_Maxdays"]);
                txt_YearlyHoliday.Text = Convert.ToString(ds_HolidaySetting.Tables[0].Rows[0]["Yearly_Maxdays"]);
            }
        }
        catch
        {
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Menu_OrganizationSettings_HolidaySetting", ci);
        lbl_maxGolbalHoliday.Text = rm.GetString("HolidaySetting_MaxNoOfGlobalHolidays", ci);
        lbl_MaxRestrictedHoliday1.Text = rm.GetString("HolidaySetting_MaxNoOfRestrictedHolidays", ci);
        lbl_definedGlobalholiday.Text = rm.GetString("HolidaySetting_NoOfDefinedGlobalHolidays", ci);
        lbl_definedRestrictedHoliday.Text = rm.GetString("HolidaySetting_NoOfDefinedRestrictedHolidays", ci);
        lblPerYear.Text = rm.GetString("Label_PerYear", ci);
        lblPerYear2.Text = rm.GetString("Label_PerYear", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        rngValidateGlobalHoliday.ErrorMessage = rm.GetString("Validator_rngValidateGlobalHoliday", ci);
        rngValidateRestrictedHoliday.ErrorMessage = rm.GetString("Validator_rngValidateRestrictedHoliday", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("ReqField_GlobalHoliday_HolidaySettings", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("ReqField_RestrictedHoliday_HolidaySettings", ci);
        rngValidateGlobalHoliday.ErrorMessage = rm.GetString("Validator_rngValidateGlobalHoliday", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
    }
    public void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(52, 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"]) == 0)
                {
                    Response.Redirect("OrganizationLandingPage.aspx");
                }
                if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
                {
                    this.btn_Add.Visible = true;
                }
                else
                {
                    this.btn_Add.Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    #endregion
    #region Button Click Events
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToInt32(lbl_GlobalHoliday.Text) > Convert.ToInt32(txt_GolbalHoliday.Text))
            {
                lblError.Text = rm.GetString("HolidaySetting_NoOfMaxGlobalHolidays_NoOfDefinedGlobalHolidays", ci);
                return;
            }
            else
            {
                count = objHolidaysettings.GetNumberOfRestrictedHolidaysCount();
                if (count > Convert.ToInt32(txt_YearlyHoliday.Text))
                {
                    lblError.Text = rm.GetString("HolidaySetting_Restricted_Holidays_InUse", ci);
                    return;
                }
            }
            objHolidaysettings.InsertHolidaySettings(Convert.ToInt16(txt_GolbalHoliday.Text), Convert.ToInt16(txt_YearlyHoliday.Text), Convert.ToInt32(hdnYearSettingId.Value));
            lblError.Text = "";
            string str = "alert('" + rm.GetString("Alert_Holiday_Setting_Saved_Successfully", ci) + "');location.replace('Organization_HolidaySetting.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    #endregion
}
