// ////////////////////////////////////////////////////////////////////////
        // STEP1 - PROPOSALS - METHODS
        //
        public ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable GetProposals()
        {
            addDuplicateProjectNavigator = (ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable)Session["projectNavigatorNewDummy"];
            if (addDuplicateProjectNavigator == null)
            {
                addDuplicateProjectNavigator = ((ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable)Session["addDuplicateProjectNavigator"]);
            }

            return addDuplicateProjectNavigator;
        }
        // ////////////////////////////////////////////////////////////////////////
        //  METHODS
        //
        public ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable GetProjects()
        {
            projectNavigator = (ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable)Session["projectNavigatorNewDummy"];
            if (projectNavigator == null)
            {
                projectNavigator = ((ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable)Session["projectNavigator"]);
            }

            return projectNavigator;
        }
        protected void AddProposalsNewEmptyFix(GridView grdProposals)
        {
            if (grdProposals.Rows.Count == 0)
            {
                ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable dt = new ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable();
                dt.AddLFS_PROJECT_NAVIGATORRow("", "", "", "", -1, "", false, -1, false, "");
                Session["projectNavigatorNewDummy"] = dt;

                grdProposals.DataBind();
            }

            // normally executes at all postbacks
            if (grdProposals.Rows.Count == 1)
            {
                ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable dt = (ProjectNavigatorTDS.LFS_PROJECT_NAVIGATORDataTable)Session["projectNavigatorNewDummy"];
                if (dt != null)
                {
                    grdProposals.Rows[0].Visible = false;
                    grdProposals.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

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

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                {
                    ddlProjectType.Visible = true;
                    ddlProjectTypeAdmin.Visible = false;
                    ddlProjectType.SelectedIndex = 0;

                    ddlProjectState.Visible = true;
                    ddlProjectStateAdmin.Visible = false;
                    ddlProjectState.SelectedIndex = 0;
                }
                else
                {
                    ddlProjectType.Visible = false;
                    ddlProjectTypeAdmin.Visible = true;
                    ddlProjectTypeAdmin.SelectedIndex = 0;

                    ddlProjectState.Visible = false;
                    ddlProjectStateAdmin.Visible = true;
                    ddlProjectStateAdmin.SelectedIndex = 0;
                }

                // Tag Page
                Session.Remove("projectNavigatorNewDummy");
                Session.Remove("projectNavigator");
                Session.Remove("projectsSelected");
                hdfPageIndex.Value = "0";

                // Prepare initial data
                lblError.Visible = false;
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("lastUsedProjectsDummy");

                // If coming from
                projectSelectProjectTDS = new ProjectSelectProjectTDS();
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                projectSelectProjectLastUsedProjectsGateway.LoadByLoginId(Int32.Parse(hdfLoginId.Value), Int32.Parse(hdfCompanyId.Value));

                // ... projects.aspx or projects2.aspx
                if ((Request.QueryString["source_page"] == "projects.aspx") || (Request.QueryString["source_page"] == "projects2.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    // Restore data
                    projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                    projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    // Store data
                    Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_summary.aspx, project_edit.aspx, project_sections_navigator.aspx or project_sections_navigator2.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

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

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_delete.aspx
                if (Request.QueryString["source_page"] == "project_delete.aspx")
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

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

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }

                    // Databind
                    if (Request.QueryString["update"] != "no")
                    {
                        if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count == 0)
                        {
                            string url = "./projects.aspx?source_page=projects2.aspx&" + GetNavigatorState() + "&no_results=no";
                            Response.Redirect(url);
                        }
                    }
                }

                // ... Store datasets
                Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
            }
            else
            {
                // Restore datasets
                projectSelectProjectTDS = (ProjectSelectProjectTDS)Session["projectSelectProjectTDS"];

                // Restore searched data (if any)
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                //... for the total rows
                if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }