using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 12-Aug-2007
* Module          : Holiday Master                                    Last Modified : 20-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_HolidayAdd : Base.BasePage
{
    #region "Variable Declaration"
    AddlWeekOffEventData objAddlWeekOff = new AddlWeekOffEventData();
    ResourceManager rm;
    CultureInfo ci;
    string strHolidaytype, gstrDateFormat;
    string strFromdate, strTodate, strHolidayFromdate, strHolidayTodate;
    int count, holidaycount, GlobalMax, StartYear, EndYear;
    int Emp_Id;
    int intPolicyYear = 0;
    DataSet ds = new DataSet();
    HolidayEventData objHolidayDeatails = new HolidayEventData();
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int gintTempWeekdayCount = 0;
    int HolidayID;
    int AddWeekOffId = 0;
    #endregion
    #region PageLoad
    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;
        if (source_Language == "Resources.Resource_AR")
        {
            tvLevel.LineImagesFolder = "../dist/img/TreeLineImage_RTL";
        }
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        Emp_Id = Convert.ToInt32(Session["EmpAutoID"]);
        string strSetAlert = "";
        if (!Page.IsPostBack)
        {
            LoadStrings(ci);
            UserRights();
            ddl_Holidaytype.Focus();
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            GetNodes();
            objCommon.menu("Configuration", "16");
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_Holiday_SelectHolidayType", ci) + "','" + rm.GetString("Alert_Fromdate", ci) + "','" + rm.GetString("Alert_ToDate", ci) + "','" + rm.GetString("Alert_Holiday_FillDescription", ci) + "','" + rm.GetString("Alert_EnterToDate", ci) + "','" + rm.GetString("Alert_ConfirmSave", ci) + "');";
            strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
        DataSet ds_Year = new DataSet();
        if (ViewState["DsYearSetting"] != null)
        {
            ds_Year = (DataSet)ViewState["DsYearSetting"];
        }
        else
        {
            ds_Year = objCommon.GetYearsetting();
        }
        if (ds_Year.Tables[0].Rows.Count <= 0)
        {
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "alert('" + rm.GetString("Alert_DefineYearSettinginOrganizationSettings", ci) + " ');location.replace('../Organization Settings/Organization_YearSetting.aspx')";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("AlertLeavePolicyYear", strSetAlert);
        }
        else
        {
            ViewState["DsYearSetting"] = ds_Year;
            lbl_Year.Text = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSetting"]);
            GetYearSetting(lbl_Year.Text);
            intPolicyYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
            StartYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["StartYear"]);
            EndYear = Convert.ToInt32(ds_Year.Tables[0].Rows[0]["EndYear"]);
            strHolidayFromdate = Convert.ToString(ds_Year.Tables[0].Rows[0]["FromDate"]);
            strHolidayTodate = Convert.ToString(ds_Year.Tables[0].Rows[0]["ToDate"]);
            ds_Year.Dispose();
        }
        Page.RegisterStartupScript("displayLevel", "<script>DisplayLevel();</script>");
    }
    #endregion
    #region UserDefinedFunctions
    public void GetYearSetting(string ActiveYearSetting)
    {
        string sYearValue = ActiveYearSetting;
        if (sYearValue != null && sYearValue != "")
        {
            lbl_Year.Text = sYearValue;
            lbl_Year.Text = lbl_Year.Text.Replace("January", rm.GetString("January", ci))
                .Replace("February", rm.GetString("February", ci))
                .Replace("March", rm.GetString("March", ci))
                .Replace("April", rm.GetString("April", ci))
                .Replace("May", rm.GetString("May", ci))
                .Replace("June", rm.GetString("June", ci))
                .Replace("July", rm.GetString("July", ci))
                .Replace("August", rm.GetString("August", ci))
                .Replace("September", rm.GetString("September", ci))
                .Replace("October", rm.GetString("October", ci))
                .Replace("November", rm.GetString("November", ci))
                .Replace("December", rm.GetString("December", ci));
        }
        else
        {
            lbl_Year.Text = string.Empty;
        }
    }
    /// <summary>
    /// Compare ToDate with FromDate
    /// </summary>
    /// <param name="s"></param>
    /// <param name="e"></param>
    public void CompareDate(object s, ServerValidateEventArgs e)
    {
        try
        {
            strFromdate = txt_HFromDate.Text;
            strTodate = txt_HToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            DateTime dtToDate = DateTime.Parse(strTodate);
            DateTime dtFromDate = DateTime.Parse(strFromdate);
            TimeSpan diff = dtToDate.Subtract(dtFromDate);
            int day = diff.Days;
            if (day >= 0)
                e.IsValid = true;
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_GrearterThanFrmDate", ci) + "');", true);
                e.IsValid = false;
            }
        }
        catch
        {
        }
    }
    //Compare FromMonth With Current Month
    public void CompareCurrentdate(object s, ServerValidateEventArgs e)
    {
        try
        {
            if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
                e.IsValid = true;
            else
            {
                strFromdate = txt_HFromDate.Text;
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
                DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
                DateTime dtFromDate = DateTime.Parse(strFromdate);
                TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
                int day = diff.Days;
                if (day >= 0)
                    e.IsValid = true;
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Validator_Holidays_FromDate", ci) + "');", true);
                    e.IsValid = false;
                }
            }
        }
        catch
        {
        }
    }
    //Compare Tomonth with Current Month
    public void CompareTodate(object s, ServerValidateEventArgs e)
    {
        try
        {
            if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin" || Convert.ToString(Session["HasSpecialRights"]) == "True")
                e.IsValid = true;
            else
            {
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                strTodate = txt_HToDate.Text;
                strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
                DateTime dtCurrentDate = Convert.ToDateTime(DateTime.Today.Date);
                DateTime dtFromDate = DateTime.Parse(strTodate);
                TimeSpan diff = dtFromDate.Subtract(dtCurrentDate);
                int day = diff.Days;
                if (day >= 0)
                    e.IsValid = true;
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Validator_Holidays_ToDate2", ci) + "');", true);
                    e.IsValid = false;
                }
            }
        }
        catch
        {
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_HolidayType.Text = rm.GetString("Holidays_Holiday_Type", ci);
        lbl_HolidayDescription.Text = rm.GetString("Holidays_Desc", ci);
        lbl_From.Text = rm.GetString("OnDuty_InDate", ci);
        lbl_To.Text = rm.GetString("OnDuty_OutDate", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        CustomValidator1.ErrorMessage = rm.GetString("Validator_Holidays_FromDate", ci);
        cus_ComDate.ErrorMessage = rm.GetString("Msg_GrearterThanFrmDate", ci);
        CustomValidator2.ErrorMessage = rm.GetString("Validator_Holidays_ToDate2", ci);
        lbl_HeaderHolidays.Text = rm.GetString("Masters_Holidays_Holidays", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        ddl_Holidaytype.Items[0].Text = rm.GetString("Select", ci);
        ddl_Holidaytype.Items[1].Text = rm.GetString("Holiday_GlobalHoliday", ci);
        ddl_Holidaytype.Items[2].Text = rm.GetString("Holiday_RestrictedHoliday", ci);
        ddl_Holidaytype.Items[0].Text = rm.GetString("Select", ci);
        lblCompanyWise.Text = rm.GetString("Holiday_CompanyWise", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(16, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #region Holiday - GetNodes
    public void GetNodes()
    {
        try
        {
            userRightsEventData objClass = new userRightsEventData();
            DataSet ds = new DataSet();
            string strLevelID = string.Empty;
            ds = objAddlWeekOff.SelectAdditionalWeekOffLevelRights(AddWeekOffId);
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["LevelId"] != DBNull.Value)
                        {
                            strLevelID = Convert.ToString(ds.Tables[0].Rows[0]["LevelId"]);
                        }
                    }
                }
            }
            string str = strLevelID;
            char[] comma = { ',' };
            string[] str1 = str.Split(comma);
            DataSet dsRightsLevel = new DataSet();
            if (Session["OrgLevels"] != null)
                dsRightsLevel = (DataSet)Session["OrgLevels"];
            GetReports levl = new GetReports();
            DataSet dsLev = new DataSet();
            dsLev = levl.SelectLevelDetailsBasedOnRights(Convert.ToString(Session["UserGroupName"]));
            int count;
            for (count = 0; count <= dsLev.Tables[0].Rows.Count - 1; count++)
            {
                TreeNode root = new TreeNode();
                if (Convert.ToInt32(dsLev.Tables[0].Rows[count]["parentid"]) == 0)
                {
                    DropDownList dd = new DropDownList();
                    dd.DataTextField = Convert.ToString(dsLev.Tables[0].Rows[count]["Name"]);
                    dd.DataBind();
                    root.Text = Convert.ToString(dsLev.Tables[0].Rows[count]["Name"]);
                    root.Value = Convert.ToString(dsLev.Tables[0].Rows[count]["id"]);
                    root.NavigateUrl = "";
                    getChildNodes(root, Convert.ToInt32(dsLev.Tables[0].Rows[count]["id"]), strLevelID);
                    this.tvLevel.Nodes.Add(root);
                    DataRow[] row = dsRightsLevel.Tables[0].Select("id='" + Convert.ToString(dsLev.Tables[0].Rows[count]["Id"]) + "'");
                    if (row.Length > 0)
                    {
                        if (Convert.ToString(row[0].ItemArray[0]) != string.Empty)
                        {
                        }
                    }
                    else
                    {
                        root.SelectAction = TreeNodeSelectAction.None;
                    }
                }
            }
            dsLev.Dispose();
        }
        catch (Exception ex)
        {
            Message(ex.ToString());
        }
    }
    public void getChildNodes(TreeNode parent, Int32 menuNo, string strstrLevelID)
    {
        DataSet ds = new DataSet();
        string strLevelID = string.Empty;
        ds = objAddlWeekOff.SelectAdditionalWeekOffLevelRights(AddWeekOffId);
        if (ds != null)
        {
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["LevelId"] != DBNull.Value)
                    {
                        strLevelID = Convert.ToString(ds.Tables[0].Rows[0]["LevelId"]);
                    }
                    string str = strLevelID;
                    char[] comma = { ',' };
                    string[] str1 = str.Split(comma);
                }
            }
        }
        DataSet dsRightsLevel = new DataSet();
        if (Session["OrgLevels"] != null)
            dsRightsLevel = (DataSet)Session["OrgLevels"];
        GetReports levl = new GetReports();
        DataSet dsLev1 = new DataSet();
        dsLev1 = levl.SelectLevelDetailsBasedOnRights(Convert.ToString(Session["UserGroupName"]));
        TreeNode childNode;
        int rowCount = 0, kloop = 0;
        for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
        {
            if (Convert.ToInt32(dsLev1.Tables[0].Rows[kloop]["parentId"]) == menuNo)
            {
                rowCount += 1;
            }
        }
        if (rowCount != 0)
        {
            for (kloop = 0; kloop <= dsLev1.Tables[0].Rows.Count - 1; kloop++)
            {
                if (Convert.ToInt32(dsLev1.Tables[0].Rows[kloop]["parentId"]) == menuNo)
                {
                    childNode = new TreeNode();
                    childNode.Text = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["Name"]);
                    childNode.Value = Convert.ToString(dsLev1.Tables[0].Rows[kloop]["Id"]);
                    childNode.NavigateUrl = "";
                    parent.ChildNodes.Add(childNode);
                    DataRow[] row = dsRightsLevel.Tables[0].Select("id='" + Convert.ToString(dsLev1.Tables[0].Rows[kloop]["Id"]) + "'");
                    if (row.Length > 0)
                    {
                        if (Convert.ToString(row[0].ItemArray[0]) != string.Empty)
                        {
                        }
                    }
                    else
                    {
                        childNode.SelectAction = TreeNodeSelectAction.None;
                    }
                    getChildNodes(childNode, Convert.ToInt32(dsLev1.Tables[0].Rows[kloop]["id"]), strLevelID);
                }
            }
        }
        dsLev1.Dispose();
    }
    #endregion
    #endregion
    #region ButtonEvents
    protected void Button1_Click(object sender, EventArgs e)
    {
        StringWriter strLevelId = new StringWriter();
        if (Page.IsValid == true)
        {
            strFromdate = txt_HFromDate.Text;
            strTodate = txt_HToDate.Text;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strFromdate = objCommon.DateConvertion(gstrDateFormat, strFromdate);
            strTodate = objCommon.DateConvertion(gstrDateFormat, strTodate);
            int HolidayStartYear = DateTime.Parse(strFromdate).Year;
            int HolidayEndYear = DateTime.Parse(strTodate).Year;
            if ((DateTime.Parse(strFromdate) >= DateTime.Parse(strHolidayFromdate) && DateTime.Parse(strFromdate) <= DateTime.Parse(strHolidayTodate)) && (DateTime.Parse(strTodate) >= DateTime.Parse(strHolidayFromdate) && DateTime.Parse(strTodate) <= DateTime.Parse(strHolidayTodate)))
            {
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Master_Holiday_Select_Valid_Year", ci) + "');", true);
                return;
            }
            strHolidaytype = ddl_Holidaytype.SelectedValue == "Global Holiday" ? "G" : "Y";
            if (ddl_Holidaytype.SelectedValue != "-Select-")
            {
                ds = objHolidayDeatails.MaxHoliday();
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_DefineHolidaysettingsinOrganisationSettings", ci) + "');location.replace('../Organization%20Settings/Organization_HolidaySetting.aspx');", true);
                    return;
                }
                GlobalMax = Convert.ToInt16(ds.Tables[0].Rows[0]["Global_Maxdays"]);
                holidaycount = objHolidayDeatails.HoildayCount(strHolidaytype);
                DateTime dtFromDate = DateTime.Parse(strFromdate);
                DateTime dtToDate = DateTime.Parse(strTodate);
                TimeSpan diff = dtToDate.Subtract(dtFromDate);
                int day = diff.Days;
                DataSet dsGlobalDate = new DataSet();
                if (rbReportType.SelectedValue == "0")
                {
                    TreeNodeCollection collection = tvLevel.CheckedNodes;
                    if (collection.Count > 0)
                    {
                        TreeNode[] trc = new TreeNode[collection.Count];
                        collection.CopyTo(trc, 0);
                        foreach (TreeNode tr in trc)
                        {
                            if (tr.ChildNodes.Count == 0)
                            {
                                count = objHolidayDeatails.checkHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToInt32(tr.Value));
                                if (count > 0)
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Holidayhasbeendeclaredalready", ci) + "');", true);
                                    return;
                                }
                            }
                            else
                            {
                                count = objHolidayDeatails.checkHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToInt32(tr.Value));
                                if (count > 0)
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Holidayhasbeendeclaredalready", ci) + "');", true);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Organizationdetailscannotbeempty", ci) + "');", true);
                        return;
                    }
                }
                else
                {
                    count = objHolidayDeatails.checkHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), 0);
                }
                gintTempWeekdayCount = objHolidayDeatails.checkHolidayTempWeekDay(strFromdate, strTodate);
                if (strHolidaytype == "G" && rbReportType.SelectedValue == "0")
                {
                    if (gintTempWeekdayCount > 0)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_CannotcreateGlobalholidayonTemporaryWeekday", ci) + "');", true);
                        return;
                    }
                }
                switch (strHolidaytype)
                {
                    case "G":
                        holidaycount = holidaycount + day;
                        if (holidaycount < GlobalMax)
                        {
                            if (count == 0)
                            {
                                if (rbReportType.SelectedValue == "0")
                                {
                                    TreeNodeCollection collection = tvLevel.CheckedNodes;
                                    if (collection.Count > 0)
                                    {
                                        TreeNode[] trc = new TreeNode[collection.Count];
                                        collection.CopyTo(trc, 0);
                                        DataTable dtTempWeekday = new DataTable("TA_Tbl_Holiday_Levels");
                                        DataColumn dcTempWeekId = new DataColumn("LevelId", System.Type.GetType("System.Int32"));
                                        dtTempWeekday.Columns.Add(dcTempWeekId);
                                        DataRow drNew;
                                        foreach (TreeNode tr in trc)
                                        {
                                            drNew = dtTempWeekday.NewRow();
                                            drNew.BeginEdit();
                                            drNew["LevelId"] = tr.Value;
                                            drNew.EndEdit();
                                            dtTempWeekday.Rows.Add(drNew);
                                        }
                                        if (dtTempWeekday.Rows.Count > 0)
                                        {
                                            dtTempWeekday = RemoveDuplicateRows(dtTempWeekday, "LevelId");
                                            dtTempWeekday.WriteXml(strLevelId);
                                        }
                                    }
                                    objHolidayDeatails.InsertHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), intPolicyYear.ToString(), Emp_Id.ToString(), Convert.ToString(strLevelId));
                                }
                                else
                                {
                                    objHolidayDeatails.InsertHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), intPolicyYear.ToString().Replace("'", "''"), Emp_Id.ToString(), "0");
                                }
                                if (DateTime.Parse(strFromdate) <= DateTime.Parse(DateTime.Now.ToShortDateString()))
                                {
                                    objHolidayDeatails.UpdateProcessedDataFlag(strFromdate, strTodate);
                                }
                                string strScript = "";
                                strScript = strScript + "<script language='javascript'>";
                                strScript = strScript + "alert('" + rm.GetString("Alert_Holidaysavedsuccessfully", ci) + "');";
                                strScript = strScript + "location.replace('TA_UI_Master_Holiday.aspx');";
                                strScript = strScript + "</script>";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Master_Holiday_Already_Declared", ci) + "');", true);
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Master_Holiday_Global_Reaches_Max_Nos", ci) + "');", true);
                        }
                        break;
                    case "Y":
                        if (count == 0)
                        {
                            if (rbReportType.SelectedValue == "0")
                            {
                                TreeNodeCollection collection = tvLevel.CheckedNodes;
                                if (collection.Count > 0)
                                {
                                    TreeNode[] trc = new TreeNode[collection.Count];
                                    collection.CopyTo(trc, 0);
                                    DataTable dtTempWeekday = new DataTable("TA_Tbl_Holiday_Levels");
                                    DataColumn dcTempWeekId = new DataColumn("LevelId", System.Type.GetType("System.Int32"));
                                    dtTempWeekday.Columns.Add(dcTempWeekId);
                                    DataRow drNew;
                                    foreach (TreeNode tr in trc)
                                    {
                                        drNew = dtTempWeekday.NewRow();
                                        drNew.BeginEdit();
                                        drNew["LevelId"] = tr.Value;
                                        drNew.EndEdit();
                                        dtTempWeekday.Rows.Add(drNew);
                                    }
                                    if (dtTempWeekday.Rows.Count > 0)
                                    {
                                        dtTempWeekday = RemoveDuplicateRows(dtTempWeekday, "LevelId");
                                        dtTempWeekday.WriteXml(strLevelId);
                                    }
                                }
                                else
                                {
                                    base.Message("Organization details cannot be empty");
                                    return;
                                }
                                objHolidayDeatails.InsertHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), intPolicyYear.ToString(), Emp_Id.ToString(), Convert.ToString(strLevelId));
                            }
                            else
                            {
                                objHolidayDeatails.InsertHoliday(strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), intPolicyYear.ToString(), Emp_Id.ToString(), "0");
                            }
                            if (DateTime.Parse(strFromdate) <= DateTime.Parse(DateTime.Now.ToShortDateString()))
                            {
                                objHolidayDeatails.UpdateProcessedDataFlag(strFromdate, strTodate);
                            }
                            string strScript = "";
                            strScript = strScript + "<script language='javascript'>";
                            strScript = strScript + "alert('" + rm.GetString("Alert_Holidaysavedsuccessfully", ci) + "');";
                            strScript = strScript + "location.replace('TA_UI_Master_Holiday.aspx');";
                            strScript = strScript + "</script>";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Master_Holiday_Already_Declared", ci) + "');", true);
                        }
                        break;
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Holiday_SelectHolidayType", ci) + "');", true);
            }
        }
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_Holiday.aspx");
    }
    #endregion
    protected void rbReportType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbReportType.SelectedValue == "0")
        {
            divTreeview.Attributes.Add("style", "width: 450; overflow: auto;height:300");
            tvLevel.Visible = true;
            GetNodes();
        }
        else
        {
            divTreeview.Attributes.Add("style", "width: 450; overflow: auto;display:none");
            tvLevel.Visible = false;
            tvLevel.Nodes.Clear();
        }
    }
    public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
    {
        Hashtable hTable = new Hashtable();
        ArrayList duplicateList = new ArrayList();
        foreach (DataRow dtRow in dTable.Rows)
        {
            if (hTable.Contains(dtRow[colName]))
                duplicateList.Add(dtRow);
            else
                hTable.Add(dtRow[colName], string.Empty);
        }
        foreach (DataRow dtRow in duplicateList)
            dTable.Rows.Remove(dtRow);
        return dTable;
    }
}