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_HolidayModify : Base.BasePage
{
    ResourceManager rm;
    AddlWeekOffEventData objAddlWeekOff = new AddlWeekOffEventData();
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int HolidayID, count, GlobalMax, holidaycount, StartYear, EndYear;
    string strHolidaytype, gstrDateFormat;
    string gstrPrevFromDate, gstrPrevToDate;
    string strFromdate, strTodate, strHolidayFromdate, strHolidayTodate;
    int Emp_Id;
    int intPolicyYear = 0;
    DataSet ds_HolidayDetails, ds;
    HolidayEventData objHoliday = new HolidayEventData();
    cls_Common objCommon = new cls_Common();
    int gintTempWeekdayCount = 0;
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        Emp_Id = Convert.ToInt32(Session["EmpAutoID"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        if (source_Language == "Resources.Resource_AR")
        {
            tvLevel.LineImagesFolder = "../dist/img/TreeLineImage_RTL";
        }
        DataSet ds_Year = new DataSet();
        HolidayID = Convert.ToInt16(Request.QueryString["Holiday_Id"]);
        if (!Page.IsPostBack)
        {
            LoadStrings(ci);
            UserRights();
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            GetHolidayDetails();
            GetNodes();
            ddl_Holidaytype.Focus();
            string strSetAlert = "";
            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);
            objCommon.menu("Configuration", "16");
        }
        if (ViewState["DsYearSetting"] != null)
        {
            ds_Year = (DataSet)ViewState["DsYearSetting"];
        }
        else
        {
            ds_Year = objCommon.GetYearsetting();
        }
        if (ds_Year.Tables.Count > 0)
        {
            if (ds_Year.Tables[0].Rows.Count > 0)
            {
                ViewState["YearSettings_Id"] = Convert.ToString(ds_Year.Tables[0].Rows[0]["YearSettings_Id"]);
                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"]);
            }
        }
        int Count = 0;
        if (ViewState["RestrictedHolidayCount"] != null)
        {
            count = (int)ViewState["RestrictedHolidayCount"];
        }
        else
        {
            count = objHoliday.GetRestrictedHolidayCount(HolidayID);
        }
        if (Convert.ToString(Session["UserGroupName"]) != null && Convert.ToString(Session["UserGroupName"]) != "")
        {
            if (Count > 0 && Convert.ToString(Session["UserGroupName"]) != "SuperAdmin")
            {
                TohandleControls();
            }
        }
        else
        {
            if (Count > 0)
            {
                TohandleControls();
            }
        }
    }

    private void TohandleControls()
    {
        btn_modify.Enabled = false;
        btn_modify.OnClientClick = null;
    }

    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;
        }
    }
    protected void btn_modify_Click(object sender, EventArgs e)
    {
        StringWriter strLevelId = new StringWriter();
        if (Page.IsValid == true)
        {
            try
            {
                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 = objHoliday.MaxHoliday();
                    GlobalMax = Convert.ToInt16(ds.Tables[0].Rows[0]["Global_Maxdays"]);
                    holidaycount = objHoliday.HoildayCountUpdate(HolidayID, strHolidaytype);
                    DateTime dtFromDate = DateTime.Parse(strFromdate);
                    DateTime dtToDate = DateTime.Parse(strTodate);
                    TimeSpan diff = dtToDate.Subtract(dtFromDate);
                    int day = diff.Days;
                    if (rbYes.Checked == true)
                    {
                        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 = objHoliday.checkHolidayUp(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), Convert.ToInt32(Session["ParentLevelId"]));
                                    if (count > 0)
                                    {
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Holidayhasbeendeclaredalready", ci) + "');", true);
                                        return;
                                    }
                                }
                                else
                                {
                                    count = objHoliday.checkHolidayUp(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), Convert.ToInt32(Session["ParentLevelId"]));
                                    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 = objHoliday.checkHolidayUp(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Replace("'", "''"), Convert.ToInt32(Session["ParentLevelId"]));
                    }
                    gintTempWeekdayCount = objHoliday.checkHolidayTempWeekDay(strFromdate, strTodate);
                    if (strHolidaytype == "G")
                    {
                        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 (rbYes.Checked == true)
                                    {
                                        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);
                                            }
                                        }
                                        objHoliday.UpdateHolidayDetails(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToString(intPolicyYear), Convert.ToString(Emp_Id), Convert.ToString(strLevelId));
                                    }
                                    else
                                    {
                                        objHoliday.UpdateHolidayDetails(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToString(intPolicyYear), Convert.ToString(Emp_Id), "0");
                                    }
                                    if (DateTime.Parse(strFromdate) <= DateTime.Parse(DateTime.Now.ToShortDateString()))
                                    {
                                        objHoliday.UpdateProcessedDataFlag(strFromdate, strTodate);
                                    }
                                    string strScript = "";
                                    strScript = strScript + "<script language='javascript'>";
                                    strScript = strScript + "alert('" + rm.GetString("Alert_Holidaymodifiedsuccessfully", 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 (rbYes.Checked == true)
                                {
                                    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);
                                        }
                                    }
                                    objHoliday.UpdateHolidayDetails(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToString(intPolicyYear), Convert.ToString(Emp_Id), Convert.ToString(strLevelId));
                                }
                                else
                                {
                                    objHoliday.UpdateHolidayDetails(HolidayID, strHolidaytype, strFromdate, strTodate, txt_HDescription.Text.Trim().Replace("'", "''"), Convert.ToString(intPolicyYear), Convert.ToString(Emp_Id), "0");
                                }
                                if (DateTime.Parse(strFromdate) <= DateTime.Parse(DateTime.Now.ToShortDateString()))
                                {
                                    objHoliday.UpdateProcessedDataFlag(strFromdate, strTodate);
                                }
                                string strRedirectPage = "TA_UI_Master_Holiday.aspx";
                                string strScript = "";
                                strScript = strScript + "<script language='javascript'>";
                                strScript = strScript + "alert('" + rm.GetString("Alert_Holidaymodifiedsuccessfully", ci) + "');";
                                strScript = strScript + "location.replace('" + strRedirectPage + "');";
                                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);
                }
            }
            catch
            {
            }
        }
    }
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_Holiday.aspx");
    }
    private void GetHolidayDetails()
    {
        string UserGroupName = string.Empty;
        ds_HolidayDetails = objHoliday.SelectHolidayDetailsById(HolidayID, UserGroupName, Convert.ToInt32(ViewState["YearSettings_Id"]));
        if (ds_HolidayDetails.Tables.Count > 0)
            if (ds_HolidayDetails.Tables[0].Rows.Count > 0)
            {
                strHolidaytype = Convert.ToString(ds_HolidayDetails.Tables[0].Rows[0]["Holiday_Type"]);
                ddl_Holidaytype.Text = strHolidaytype == "G" ? ddl_Holidaytype.Items[1].Text : ddl_Holidaytype.Items[2].Text;
                DateTime date1, date2;
                date1 = Convert.ToDateTime(ds_HolidayDetails.Tables[0].Rows[0]["Holiday_FromDate"]);
                date2 = Convert.ToDateTime(ds_HolidayDetails.Tables[0].Rows[0]["Holiday_ToDate"]);
                txt_HFromDate.Text = date1.ToString(Convert.ToString(Session["MDateFormat"]));
                txt_HToDate.Text = date2.ToString(Convert.ToString(Session["MDateFormat"]));
                gstrPrevFromDate = txt_HFromDate.Text;
                gstrPrevToDate = txt_HToDate.Text;
                txt_HDescription.Text = Convert.ToString(ds_HolidayDetails.Tables[0].Rows[0]["Holiday_Description"]);
                if (Convert.ToString(ds_HolidayDetails.Tables[0].Rows[0]["LevelId"]) == "0")
                {
                    rbNo.Checked = true;
                    Session["parentLevelId_modify"] = null;
                }
                else
                {
                    rbYes.Checked = true;
                    Session["parentLevelId_modify"] = Convert.ToString(ds_HolidayDetails.Tables[0].Rows[0]["LevelId"]);
                }
            }
    }
    /// <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
        {
            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 (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
            {
                e.IsValid = true;
                return;
            }
            if (day >= 0)
                e.IsValid = true;
            else
            {
                e.IsValid = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Validator_Holidays_FromDate", ci) + "');", true);
            }
        }
        catch
        {
        }
        if (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
        {
            e.IsValid = true;
        }
    }
    //Compare Tomonth with Current Month
    public void CompareTodate(object s, ServerValidateEventArgs e)
    {
        try
        {
            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 (Convert.ToString(Session["UserGroupName"]) == "SuperAdmin")
            {
                e.IsValid = true;
                return;
            }
            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("email_FromDate", ci);
        lbl_To.Text = rm.GetString("email_ToDate", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_HeaderHolidays.Text = rm.GetString("Masters_Holidays_Holidays", ci);
        btn_modify.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); rbYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbNo.Text = rm.GetString("ShiftSetting_No", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(16, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        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;
            if (ds_HolidayDetails != null)
            {
                if (ds_HolidayDetails.Tables.Count > 0)
                {
                    if (ds_HolidayDetails.Tables[0].Rows.Count > 0)
                    {
                        if (ds_HolidayDetails.Tables[0].Rows[0]["LevelId"] != DBNull.Value)
                        {
                            strLevelID = Convert.ToString(ds_HolidayDetails.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);
                    if (HolidayID != 0)
                    {
                        foreach (DataRow drLevel in ds_HolidayDetails.Tables[0].Rows)
                        {
                            if (drLevel["LevelId"].ToString() == root.Value)
                            {
                                root.Checked = true;
                            }
                        }
                    }
                    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)
        {
            Response.Write(ex);
        }
    }
    public void getChildNodes(TreeNode parent, Int32 menuNo, string strstrLevelID)
    {
        DataSet ds = new DataSet();
        string strLevelID = string.Empty;
        if (HolidayID != 0)
        {
            if (ds_HolidayDetails != null)
            {
                if (ds_HolidayDetails.Tables.Count > 0)
                {
                    if (ds_HolidayDetails.Tables[0].Rows.Count > 0)
                    {
                        if (ds_HolidayDetails.Tables[0].Rows[0]["LevelId"] != DBNull.Value)
                        {
                            strLevelID = Convert.ToString(ds_HolidayDetails.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 = "";
                    if (HolidayID != 0)
                    {
                        foreach (DataRow drLevel in ds_HolidayDetails.Tables[0].Rows)
                        {
                            if (drLevel["LevelId"].ToString() == childNode.Value)
                            {
                                childNode.Checked = true;
                            }
                        }
                    }
                    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
    // This method is used to delete duplicate rows of table
    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;
    }
}
