public ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable GetProjectAddSectionsSearch()
        {
            projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)Session["projectAddSectionsSearchDummy"];
            if (projectAddSectionsSearch == null)
            {
                projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)Session["projectAddSectionsSearch"];
            }

            return projectAddSectionsSearch;
        }
        private void StepSelectSectionsProcessGrid()
        {
            ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
            dataSet.ProjectAddSectionsSearch.Merge(projectAddSectionsSearch, true);
            ProjectAddSectionsSearch model = new ProjectAddSectionsSearch(dataSet);

            // update rows
            if (Session["projectAddSectionsSearchDummy"] == null)
            {
                foreach (GridViewRow row in grdProjectAddSectionsSearch.Rows)
                {
                    string sectionId = ((Label)row.FindControl("lblSectionID")).Text.Trim();
                    bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;

                    bool rehabAssessment = ((CheckBox)row.FindControl("cbxRehabAssessmentPrevWork")).Checked;
                    bool fullLengthLining = ((CheckBox)row.FindControl("cbxFullLengthLiningPrevWork")).Checked;
                    bool pointRepairs = ((CheckBox)row.FindControl("cbxPointRepairsPrevWork")).Checked;
                    bool junctionLining = ((CheckBox)row.FindControl("cbxJunctionLiningPrevWork")).Checked;

                    bool rehabAssessmentPrevWork = ((CheckBox)row.FindControl("cbxRehabAssessmentPrevWorkReadOnly")).Checked;
                    bool fullLengthLiningPrevWork = ((CheckBox)row.FindControl("cbxFullLengthLiningPrevWorkReadOnly")).Checked;
                    bool pointRepairsPrevWork = ((CheckBox)row.FindControl("cbxPointRepairsPrevWorkReadOnly")).Checked;
                    bool junctionLiningPrevWork = ((CheckBox)row.FindControl("cbxJunctionLiningPrevWorkReadOnly")).Checked;

                    model.UpdateBySectionId(sectionId, rehabAssessment, fullLengthLining, pointRepairs, junctionLining, selected, rehabAssessmentPrevWork, fullLengthLiningPrevWork, pointRepairsPrevWork, junctionLiningPrevWork);
                }

                model.Table.AcceptChanges();

                projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)model.Table;
                Session["projectAddSectionsSearch"] = projectAddSectionsSearch;
            }
        }
        private void StepSelectForIntermediateSectionsProcessGrid()
        {
            ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
            dataSet.ProjectAddSectionsSearch.Merge(projectAddSectionsSearch, true);
            ProjectAddSectionsSearch model = new ProjectAddSectionsSearch(dataSet);

            // update rows
            if (Session["projectAddSectionsSearchDummy"] == null)
            {
                foreach (GridViewRow row in grdSelectForIntermediateSectionsSearch.Rows)
                {
                    string sectionId = ((Label)row.FindControl("lblSectionID_")).Text.Trim();
                    bool selected = ((CheckBox)row.FindControl("cbxSelected_")).Checked;

                    model.UpdateBySectionId(sectionId, false, false, false, false, selected, false, false, false, false);
                }

                model.Table.AcceptChanges();

                projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)model.Table;
                Session["projectAddSectionsSearch"] = projectAddSectionsSearch;
            }
        }
        private bool StepSearchSectionsNext()
        {
            // Get where clause and order by clasue
            string whereClause = GetWhereClause();
            string orderByClause = GetOderByClause();

            // Search
            ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
            dataSet.ProjectAddSectionsSearch.Merge(projectAddSectionsSearch, true);
            ProjectAddSectionsSearch model = new ProjectAddSectionsSearch(dataSet);

            model.Load(whereClause, orderByClause);

            // Review Previous Work
            int projectId = Int32.Parse(hdfProjectId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);

            model.UpdatePreviousWorks(projectId, companyId);

            // Store tables
            projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable) model.Table;
            Session["projectAddSectionsSearch"] = projectAddSectionsSearch;

            return true;
        }
        private bool StepSearchIntermediateSectionsNext()
        {
            // Get where clause and order by clause
            string whereClause = GetIntermediateWhereClause();

            string orderByClause = GetIntermediateOderByClause();

            // Search
            ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS();
            dataSet.ProjectAddSectionsSearch.Merge(projectAddSectionsSearch, true);
            ProjectAddSectionsSearch model = new ProjectAddSectionsSearch(dataSet);

            model.Load(whereClause, orderByClause);

            // Store tables
            projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)model.Table;
            Session["projectAddSectionsSearch"] = projectAddSectionsSearch;

            return true;
        }
        protected void ProjectAddSectionsSearchEmptyFix(GridView grdView)
        {
            if (grdView.Rows.Count == 0)
            {
                ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable dt = new ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable();
                dt.AddProjectAddSectionsSearchRow(0, "", "", "", "", false, false, false, false, false, "", "", "", false, false, false, false, false);
                Session["projectAddSectionsSearchDummy"] = dt;

                grdView.DataBind();
            }

            // normally executes at all postbacks
            if (grdView.Rows.Count == 1)
            {
                ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable dt = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)Session["projectAddSectionsSearchDummy"];
                if (dt != null)
                {
                    // hide row
                    grdView.Rows[0].Visible = false;
                    grdView.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["client_id"] == null) || ((string)Request.QueryString["project_id"] == null) || ((string)Request.QueryString["work_type"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_add_sections.aspx");
                }

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

                if ((string)Request.QueryString["work_type"] == "Full Length Lining")
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_ADD"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                if ((string)Request.QueryString["work_type"] == "Junction Lining")
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_ADD"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                if ((string)Request.QueryString["work_type"] == "Point Repairs")
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_CWP_POINTREPAIRS_ADD"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                if ((string)Request.QueryString["work_type"] == "Manhole Rehabilitation")
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_CWP_MANHOLEREHABILITATION_ADD"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                // Tag Page
                TagPage();

                // Prepare initial data
                Session.Remove("projectAddSectionsNew");
                Session.Remove("projectAddSectionsNewDummy");
                Session.Remove("projectAddSectionsSearch");
                Session.Remove("projectAddSectionsSearchDummy");
                Session.Remove("projectAddSectionsTemp");
                Session.Remove("projectAddSectionsTempDummy");

                // Initialize viewstate variables
                ViewState["StepFrom"] = "Out";

                // If coming from
                // ... ra_navigator.aspx, ra_navigator2.aspx, jl_navigator.aspx, jl_navigator2.aspx, project_sections_navigator.aspx, project_sections_navigator2.aspx, fl_navigator.aspx, fl_navigator2.aspx, ra_lining_plan.aspx, fl_edit.aspx, fl_summary.aspx, ra_edit.aspx, ra_summary.aspx, flat_section_jl_summary.aspx, flat_section_jl_edit.aspx, flat_section_jls_summary.aspx, flat_section_jls_edit.aspx, jl_lining_plan.aspx, pr_navigator.aspx, pr_navigator2.aspx, pr_summay.aspx, pr_edit.aspx, pr_lining_plan, mr_navigator.aspx, mr_navigator2.aspx, mr_edit.aspx, mr_summary.aspx
                if ((Request.QueryString["source_page"] == "ra_navigator.aspx") || (Request.QueryString["source_page"] == "ra_navigator2.aspx") || (Request.QueryString["source_page"] == "jl_navigator.aspx") || (Request.QueryString["source_page"] == "jl_navigator2.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx") || (Request.QueryString["source_page"] == "fl_navigator.aspx") || (Request.QueryString["source_page"] == "fl_navigator2.aspx") || (Request.QueryString["source_page"] == "ra_lining_plan.aspx") || (Request.QueryString["source_page"] == "fl_edit.aspx") || (Request.QueryString["source_page"] == "fl_summary.aspx") || (Request.QueryString["source_page"] == "ra_edit.aspx") || (Request.QueryString["source_page"] == "ra_summary.aspx") || (Request.QueryString["source_page"] == "flat_section_jl_summary.aspx") || (Request.QueryString["source_page"] == "flat_section_jl_edit.aspx") || (Request.QueryString["source_page"] == "flat_section_jls_summary.aspx") || (Request.QueryString["source_page"] == "flat_section_jls_edit.aspx") || (Request.QueryString["source_page"] == "jl_lining_plan.aspx") || (Request.QueryString["source_page"] == "pr_navigator.aspx") || (Request.QueryString["source_page"] == "pr_navigator2.aspx") || (Request.QueryString["source_page"] == "pr_summary.aspx") || (Request.QueryString["source_page"] == "pr_edit.aspx") || (Request.QueryString["source_page"] == "pr_lining_plan.aspx") || (Request.QueryString["source_page"] == "mr_navigator.aspx") || (Request.QueryString["source_page"] == "mr_navigator2.aspx")  || (Request.QueryString["source_page"] == "mr_edit.aspx")  || (Request.QueryString["source_page"] == "mr_summary.aspx"))
                {
                    // ... Initialize tables
                    projectAddSectionsNew = new ProjectAddSectionsTDS.ProjectAddSectionsNewDataTable();
                    projectAddSectionsSearch = new ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable();
                    projectAddSectionsTemp = new ProjectAddSectionsTDS.ProjectAddSectionsTempDataTable();

                    // ... Store tables
                    Session["projectAddSectionsNew"] = projectAddSectionsNew;
                    Session["projectAddSectionsSearch"] = projectAddSectionsSearch;
                    Session["projectAddSectionsTemp"] = projectAddSectionsTemp;
                }

                // StepSection1In
                wzSections.ActiveStepIndex = 0;
                StepBeginIn();
            }
            else
            {
                // Restore tables
                projectAddSectionsNew = (ProjectAddSectionsTDS.ProjectAddSectionsNewDataTable) Session["projectAddSectionsNew"];
                projectAddSectionsSearch = (ProjectAddSectionsTDS.ProjectAddSectionsSearchDataTable)Session["projectAddSectionsSearch"];
                projectAddSectionsTemp = (ProjectAddSectionsTDS.ProjectAddSectionsTempDataTable)Session["projectAddSectionsTemp"];
            }

            // control for postback
            hdfTag.Value = DateTime.Now.ToLongTimeString();
        }