/// <summary>
        /// GetNextRefId
        /// </summary>
        /// <param name="RevenueNavigatorTDS">RevenueNavigatorTDS</param>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="currentRefID">currentRefID</param>
        /// <returns>nextRefID</returns>
        public static int GetNextRefId(RevenueNavigatorTDS RevenueNavigatorTDS, int currentProjectId, int currentRefId)
        {
            int nextRefId = currentRefId;

            for (int i = 0; i < RevenueNavigatorTDS.RevenueNavigator.DefaultView.Count; i++)
            {
                if (((int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i]["RefID"] == currentRefId) && ((int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i]["ProjectID"] == currentProjectId))
                {
                    if (i == RevenueNavigatorTDS.RevenueNavigator.DefaultView.Count - 1)
                    {
                        nextRefId = currentRefId;
                    }
                    else
                    {
                        nextRefId = (int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i + 1]["RefID"];
                    }
                    break;
                }
            }

            return nextRefId;
        }
 /// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new RevenueNavigatorTDS();
 }
        /// <summary>
        /// GetPreviousRefId
        /// </summary>
        /// <param name="RevenueNavigatorTDS">RevenueNavigatorTDS</param>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="currentRefID">currentRefID</param>
        /// <returns>prevRefID</returns>
        public static int GetPreviousRefId(RevenueNavigatorTDS RevenueNavigatorTDS, int currentProjectId, int currentRefId)
        {
            int prevRefId = currentRefId;

            for (int i = 0; i < RevenueNavigatorTDS.RevenueNavigator.DefaultView.Count; i++)
            {
                if (((int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i]["RefID"] == currentRefId) && ((int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i]["ProjectID"] == currentProjectId))
                {
                    if (i == 0)
                    {
                        prevRefId = currentRefId;
                    }
                    else
                    {
                        prevRefId = (int)RevenueNavigatorTDS.RevenueNavigator.DefaultView[i - 1]["RefID"];
                    }

                    break;
                }
            }

            return prevRefId;
        }
        private RevenueNavigatorTDS SubmitSearch()
        {
            // Retrieve clauses
            string whereClause = GetWhereClause();
            string orderByClause = GetOrderByClause();

            RevenueNavigatorTDS dataSet = new RevenueNavigatorTDS();
            RevenueNavigatorGateway revenueNavigatorGateway = new RevenueNavigatorGateway(dataSet);

            //... Load data
            RevenueNavigator revenueNavigator = new RevenueNavigator(dataSet);
            revenueNavigator.Load(whereClause, orderByClause);

            return dataSet;
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_REVENUE_VIEW"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in revenue_navigator2.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("revenueNavigatorNewDummy");

                // If coming from
                // ... revenue_navigator.aspx or revenue_navigator2.aspx
                if ((Request.QueryString["source_page"] == "revenue_navigator.aspx") || (Request.QueryString["source_page"] == "revenue_navigator2.aspx"))
                {
                    RestoreNavigatorState();
                    revenueNavigatorTDS = (RevenueNavigatorTDS)Session["revenueNavigatorTDS"];
                }

                // ... revenue_edit.aspx, revenue_summary.aspx or revenue_delete.aspx
                if ((Request.QueryString["source_page"] == "revenue_edit.aspx") || (Request.QueryString["source_page"] == "revenue_summary.aspx") || (Request.QueryString["source_page"] == "revenue_delete.aspx"))
                {
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        revenueNavigatorTDS = (RevenueNavigatorTDS)Session["revenueNavigatorTDS"];
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("revenueNavigatorTDS");

                        // ... Search data with updates
                        revenueNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["revenueNavigatorTDS"] = revenueNavigatorTDS;
                    }
                }

                // ... revenue_delete.aspx, revenue_summary.aspx or revenue_edit.aspx
                if ((Request.QueryString["source_page"] == "revenue_delete.aspx") || (Request.QueryString["source_page"] == "revenue_summary.aspx") || (Request.QueryString["source_page"] == "revenue_edit.aspx"))
                {
                    if (revenueNavigatorTDS.RevenueNavigator.Rows.Count == 0)
                    {
                        string url = "./revenue_navigator.aspx?source_page=revenue_navigator2.aspx" + GetNavigatorState() + "&no_results=yes";

                        Response.Redirect(url);
                    }
                }

                Session["revenueNavigatorTDS"] = revenueNavigatorTDS;
                Session["revenueNavigator"] = revenueNavigatorTDS.RevenueNavigator;

                // ... for the total rows
                if (revenueNavigatorTDS.RevenueNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + revenueNavigatorTDS.RevenueNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
            else
            {
                // Restore searched data (if any)
                revenueNavigatorTDS = (RevenueNavigatorTDS)Session["revenueNavigatorTDS"];
                revenueNavigator = revenueNavigatorTDS.RevenueNavigator;

                // ... for the total rows
                if (revenueNavigatorTDS.RevenueNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + revenueNavigatorTDS.RevenueNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                // Tag Page
                string url = "";

                // Delete store data
                Session.Contents.Remove("revenueNavigatorTDS");

                // Get data from DA gateway
                revenueNavigatorTDS = SubmitSearch();

                // Show results
                if (revenueNavigatorTDS.RevenueNavigator.Rows.Count > 0)
                {
                    // ... Store data
                    Session["revenueNavigatorTDS"] = revenueNavigatorTDS;

                    // ... Go to the results page
                    url = "./revenue_navigator2.aspx?source_page=revenue_navigator2.aspx"+ GetNavigatorState();
                }
                else
                {
                    // ... Go to the search page
                    url = "./revenue_navigator.aspx?source_page=revenue_navigator2.aspx" + GetNavigatorState() + "&no_results=yes";
                }

                Response.Redirect(url);
            }
        }