/// <summary>
        /// UpdateSection
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="lateralWorkId">lateralWorkId</param>
        /// <param name="companyId">companyId</param>
        public void UpdateSection(int sectionWorkId, int lateralWorkId, int companyId)
        {
            // load section
            WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
            workJunctionLiningSectionGateway.LoadByWorkId(sectionWorkId, companyId);

            // get old values of section
            int numLats = workJunctionLiningSectionGateway.GetNumLats(sectionWorkId);
            int notLinedYet = workJunctionLiningSectionGateway.GetNotLinedYet(sectionWorkId);
            bool allMeasured = workJunctionLiningSectionGateway.GetAllMeasured(sectionWorkId);
            bool deleted = workJunctionLiningSectionGateway.GetDeleted(sectionWorkId);
            string issueWithLaterals = workJunctionLiningSectionGateway.GetIssueWithLaterals(sectionWorkId);
            int notMeasuredYet = workJunctionLiningSectionGateway.GetNotMeasuredYet(sectionWorkId);
            int notDeliveredYet = workJunctionLiningSectionGateway.GetNotDeliveredYet(sectionWorkId);
            string trafficControl = workJunctionLiningSectionGateway.GetTrafficControl(sectionWorkId);
            string trafficControlDetails = workJunctionLiningSectionGateway.GetTrafficControlDetails(sectionWorkId);
            bool standardBypass = workJunctionLiningSectionGateway.GetStandardBypass(sectionWorkId);
            string standardBypassComments = workJunctionLiningSectionGateway.GetStandardBypassComments(sectionWorkId);
            int availableToLine = workJunctionLiningSectionGateway.GetAvailableToLine(sectionWorkId);

            //  get new values of section
            int newNumLats = 0;
            int newNotLinedYet = 0;
            bool newAllMeasured = true;
            int newNotMeasuredYet = 0;
            int newNotDeliveredYet = 0;
            string newIssueWithLaterals = "No";
            int newAvailableToLine = 0;
            int totDelivered = 0;
            int totInstalled = 0;

            // load laterals
            WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
            workJunctionLiningLateralGateway.LoadBySectionWorkId(sectionWorkId, companyId);

            foreach (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALRow row in (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALDataTable)workJunctionLiningLateralGateway.Table)
            {
                if (!row.Deleted)
                {
                    // ... With no outofscope issue
                    if (!row.OutOfScope)
                    {
                        newNumLats++;
                        if (row.IsLinerInstalledNull()) newNotLinedYet++;
                        if (row.IsMeasuredNull()) newAllMeasured = false;
                        if (row.IsMeasuredNull()) newNotMeasuredYet++;
                        if (row.IsDeliveredNull()) newNotDeliveredYet++;
                        if (!row.IsDeliveredNull()) totDelivered++;
                        if (!row.IsLinerInstalledNull()) totInstalled++;
                    }
                }
            }

            if (newNumLats == 0) newAllMeasured = false;

            if (newNumLats > 0)
            {
                newAvailableToLine = totDelivered - totInstalled;

                // lining plan
                JlLiningPlanGateway jlLiningPlanGateway = new JlLiningPlanGateway();

                if (jlLiningPlanGateway.IsLateralsIssueNo(sectionWorkId))
                {
                    newIssueWithLaterals = "No";
                }
                else
                {
                    if (jlLiningPlanGateway.IsLateralsIssueOutOfScope(sectionWorkId))
                    {
                        newIssueWithLaterals = "Out Of Scope";
                    }
                    else
                    {
                        if (jlLiningPlanGateway.IsLateralsIssueYesOutOfScope(sectionWorkId))
                        {
                            newIssueWithLaterals = "Yes, Out Of Scope";
                        }
                        else
                        {
                            if (jlLiningPlanGateway.IsLateralsIssueYes(sectionWorkId))
                            {
                                newIssueWithLaterals = "Yes";
                            }
                        }
                    }
                }
            }

            // Update Work Juntion Lining Section
            WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
            workJunctionLiningSection.UpdateDirect(sectionWorkId, numLats, notLinedYet, allMeasured, deleted, issueWithLaterals, notMeasuredYet, notDeliveredYet, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine, newNumLats, newNotLinedYet, newAllMeasured, newIssueWithLaterals, newNotMeasuredYet, newNotDeliveredYet, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, newAvailableToLine);
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_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) || ((string)Request.QueryString["client_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in jl_lining_plan.aspx");
                }

                // Tag Page
                hdfGeneralCompanyId.Value = Session["companyID"].ToString();
                hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
                hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
                hdfWorkType.Value = Request.QueryString["work_type"].ToString();

                // Prepare initial data
                // ... for client
                int currentClientId = Int32.Parse(hdfCurrentClientId.Value.ToString());
                int companyId = Int32.Parse(Session["companyID"].ToString());

                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                // ... for project
                int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());
                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(currentProjectId);
                string name = projectGateway.GetName(currentProjectId);
                if (name.Length > 23) name = name.Substring(0, 20) + "...";
                lblTitleProjectName.Text = " > Project: " + name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")";

                // ... for the grid
                jlLiningPlanTDS = new JlLiningPlanTDS();
                JlLiningPlanGateway jlLiningPlanGateway = new JlLiningPlanGateway(jlLiningPlanTDS);
                jlLiningPlanGateway.ClearBeforeFill = false;
                jlLiningPlanGateway.LoadByProjectIdIssueWithLateralsNoOutOfScope(int.Parse(hdfGeneralCompanyId.Value), int.Parse(hdfCurrentProjectId.Value));
                jlLiningPlanGateway.LoadByProjectIdOtherIssueWithLaterals(int.Parse(hdfGeneralCompanyId.Value), int.Parse(hdfCurrentProjectId.Value));

                grdLiningPlan.DataSource = jlLiningPlanGateway.Table;
                grdLiningPlan.DataBind();

                // Check results
                if (jlLiningPlanTDS.JlLiningPlan.Rows.Count > 0)
                {
                    tPreview.Visible = true;
                    tdNoResults.Visible = false;
                    tbFooterToolbar.Visible = true;
                }
                else
                {
                    tPreview.Visible = false;
                    tdNoResults.Visible = true;
                    tbFooterToolbar.Visible = false;
                }

                // Check results
                if (jlLiningPlanTDS.JlLiningPlan.Rows.Count == 1)
                {
                    tbFooterToolbar.Visible = false;
                }

                // Store dataset
                Session["jlLiningPlanTDS"] = jlLiningPlanTDS;
            }
            else
            {
                // Restore dataset
                jlLiningPlanTDS = (JlLiningPlanTDS)Session["jlLiningPlanTDS"];

                // ... for the grid
                JlLiningPlanGateway jlLiningPlanGateway = new JlLiningPlanGateway(jlLiningPlanTDS);
                grdLiningPlan.DataSource = jlLiningPlanGateway.Table;
                grdLiningPlan.DataBind();
            }
        }