using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Year Settings                               Last Modified : 14-Aug-2007
* Programmer      : Prabakaran.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_YearSetting : Base.BasePage
{
    #region Global Variable Declaration
    YearSettingsEventData objYearSettingsEventData = new YearSettingsEventData();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DemoVersion objDemoVersion = new DemoVersion();
    cls_Common objCommon = new cls_Common();
    ResourceManager rm;
    CultureInfo ci;
    int YearsettingId;
    int ActiveYearsettingId;
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(50);
            objCommon.menu("Configuration", "50");
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        string str = Convert.ToString(Session["SiteMapProvider"]);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_Select_Start_Month", ci) + "','" + rm.GetString("Alert_Select_Start_Year", ci) + "','" + rm.GetString("Alert_Select_End_Month", ci) + "','" + rm.GetString("Alert_Select_End_Year", ci) + "','" + rm.GetString("Alert_Start_Year_should_not_be_greater_than_End_Year", ci) + "','" + rm.GetString("YearSetting_StartMonthGreaterThanEndMonth", ci) + "','" + rm.GetString("Alert_Invalid_Year_Setting", ci) + "','" + rm.GetString("Alert_Select_a_Year_to_Delete", ci) + "','" + rm.GetString("Alert_Selected_year_already_set_as_current_year", ci) + "','" + rm.GetString("Alert_AreYouSureToSaveYearSetting", ci) + "','" + rm.GetString("Alert_AreYouSureToDeleteTheSelectedYearSetting", ci) + "','" + rm.GetString("Alert_AreYouSureToSetTheSelectedYearAsCurrentYear", ci) + "','" + rm.GetString("Alert_Theyearcreationexceedsthelimitof12months", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        UserRights();
        if (!IsPostBack)
        {
            AddStartMonthNames(ddlStartMonth);
            AddStartYearsList(ddlStartYear);
            AddStartYearsList(ddlEndYear);
            //AddEndYearsList();
            AddEndMonthNames();
            loadyearsettings();
            SetCurrentYear();
        }
        GetYearSetting(lbl_ActiveYear.Text);
        chkShift.Visible = false;
        chkHoliday.Visible = false;
        btn_Add.Attributes.Add("onclick", "javascript:return confirm('" + rm.GetString("Alert_AreyouChangeYearSetting", ci) + "')");
    }
    #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 AddEndMonthNames()
    {
        int i;
        DateTime month = Convert.ToDateTime("1/1/2000");
        ddlEndMonth.Items.Insert(0, rm.GetString("Select", ci));
        for (i = 0; i <= 11; i++)
        {
            DateTime Months = month.AddMonths(i);
            ListItem list = new ListItem();
            list.Text = Months.ToString("MMMM");
            switch (list.Text)
            {
                case "January":
                    list.Text = rm.GetString("January", ci);
                    break;
                case "February":
                    list.Text = rm.GetString("February", ci);
                    break;
                case "March":
                    list.Text = rm.GetString("March", ci);
                    break;
                case "April":
                    list.Text = rm.GetString("April", ci);
                    break;
                case "May":
                    list.Text = rm.GetString("May", ci);
                    break;
                case "June":
                    list.Text = rm.GetString("June", ci);
                    break;
                case "July":
                    list.Text = rm.GetString("July", ci);
                    break;
                case "August":
                    list.Text = rm.GetString("August", ci);
                    break;
                case "September":
                    list.Text = rm.GetString("September", ci);
                    break;
                case "October":
                    list.Text = rm.GetString("October", ci);
                    break;
                case "November":
                    list.Text = rm.GetString("November", ci);
                    break;
                case "December":
                    list.Text = rm.GetString("December", ci);
                    break;
            }
            list.Value = Convert.ToString(i + 1);
            ddlEndMonth.Items.Add(list);
        }
    }
    private void AddStartMonthNames(DropDownList ddlStartMonth)
    {
        int i;
        DateTime month = Convert.ToDateTime("1/1/2000");
        ddlStartMonth.Items.Insert(0, rm.GetString("Select", ci));
        for (i = 0; i <= 11; i++)
        {
            DateTime Months = month.AddMonths(i);
            ListItem list = new ListItem();
            list.Text = Months.ToString("MMMM");
            switch (list.Text)
            {
                case "January":
                    list.Text = rm.GetString("January", ci);
                    break;
                case "February":
                    list.Text = rm.GetString("February", ci);
                    break;
                case "March":
                    list.Text = rm.GetString("March", ci);
                    break;
                case "April":
                    list.Text = rm.GetString("April", ci);
                    break;
                case "May":
                    list.Text = rm.GetString("May", ci);
                    break;
                case "June":
                    list.Text = rm.GetString("June", ci);
                    break;
                case "July":
                    list.Text = rm.GetString("July", ci);
                    break;
                case "August":
                    list.Text = rm.GetString("August", ci);
                    break;
                case "September":
                    list.Text = rm.GetString("September", ci);
                    break;
                case "October":
                    list.Text = rm.GetString("October", ci);
                    break;
                case "November":
                    list.Text = rm.GetString("November", ci);
                    break;
                case "December":
                    list.Text = rm.GetString("December", ci);
                    break;
            }
            list.Value = Convert.ToString(i + 1);
            ddlStartMonth.Items.Add(list);
        }
    }
    private void AddStartYearsList(DropDownList ddl)
    {
        int FromYear, ToYear;
        FromYear = DateTime.Now.Year - 3;
        ToYear = DateTime.Now.Year + 5;
        ddl.Items.Insert(0, rm.GetString("Select", ci));
        for (int YearsCount = FromYear; YearsCount <= ToYear; YearsCount++)
        {
            ddl.Items.Add(YearsCount.ToString());
        }
    }
   
    private void SetCurrentYear()
    {
        int Monthval = 0;
        DataSet dsCurrentYear = objYearSettingsEventData.GetActiveYearSettings();
        if (dsCurrentYear.Tables[0].Rows.Count > 0)
        {
            if (dsCurrentYear.Tables[0].Rows[0]["YearSettings_Id"] != DBNull.Value)
            {
                lst_Currentyear.SelectedValue = dsCurrentYear.Tables[0].Rows[0]["YearSettings_Id"].ToString();
                hdnActiveYear.Value = lst_Currentyear.SelectedValue;
            }
            if (dsCurrentYear.Tables[0].Rows[0]["StartMonth"] != DBNull.Value)
            {
                Monthval = Monthvalue(dsCurrentYear.Tables[0].Rows[0]["StartMonth"].ToString());
                ddlStartMonth.SelectedValue = Monthval.ToString();
            }
            if (dsCurrentYear.Tables[0].Rows[0]["EndMonth"] != DBNull.Value)
            {
                Monthval = Monthvalue(dsCurrentYear.Tables[0].Rows[0]["EndMonth"].ToString());
                ddlEndMonth.SelectedValue = Monthval.ToString();
            }
            if (dsCurrentYear.Tables[0].Rows[0]["StartYear"] != DBNull.Value)
            {
                ddlStartYear.SelectedValue = dsCurrentYear.Tables[0].Rows[0]["StartYear"].ToString();
            }
            if (dsCurrentYear.Tables[0].Rows[0]["EndYear"] != DBNull.Value)
            {
                ddlEndYear.SelectedValue = dsCurrentYear.Tables[0].Rows[0]["EndYear"].ToString();
            }
            if (dsCurrentYear.Tables[0].Rows[0]["YearSetting"] != DBNull.Value)
            {
                lbl_ActiveYear.Text = "Year : " + dsCurrentYear.Tables[0].Rows[0]["YearSetting"].ToString();
            }
        }
        if (hdnActiveYear.Value == "")
        {
            btn_SetCurrentyear.Enabled = false;
            btn_SetCurrentyear.OnClientClick = null;
        }
        else
        {
            btn_SetCurrentyear.Enabled = true;
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_header.Text = rm.GetString("UserGroups_YearSetting", ci);
        lbl_currentyear.Text = rm.GetString("YearSetting_CurrentYear", ci);
        lbl_startmonth.Text = rm.GetString("YearSetting_StartMonthAndYear", ci);
        lbl_EndMonth.Text = rm.GetString("YearSetting_EndMonthAndYear", ci);
        btn_Add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Cancel", ci);
        btn_Createyear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_CreateYear", ci);
        btn_SetCurrentyear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_SetasCurrentYear", ci);
        btn_DeleteYear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_DeleteYearSettingYear", ci);
        chkHoliday.Text = rm.GetString("chkShiftHoliday", ci);
        chkShift.Text = rm.GetString("chkShiftCarryForward", ci);
        lblWeeklyOffDays.Text = rm.GetString("ShiftAllocationWeeklyOffDaysYrsSettings", ci);
        ChbMonday.Text = rm.GetString("Monday", ci);
        ChbTuesday.Text = rm.GetString("Tuesday", ci);
        ChbWednesday.Text = rm.GetString("Wednesday", ci);
        ChbThuday.Text = rm.GetString("Thursday", ci);
        ChbFriday.Text = rm.GetString("Friday", ci);
        ChbSaturday.Text = rm.GetString("Saturday", ci);
        ChbSunday.Text = rm.GetString("Sunday", ci);
    }
    private int Monthvalue(string monthName)
    {
        int Monthval = 0;
        switch (monthName)
        {
            case "January":
                Monthval = 1;
                break;
            case "February":
                Monthval = 2;
                break;
            case "March":
                Monthval = 3;
                break;
            case "April":
                Monthval = 4;
                break;
            case "May":
                Monthval = 5;
                break;
            case "June":
                Monthval = 6;
                break;
            case "July":
                Monthval = 7;
                break;
            case "August":
                Monthval = 8;
                break;
            case "September":
                Monthval = 9;
                break;
            case "October":
                Monthval = 10;
                break;
            case "November":
                Monthval = 11;
                break;
            case "December":
                Monthval = 12;
                break;
        }
        return Monthval;
    }
    protected void loadyearsettings()
    {
        try
        {
            try
            {
                DataSet ds = new DataSet();
                ds = objYearSettingsEventData.GetYearsettings();
                lst_Currentyear.DataTextField = "YearSetting";
                lst_Currentyear.DataValueField = "YearSettings_Id";
                lst_Currentyear.DataSource = ds.Tables[0];
                lst_Currentyear.DataBind();
                foreach (ListItem item in lst_Currentyear.Items)
                {
                    item.Attributes.Add("title", item.Text);
                }
            }
            catch
            {
            }
        }
        catch
        {
        }
    }
    protected void UpdateYearSetting()
    {
        try
        {
            objYearSettingsEventData.UpdateYearSettingId(Convert.ToInt16(lst_Currentyear.SelectedValue));
            SetCurrentYear();
        }
        catch
        {
        }
    }
    private string setFromDate(int StartMonth, int StartYear)
    {
        string Fromdate = StartMonth.ToString() + "/1/" + StartYear.ToString();
        return Fromdate;
    }
    private string setToDate(int EndMonth, int EndYear)
    {
        string Todate = DateTime.DaysInMonth(EndYear, EndMonth).ToString();
        Todate = EndMonth.ToString() + "/" + Todate + "/" + EndYear.ToString();
        return Todate;
    }
    public void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(50, 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_Createyear.Visible = true;
                }
                else
                {
                    this.btn_Createyear.Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
                {
                    this.btn_DeleteYear.Visible = true;
                }
                else
                {
                    this.btn_DeleteYear.Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
                {
                    this.btn_SetCurrentyear.Visible = true;
                }
                else
                {
                    this.btn_SetCurrentyear.Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    #endregion
    #region Button Click Events
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        string strAlert = "";
        string[] fileArr = Directory.GetFiles(Server.MapPath("../LicenseFile"), "*.lic");
        int arrCount = fileArr.Length;
        if (arrCount > 0)
        {
            string licenseFileName = fileArr[arrCount - 1].ToString();
            FileStream licenseFileStream = new FileStream(licenseFileName, FileMode.Open);
            StreamReader licenseFileStreamReader = new StreamReader(licenseFileStream);
            string encryptedLicFileInfo = licenseFileStreamReader.ReadToEnd();
            licenseFileStreamReader.Close();
            licenseFileStream.Close();
            try
            {
                string decryptedLicFileInfo = Encryption.Decrypt(encryptedLicFileInfo, "");
            }
            catch
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Alert_Licenseinformationarenotcorrect", ci) + "');";
                strScript += "location.href='../Index.aspx';";
                strScript += " </script>";
                this.RegisterStartupScript("AlertLicInfoNotCorrect", strScript);
                return;
            }
        }
        else
        {
            bool demoContinue = false;
            demoContinue = objDemoVersion.DVCheckYearSetting();
            demoContinue = true;
            if (demoContinue == true)
            {
            }
            else
            {
                string strScript = "<script language='javascript' type='text/javascript'>";
                strScript += "alert('" + rm.GetString("Aler_This_is_Demo_Version_Cannot_create_more_years", ci) + "');";
                strScript += " </script>";
                this.RegisterStartupScript("setScript", strScript);
                return;
            }
        }
        if (Convert.ToInt32(ddlStartYear.SelectedValue) > Convert.ToInt32(ddlEndYear.SelectedValue))
        {
            strAlert = rm.GetString("YearSetting_StartYearGreaterThanEndYear", ci);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", "alert('" + strAlert + "');", true);
            return;
        }
        else if (Convert.ToInt32(ddlStartYear.SelectedValue) == Convert.ToInt32(ddlEndYear.SelectedValue))
        {
            if (Convert.ToInt32(ddlStartMonth.SelectedValue) > Convert.ToInt32(ddlEndMonth.SelectedValue))
            {
                strAlert = rm.GetString("YearSetting_StartMonthGreaterThanEndMonth", ci);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", "alert('" + strAlert + "');", true);
                return;
            }
            else if (Convert.ToInt32(ddlStartMonth.SelectedValue) == Convert.ToInt32(ddlEndMonth.SelectedValue))
            {
                strAlert = rm.GetString("YearSetting_StartMonthGreaterThanEndMonth", ci);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", "alert('" + strAlert + "');", true);
                return;
            }
        }
        string FromDate = setFromDate(Convert.ToInt32(ddlStartMonth.SelectedValue), Convert.ToInt32(ddlStartYear.SelectedValue));
        string ToDate = setToDate(Convert.ToInt32(ddlEndMonth.SelectedValue), Convert.ToInt32(ddlEndYear.SelectedValue));
        char YearType = 'P';
        int YearExists = objYearSettingsEventData.CheckYearSettingExists(FromDate, ToDate, YearType, 0);
        if (YearExists > 0)
        {
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_Year_Already_Exists", ci) + "');";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertYearSettingExists", strScript);
            return;
        }
        string strMonth_Start = string.Empty;
        string strMonth_end = string.Empty;
        try
        {
            strMonth_Start = GetMonthName(ddlStartMonth.SelectedValue);
            strMonth_end = GetMonthName(ddlEndMonth.SelectedValue);
            int InsertedYearSettingsID = objYearSettingsEventData.InsertYearsettingDetails(strMonth_Start, Convert.ToInt32(ddlStartYear.SelectedItem.Text), strMonth_end, Convert.ToInt32(ddlEndYear.SelectedItem.Text), FromDate, ToDate, Session["EmpAutoID"].ToString());
            if (Session["YearSettingsId"] != null)
            {
                ActiveYearsettingId = Convert.ToInt16(Session["YearSettingsId"]);
            }
            if (chkHoliday.Checked == true && InsertedYearSettingsID > 0)
            {
                objYearSettingsEventData.AutoInsertHoliday(ActiveYearsettingId, InsertedYearSettingsID);
            }
            if (chkShift.Checked == true && InsertedYearSettingsID > 0)
            {
                string strWeekOff = string.Empty;
                if (ChbMonday.Checked)
                    strWeekOff = strWeekOff + "2,";
                if (ChbTuesday.Checked)
                    strWeekOff = strWeekOff + "3,";
                if (ChbWednesday.Checked)
                    strWeekOff = strWeekOff + "4,";
                if (ChbThuday.Checked)
                    strWeekOff = strWeekOff + "5,";
                if (ChbFriday.Checked)
                    strWeekOff = strWeekOff + "6,";
                if (ChbSaturday.Checked)
                    strWeekOff = strWeekOff + "7,";
                if (ChbSunday.Checked)
                    strWeekOff = strWeekOff + "1";
                objYearSettingsEventData.AutoInsertShiftAllocation(ToDate, InsertedYearSettingsID, Convert.ToString(Session["UserGroupName"]), Convert.ToString(0), Session["EmpAutoID"].ToString(), strWeekOff);
            }

        }
        catch (Exception ex)
        {
            throw (ex);
        }
        string strYearData = strMonth_Start + " " + ddlStartYear.SelectedItem.Text + " - " + strMonth_end + " " + ddlEndYear.SelectedItem.Text;
        string sYearValue = Convert.ToString(Cache["ActiveYearSetting"]);
        if (sYearValue == string.Empty)
        {
            TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
            HttpContext.Current.Cache.Remove("ActiveYearSetting");
            HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
        }
        string str = "alert('" + rm.GetString("Alert_Year_Setting_Saved_Successfully", ci) + ".');location.replace('Organization_YearSetting.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }

    private string GetMonthName(string selectedMonth)
    {
        switch (selectedMonth)
        {
            case "1":
                selectedMonth = "January";
                break;
            case "2":
                selectedMonth = "February";
                break;
            case "3":
                selectedMonth = "March";
                break;
            case "4":
                selectedMonth = "April";
                break;
            case "5":
                selectedMonth = "May";
                break;
            case "6":
                selectedMonth = "June";
                break;
            case "7":
                selectedMonth = "July";
                break;
            case "8":
                selectedMonth = "August";
                break;
            case "9":
                selectedMonth = "September";
                break;
            case "10":
                selectedMonth = "October";
                break;
            case "11":
                selectedMonth = "November";
                break;
            case "12":
                selectedMonth = "December";
                break;
        }

        return selectedMonth;
    }

    protected void btn_SetCurrentyear_Click1(object sender, EventArgs e)
    {
        if (lst_Currentyear.SelectedValue != "" || lst_Currentyear.SelectedValue != null)
        {
            UpdateYearSetting();
            cls_Common objClassCommon = new cls_Common();
            DataSet ds_Year = new DataSet();
            string strYearData = string.Empty;
            string StartYear = string.Empty, EndYear = string.Empty, StartMonth = string.Empty, EndMonth = string.Empty;
            ds_Year = objClassCommon.GetYearsetting();
            if (ds_Year.Tables[0].Rows.Count > 0)
            {
                Session["YearSettingsId"] = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
                Session["YearSettingFromDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingFromDate"]);
                Session["YearSettingToDate"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettingToDate"]);
                StartYear = ds_Year.Tables[0].Rows[0]["StartYear"].ToString();
                StartMonth = ds_Year.Tables[0].Rows[0]["StartMonth"].ToString();
                EndYear = ds_Year.Tables[0].Rows[0]["EndYear"].ToString();
                EndMonth = ds_Year.Tables[0].Rows[0]["EndMonth"].ToString();
                strYearData = StartMonth + " " + StartYear + " - " + EndMonth + " " + EndYear;
                string sYearValue = Convert.ToString(Cache["ActiveYearSetting"]);
                if (strYearData != sYearValue)
                {
                    TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
                    HttpContext.Current.Cache.Remove("ActiveYearSetting");
                    HttpContext.Current.Cache.Insert("ActiveYearSetting", strYearData, null, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, null); // cache handling
                }
            }
            else
            {
            }
            string strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("Alert_Year_setting_has_been_changed", ci) + "');location.replace('Organization_YearSetting.aspx');";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("AlertYearSettingExists", strScript);
            return;
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_YearSetting.aspx");
    }
    protected void btn_DeleteYear_Click(object sender, EventArgs e)
    {
        bool checkdelete;
        checkdelete = false;
        YearsettingId = Convert.ToInt32(lst_Currentyear.SelectedValue);
        objYearSettingsEventData.DeleteShiftHolidayYearSetting(YearsettingId);
        int YearCount = objYearSettingsEventData.CheckYearSettingExists("", "", 'A', YearsettingId);
        if (YearCount == 0)
        {
            objYearSettingsEventData.DeleteYearSettingYearSetting(YearsettingId);
            checkdelete = true;
        }
        else
        {
            string strAlert = rm.GetString("Alert_Year_Setting_cannot_be_deleted", ci);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", "alert('" + strAlert + "');", true);
        }
        if (checkdelete == true)
        {
            string str = "alert('" + rm.GetString("Alert_Year_Setting_Deleted_Successfully", ci) + ".');location.replace('Organization_YearSetting.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    #endregion
}
