// ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        private void UpdateForReport()
        {
            double total = 0.0F;
            double totalConfirmed = 0;
            Distance d;

            foreach (FLWorkAheadReportTDS.WorkAheadRow rowTemp in (FLWorkAheadReportTDS.WorkAheadDataTable)Table)
            {
                if (!rowTemp.IsMapLengthNull())
                {
                    if (Distance.IsValidDistance(rowTemp.MapLength))
                    {
                        d = new Distance(rowTemp.MapLength);
                        total = total + d.ToDoubleInEng3();
                    }
                }

                if (!rowTemp.IsSize_Null())
                {
                    if (Distance.IsValidDistance(rowTemp.Size_))
                    {
                        d = new Distance(rowTemp.Size_);
                        totalConfirmed = totalConfirmed + d.ToDoubleInEng3();
                    }
                }
            }

            foreach (FLWorkAheadReportTDS.WorkAheadRow row in (FLWorkAheadReportTDS.WorkAheadDataTable)Table)
            {
                if (!row.IsMapLengthNull())
                {
                    if (Distance.IsValidDistance(row.MapLength))
                    {
                        d = new Distance(row.MapLength);
                        row.SumScaled = Math.Round(d.ToDoubleInEng3(), 2);
                    }
                }

                if (!row.IsSize_Null())
                {
                    if (Distance.IsValidDistance(row.Size_))
                    {
                        try
                        {
                            d = new Distance(row.Size_);
                            row.SumConfirmed = Convert.ToInt32(d.ToStringInEng3());
                        }
                        catch
                        {
                            row.SumConfirmed = 0;
                        }
                    }
                }

                row.TotalAhead = Math.Round(total, 2);
                row.TotalAhead2 = totalConfirmed;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        private void UpdateForReport()
        {
            foreach (LateralLocationSheetReportTDS.LateralLocationSheetLateralDetailsRow lateralRow in (LateralLocationSheetReportTDS.LateralLocationSheetLateralDetailsDataTable)Table)
            {
                Distance d; if (!lateralRow.IsVideoDistanceNull()) d = new Distance(lateralRow.VideoDistance); else d = new Distance();
                lateralRow.VideoDistanceDouble = (!lateralRow.IsVideoDistanceNull()) ? d.ToDoubleInEng3() : 0.0;

                Distance d2; if (!lateralRow.IsReverseSetupNull()) d2 = new Distance(lateralRow.ReverseSetup); else d2 = new Distance();
                lateralRow.ReverseSetupDouble = (!lateralRow.IsReverseSetupNull()) ? d2.ToDoubleInEng3() : 0.0;
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PRIVATE METHODS
 //
 /// <summary>
 /// UpdateFieldsForSections
 /// </summary>
 private void UpdateFieldsForSections()
 {
     foreach (GerencialDailyProductionReportTDS.DailyProductionReportRow row in (GerencialDailyProductionReportTDS.DailyProductionReportDataTable)Table)
     {
         // ... modify for length
         if (row.IsLengthNull())
         {
             row.TotalFtInstalled = 0;
         }
         else
         {
             Distance distance = new Distance(row.Length);
             row.TotalFtInstalled = distance.ToDoubleInEng3();
         }
     }
 }
        public override void Validate()
        {
            // Validate page
            base.Validate();

            if (Page.IsValid)
            {
                // Update flatSectionJlineTDS
                foreach (GridViewRow row in grdvJliner.Rows)
                {
                    // ... Get standard fields
                    Guid id = new Guid(((HiddenField)row.FindControl("hdfId")).Value);
                    int companyId = int.Parse(((HiddenField)row.FindControl("hdfCompanyId")).Value);
                    double? distanceFromUSMH = null; if (((TextBox)row.FindControl("tbxDistanceFromUSMH")).Text.Trim() != "") distanceFromUSMH = double.Parse(((TextBox)row.FindControl("tbxDistanceFromUSMH")).Text.Trim());

                    // ... Calculate fields
                    double? distanceFromDSMH = null;
                    if (distanceFromUSMH.HasValue)
                    {
                        SectionGateway sectionGateway = new SectionGateway();
                        sectionGateway.LoadById(id, companyId);

                        Distance length = new Distance(sectionGateway.GetActualLength(id)) - new Distance(((double)distanceFromUSMH).ToString());
                        distanceFromDSMH = length.ToDoubleInEng3();
                    }

                    // ... Check validation fields
                    if (distanceFromDSMH.HasValue)
                    {
                        if ((double)distanceFromDSMH < 0)
                        {
                            CompareValidator cvDistanceFromDSMH = ((CompareValidator)row.FindControl("cvDistanceFromDSMH"));
                            cvDistanceFromDSMH.IsValid = false;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        private void ProcessDataForProject(int companyId)
        {
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;
            int numPeriods = 0;

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRARow rowOriginal in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRADataTable)Table)
            {
                if (!rowOriginal.IsTotalFtNull())
                {
                    Distance distOriginal = new Distance(rowOriginal.TotalFt);
                    rowOriginal.TotalFtDouble = distOriginal.ToDoubleInEng3();
                    rowOriginal.RealFt = distOriginal.ToDoubleInEng3();
                }
                else
                {
                    rowOriginal.TotalFtDouble = 0;
                    rowOriginal.RealFt = 0;
                }

                rateAcum = rateAcum + rowOriginal.RealFt / rowOriginal.Hrs;

                // For get number of periods
                if (!alDays.Contains(rowOriginal.Date))
                {
                    alDays.Add(rowOriginal.Date);
                    numPeriods = numPeriods + 1;
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRARow row3 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRADataTable)Table)
            {
                row3.AverageRate = rateAcum / numPeriods;
                row3.NumPeriods = numPeriods;
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        public void ProcessDataForProject(int companyId)
        {
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseMHPrepRow row in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseMHPrepDataTable)Table)
            {
                if (!row.IsTotalFtNull())
                {
                    Distance dist = new Distance(row.TotalFt);
                    row.RealFt = dist.ToDoubleInEng3();
                    row.TotalFtDouble = dist.ToDoubleInEng3();
                }
                else
                {
                    row.RealFt = 0;
                    row.TotalFtDouble = 0;
                }

                if (!alDays.Contains(row.Date))
                {
                    alDays.Add(row.Date);
                }

                rateAcum = rateAcum + row.RealFt / row.Hrs;
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseMHPrepRow row2 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseMHPrepDataTable)Table)
            {
                row2.NumPeriods = alDays.Count;
                row2.AverageRate = rateAcum / alDays.Count;
            }
        }
        private void Save2()
        {
            //Save changes without validate

            // Laterals Gridview
            // ... If the gridview is edition mode
            if (grdLaterals.EditIndex >= 0)
            {
                grdLaterals.UpdateRow(grdLaterals.EditIndex, true);
            }

            // Save Lateral data
            GrdFLAddLateralsNewAdd();

            // Catalysts Gridview
            if (ckbxWetOutDataIncludeWetOutInformation.Checked)
            {
                // ... If the gridview is edition mode
                if (grdCatalysts.EditIndex >= 0)
                {
                    grdCatalysts.UpdateRow(grdCatalysts.EditIndex, true);
                }

                // Save Lateral data
                GrdCatalystsAdd();
            }

            // Save data
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());

            // Get Section Details
            // ... FullLengthLiningSectionDetails data
            string newStreet = ""; if (tbxStreet.Text != "") newStreet = tbxStreet.Text.Trim();
            string newUsmh = ""; if (tbxUSMH.Text != "") newUsmh = tbxUSMH.Text.Trim();
            string newDsmh = ""; if (tbxDSMH.Text != "") newDsmh = tbxDSMH.Text.Trim();
            string newMapSize = ""; if (tbxMapSize.Text != "") newMapSize = tbxMapSize.Text.Trim();
            string newSize = ""; if (tbxConfirmedSize.Text != "") newSize = tbxConfirmedSize.Text.Trim();
            string newThickness = ""; if (ddlThickness.SelectedValue != "") newThickness = ddlThickness.SelectedValue;
            string newMapLength = ""; if (tbxMapLength.Text != "") newMapLength = tbxMapLength.Text.Trim();

            string newSteelTapeThroughSewer = "";
            string newLength = "";
            if (tbxM1DataSteelTapeThroughSewer.Text != "")
            {
                newSteelTapeThroughSewer = tbxM1DataSteelTapeThroughSewer.Text.Trim();
                newLength = tbxM1DataSteelTapeThroughSewer.Text.Trim();
            }

            int? newLaterals = null; if (tbxLaterals.Text != "") newLaterals = Int32.Parse(tbxLaterals.Text.Trim());
            int? newLiveLaterals = null; if (tbxLiveLaterals.Text != "") newLiveLaterals = Int32.Parse(tbxLiveLaterals.Text.Trim());

            // Get m1 data
            // ... assetSewerSection data
            string newUsmhDepth = ""; if ((tbxM1DataUsmhDepth.Text != "") && (tbxUSMH.Text != "")) newUsmhDepth = tbxM1DataUsmhDepth.Text.Trim();
            string newDsmhDepth = ""; if ((tbxM1DataDsmhDepth.Text != "") && (tbxDSMH.Text != "")) newDsmhDepth = tbxM1DataDsmhDepth.Text.Trim();

            // ... lfsAssetSewerSection data
            string newUsmhMouth12 = ""; if ((tbxM1DataUsmhMouth12.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth12 = tbxM1DataUsmhMouth12.Text.Trim();
            string newUsmhMouth1 = ""; if ((tbxM1DataUsmhMouth1.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth1 = tbxM1DataUsmhMouth1.Text.Trim();
            string newUsmhMouth2 = ""; if ((tbxM1DataUsmhMouth2.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth2 = tbxM1DataUsmhMouth2.Text.Trim();
            string newUsmhMouth3 = ""; if ((tbxM1DataUsmhMouth3.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth3 = tbxM1DataUsmhMouth3.Text.Trim();
            string newUsmhMouth4 = ""; if ((tbxM1DataUsmhMouth4.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth4 = tbxM1DataUsmhMouth4.Text.Trim();
            string newUsmhMouth5 = ""; if ((tbxM1DataUsmhMouth5.Text != "") && (tbxUSMH.Text != "")) newUsmhMouth5 = tbxM1DataUsmhMouth5.Text.Trim();
            string newDsmhMouth12 = ""; if ((tbxM1DataDsmhMouth12.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth12 = tbxM1DataDsmhMouth12.Text.Trim();
            string newDsmhMouth1 = ""; if ((tbxM1DataDsmhMouth1.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth1 = tbxM1DataDsmhMouth1.Text.Trim();
            string newDsmhMouth2 = ""; if ((tbxM1DataDsmhMouth2.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth2 = tbxM1DataDsmhMouth2.Text.Trim();
            string newDsmhMouth3 = ""; if ((tbxM1DataDsmhMouth3.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth3 = tbxM1DataDsmhMouth3.Text.Trim();
            string newDsmhMouth4 = ""; if ((tbxM1DataDsmhMouth4.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth4 = tbxM1DataDsmhMouth4.Text.Trim();
            string newDsmhMouth5 = ""; if ((tbxM1DataDsmhMouth5.Text != "") && (tbxDSMH.Text != "")) newDsmhMouth5 = tbxM1DataDsmhMouth5.Text.Trim();
            string newGeneralSubArea = ""; if (tbxGeneralSubArea.Text != "") newGeneralSubArea = tbxGeneralSubArea.Text.Trim();

            // ... assetSewerMH data
            string newUsmhAddress = ""; if (tbxM1DataUsmhAddress.Text != "") newUsmhAddress = tbxM1DataUsmhAddress.Text.Trim();
            string newDsmhAddress = ""; if (tbxM1DataDsmhAddress.Text != "") newDsmhAddress = tbxM1DataDsmhAddress.Text.Trim();

            // Update section details
            FullLengthLiningSectionDetails fullLengthLiningSectionDetails = new FullLengthLiningSectionDetails(fullLengthLiningTDS);
            fullLengthLiningSectionDetails.Update(workId, assetId, newStreet, newMapSize, newSize, newMapLength, newLength, newLaterals, newLiveLaterals, newUsmhDepth, newDsmhDepth, newSteelTapeThroughSewer, newUsmhMouth12, newUsmhMouth1, newUsmhMouth2, newUsmhMouth3, newUsmhMouth4, newUsmhMouth5, newDsmhMouth12, newDsmhMouth1, newDsmhMouth2, newDsmhMouth3, newDsmhMouth4, newDsmhMouth5, newUsmh, newDsmh, newUsmhAddress, newDsmhAddress, newGeneralSubArea, newThickness);

            // Get generalData
            // ... Ra new data
            DateTime? newPreFlushDate = null;
            if (tkrdpGeneralPreFlushDate.Visible == true)
            {
                if (tkrdpGeneralPreFlushDate.SelectedDate.HasValue)
                {
                    newPreFlushDate = tkrdpGeneralPreFlushDate.SelectedDate.Value;
                }
            }
            else
            {
                if (tkrdpGeneralPreFlushDateReadOnly.SelectedDate.HasValue)
                {
                    newPreFlushDate = tkrdpGeneralPreFlushDateReadOnly.SelectedDate.Value;
                }
            }

            DateTime? newPreVideoDate = null;
            if (tkrdpGeneralPreVideoDate.Visible == true)
            {
                if (tkrdpGeneralPreVideoDate.SelectedDate.HasValue)
                {
                    newPreVideoDate = tkrdpGeneralPreVideoDate.SelectedDate.Value;
                }
            }
            else
            {
                if (tkrdpGeneralPreVideoDateReadOnly.SelectedDate.HasValue)
                {
                    newPreVideoDate = tkrdpGeneralPreVideoDateReadOnly.SelectedDate.Value; ;
                }
            }

            // ... FullLengthLining data
            string newGeneralClientId = ""; if (tbxGeneralClientId.Text != "") newGeneralClientId = tbxGeneralClientId.Text.Trim();
            DateTime? newGeneralProposedLiningDate = null; if (tkrdpGeneralProposedLiningDate.SelectedDate.HasValue) newGeneralProposedLiningDate = tkrdpGeneralProposedLiningDate.SelectedDate.Value;
            DateTime? newGeneralDeadlineLiningDate = null; if (tkrdpGeneralDeadlineLiningDate.SelectedDate.HasValue) newGeneralDeadlineLiningDate = tkrdpGeneralDeadlineLiningDate.SelectedDate.Value;
            DateTime? newGeneralP1Date = null; if (tkrdpPrepDataP1Date.SelectedDate.HasValue) newGeneralP1Date = tkrdpPrepDataP1Date.SelectedDate.Value;
            DateTime? newGeneralM1Date = null; if (tkrdpM1DataM1Date.SelectedDate.HasValue) newGeneralM1Date = tkrdpM1DataM1Date.SelectedDate.Value;
            DateTime? newGeneralM2Date = null; if (tkrdpM2DataM2Date.SelectedDate.HasValue) newGeneralM2Date = tkrdpM2DataM2Date.SelectedDate.Value;
            DateTime? newGeneralInstallDate = null; if (tkrdpInstallDataInstallDate.SelectedDate.HasValue) newGeneralInstallDate = tkrdpInstallDataInstallDate.SelectedDate.Value;
            DateTime? newGeneralFinalVideo = null; if (tkrdpInstallDataFinalVideoDate.SelectedDate.HasValue) newGeneralFinalVideo = tkrdpInstallDataFinalVideoDate.SelectedDate.Value;
            bool newGeneralIssueIdentified = ckbxGeneralIssueIdentified.Checked;
            bool newGeneralLfsIssue = ckbxGeneralLfsIssue.Checked;
            bool newGeneralClientIssue = ckbxGeneralClientIssue.Checked;
            bool newGeneralSalesIssue = ckbxGeneralSalesIssue.Checked;
            bool newGeneralIssueGivenToClient = ckbxGeneralIssueGivenToClient.Checked;
            bool newGeneralIssueResolved = ckbxGeneralIssueResolved.Checked;
            bool newGeneralIssueInvestigation = ckbxGeneralIssueInvestigation.Checked;
            int? newPrepDataCXIsRemoved = null; if (tbxPrepDataCXIsRemoved.Text != "") newPrepDataCXIsRemoved = Int32.Parse(tbxPrepDataCXIsRemoved.Text.Trim());
            bool newRoboticPrepCompleted = ckbxPrepDataRoboticPrepCompleted.Checked;
            DateTime? newRoboticPrepCompletedDate = null; if (tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.HasValue) newRoboticPrepCompletedDate = tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.Value;
            bool newP1Completed = ckbxPrepDataP1Completed.Checked;

            // ... WorkFullLengthLiningM1 data
            string newMeasurementsTakenBy = ""; if (tbxM1DataMeasurementsTakenBy.Text != "") newMeasurementsTakenBy = tbxM1DataMeasurementsTakenBy.Text.Trim();
            string newMaterial = ddlM1DataMaterial.SelectedValue;
            string newTrafficControl = ddlM1DataTrafficControl.SelectedValue;
            string newSiteDetails = ""; if (ddlM1DataSiteDetails.SelectedValue != "(Select)") newSiteDetails = ddlM1DataSiteDetails.SelectedValue;
            bool newPipeSizeChange = ckbxM1DataPipeSizeChange.Checked;
            bool newStandardByPass = ckbxM1DataStandardBypass.Checked;
            string newStandardBypassComments = ""; if (tbxM1DataStandardBypassComments.Text != "") newStandardBypassComments = tbxM1DataStandardBypassComments.Text.Trim();
            string newTrafficControlDetails = ""; if (tbxM1DataTrafficControlDetails.Text != "") newTrafficControlDetails = tbxM1DataTrafficControlDetails.Text.Trim();
            string newMeasurementType = ddlM1DataMeasurementType.SelectedValue;
            string newMeasuredFromMh = null; if (tbxM1DataMeasuredFromMh.Visible) newMeasuredFromMh = tbxM1DataMeasuredFromMh.Text; else newMeasuredFromMh = ddlM1DataMeasuredFromMh.SelectedValue;
            string newVideoDoneFromMh = ""; if (tbxM1DataVideoDoneFromMh.Visible) newVideoDoneFromMh = tbxM1DataVideoDoneFromMh.Text; else newVideoDoneFromMh = ddlM1DataVideoDoneFromMh.SelectedValue;
            string newVideoDoneToMh = ""; if (tbxM1DataVideoDoneToMh.Visible) newVideoDoneToMh = tbxM1DataVideoDoneToMh.Text; else newVideoDoneToMh = ddlM1DataVideoDoneToMh.SelectedValue;
            string newAccessType = ""; if (ddlM1DataAccessType.SelectedValue != "(Select)") newAccessType = ddlM1DataAccessType.SelectedValue;

            // ... ... For header values
            string newVideoLength = tbxVideoLength.Text.Trim();

            // ... WorkFullLengthLiningM2 data
            string newMeasurementTakenByM2 = tbxM2DataMeasurementsTakenBy.Text.Trim();
            bool newDropPipe = ckbxM2DataDropPipe.Checked;
            string newDropPipeInvertDepth = tbxM2DataDropPipeInvertdepth.Text.Trim();
            int? newCappedLaterals = null; if (tbxM2DataCappedLaterals.Text != "") newCappedLaterals = Int32.Parse(tbxM2DataCappedLaterals.Text.Trim());
            string newLineWidthId = ""; if (tbxM2DataLineWidthId.Text != "") newLineWidthId = tbxM2DataLineWidthId.Text.Trim();
            string newHydrantAddress = ""; if (tbxM2DataHydrantAddress.Text != "") newHydrantAddress = tbxM2DataHydrantAddress.Text.Trim();
            string newHydroWireWithin10FtOfInversionMH = ddlM2DataHydroWireWithin10FtOfInversionMh.SelectedValue.Trim();
            string newDistanceToInversionMH = ""; if (tbxM2DataDistanceToInversionMH.Text != "") newDistanceToInversionMH = tbxM2DataDistanceToInversionMH.Text.Trim();
            string newSurfaceGrade = ""; if (ddlM2DataSurfaceGrade.SelectedValue != "(Select)") newSurfaceGrade = ddlM2DataSurfaceGrade.SelectedValue;
            bool newHydroPulley = cbxM2DataHydroPulley.Checked;
            bool newFridgeCart = cbxM2DataFridgeCart.Checked;
            bool newTwoPump = cbxM2DataTwoPump.Checked;
            bool newSixBypass = cbxM2DataSixBypass.Checked;
            bool newScaffolding = cbxM2DataScaffolding.Checked;
            bool newWinchExtension = cbxM2DataWinchExtension.Checked;
            bool newExtraGenerator = cbxM2DataExtraGenerator.Checked;
            bool newGreyCableExtension = cbxM2DataGreyCableExtension.Checked;
            bool newEasementMats = cbxM2DataEasementMats.Checked;
            bool newRampsRequired = cbxM2DataRampsRequired.Checked;
            bool newCameraSkid = cbxM2DataCameraSkid.Checked;

            // ... Update work details
            FullLengthLiningWorkDetails fullLengthLiningWorkDetails = new FullLengthLiningWorkDetails(fullLengthLiningTDS);

            // ... ... If it doen's have wet out information and inversion information
            if ((!ckbxWetOutDataIncludeWetOutInformation.Checked) && (!ckbxInversionDataIncludeInversionInformation.Checked))
            {
                fullLengthLiningWorkDetails.Update(workId, newGeneralClientId, newGeneralProposedLiningDate, newGeneralDeadlineLiningDate, newGeneralP1Date, newGeneralM1Date, newGeneralM2Date, newGeneralInstallDate, newGeneralFinalVideo, newGeneralIssueIdentified, newGeneralLfsIssue, newGeneralClientIssue, newGeneralSalesIssue, newGeneralIssueGivenToClient, newGeneralIssueResolved, newGeneralIssueInvestigation, newPrepDataCXIsRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementsTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardByPass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasuredFromMh, newVideoDoneFromMh, newVideoDoneToMh, newMeasurementTakenByM2, newDropPipe, newDropPipeInvertDepth, newCappedLaterals, newLineWidthId, newHydrantAddress, newHydroWireWithin10FtOfInversionMH, newDistanceToInversionMH, newSurfaceGrade, newHydroPulley, newFridgeCart, newTwoPump, newSixBypass, newScaffolding, newWinchExtension, newExtraGenerator, newGreyCableExtension, newEasementMats, newRampsRequired, newVideoLength, newPreFlushDate, newPreVideoDate, newCameraSkid, newAccessType, newP1Completed);
            }
            else
            {
                // Wet out data
                string newLinerTuber = "";
                int newResinId = 0;
                decimal newExcessResin = 0;
                string newPoundsDrums = "";
                decimal newDrumDiameter = 0;
                decimal newHoistMaximumHeight = 0;
                decimal newHoistMinimumHeight = 0;
                decimal newDownDropTubeLenght = 0;
                decimal newPumpHeightAboveGround = 0;
                int newTubeResinToFeltFactor = 0;
                DateTime newDateOfSheet = DateTime.Now;
                int newEmployeeID = 0;
                string newRunDetails = "";
                string newRunDetails2 = "";
                DateTime newWetOutDate = DateTime.Now;
                DateTime? newInstallDate = null;
                string newInversionThickness = "";
                Distance lengthToLine = new Distance("0");
                decimal newLengthToLine = 0;
                decimal newPlusExtra = 0;
                decimal newForTurnOffset = 0;
                decimal newLengthToWetOut = 0;

                decimal newTubeMaxColdHead = 0;
                decimal newTubeMaxColdHeadPsi = 0;
                decimal newTubeMaxHotHead = 0;
                decimal newTubeMaxHotHeadPsi = 0;
                decimal newTubeIdealHead = 0;
                decimal newTubeIdealHeadPsi = 0;

                decimal newNetResinForTube = 0;
                decimal newNetResinForTubeUsgals = 0;
                string newNetResinForTubeDrumsIns = "";
                decimal newNetResinForTubeLbsFt = 0;
                decimal newNetResinForTubeUsgFt = 0;

                int newExtraResinForMix = 0;
                decimal newExtraLbsForMix = 0;
                decimal newTotalMixQuantity = 0;
                decimal newTotalMixQuantityUsgals = 0;
                string newTotalMixQuantityDrumsIns = "";

                string newInversionType = "";
                decimal newDepthOfInversionMH = 0;
                decimal newTubeForColumn = 0;
                decimal newTubeForStartDry = 0;
                decimal newTotalTube = 0;
                string newDropTubeConnects = "";
                decimal newAllowsHeadTo = 0;
                decimal newRollerGap = 0;

                decimal newHeightNeeded = 0;
                string newAvailable = "";
                string newHoistHeight = "";
                string newCommentsCipp = "";

                string newResinLabel = "";
                string newDrumContainsLabel = "";
                string newLinerTubeLabel = "";
                string newForLbDrumsLabel = "";
                string newNetResinLabel = "";
                string newCatalystLabel = "";

                if (ckbxWetOutDataIncludeWetOutInformation.Checked)
                {
                    // .... ... Wet Out Sheet
                    newLinerTuber = ddlWetOutDataLinerTube.SelectedValue;
                    newResinId = Int32.Parse(ddlWetOutDataResins.SelectedValue);
                    newExcessResin = decimal.Round(decimal.Parse(tbxWetOutDataExcessResin.Text), 1);
                    newPoundsDrums = ddlWetOutDataPoundsDrums.SelectedValue;
                    newDrumDiameter = decimal.Round(decimal.Parse(tbxWetOutDataDrumDiameter.Text), 1);
                    newHoistMaximumHeight = decimal.Round(decimal.Parse(tbxWetOutDataHoistMaximumHeight.Text), 0);
                    newHoistMinimumHeight = decimal.Round(decimal.Parse(tbxWetOutDataHoistMinimumHeight.Text), 0);
                    newDownDropTubeLenght = decimal.Round(decimal.Parse(tbxWetOutDataDownDropTubeLength.Text), 0);
                    newPumpHeightAboveGround = decimal.Round(decimal.Parse(tbxWetOutDataPumpHeightAboveGround.Text), 2);
                    newTubeResinToFeltFactor = Int32.Parse(tbxWetOutDataTubeResinToFeltFactor.Text);

                    newDateOfSheet = DateTime.Parse(tbxWetOutDataDateOfSheet.Text);
                    newEmployeeID = Int32.Parse(ddlWetOutDataMadeBy.SelectedValue);

                    foreach (ListItem lst in cbxlSectionId.Items)
                    {
                        if (lst.Selected)
                        {
                            newRunDetails = newRunDetails + lst.Value + ">";
                        }
                    }
                    newRunDetails = newRunDetails.Substring(0, newRunDetails.Length - 1);

                    newRunDetails2 = ddlWetOutDataRunDetails2.SelectedValue;
                    newWetOutDate = (DateTime)tkrdpWetOutDataWetOutDate.SelectedDate;

                    if (tkrdpInstallDataInstallDate.SelectedDate.ToString() != "")
                    {
                        newInstallDate = (DateTime)tkrdpInstallDataInstallDate.SelectedDate;
                    }

                    newInversionThickness = ddlThickness.SelectedValue;
                    lengthToLine = new Distance(tbxWetOutDataLengthToLine.Text);
                    newLengthToLine = decimal.Round(decimal.Parse(lengthToLine.ToStringInEng3()), 1);
                    newPlusExtra = decimal.Round(decimal.Parse(tbxWetOutDataPlusExtra.Text), 0);
                    newForTurnOffset = decimal.Round(decimal.Parse(tbxWetOutDataForTurnOffset.Text), 0);
                    newLengthToWetOut = decimal.Round(decimal.Parse(tbxWetOutDataLengthtToWetOut.Text), 1);

                    newTubeMaxColdHead = decimal.Round(decimal.Parse(tbxWetOutDataTubeMaxColdHead.Text), 1);
                    newTubeMaxColdHeadPsi = decimal.Round(decimal.Parse(tbxWetOutDataTubeMaxColdHeadPSI.Text), 1);
                    newTubeMaxHotHead = decimal.Round(decimal.Parse(tbxWetOutDataTubeMaxHotHead.Text), 1);
                    newTubeMaxHotHeadPsi = decimal.Round(decimal.Parse(tbxWetOutDataTubeMaxHotHeadPSI.Text), 1);
                    newTubeIdealHead = decimal.Round(decimal.Parse(tbxWetOutDataTubeIdealHead.Text), 1);
                    newTubeIdealHeadPsi = decimal.Round(decimal.Parse(tbxWetOutDataTubeIdealHeadPSI.Text), 1);

                    newNetResinForTube = decimal.Round(decimal.Parse(tbxWetOutDataNetResinForTube.Text), 0);
                    newNetResinForTubeUsgals = decimal.Round(decimal.Parse(tbxWetOutDataNetResinForTubeUsgals.Text), 1);
                    newNetResinForTubeDrumsIns = tbxWetOutDataNetResinForTubeDrumsIns.Text;
                    newNetResinForTubeLbsFt = decimal.Round(decimal.Parse(tbxWetOutDataNetResinForTubeLbsFt.Text), 2);
                    newNetResinForTubeUsgFt = decimal.Round(decimal.Parse(tbxWetOutDataNetResinForTubeUsgFt.Text), 3);

                    newExtraResinForMix = Int32.Parse(tbxWetOutDataExtraResinForMix.Text);
                    newExtraLbsForMix = decimal.Round(decimal.Parse(tbxWetOutDataExtraLbsForMix.Text), 2);
                    newTotalMixQuantity = decimal.Round(decimal.Parse(tbxWetOutDataTotalMixQuantity.Text), 0);
                    newTotalMixQuantityUsgals = decimal.Round(decimal.Parse(tbxWetOutDataTotalMixQuantityUsgals.Text), 1);
                    newTotalMixQuantityDrumsIns = tbxWetOutDataTotalMixQuantityDrumsIns.Text;

                    newInversionType = ddlWetOutDataInversionType.SelectedValue;
                    newDepthOfInversionMH = decimal.Round(decimal.Parse(tbxWetOutDataDepthOfInversionMH.Text), 0);
                    newTubeForColumn = decimal.Round(decimal.Parse(tbxWetOutDataTubeForColumn.Text), 0);
                    newTubeForStartDry = decimal.Round(decimal.Parse(tbxWetOutDataTubeForStartDry.Text), 0);
                    newTotalTube = decimal.Round(decimal.Parse(tbxWetOutDataTotalTube.Text), 1);
                    newDropTubeConnects = tbxWetOutDataDropTubeConnects.Text;
                    newAllowsHeadTo = decimal.Round(decimal.Parse(tbxWetOutDataAllowsHeadTo.Text), 0);
                    newRollerGap = decimal.Round(decimal.Parse(tbxWetOutDataRollerGap.Text), 0);

                    newHeightNeeded = decimal.Round(decimal.Parse(tbxWetOutDataHeightNeeded.Text), 0);
                    newAvailable = tbxWetOutDataAvailable.Text;
                    newHoistHeight = tbxWetOutDataHoistHeight.Text;
                    newCommentsCipp = tbxWetOutDataNotes.Text;

                    newResinLabel = lblWetOutDataResinGray.Text;
                    newDrumContainsLabel = lblWetOutDataDrumContainsGray.Text;
                    newLinerTubeLabel = lblWetOutDataLinerTubeGray.Text;
                    newForLbDrumsLabel = lblWetOutDataLbDrumsGrey.Text;
                    newNetResinLabel = lblWetOutDataNetResinGrey.Text;
                    newCatalystLabel = lblWetOutDataCatalystGrey.Text;
                }

                // Inversion data
                string newInversionComment = "";
                string newPipeType = "";
                string newPipeCondition = "";
                string newGroundMoisture = "";
                decimal newBoilerSize = 0;
                decimal newPumpTotalCapacity = 0;
                decimal newLayFlatSize = 0;
                decimal newLayFlatQuantityTotal = 0;

                decimal newWaterStartTemp = 0;
                decimal newTemp1 = 0;
                decimal newHoldAtT1 = 0;
                decimal newTempT2 = 0;
                decimal newCookAtT2 = 0;
                decimal newCoolDownFor = 0;
                decimal newCoolToTemp = 0;
                decimal newDropInPipeRun = 0;
                decimal newPipeSlopOf = 0;

                decimal newF45F120 = 0;
                decimal newHold = 0;
                decimal newF120F185 = 0;
                decimal newCookTime = 0;
                decimal newCoolTime = 0;
                decimal newAproxTotal = 0;

                decimal newWaterChangesPerHour = 0;
                decimal newReturnWaterVelocity = 0;
                decimal newLayflatBackPressure = 0;
                decimal newPumpLiftAtIdealHead = 0;
                decimal newWaterToFillLinerColumn = 0;
                decimal newWaterPerFit = 0;
                string newInstallationResults = "";
                string newInversionLinerTubeLabel = "";
                string newHeadsIdealLabel = "";
                string newPumpingAndCirculationLabel = "";

                if ((ckbxInversionDataIncludeInversionInformation.Checked) && (ckbxWetOutDataIncludeWetOutInformation.Checked))
                {
                    // .... ... Inversion data
                    newInversionComment = tbxInversionDataCommentsEdit.Text;
                    newPipeType = ddlInversionDataInversionPipeType.SelectedValue;
                    newPipeCondition = ddlInversionDataPipeCondition.SelectedValue;
                    newGroundMoisture = ddlInversionDataGroundMoisture.SelectedValue;
                    newBoilerSize = decimal.Round(decimal.Parse(tbxInversionDataBoilerSize.Text), 0);
                    newPumpTotalCapacity = decimal.Round(decimal.Parse(tbxInversionDataPumpsTotalCapacity.Text), 0);
                    newLayFlatSize = decimal.Round(decimal.Parse(tbxInversionDataLayflatSize.Text), 0);
                    newLayFlatQuantityTotal = decimal.Round(decimal.Parse(tbxInversionDataLayflatQuantityTotal.Text), 0);

                    newWaterStartTemp = decimal.Round(decimal.Parse(tbxInversionDataWaterStartTempTs.Text), 0);
                    newTemp1 = decimal.Round(decimal.Parse(tbxInversionDataTempT1.Text), 0);
                    newHoldAtT1 = decimal.Round(decimal.Parse(tbxInversionDataHoldAtT1For.Text), 1);
                    newTempT2 = decimal.Round(decimal.Parse(tbxInversionDataTempT2.Text), 0);
                    newCookAtT2 = decimal.Round(decimal.Parse(tbxInversionDataCookAtT2For.Text), 0);
                    newCoolDownFor = decimal.Round(decimal.Parse(tbxInversionDataCoolDownFor.Text), 0);
                    newCoolToTemp = decimal.Round(decimal.Parse(tbxInversionDataCoolToTemp.Text), 0);
                    newDropInPipeRun = decimal.Round(decimal.Parse(tbxInversionDataDropInPipeRun.Text), 1);
                    newPipeSlopOf = decimal.Round(decimal.Parse(tbxInversionDataPipeSlopeOf.Text), 2);

                    newF45F120 = decimal.Round(decimal.Parse(tbxInversionData45F120F.Text), 1);
                    newHold = decimal.Round(decimal.Parse(tbxInversionDataHold.Text), 1);
                    newF120F185 = decimal.Round(decimal.Parse(tbxInversionData120F185F.Text), 1);
                    newCookTime = decimal.Round(decimal.Parse(tbxInversionDataCookTime.Text), 1);
                    newCoolTime = decimal.Round(decimal.Parse(tbxInversionDataCoolTime.Text), 1);
                    newAproxTotal = decimal.Round(decimal.Parse(tbxInversionDataAproxTotal.Text), 1);

                    newWaterChangesPerHour = decimal.Round(decimal.Parse(tbxInversionDataWaterChangesPerHour.Text), 2);
                    newReturnWaterVelocity = decimal.Round(decimal.Parse(tbxInversionDataReturnWaterVelocity.Text), 2);
                    newLayflatBackPressure = decimal.Round(decimal.Parse(tbxInversionDataLayflatBackPressure.Text), 1);
                    newPumpLiftAtIdealHead = decimal.Round(decimal.Parse(tbxInversionDataPumpLiftAtIdealHead.Text), 1);
                    newWaterToFillLinerColumn = decimal.Round(decimal.Parse(tbxInversionDataWaterToFillLinerColumn.Text), 0);
                    newWaterPerFit = decimal.Round(decimal.Parse(tbxInversionDataWaterPerFit.Text), 2);
                    newInstallationResults = tbxInversionDataNotesAndInstallationResults.Text;
                    newInversionLinerTubeLabel = lblInversionDataLinerInfoGrey.Text;
                    newHeadsIdealLabel = lblInversionDataHeadsGrey.Text;
                    newPumpingAndCirculationLabel = lblInversionDataPumpingCirculationSubtitle.Text;
                }

                // ... Update
                fullLengthLiningWorkDetails.UpdateWithWetOutInformation(workId, newGeneralClientId, newGeneralProposedLiningDate, newGeneralDeadlineLiningDate, newGeneralP1Date, newGeneralM1Date, newGeneralM2Date, newGeneralInstallDate, newGeneralFinalVideo, newGeneralIssueIdentified, newGeneralLfsIssue, newGeneralClientIssue, newGeneralSalesIssue, newGeneralIssueGivenToClient, newGeneralIssueResolved, newGeneralIssueInvestigation, newPrepDataCXIsRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementsTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardByPass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasuredFromMh, newVideoDoneFromMh, newVideoDoneToMh, newMeasurementTakenByM2, newDropPipe, newDropPipeInvertDepth, newCappedLaterals, newLineWidthId, newHydrantAddress, newHydroWireWithin10FtOfInversionMH, newDistanceToInversionMH, newSurfaceGrade, newHydroPulley, newFridgeCart, newTwoPump, newSixBypass, newScaffolding, newWinchExtension, newExtraGenerator, newGreyCableExtension, newEasementMats, newRampsRequired, newVideoLength, newPreFlushDate, newPreVideoDate, newCameraSkid, newLinerTuber, newResinId, newExcessResin, newPoundsDrums, newDrumDiameter, newHoistMaximumHeight, newHoistMinimumHeight, newDownDropTubeLenght, newPumpHeightAboveGround, newTubeResinToFeltFactor, newDateOfSheet, newEmployeeID, newRunDetails, newRunDetails2, newWetOutDate, newInstallDate, newInversionThickness, newLengthToLine, newPlusExtra, newForTurnOffset, newLengthToWetOut, newTubeMaxColdHead, newTubeMaxColdHeadPsi, newTubeMaxHotHead, newTubeMaxHotHeadPsi, newTubeIdealHead, newTubeIdealHeadPsi, newNetResinForTube, newNetResinForTubeUsgals, newNetResinForTubeDrumsIns, newNetResinForTubeLbsFt, newNetResinForTubeUsgFt, newExtraResinForMix, newExtraLbsForMix, newTotalMixQuantity, newTotalMixQuantityUsgals, newTotalMixQuantityDrumsIns, newInversionType, newDepthOfInversionMH, newTubeForColumn, newTubeForStartDry, newTotalTube, newDropTubeConnects, newAllowsHeadTo, newRollerGap, newHeightNeeded, newAvailable, newHoistHeight, newCommentsCipp, newResinLabel, newDrumContainsLabel, newLinerTubeLabel, newForLbDrumsLabel, newNetResinLabel, newCatalystLabel, newInversionComment, newPipeType, newPipeCondition, newGroundMoisture, newBoilerSize, newPumpTotalCapacity, newLayFlatSize, newLayFlatQuantityTotal, newWaterStartTemp, newTemp1, newHoldAtT1, newTempT2, newCookAtT2, newCoolDownFor, newCoolToTemp, newDropInPipeRun, newPipeSlopOf, newF45F120, newHold, newF120F185, newCookTime, newCoolTime, newAproxTotal, newWaterChangesPerHour, newReturnWaterVelocity, newLayflatBackPressure, newPumpLiftAtIdealHead, newWaterToFillLinerColumn, newWaterPerFit, newInstallationResults, newInversionLinerTubeLabel, newHeadsIdealLabel, newPumpingAndCirculationLabel, newAccessType, newP1Completed);
            }

            if (ddlM1DataMaterial.SelectedIndex > 0)
            {
                LfsAssetSewerLateralGateway lfsAssetSewertLateralGateway = new LfsAssetSewerLateralGateway(null);
                if (!lfsAssetSewertLateralGateway.IsUsedInMaterials(assetId, newMaterial, companyId))
                {
                    MaterialInformation model = new MaterialInformation(materialInformationTDS);
                    model.Insert(assetId, newMaterial, DateTime.Now, false, companyId, false);
                }
            }

            // Store datasets
            Session["fullLengthLiningTDS"] = fullLengthLiningTDS;
            Session["materialInformationTDS"] = materialInformationTDS;

            ViewState["update"] = "no";
        }
        private void GrdFLAddLateralsNewAdd()
        {
            if (ValidateLateralFooter())
            {
                Page.Validate("AddLateralsAdd");
                if (Page.IsValid)
                {
                    string size = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewSize")).Text.Trim();
                    string material = ((DropDownList)grdLaterals.FooterRow.FindControl("ddlNewMaterial")).SelectedValue.ToString().Trim();
                    string live = ((DropDownList)grdLaterals.FooterRow.FindControl("ddlNewLive")).SelectedValue.Trim();
                    string videoDistance = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewVideoDistance")).Text.Trim();
                    string clockPosition = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewClockPosition")).Text.Trim();
                    string distanceToCentre = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewDistanceToCentre")).Text.Trim();
                    string timeOpened = "";
                    DateTime? reinstate = null;
                    string comments = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewComments")).Text.Trim();

                    // Reverse Setup calculation
                    string reverseSetup = "";
                    if (videoDistance != "")
                    {
                        Distance videoDistanceD = new Distance(videoDistance);
                        Distance videoLength = new Distance(tbxVideoLength.Text.Trim());

                        Distance reverseSetupD = videoLength - videoDistanceD;
                        switch (videoDistanceD.DistanceType)
                        {
                            case 1:
                                reverseSetup = reverseSetupD.ToStringInEng1();
                                break;
                            case 2:
                                reverseSetup = reverseSetupD.ToStringInEng2();
                                break;
                            case 3:
                                reverseSetup = reverseSetupD.ToStringInEng3();
                                break;
                            case 4:
                                reverseSetup = reverseSetupD.ToStringInMet1();
                                break;
                            case 5:
                                reverseSetup = reverseSetupD.ToStringInMil1();
                                break;
                        }
                    }

                    bool inProject = ((CheckBox)grdLaterals.FooterRow.FindControl("cbxInProject")).Checked;
                    int workId = Int32.Parse(hdfWorkId.Value);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    string lateralId = GetLateralIdIncrement();
                    string clientLateralId = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewClientLateralId")).Text.Trim();
                    string connectionType = ""; connectionType = ((DropDownList)grdLaterals.FooterRow.FindControl("ddlNewConnectionType")).SelectedValue;
                    string mn = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewMn")).Text.Trim();
                    string clientInspectionNo = ((TextBox)grdLaterals.FooterRow.FindControl("tbxNewClientInspectionNo")).Text.Trim();
                    DateTime? v1Inspection = null;
                    bool requiresRoboticPrep = ((CheckBox)grdLaterals.FooterRow.FindControl("ckbxRequiresRoboticPrepNew")).Checked;
                    DateTime? requiresRoboticPrepDate = null;
                    if (((RadDatePicker)grdLaterals.FooterRow.FindControl("tkrdpRequiresRoboticPrepDateNew")).SelectedDate.HasValue)
                    {
                        requiresRoboticPrepDate = ((RadDatePicker)grdLaterals.FooterRow.FindControl("tkrdpRequiresRoboticPrepDateNew")).SelectedDate.Value;
                    }

                    bool holdClientIssue = ((CheckBox)grdLaterals.FooterRow.FindControl("ckbxHoldClientIssueNew")).Checked;
                    bool holdLFSIssue = ((CheckBox)grdLaterals.FooterRow.FindControl("ckbxHoldLFSIssueNew")).Checked;
                    bool lineLateral = ((CheckBox)grdLaterals.FooterRow.FindControl("cbxNewJl")).Checked;
                    string flange = ((DropDownList)grdLaterals.FooterRow.FindControl("ddlFlangeNew")).SelectedValue;
                    bool dyeTestReq = ((CheckBox)grdLaterals.FooterRow.FindControl("ckbxDyeTestReqNew")).Checked;
                    DateTime? dyeTestComplete = null; if (((RadDatePicker)grdLaterals.FooterRow.FindControl("tkrdpDyeTestCompleteNew")).SelectedDate.HasValue) dyeTestComplete = ((RadDatePicker)grdLaterals.FooterRow.FindControl("tkrdpDyeTestCompleteNew")).SelectedDate.Value;

                    // Insert
                    FullLengthLiningLateralDetails model = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                    model.Insert(videoDistance, clockPosition, distanceToCentre, timeOpened, reverseSetup, reinstate, comments, lateralId, size, material, false, companyId, inProject, live, clientLateralId, connectionType, mn, clientInspectionNo, v1Inspection, requiresRoboticPrep, requiresRoboticPrepDate, holdClientIssue, holdLFSIssue, lineLateral, flange, lineLateral, dyeTestReq, dyeTestComplete);

                    // Store datasets
                    Session.Remove("flAddLateralsNewDummy");
                    Session["fullLengthLiningTDS"] = fullLengthLiningTDS;
                    grdLaterals.DataBind();
                    grdLaterals.PageIndex = grdLaterals.PageCount - 1;

                    tbxLaterals.Text = model.GetTotalLaterals().ToString();
                    tbxLiveLaterals.Text = model.GetLiveLaterals().ToString();
                }
            }
        }
        protected void btnWetOutCalculateOnClick(object sender, EventArgs e)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            double pi = double.Parse(Decimal.Round(decimal.Parse(Math.PI.ToString()),4).ToString());
            double breakSize = 10; // in
            double factor1 = 0.99;
            double factor2 = 0.01;

            // ...Section values
            // ... ... tube size = confirmed Size
            Distance confirmedSizeDistance = new Distance(tbxConfirmedSize.Text);
            double confirmedSize = 0;
            string[] confirmedSizeString = confirmedSizeDistance.ToStringInEng1().Split('\"');

            if (!confirmedSizeDistance.ToStringInEng1().Contains("'"))
            {
                if (Validator.IsValidDouble(tbxConfirmedSize.Text))
                {
                    confirmedSize = double.Parse(tbxConfirmedSize.Text);
                }
                else
                {
                    confirmedSize = double.Parse(confirmedSizeString[0]);
                }
            }
            else
            {
                confirmedSize = Math.Ceiling(confirmedSizeDistance.ToDoubleInEng3() * 12);
            }

            // ... For Calculations
            // ... ... Validate setup data
            if ((ddlWetOutDataLinerTube.SelectedValue != "") && (ddlWetOutDataResins.SelectedValue != "-1") && (tbxWetOutDataExcessResin.Text != "") && (ddlWetOutDataPoundsDrums.SelectedValue != "(Select)") && (tbxWetOutDataDrumDiameter.Text != "") && (tbxWetOutDataHoistMaximumHeight.Text != "") && (tbxWetOutDataHoistMinimumHeight.Text != "") && (tbxWetOutDataDownDropTubeLength.Text != "") && (tbxWetOutDataPumpHeightAboveGround.Text != "") && (tbxWetOutDataTubeResinToFeltFactor.Text != ""))
            {
                // ... ... validate wet out data
                if ((ddlThickness.SelectedValue != "") && (tbxWetOutDataPlusExtra.Text != "") && (tbxWetOutDataForTurnOffset.Text != "") && (tbxWetOutDataExtraResinForMix.Text != "") && (ddlWetOutDataInversionType.SelectedValue != "(Select)") && (tbxWetOutDataDepthOfInversionMH.Text != "") && (tbxWetOutDataTubeForColumn.Text != "") && (tbxWetOutDataTubeForStartDry.Text != "") && (tbxWetOutDataRollerGap.Text != ""))
                {
                    // Lenght to line of all sections (sume of lenght of asset table)
                    string newRunDetails = "";
                    foreach (ListItem lst in cbxlSectionId.Items)
                    {
                        if (lst.Selected)
                        {
                            newRunDetails = newRunDetails + lst.Value + ">";
                        }
                    }
                    newRunDetails = newRunDetails.Substring(0, newRunDetails.Length - 1);
                    string[] runDetailsList = newRunDetails.Split('>');

                    double lengthToLine = 0d;
                    for (int i = 0; i < runDetailsList.Length; i++)
                    {
                        AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                        string sectionId = runDetailsList[i].ToString();
                        if (sectionId != "-1")
                        {
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            Distance lengthDistance = new Distance(assetSewerSectionGateway.GetLength(assetId));
                            lengthToLine = lengthToLine + lengthDistance.ToDoubleInEng3();
                        }
                    }
                    tbxWetOutDataLengthToLine.Text = decimal.Round(decimal.Parse(lengthToLine.ToString()), 1).ToString();
                    tbxInversionDataRunLength.Text = decimal.Round(decimal.Parse(lengthToLine.ToString()), 1).ToString();

                    // ... Inversion run details
                    for (int i = 0; i < runDetailsList.Length; i++)
                    {
                        cbxlInversionDataSectionId.Items.FindByValue(runDetailsList[i]).Selected = true;
                    }

                    // .. Resin Information
                    int resinId = Int32.Parse(ddlWetOutDataResins.SelectedValue);
                    WorkFullLengthLiningResinsGateway workFullLengthLiningResinsGateway = new WorkFullLengthLiningResinsGateway();
                    workFullLengthLiningResinsGateway.LoadByResinId(resinId, companyId);

                    string resinMake = workFullLengthLiningResinsGateway.GetResinMake(resinId);
                    string resinType = workFullLengthLiningResinsGateway.GetResinType(resinId);
                    string resinNumber = workFullLengthLiningResinsGateway.GetResinNumber(resinId);
                    double lbUsg = double.Parse(workFullLengthLiningResinsGateway.GetLbUsg(resinId).ToString());
                    int lbDrums = Int32.Parse(workFullLengthLiningResinsGateway.GetLbDrums(resinId).ToString());
                    double activeResin = double.Parse(workFullLengthLiningResinsGateway.GetActiveResin(resinId).ToString());
                    string applyCatalystTo = workFullLengthLiningResinsGateway.GetApplyCatalystTo(resinId);
                    double filter = double.Parse(workFullLengthLiningResinsGateway.GetFilter(resinId).ToString());

                    // ... Calculations
                    // ... ... LengthtToWetOut
                    Double plusExtra = double.Parse(tbxWetOutDataPlusExtra.Text);
                    Double forTurnOffset = double.Parse(tbxWetOutDataForTurnOffset.Text);

                    Double lengthtToWetOut = lengthToLine + plusExtra + forTurnOffset;
                    tbxWetOutDataLengthtToWetOut.Text = decimal.Round(decimal.Parse(lengthtToWetOut.ToString()), 1).ToString();
                    tbxInversionDataWetOutLenght.Text = decimal.Round(decimal.Parse(lengthtToWetOut.ToString()), 1).ToString();

                    // ... ... Resin label
                    lblWetOutDataResinGray.Text = "RESIN: " + resinMake + resinType + resinNumber + ", " + lbUsg + "lbs/usg, " + activeResin.ToString() + " % Active Resin ";

                    // ... ... Lb drum label
                    lblWetOutDataLbDrumsGrey.Text = "For " + lbDrums.ToString() + " lb drums";

                    // ... ... Drum contains label
                    // ... ... Drum Fill Height Information
                    double usgDrum = lbDrums / lbUsg;
                    double lbsPerUsg = lbUsg;
                    double lbsPerDrum = lbDrums;
                    double usgalsPerDrum = lbsPerDrum / lbsPerUsg;
                    double drumInsideDiameter = Double.Parse(tbxWetOutDataDrumDiameter.Text);
                    double drumInsideDiameterPow = Math.Pow(drumInsideDiameter, 2);
                    double usgalsPerDrumInch = (1 * (pi * drumInsideDiameterPow) / 4) * 0.004329;
                    double lbsPerDrumInch = usgalsPerDrumInch * lbsPerUsg;
                    double drumFillHeightShouldBeApprox = lbsPerDrum / lbsPerDrumInch;

                    if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums")  // OP 1
                    {
                        lblWetOutDataDrumContainsGray.Text = "Drum contains: " + lbDrums.ToString() + "lbs / " + Decimal.Round(decimal.Parse(usgDrum.ToString()), 1).ToString() + "usg.  Full drum level: Approx " + Decimal.Round(Decimal.Parse(drumFillHeightShouldBeApprox.ToString()), 1).ToString() + "ins.";
                    }
                    else
                    {
                        lblWetOutDataDrumContainsGray.Text = "-";
                    }

                    // ... ... Liner Tube
                    string linerTube = ddlWetOutDataLinerTube.SelectedValue;
                    double tubeThickness = Double.Parse(ddlThickness.SelectedValue);
                    lblWetOutDataLinerTubeGray.Text = "LINER TUBE: " + linerTube.ToString() + ", Inversion. Tube Size: " + confirmedSize.ToString() + " ins x " + tubeThickness.ToString() + " mm.";
                    tbxInversionDataLinerSize.Text = confirmedSize + " ins x " + tubeThickness + " mm";
                    lblInversionDataSubtitle.Text = ddlWetOutDataLinerTube.SelectedValue;

                    double maxCold = -1;
                    double maxColdExact = -1;
                    double maxColdRounded = -1;

                    double maxHot = -1;
                    double maxHotExact = -1;
                    double maxHotRounded = -1;

                    double idealHead = -1;
                    double idealHeadExact = -1;
                    double idealHeadRounded = -1;

                    switch (linerTube)
                    {
                        case "Applied Felts":
                            double sizeAppliedFelts = confirmedSize * 25.4;

                            // ...  ... For max cold
                            maxColdExact = (tubeThickness / sizeAppliedFelts) * 308 * 3.2808;
                            maxColdRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxColdExact.ToString()), 1).ToString());
                            maxCold = maxColdRounded;

                            // ... ... For max hot
                            maxHotExact = (tubeThickness / sizeAppliedFelts) * 269 * 3.2808;
                            maxHotRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxHotExact.ToString()), 1).ToString());
                            maxHot = maxHotRounded;

                            // ... ... For Idead head
                            double sizeToUseAppliedFelts = 0d;
                            if (confirmedSize > breakSize)
                            {
                                sizeToUseAppliedFelts = sizeAppliedFelts;
                            }
                            else
                            {
                                sizeToUseAppliedFelts = sizeAppliedFelts - 25;
                            }
                            idealHeadExact = (tubeThickness / sizeToUseAppliedFelts) * 201 * 3.2808;
                            idealHeadRounded = Double.Parse(Decimal.Round(Decimal.Parse(idealHeadExact.ToString()), 1).ToString());
                            idealHead = idealHeadRounded;
                            break;

                        case "Novapipe":
                            // ...  ... For max cold
                            maxColdExact = (39 * tubeThickness) / confirmedSize;
                            maxColdRounded = double.Parse(Decimal.Round(Decimal.Parse(maxColdExact.ToString()), 1).ToString());
                            maxCold = maxColdRounded;

                            // ... ... For max hot
                            maxHotExact = (33.1 * tubeThickness) / confirmedSize;
                            maxHotRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxHotExact.ToString()), 1).ToString());
                            maxHot = maxHotRounded;

                            // ... ... For Idead head
                            idealHeadExact = (25.76 * tubeThickness) / confirmedSize;
                            idealHeadRounded = Double.Parse(Decimal.Round(Decimal.Parse(idealHeadExact.ToString()), 1).ToString());
                            idealHead = idealHeadRounded;
                            break;

                        case "Liner Products":
                            // ...  ... For max cold
                            maxColdExact = (tubeThickness / confirmedSize) * 34.057;
                            maxColdRounded = double.Parse(Decimal.Round(Decimal.Parse(maxColdExact.ToString()), 1).ToString());
                            maxCold = maxColdRounded;

                            // ... ... For max hot
                            maxHotExact = (tubeThickness / confirmedSize) * 28.381;
                            maxHotRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxHotExact.ToString()), 1).ToString());
                            maxHot = maxHotRounded;

                            // ... ... For Idead head
                            idealHeadExact = (tubeThickness / confirmedSize) * 20.888;
                            idealHeadRounded = Double.Parse(Decimal.Round(Decimal.Parse(idealHeadExact.ToString()), 1).ToString());
                            idealHead = idealHeadRounded;
                            break;

                        case "Generic":
                            double sizeGeneric = confirmedSize * 25.4;

                            // ...  ... For max cold
                            maxColdExact = (tubeThickness / sizeGeneric) * 308 * 3.2808;
                            maxColdRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxColdExact.ToString()), 1).ToString());
                            maxCold = maxColdRounded;

                            // ... ... For max hot
                            maxHotExact = (tubeThickness / sizeGeneric) * 269 * 3.2808;
                            maxHotRounded = Double.Parse(Decimal.Round(Decimal.Parse(maxHotExact.ToString()), 1).ToString());
                            maxHot = maxHotRounded;

                            // ... ... For Idead head
                            double sizeToUseGeneric = 0d;

                            if (confirmedSize > breakSize)
                            {
                                sizeToUseGeneric = sizeGeneric;
                            }
                            else
                            {
                                sizeToUseGeneric = sizeGeneric - 25;
                            }
                            idealHeadExact = (tubeThickness / sizeToUseGeneric) * 201 * 3.2808;
                            idealHeadRounded = Double.Parse(Decimal.Round(Decimal.Parse(idealHeadExact.ToString()), 1).ToString());
                            idealHead = idealHeadRounded;
                            break;

                        case "Tube 5 No Data":
                            // ...  ... For max cold
                            maxCold = -1;

                            // ... ... For max hot
                            maxHot = -1;

                            // ... ... For Idead head
                            idealHead = -1;
                            break;

                        case "Tube 6 No Data":
                            // ...  ... For max cold
                            maxCold = -1;

                            // ... ... For max hot
                            maxHot = -1;

                            // ... ... For Idead head
                            idealHead = -1;
                            break;
                    }

                    // ... ... .... Tube Max Cold Head, Tube Max Cold head PSI
                    if (maxCold != -1)
                    {
                        tbxWetOutDataTubeMaxColdHead.Text = maxCold.ToString();
                        double maxColdPsi = 0.434 * maxCold;
                        tbxWetOutDataTubeMaxColdHeadPSI.Text = decimal.Round(decimal.Parse(maxColdPsi.ToString()), 1).ToString();
                    }
                    else
                    {
                        tbxWetOutDataTubeMaxColdHead.Text = "NA";
                        tbxWetOutDataTubeMaxColdHeadPSI.Text = "NA";
                    }

                    // ... ... .... Tube Max Hot Head, Tube Max Hot Head PSI
                    if (maxHot != -1)
                    {
                        tbxWetOutDataTubeMaxHotHead.Text = maxHot.ToString();
                        double maxHotPsi = 0.434 * maxHot;
                        tbxWetOutDataTubeMaxHotHeadPSI.Text = decimal.Round(decimal.Parse(maxHotPsi.ToString()), 1).ToString();
                    }
                    else
                    {
                        tbxWetOutDataTubeMaxHotHead.Text = "NA";
                        tbxWetOutDataTubeMaxHotHeadPSI.Text = "NA";
                    }

                    // ... ... .... Tube Ideal Head, Tube Ideal Head PSI
                    if (idealHead != -1)
                    {
                        tbxWetOutDataTubeIdealHead.Text = idealHead.ToString();
                        double idealHeadPsi = 0.434 * idealHead;
                        tbxWetOutDataTubeIdealHeadPSI.Text = Decimal.Round(Decimal.Parse(idealHeadPsi.ToString()), 1).ToString();
                    }
                    else
                    {
                        tbxWetOutDataTubeIdealHead.Text = "NA";
                        tbxWetOutDataTubeIdealHeadPSI.Text = "NA";
                    }

                    // ... ... Net Resins
                    // ... ... ... For net resin for tube lbs ft(lbs/ft)
                    double lbsFt = 0d;
                    double usgFt = 0d;
                    double excessResin = Double.Parse(tbxWetOutDataExcessResin.Text)/100;
                    double tubeResinToFeltFactor = Double.Parse(tbxWetOutDataTubeResinToFeltFactor.Text);

                    switch (linerTube)
                    {
                        case "Applied Felts":
                            // ... ... .... For lbsFt
                            double fromSetUp = tubeResinToFeltFactor / 100;
                            double t = tubeThickness / 25.4;
                            double id = confirmedSize - 2 * t;
                            double area = pi * (Math.Pow(confirmedSize, 2) - Math.Pow(id, 2)) / 4;
                            double v1 = 12 * area * 0.004329;
                            double v2 = v1 * fromSetUp;
                            double v3 = v2 * excessResin;
                            double v4 = v3 + v2;
                            lbsFt = v4 * lbUsg;

                            // ... ... .... For usgFt
                            usgFt = v4;
                            break;

                        case "Novapipe":
                            // ... ... .... For lbsFt
                            double fromSetUpNovapipe = tubeResinToFeltFactor / 100;
                            double tNovapipe = tubeThickness / 25.4;
                            double idNovapipe = confirmedSize - 2 * tNovapipe;
                            double areaNovapipe = pi * (Math.Pow(confirmedSize, 2) - Math.Pow(idNovapipe, 2)) / 4;
                            double v1Novapipe = 12 * areaNovapipe * 0.004329;
                            double v2Novapipe = v1Novapipe * fromSetUpNovapipe;
                            double v3Novapipe = v2Novapipe * excessResin;
                            double v4Novapipe = v3Novapipe + v2Novapipe;
                            lbsFt = v4Novapipe * lbUsg;

                            // ... ... .... For usgFt
                            usgFt = v4Novapipe;
                            break;

                        case "Liner Products":
                            // ... ... .... For lbsFt
                            double lbft3 = lbUsg / 0.1337;
                            double specificGravity = double.Parse(decimal.Round(decimal.Parse((lbft3 / 62.4).ToString()), 3).ToString());

                            double midCalc = 0d;
                            if (confirmedSize > 8)
                            {
                                midCalc = 261.5184;
                            }
                            else
                            {
                                midCalc = 217.932;
                            }

                            Decimal confirmedSizeDecimal = Decimal.Parse(confirmedSize.ToString());
                            Decimal firstDivision = confirmedSizeDecimal / 24;
                            Double firstDivisionDouble = Double.Parse(firstDivision.ToString());
                            double midCalc2 = RoundUp(firstDivisionDouble, 0);

                            Decimal secondDivision = confirmedSizeDecimal / 30;
                            double secondDivisionDouble = double.Parse(secondDivision.ToString());
                            double midCalc3 = RoundUp(secondDivisionDouble, 0);
                            double estimatedResinMultiplier = (((545.2 * (tubeThickness / 25.4) * ((((confirmedSize - 2 * (tubeThickness / 25.4)) * pi * 0.92) / pi) + (tubeThickness / 25.4)) + (midCalc * midCalc3 * ((tubeThickness - 3) / 25.4)) + (55.98 * midCalc2)) * specificGravity) / 453.59) * 0.92;

                            double excessResinAdded = excessResin * estimatedResinMultiplier;
                            lbsFt = excessResinAdded + estimatedResinMultiplier;

                            // ... ... .... For usgFt
                            double totalResin = excessResinAdded + estimatedResinMultiplier;
                            usgFt = totalResin / lbUsg;
                            break;

                        case "Generic":
                            // ... ... .... For lbsFt
                            double fromSetUpGeneric = tubeResinToFeltFactor / 100;
                            double tGeneric = tubeThickness / 25.4;
                            double idGeneric = confirmedSize - 2 * tGeneric;
                            double areaGeneric = pi * (Math.Pow(confirmedSize, 2) - Math.Pow(idGeneric, 2)) / 4;
                            double v1Generic = 12 * areaGeneric * 0.004329;
                            double v2Generic = v1Generic * fromSetUpGeneric;
                            double v3Generic = v2Generic * excessResin;
                            double v4Generic = v3Generic + v2Generic;
                            lbsFt = v4Generic * lbUsg;

                            // ... ... .... For usgFt
                            usgFt = v4Generic;
                            break;

                        case "Tube 5 No Data":
                            // ... ... .... For lbsFt
                            lbsFt = -1;

                            // ... ... .... For usgFt
                            usgFt = -1;
                            break;

                        case "Tube 6 No Data":
                            // ... ... .... For lbsFt
                            lbsFt = -1;

                            // ... ... .... For usgFt
                            usgFt = -1;
                            break;
                    }

                    double netResinForTubeLbsFt = Double.Parse(Decimal.Round(Decimal.Parse(lbsFt.ToString()), 2).ToString());
                    tbxWetOutDataNetResinForTubeLbsFt.Text = netResinForTubeLbsFt.ToString();

                    // ... ... ... For net resin for tube (lbs)
                    double netResinForTube = lengthtToWetOut * netResinForTubeLbsFt;
                    tbxWetOutDataNetResinForTube.Text = Decimal.Round(decimal.Parse(netResinForTube.ToString()), 0).ToString();

                    // ... ... ... For net resin for tube usg/ft (usg/ft)
                    double netResinForTubeUsgFt = Double.Parse(Decimal.Round(Decimal.Parse(usgFt.ToString()), 3).ToString());
                    tbxWetOutDataNetResinForTubeUsgFt.Text = netResinForTubeUsgFt.ToString();

                    // ... ... ... For net resin for tube (usgals)
                    double netResinForTubeUsgals = lengthtToWetOut * netResinForTubeUsgFt;
                    tbxWetOutDataNetResinForTubeUsgals.Text = Decimal.Round(decimal.Parse(netResinForTubeUsgals.ToString()), 1).ToString();

                    // ... ... ... For net resin for tube drums Ins
                    // ... ... ... .... Drum Fill Height Information
                    double exactDrumsRequired = netResinForTube / lbDrums;
                    double rounddownToWholeDrums = RoundDown(exactDrumsRequired, 0);
                    double remainingPartDrum = exactDrumsRequired - rounddownToWholeDrums;
                    double fillHeight = drumFillHeightShouldBeApprox;
                    double remainingPartDrumInInches = fillHeight * remainingPartDrum;
                    double drumFillHeight = fillHeight;
                    double difference = drumFillHeight - remainingPartDrumInInches;

                    double drumsToUseInString = 0d;
                    if (remainingPartDrum > factor1)
                    {
                        drumsToUseInString = rounddownToWholeDrums + 1;
                    }
                    else
                    {
                        if (remainingPartDrum < factor2)
                        {
                            drumsToUseInString = rounddownToWholeDrums;
                        }
                        else
                        {
                            drumsToUseInString = rounddownToWholeDrums;
                        }
                    }

                    double inchesToUseInString = 0;
                    if (remainingPartDrum > factor1)
                    {
                        inchesToUseInString = 0;
                    }
                    else
                    {
                        if (remainingPartDrum < factor2)
                        {
                            inchesToUseInString = 0;
                        }
                        else
                        {
                            inchesToUseInString = remainingPartDrumInInches;
                        }
                    }

                    string stringForDrumInches = "= " + drumsToUseInString + " Drum + " + Decimal.Round(Decimal.Parse(inchesToUseInString.ToString()), 1).ToString() + " ins";
                    string stringForDrumsInches = "= " + drumsToUseInString + " Drums + " + Decimal.Round(Decimal.Parse(inchesToUseInString.ToString()), 1).ToString() + " ins";

                    string stringToCarry = "";
                    if (drumsToUseInString == 1)
                    {
                        stringToCarry = stringForDrumInches;
                    }
                    else
                    {
                        stringToCarry = stringForDrumsInches;
                    }
                    tbxWetOutDataNetResinForTubeDrumsIns.Text = stringToCarry.ToString();

                    // ... ... Newt resin label
                    lblWetOutDataNetResinGrey.Text = "Net resin is amount required in the tube after wet out complete and tube ready for installation. Includes excess at " + excessResin * 100 + "%";

                    // ... ... Extra lbs for Mix
                    double extraResinForMix = Double.Parse(tbxWetOutDataExtraResinForMix.Text);
                    double extraLbsForMix = netResinForTube * extraResinForMix/100;
                    tbxWetOutDataExtraLbsForMix.Text = Decimal.Round(decimal.Parse(extraLbsForMix.ToString()), 0).ToString();

                    // ... ... Total Mix Quantity
                    double totalMixQuantity = (1 + extraResinForMix / 100) * netResinForTube;
                    tbxWetOutDataTotalMixQuantity.Text = Decimal.Round(decimal.Parse(totalMixQuantity.ToString()), 0).ToString();

                    // .... ... Total Mix Quantity usgals
                    double totalMixQuantityUsgals = (1 + extraResinForMix / 100) * netResinForTubeUsgals;
                    tbxWetOutDataTotalMixQuantityUsgals.Text = Decimal.Round(decimal.Parse(totalMixQuantityUsgals.ToString()), 1).ToString(); ;

                    // ... ... Total Mix Quantity Drums Ins
                    if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums")  // OP 1
                    {
                        tbxWetOutDataTotalMixQuantityDrumsIns.Text = stringToCarry;
                    }
                    else
                    {
                        tbxWetOutDataTotalMixQuantityDrumsIns.Text = "-";
                    }

                    // ... ... Catalyst label
                    string catalystLabel = "";

                    if (applyCatalystTo == "Active Resin")
                    {
                        double activeResinVal = totalMixQuantity * activeResin/100;
                        double activeResinInDrum = lbsPerDrum * activeResin/100;
                        if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums")  // OP 1
                        {
                            catalystLabel = "Catalyst % applied to weight of Active Resin = " + decimal.Round(decimal.Parse(activeResinVal.ToString()), 0) + " lbs  (" + decimal.Round(decimal.Parse(activeResinInDrum.ToString()), 1).ToString() + " lbs per drum )";
                        }
                        else
                        {
                            catalystLabel = "Catalyst % applied to weight of Active Resin = " + decimal.Round(decimal.Parse(activeResinVal.ToString()), 0) + " lbs";
                        }
                    }
                    else
                    {
                        if (applyCatalystTo == "Active Resin & Filter")
                        {
                            if (ddlWetOutDataPoundsDrums.SelectedValue == "Pounds & Drums")  // OP 1
                            {
                                catalystLabel = "Catalyst % applied to weight of Active Resin and Filler = " + decimal.Round(decimal.Parse(totalMixQuantity.ToString()), 0).ToString() + " lbs (" + decimal.Round(decimal.Parse(lbsPerDrum.ToString()), 1).ToString() + " lbs per drum )";
                            }
                            else
                            {
                                catalystLabel = "Catalyst % applied to weight of Active Resin and Filler = " + decimal.Round(decimal.Parse(totalMixQuantity.ToString()), 0).ToString() + " lbs";
                            }
                        }
                        else
                        {
                            catalystLabel = "ERROR IN RESIN LIST ENTRY(S). CATALYST QTYS ARE INCORRECT!";
                        }
                    }

                    lblWetOutDataCatalystGrey.Text = catalystLabel;

                    // ... ... Total Tube
                    double tubeForColumn = Double.Parse(tbxWetOutDataTubeForColumn.Text);
                    double tubeForStartDry = Double.Parse(tbxWetOutDataTubeForStartDry.Text);
                    double totalTube = tubeForColumn + tubeForStartDry + lengthtToWetOut; ;
                    tbxWetOutDataTotalTube.Text = Decimal.Round(decimal.Parse(totalTube.ToString()), 1).ToString();

                    // ... ... Drop Tube Connects
                    string inversionType = ddlWetOutDataInversionType.SelectedValue;
                    double depthOfInversionMH = Double.Parse(tbxWetOutDataDepthOfInversionMH.Text);

                    if (inversionType == "Bottom")
                    {
                        if (depthOfInversionMH == tubeForColumn)
                        {
                            tbxWetOutDataDropTubeConnects.Text = "At MH lid";
                        }
                        else
                        {
                            if (depthOfInversionMH > tubeForColumn)
                            {
                                tbxWetOutDataDropTubeConnects.Text = "Below MH lid";
                            }
                            else
                            {
                                tbxWetOutDataDropTubeConnects.Text = "Above MH lid";
                            }
                        }
                    }
                    else
                    {
                        tbxWetOutDataDropTubeConnects.Text = "-";
                    }

                    // ... ... Allows Head To
                    double allowsToHeadTo = 0d;
                    double downDropTubeLength = Double.Parse(tbxWetOutDataDownDropTubeLength.Text);
                    if (inversionType == "Top")
                    {
                        allowsToHeadTo = tubeForColumn;
                        tbxWetOutDataAllowsHeadTo.Text = allowsToHeadTo.ToString();
                    }
                    else
                    {
                        if (inversionType == "Bottom")
                        {
                            allowsToHeadTo = tubeForColumn + downDropTubeLength;
                            tbxWetOutDataAllowsHeadTo.Text = allowsToHeadTo.ToString();
                        }
                        else
                        {
                            tbxWetOutDataAllowsHeadTo.Text = "NA";
                        }
                    }

                    // ... ... Height Needed
                    double heightNeeded = 0;
                    if (tbxWetOutDataAllowsHeadTo.Text != "NA")
                    {
                        heightNeeded = allowsToHeadTo - depthOfInversionMH;
                        tbxWetOutDataHeightNeeded.Text = heightNeeded.ToString();
                    }

                    // ... ... Available
                    double hoistMinimumHeight = Double.Parse(tbxWetOutDataHoistMinimumHeight.Text);
                    double hoistMaximunHeight = Double.Parse(tbxWetOutDataHoistMaximumHeight.Text);
                    tbxWetOutDataAvailable.Text = hoistMinimumHeight.ToString() + " ft to " + hoistMaximunHeight.ToString() + " ft";

                    // ... ... Hoist Height?
                    if (heightNeeded > hoistMaximunHeight)
                    {
                        tbxWetOutDataHoistHeight.Text = "Too High";
                    }
                    else
                    {
                        if (heightNeeded < hoistMinimumHeight)
                        {
                            tbxWetOutDataHoistHeight.Text = "Too Low";
                        }
                        else
                        {
                            tbxWetOutDataHoistHeight.Text = "OK";
                        }
                    }

                    // ... ... Warning
                    if ((tbxWetOutDataHoistHeight.Text == "OK") || (tbxWetOutDataHoistHeight.Text == ""))
                    {
                        lblWetOutDataWarning.Visible = false;
                    }
                    else
                    {
                        lblWetOutDataWarning.Visible = true;
                    }

                    // ... ... graphic labels
                    lblWetOutDataDimensionLabel.Text = confirmedSize + " ins x " + tubeThickness + " mm Tube";
                    lblWetOutDataTotalTubeLengthlabel.Text = "Total Tube Length " + tbxWetOutDataTotalTube.Text + " ft";
                    lblWetOutDataForColumnLabel.Text = tbxWetOutDataTubeForColumn.Text + " ft  for Column";
                    lblWetOutDataDryFtLabel.Text = "Dry " + tbxWetOutDataTubeForStartDry.Text + " ft";
                    lblWetOutDataWetOutLengthlabel.Text = "Wet-Out Length " + tbxWetOutDataLengthtToWetOut.Text + " ft";
                    lblWetOutDataDryFtEndLabel.Text = "Dry " + tbxWetOutDataTubeForColumn.Text + " ft";
                    lblWetOutDataTailEndlabel.Text = "Tail End";
                    lblWetOutDataColumnEndlabel.Text = "Column End";
                    lblWetOutDataRollerGapLabel.Text = "Roller Gap " + tbxWetOutDataRollerGap.Text + " mm";

                    // ... ... Inversion Liner Size
                    tbxInversionDataLinerSize.Text = confirmedSize + " ins x " + tubeThickness + " mm";

                    // ... ... Inversion Gray texts
                    lblInversionDataSubtitle.Text = "For: " + ddlWetOutDataLinerTube.SelectedValue;
                    lblInversionDataLinerInfoGrey.Text = linerTube + " tube with " + resinMake + " " + resinType + " " + resinNumber + " resin";
                    lblInversionDataHeadsGrey.Text = "Heads Ideal: " + tbxWetOutDataTubeIdealHead.Text + " ft (" + tbxWetOutDataTubeIdealHeadPSI.Text + ");  Max Hot: " + tbxWetOutDataTubeMaxHotHead.Text + " ft (" + tbxWetOutDataTubeMaxHotHeadPSI.Text + "psi);  Max Cold: " + tbxWetOutDataTubeMaxColdHead.Text + " ft (" + tbxWetOutDataTubeMaxColdHeadPSI.Text + ")";

                    // ... ... .... Validate data for calcs
                    if ((ddlInversionDataInversionPipeType.SelectedValue != "(Select)") && (ddlInversionDataPipeCondition.SelectedValue != "(Select)") && (ddlInversionDataGroundMoisture.SelectedValue != "(Select)") && (tbxInversionDataBoilerSize.Text != "") && (tbxInversionDataPumpsTotalCapacity.Text != "") && (tbxInversionDataLayflatSize.Text != "") && (tbxInversionDataLayflatQuantityTotal.Text != ""))
                    {
                        if ((tbxInversionDataWaterStartTempTs.Text != "") && (tbxInversionDataTempT1.Text != "") && (tbxInversionDataHoldAtT1For.Text != "") && (tbxInversionDataTempT2.Text != "") && (tbxInversionDataCookAtT2For.Text != "") && (tbxInversionDataCoolDownFor.Text != "") && (tbxInversionDataCoolToTemp.Text != "") && (tbxInversionDataDropInPipeRun.Text != ""))
                        {
                            // ... ... Inversion Pipe Slope Of
                            Decimal dropInPipeRun = Decimal.Parse(tbxInversionDataDropInPipeRun.Text);
                            Decimal pipeSlopeOf = Decimal.Round(dropInPipeRun, 1) / Decimal.Parse(lengthToLine.ToString())*100;
                            tbxInversionDataPipeSlopeOf.Text = Decimal.Round(decimal.Parse(pipeSlopeOf.ToString()), 2).ToString();

                            // ... ... Inversion 45F120F
                            double odsIns = confirmedSize;
                            double tIns = (tubeThickness / 25.4);
                            double inversionId = (odsIns - 2 * tIns);
                            lblInversionData45F120F.Text = tbxInversionDataWaterStartTempTs.Text + "°F-" + tbxInversionDataTempT1.Text + "°F (hr)";

                            // ... ... Inversion Hold
                            tbxInversionDataHold.Text = Decimal.Round(decimal.Parse(tbxInversionDataHoldAtT1For.Text), 1).ToString();

                            // ... ... Inversion 120F185F
                            lblInversionData120F185F.Text = tbxInversionDataTempT1.Text + "°F-" + tbxInversionDataTempT2.Text + "°F (hr)";
                            double pipeTypeFactor = 0d;
                            string pipeType = ddlInversionDataInversionPipeType.SelectedValue;
                            if (pipeType == "Clay") pipeTypeFactor = 0.90;
                            if (pipeType == "Concrete") pipeTypeFactor = 0.80;
                            if (pipeType == "Brick") pipeTypeFactor = 1.00;

                            double pipeConditionFactor = 0d;
                            string pipeCondition = ddlInversionDataPipeCondition.SelectedValue;
                            if (pipeCondition == "Good") pipeConditionFactor = 1.00;
                            if (pipeCondition == "Fair") pipeConditionFactor = 0.90;
                            if (pipeCondition == "Poor") pipeConditionFactor = 0.80;
                            if (pipeCondition == "Badly Broken") pipeConditionFactor = 0.60;

                            double groundMoistureFactor = 0d;
                            string groundMoisture = ddlInversionDataGroundMoisture.SelectedValue;
                            if (groundMoisture == "Dry") groundMoistureFactor = 1.00;
                            if (groundMoisture == "Typical") groundMoistureFactor = 0.80;
                            if (groundMoisture == "Wet") groundMoistureFactor = 0.60;

                            double boilerSize = double.Parse(tbxInversionDataBoilerSize.Text);
                            double matFactorF1 = pipeTypeFactor;
                            double conditionFactorF2 = pipeConditionFactor;
                            double groundMoistureFactorF3 = groundMoistureFactor;
                            double overallFactorF3 = matFactorF1 * conditionFactorF2 * groundMoistureFactorF3;
                            double ianCorrectionFactor = 0.85;
                            double tubeMaxColdHead = double.Parse(tbxWetOutDataTubeMaxColdHead.Text);
                            double totalTubee = tubeMaxColdHead + lengthToLine;
                            double idForLinerFt = inversionId / 12;
                            double particalCalc = Math.Pow(idForLinerFt, 2);
                            double areaFt2 = (pi * particalCalc) / 4;
                            double ft3PerFt = areaFt2 * 1;
                            double usgPerFt = 7.481 * ft3PerFt;
                            double totalUsg = totalTubee * usgPerFt;
                            double cubFt = totalUsg / 7.481;
                            double punds = cubFt * 62.4;
                            double temp1 = double.Parse(tbxInversionDataTempT1.Text);
                            double temp2 = double.Parse(tbxInversionDataTempT2.Text);
                            double ts = double.Parse(tbxInversionDataWaterStartTempTs.Text);
                            double t1t2Btus = ((temp2 - temp1) * punds);
                            double netBtu = (ianCorrectionFactor * overallFactorF3 * boilerSize);
                            double timeHrs = (t1t2Btus / netBtu);
                            tbxInversionData120F185F.Text = Decimal.Round(decimal.Parse(timeHrs.ToString()), 1).ToString();

                            double tsT1Btus = (temp1 - ts) * punds;
                            double timeHrs1 = tsT1Btus / netBtu;
                            tbxInversionData45F120F.Text = Decimal.Round(decimal.Parse(timeHrs1.ToString()), 1).ToString();

                            // ... ... Inversion Cook Time
                            tbxInversionDataCookTime.Text = Decimal.Round(decimal.Parse(tbxInversionDataCookAtT2For.Text), 1).ToString(); ;

                            // ... ... Inversion Cool Time
                            tbxInversionDataCoolTime.Text = Decimal.Round(decimal.Parse(tbxInversionDataCoolDownFor.Text), 1).ToString();

                            // ... ... Inversion Aprox Total
                            double f45f120 = timeHrs1;
                            double hold = Double.Parse(tbxInversionDataHold.Text);
                            double f120f185 = timeHrs;
                            double cookTime = Double.Parse(tbxInversionDataCookTime.Text);
                            double coolTime = Double.Parse(tbxInversionDataCoolTime.Text);
                            tbxInversionDataAproxTotal.Text = Decimal.Round(decimal.Parse((f45f120 + hold + f120f185 + cookTime + coolTime).ToString()), 1).ToString();

                            // ... ... Inversion pumping circulation subtitle
                            double pumpsTotalCapacity = double.Parse(tbxInversionDataPumpsTotalCapacity.Text);
                            lblInversionDataPumpingCirculationSubtitle.Text = "Pumping and Circulation Parameters at " + tbxInversionDataPumpsTotalCapacity.Text + "usgpm (= " + (pumpsTotalCapacity * 60).ToString() + " usgph)";

                            // ... ... Inversion water changes per hour
                            double totalLinerInWaterCol = totalUsg;
                            double pumpsTotalCapacity60 = pumpsTotalCapacity * 60;
                            double changesPerHour = pumpsTotalCapacity60 / totalLinerInWaterCol;
                            decimal waterChangesPerHour = Decimal.Round(decimal.Parse(changesPerHour.ToString()), 2);
                            tbxInversionDataWaterChangesPerHour.Text = Decimal.Round(decimal.Parse(waterChangesPerHour.ToString()), 2).ToString();

                            // ... ... Inversion return water velocity
                            double layFlatQuantity = double.Parse(tbxInversionDataLayflatQuantityTotal.Text);
                            double layFlatSize = double.Parse(tbxInversionDataLayflatSize.Text);
                            double middleCalcEach = Math.Pow(layFlatSize, 2);
                            double areaLayFlatft2Each = ((pi * (middleCalcEach)) / 4) / 144;
                            double areaLayflatft2 = areaLayFlatft2Each * layFlatQuantity;
                            double qInCfs = pumpsTotalCapacity / 448.8;
                            double netQAreaFt2 = areaFt2 - areaLayflatft2;
                            double returnFlowArea = netQAreaFt2;
                            double returnsWaterVelocity = qInCfs / returnFlowArea;
                            tbxInversionDataReturnWaterVelocity.Text = Decimal.Round(decimal.Parse(returnsWaterVelocity.ToString()), 2).ToString();

                            // ... ... Inversion layflat back pressure
                            double c = 130;
                            double dFt = layFlatSize / 12;
                            double flowPerLayFlat = pumpsTotalCapacity / layFlatQuantity;
                            double qCfm = flowPerLayFlat * 0.1336;
                            double qCfs = qCfm / 60;
                            double middleCalcAreaIns2 = Math.Pow(layFlatSize, 2);
                            double areaIns2 = (pi * middleCalcAreaIns2) / 4;
                            double areaft2 = areaIns2 / 144;
                            double vFtS = qCfs / areaft2;
                            double wetOutLenght = double.Parse(tbxInversionDataWetOutLenght.Text);
                            double totalLfLength = tubeMaxColdHead + wetOutLenght;
                            double hfFtL = (Math.Pow((1.816 / c), 1.852) * ((totalLfLength / (Math.Pow(dFt, 1.167))) * Math.Pow(vFtS, 1.852)));
                            double hfPsiL = hfFtL * 0.4335;
                            double layFlatBackPressure = hfPsiL;
                            tbxInversionDataLayflatBackPressure.Text = Decimal.Round(decimal.Parse(layFlatBackPressure.ToString()), 1).ToString();

                            // ... ... Inversion pump lift at ideal head
                            double pumpHeightAboveGround = double.Parse(tbxWetOutDataPumpHeightAboveGround.Text);
                            double pumpFromInvert = pumpHeightAboveGround + depthOfInversionMH;
                            double lift = pumpFromInvert - idealHead;
                            double pumpLiftAtIdealHead = lift;
                            tbxInversionDataPumpLiftAtIdealHead.Text = Decimal.Round(decimal.Parse(pumpLiftAtIdealHead.ToString()), 1).ToString();

                            // ... ... Inversion water to fil liner column
                            double waterToFillLinerColumn = totalUsg;
                            tbxInversionDataWaterToFillLinerColumn.Text = Decimal.Round(decimal.Parse(waterToFillLinerColumn.ToString()), 0).ToString();

                            // ... ... Inversion water per ft
                            double waterPerFt = usgPerFt;
                            tbxInversionDataWaterPerFit.Text = Decimal.Round(decimal.Parse(waterPerFt.ToString()), 2).ToString();

                            // ... ... graphic labels
                            lblInversionDataMaxColdForTubeLabel.Text = tbxWetOutDataTubeMaxColdHead.Text + " ft = Max Cold for tube";
                            lblInversionDataMaxHotForTubeLabel.Text = tbxWetOutDataTubeMaxHotHead.Text + " ft = Max Hot for tube";
                            lblInversionDataIdelForTubeLabel.Text = tbxWetOutDataTubeIdealHead.Text + " ft = Ideal for tube";

                            double maxColdForTubeEnd = double.Parse(tbxWetOutDataTubeMaxColdHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                            lblInversionDataMaxColdForTubeEndLabel.Text = decimal.Round(decimal.Parse(maxColdForTubeEnd.ToString()), 1).ToString() + " ft";

                            double maxHotForTubeEnd = double.Parse(tbxWetOutDataTubeMaxHotHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                            lblInversionDataMaxHotForTubeEndLabel.Text = decimal.Round(decimal.Parse(maxHotForTubeEnd.ToString()), 1).ToString() + " ft";

                            double idealForTubeEnd = double.Parse(tbxWetOutDataTubeIdealHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                            lblInversionDataIdelForTubeEndLabel.Text = decimal.Round(decimal.Parse(idealForTubeEnd.ToString()), 1).ToString() + " ft";

                            lblInversionDataPumpHeightLabel.Text = "   " + tbxWetOutDataPumpHeightAboveGround.Text + " ft";
                            lblInversionDataLinerSizeLabel.Text = confirmedSize.ToString() + " ins x" + tubeThickness.ToString() + " Liner";

                            lblInversionDataRunLengthLabel.Text = "Run Length: " + tbxInversionDataRunLength.Text + " ft; Fall: " + tbxInversionDataDropInPipeRun.Text + " ft";
                            lblInversionDataDepthOfInversionMHLabel.Text = "   " + tbxWetOutDataDepthOfInversionMH.Text + " ft";
                            lblInversionDataEndLabel.Text = "End";
                        }
                    }
                }
            }
        }
 protected string GetDistance(object distance)
 {
     if (distance != DBNull.Value)
     {
         Distance distanceInch = new Distance(distance.ToString());
         return distanceInch.ToStringInEng1();
     }
     else
     {
         return "";
     }
 }
        protected void cvDistanceDsmhFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = true;
            double? distanceFromUsmhFooter = null;
            double? distanceFromDSMH = null;

            // Calculate distance form dsmh
            if (((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim() != "")
            {
                distanceFromUsmhFooter = double.Parse(((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim());
                Distance length = new Distance(tbxActualLength.Text.Trim()) - new Distance(distanceFromUsmhFooter.ToString());
                distanceFromDSMH = length.ToDoubleInEng3();

                if (distanceFromDSMH < 0)
                {
                    args.IsValid = false;
                }
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        public void ProcessDataForProject(int companyId)
        {
            ArrayList al = new ArrayList();
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;
            int lateralsAcum = 0;
            double totalHrsAcum = 0;

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoRow row1 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoDataTable)Table)
            {
                if (row1.Phase.Contains("Prep") || row1.Phase.Contains("Reinstate"))
                {
                    if (!row1.Completed)
                    {
                        if (!al.Contains(row1.SectionID))
                        {
                            al.Add(row1.SectionID);
                        }
                    }
                }

                if (!row1.IsTotalFtNull())
                {
                    Distance distOriginal = new Distance(row1.TotalFt);
                    row1.TotalFtDouble = distOriginal.ToDoubleInEng3();
                }
                else
                {
                    row1.TotalFtDouble = 0;
                }

                if (!alDays.Contains(row1.Date))
                {
                    alDays.Add(row1.Date);
                    totalHrsAcum = totalHrsAcum + row1.Hrs;
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoRow row2 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoDataTable)Table)
            {
                if (row2.Phase.Contains("Prep"))
                {
                    if (!row2.IsTotalFtNull())
                    {
                        Distance dist = new Distance(row2.TotalFt);
                        double distD = dist.ToDoubleInEng3();

                        if (!row2.Completed)
                        {
                            row2.RealFt = distD / 2;
                        }
                        else
                        {
                            if (al.Contains(row2.SectionID))
                            {
                                row2.RealFt = distD / 2;
                            }
                            else
                            {
                                row2.RealFt = dist.ToDoubleInEng3();
                            }
                        }
                    }
                    else
                    {
                        row2.RealFt = 0;
                    }

                    rateAcum = rateAcum + row2.RealFt / row2.Hrs;
                }

                if (row2.Phase.Contains("Reinstate"))
                {
                    if (!row2.IsLiveLateralsNull())
                    {
                        if (!row2.Completed)
                        {
                            row2.RealLiveLaterals = row2.LiveLaterals / 2;
                        }
                        else
                        {
                            if (al.Contains(row2.SectionID))
                            {
                                row2.RealLiveLaterals = row2.LiveLaterals / 2;
                            }
                            else
                            {
                                row2.RealLiveLaterals = row2.LiveLaterals;
                            }
                        }
                    }
                    else
                    {
                        row2.RealLiveLaterals = 0;
                    }

                    lateralsAcum = lateralsAcum + row2.RealLiveLaterals;
                    rateAcum = rateAcum + (row2.Hrs / row2.RealLiveLaterals);
                    row2.TotalHrs = totalHrsAcum;
                }

                if (row2.Phase.Contains("Install"))
                {
                    if (!row2.IsTotalFtNull())
                    {
                        Distance dist = new Distance(row2.TotalFt);
                        row2.RealFt = dist.ToDoubleInEng3();
                    }
                    else
                    {
                        row2.RealFt = 0;
                    }

                    rateAcum = rateAcum + row2.RealFt / row2.Hrs;
                }

                row2.NumPeriods = alDays.Count;
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoRow row3 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLReinstatePostVideoDataTable)Table)
            {
                if (row3.Phase.Contains("Reinstate"))
                {
                    row3.AverageRate = totalHrsAcum / lateralsAcum;
                }
                else
                {
                    row3.AverageRate = rateAcum / alDays.Count;
                }
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        private void ProcessDataForProject(int currentProjectId, string currentPhase, int companyId)
        {
            ArrayList al = new ArrayList();
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;
            int lateralsAcum = 0;
            double totalHrsAcum = 0;

            string projectName = "";
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(currentProjectId);
            projectName = projectGateway.GetName(currentProjectId);

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLRow row1 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLDataTable)Table)
            {
                if (row1.ProjectName.Contains(projectName) && row1.Phase.Contains(currentPhase))
                {
                    if (row1.Phase.Contains("Prep") || row1.Phase.Contains("Reinstate"))
                    {
                        if (!row1.Completed)
                        {
                            if (!al.Contains(row1.SectionID))
                            {
                                al.Add(row1.SectionID);
                            }
                        }
                    }

                    if (!row1.IsTotalFtNull())
                    {
                        Distance distOriginal = new Distance(row1.TotalFt);
                        row1.TotalFtDouble = distOriginal.ToDoubleInEng3();
                    }
                    else
                    {
                        row1.TotalFtDouble = 0;
                    }

                    if (!alDays.Contains(row1.Date))
                    {
                        alDays.Add(row1.Date);
                        totalHrsAcum = totalHrsAcum + row1.Hrs;
                    }
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLRow row2 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLDataTable)Table)
            {
                if (row2.ProjectName.Contains(projectName) && row2.Phase.Contains(currentPhase))
                {
                    if (row2.Phase.Contains("Prep"))
                    {
                        if (!row2.IsTotalFtNull())
                        {
                            Distance dist = new Distance(row2.TotalFt);
                            double distD = dist.ToDoubleInEng3();

                            if (!row2.Completed)
                            {
                                row2.RealFt = distD / 2;
                            }
                            else
                            {
                                if (al.Contains(row2.SectionID))
                                {
                                    row2.RealFt = distD / 2;
                                }
                                else
                                {
                                    row2.RealFt = dist.ToDoubleInEng3();
                                }
                            }
                        }
                        else
                        {
                            row2.RealFt = 0;
                        }

                        rateAcum = rateAcum + row2.RealFt / row2.Hrs;
                    }

                    if (row2.Phase.Contains("Reinstate"))
                    {
                        if (!row2.IsLiveLateralsNull())
                        {
                            if (!row2.Completed)
                            {
                                row2.RealLiveLaterals = row2.LiveLaterals / 2;
                            }
                            else
                            {
                                if (al.Contains(row2.SectionID))
                                {
                                    row2.RealLiveLaterals = row2.LiveLaterals / 2;
                                }
                                else
                                {
                                    row2.RealLiveLaterals = row2.LiveLaterals;
                                }
                            }
                        }
                        else
                        {
                            row2.RealLiveLaterals = 0;
                        }

                        lateralsAcum = lateralsAcum + row2.RealLiveLaterals;
                        rateAcum = rateAcum + (row2.Hrs / row2.RealLiveLaterals);
                        row2.TotalHrs = totalHrsAcum;
                    }

                    if (row2.Phase.Contains("Install"))
                    {
                        if (!row2.IsTotalFtNull())
                        {
                            Distance dist = new Distance(row2.TotalFt);
                            row2.RealFt = dist.ToDoubleInEng3();
                        }
                        else
                        {
                            row2.RealFt = 0;
                        }

                        rateAcum = rateAcum + row2.RealFt / row2.Hrs;
                    }

                    row2.NumPeriods = alDays.Count;
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLRow row3 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseFLLDataTable)Table)
            {
                if (row3.ProjectName.Contains(projectName) && row3.Phase.Contains(currentPhase))
                {
                    if (row3.Phase.Contains("Reinstate"))
                    {
                        row3.AverageRate = totalHrsAcum / lateralsAcum;
                    }
                    else
                    {
                        row3.AverageRate = rateAcum / alDays.Count;
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        /// <param name="unitType">unitType</param>
        private void UpdateForReport(string unitType)
        {
            // Load comments
            foreach (FlM1ReportTDS.M1ReportByClientRow row in (FlM1ReportTDS.M1ReportByClientDataTable)Table)
            {
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(row.WorkID, row.COMPANY_ID);
                row.M1Comments = workGateway.GetComments(row.WorkID);
            }

            // Update for unit type
            FlM1LateralReportGateway flM1LateralReportGateway = new FlM1LateralReportGateway(Data);
            flM1LateralReportGateway.ClearBeforeFill = false;
            FlM1LateralReport flM1LateralReport = new FlM1LateralReport(Data);

            foreach (FlM1ReportTDS.M1ReportByClientRow row in (FlM1ReportTDS.M1ReportByClientDataTable)Table)
            {
                if (!row.IsM1CommentsNull())
                {
                    row.M1Comments = row.M1Comments.Replace("<br>", "\n");
                }

                Distance d;

                if (unitType == "Metric")
                {
                    if (!row.IsSize_Null())
                    {
                        if (Distance.IsValidDistance(row.Size_))
                        {
                            d = new Distance(row.Size_);
                            row.Size_ = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsLengthNull())
                    {
                        if (Distance.IsValidDistance(row.Length))
                        {
                            d = new Distance(row.Length);
                            row.Length = d.ToStringInMet2();
                        }
                    }

                    if (!row.IsUSMHDepthNull())
                    {
                        if (Distance.IsValidDistance(row.USMHDepth))
                        {
                            d = new Distance(row.USMHDepth);
                            row.USMHDepth = d.ToStringInMet2();
                        }
                    }

                    if (!row.IsDSMHDepthNull())
                    {
                        if (Distance.IsValidDistance(row.DSMHDepth))
                        {
                            d = new Distance(row.DSMHDepth);
                            row.DSMHDepth = d.ToStringInMet2();
                        }
                    }

                    if (!row.IsUSMHMouth12Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth12))
                        {
                            d = new Distance(row.USMHMouth12);
                            row.USMHMouth12 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsUSMHMouth1Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth1))
                        {
                            d = new Distance(row.USMHMouth1);
                            row.USMHMouth1 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsUSMHMouth2Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth2))
                        {
                            d = new Distance(row.USMHMouth2);
                            row.USMHMouth2 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsUSMHMouth3Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth3))
                        {
                            d = new Distance(row.USMHMouth3);
                            row.USMHMouth3 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsUSMHMouth4Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth4))
                        {
                            d = new Distance(row.USMHMouth4);
                            row.USMHMouth4 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsUSMHMouth5Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth5))
                        {
                            d = new Distance(row.USMHMouth5);
                            row.USMHMouth5 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth12Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth12))
                        {
                            d = new Distance(row.DSMHMouth12);
                            row.DSMHMouth12 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth1Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth1))
                        {
                            d = new Distance(row.DSMHMouth1);
                            row.DSMHMouth1 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth2Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth2))
                        {
                            d = new Distance(row.DSMHMouth2);
                            row.DSMHMouth2 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth3Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth3))
                        {
                            d = new Distance(row.DSMHMouth3);
                            row.DSMHMouth3 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth4Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth4))
                        {
                            d = new Distance(row.DSMHMouth4);
                            row.DSMHMouth4 = d.ToStringInMil2();
                        }
                    }

                    if (!row.IsDSMHMouth5Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth5))
                        {
                            d = new Distance(row.DSMHMouth5);
                            row.DSMHMouth5 = d.ToStringInMil2();
                        }
                    }
                }

                if (unitType == "Imperial")
                {
                    if (!row.IsSize_Null())
                    {
                        if (Distance.IsValidDistance(row.Size_))
                        {
                            Distance distance = new Distance(row.Size_);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.Size_) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.Size_) * 0.03937;
                                            row.Size_ = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.Size_ = row.Size_ + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsLengthNull())
                    {
                        d = new Distance(row.Length);
                        row.Length = d.ToStringInEng1();
                    }

                    if (!row.IsUSMHDepthNull())
                    {
                        if (Distance.IsValidDistance(row.USMHDepth))
                        {
                            Distance distance = new Distance(row.USMHDepth);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHDepth = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.Size_) > 99)
                                        {
                                            double newUSMHDepth = 0;
                                            newUSMHDepth = Convert.ToDouble(row.Size_) * 0.03937;
                                            row.USMHDepth = Convert.ToString(Math.Ceiling(newUSMHDepth)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHDepth = row.USMHDepth + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHDepth = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHDepth = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHDepthNull())
                    {
                        if (Distance.IsValidDistance(row.DSMHDepth))
                        {
                            Distance distance = new Distance(row.DSMHDepth);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHDepth = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.Size_) > 99)
                                        {
                                            double newDSMHDepth = 0;
                                            newDSMHDepth = Convert.ToDouble(row.Size_) * 0.03937;
                                            row.DSMHDepth = Convert.ToString(Math.Ceiling(newDSMHDepth)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHDepth = row.USMHDepth + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHDepth = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHDepth = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth12Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth12))
                        {
                            Distance distance = new Distance(row.USMHMouth12);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth12 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth12) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth12) * 0.03937;
                                            row.USMHMouth12 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth12 = row.USMHMouth12 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth12 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth12 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth1Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth1))
                        {
                            Distance distance = new Distance(row.USMHMouth1);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth1 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth1) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth1) * 0.03937;
                                            row.USMHMouth1 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth1 = row.USMHMouth1 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth1 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth1 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth2Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth2))
                        {
                            Distance distance = new Distance(row.USMHMouth2);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth2 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth2) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth2) * 0.03937;
                                            row.USMHMouth2 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth2 = row.USMHMouth2 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth2 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth2 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth3Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth3))
                        {
                            Distance distance = new Distance(row.USMHMouth3);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth3 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth3) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth3) * 0.03937;
                                            row.USMHMouth3 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth3 = row.USMHMouth3 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth3 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth3 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth4Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth4))
                        {
                            Distance distance = new Distance(row.USMHMouth4);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth4 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth4) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth4) * 0.03937;
                                            row.USMHMouth4 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth4 = row.USMHMouth4 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth4 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth4 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsUSMHMouth5Null())
                    {
                        if (Distance.IsValidDistance(row.USMHMouth5))
                        {
                            Distance distance = new Distance(row.USMHMouth5);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.USMHMouth5 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.USMHMouth5) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.USMHMouth5) * 0.03937;
                                            row.USMHMouth5 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.USMHMouth5 = row.USMHMouth5 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.USMHMouth5 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.USMHMouth5 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth12Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth12))
                        {
                            Distance distance = new Distance(row.DSMHMouth12);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth12 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth12) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth12) * 0.03937;
                                            row.DSMHMouth12 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth12 = row.DSMHMouth12 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth12 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth12 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth1Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth1))
                        {
                            Distance distance = new Distance(row.DSMHMouth1);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth1 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth1) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth1) * 0.03937;
                                            row.DSMHMouth1 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth1 = row.DSMHMouth1 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth1 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth1 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth2Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth2))
                        {
                            Distance distance = new Distance(row.DSMHMouth2);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth2 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth2) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth2) * 0.03937;
                                            row.DSMHMouth2 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth2 = row.DSMHMouth2 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth2 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth2 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth3Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth3))
                        {
                            Distance distance = new Distance(row.DSMHMouth3);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth3 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth3) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth3) * 0.03937;
                                            row.DSMHMouth3 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth3 = row.DSMHMouth3 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth3 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth3 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth4Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth4))
                        {
                            Distance distance = new Distance(row.DSMHMouth4);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth4 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth4) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth4) * 0.03937;
                                            row.DSMHMouth4 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth4 = row.DSMHMouth4 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth4 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth4 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsDSMHMouth5Null())
                    {
                        if (Distance.IsValidDistance(row.DSMHMouth5))
                        {
                            Distance distance = new Distance(row.DSMHMouth5);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.DSMHMouth5 = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    try
                                    {
                                        if (Convert.ToDouble(row.DSMHMouth5) > 99)
                                        {
                                            double newSize_ = 0;
                                            newSize_ = Convert.ToDouble(row.DSMHMouth5) * 0.03937;
                                            row.DSMHMouth5 = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                        }
                                        else
                                        {
                                            row.DSMHMouth5 = row.DSMHMouth5 + "\"";
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                case 4:
                                    row.DSMHMouth5 = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.DSMHMouth5 = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }
                }

                flM1LateralReportGateway.LoadByAssetId(row.AssetID, row.COMPANY_ID);
                flM1LateralReport.UpdateForReport(row.FlowOrderID, unitType);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        /// <param name="unitType">unitType</param>
        public void UpdateForReport(string unitType)
        {
            // Load comments
            foreach (FlM1ReportTDS.M2_SECTIONRow row in (FlM1ReportTDS.M2_SECTIONDataTable)Table)
            {
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(row.WorkID, row.COMPANY_ID);

                row.Comments = workGateway.GetComments(row.WorkID);

                Distance d;

                if (unitType == "Metric")
                {
                    if (!row.IsSize_Null())
                    {
                        d = new Distance(row.Size_);
                        row.Size_ = d.ToStringInMet2();
                    }

                    if (!row.IsVideoLengthNull())
                    {
                        d = new Distance(row.VideoLength);
                        row.VideoLength = d.ToStringInMet2();
                    }

                    if (!row.IsSurfaceGradeNull())
                    {
                        if (row.SurfaceGrade == "0-3 ft")
                        {
                            row.SurfaceGrade = "0-0.91 m";
                        }

                        if (row.SurfaceGrade == "3-6 ft")
                        {
                            row.SurfaceGrade = "0.91-1.83 m";
                        }

                        if (row.SurfaceGrade == "6 ft +")
                        {
                            row.SurfaceGrade = "1.83 m +";
                        }
                    }
                }

                if (unitType == "Imperial")
                {
                    if (!row.IsSize_Null())
                    {
                        if (Distance.IsValidDistance(row.Size_))
                        {
                            Distance distance = new Distance(row.Size_);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    if (Convert.ToDouble(row.Size_) > 99)
                                    {
                                        double newSize_ = 0;
                                        newSize_ = Convert.ToDouble(row.Size_) * 0.03937;
                                        row.Size_ = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                    }
                                    else
                                    {
                                        row.Size_ = row.Size_ + "\"";
                                    }
                                    break;
                                case 4:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsVideoLengthNull())
                    {
                        d = new Distance(row.VideoLength);
                        row.VideoLength = d.ToStringInEng1();
                    }
                }
            }

            // Update for unit type
            //foreach (FlM1ReportTDS.M2_SECTIONRow row in (FlM1ReportTDS.M2_SECTIONDataTable)Table)
            //{
                //Distance d;

                //if (unitType == "Metric")
                //{
                //    if (!row.IsSize_Null())
                //    {
                //        d = new Distance(row.Size_);
                //        row.Size_ = d.ToStringInMet2();
                //    }

                //    if (!row.IsVideoLengthNull())
                //    {
                //        d = new Distance(row.VideoLength);
                //        row.VideoLength = d.ToStringInMet2();
                //    }

                //    if (!row.IsSurfaceGradeNull())
                //    {
                //        if (row.SurfaceGrade == "0-3 ft")
                //        {
                //            row.SurfaceGrade = "0-0.91 m";
                //        }

                //        if (row.SurfaceGrade == "3-6 ft")
                //        {
                //            row.SurfaceGrade = "0.91-1.83 m";
                //        }

                //        if (row.SurfaceGrade == "6 ft +")
                //        {
                //            row.SurfaceGrade = "1.83 m +";
                //        }
                //    }
                //}

                //if (unitType == "Imperial")
                //{
                //    if (!row.IsSize_Null())
                //    {
                //        if (Distance.IsValidDistance(row.Size_))
                //        {
                //            Distance distance = new Distance(row.Size_);

                //            switch (distance.DistanceType)
                //            {
                //                case 2:
                //                    row.Size_ = distance.ToStringInEng1();
                //                    break;
                //                case 3:
                //                    if (Convert.ToDouble(row.Size_) > 99)
                //                    {
                //                        double newSize_ = 0;
                //                        newSize_ = Convert.ToDouble(row.Size_) * 0.03937;
                //                        row.Size_ = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                //                    }
                //                    else
                //                    {
                //                        row.Size_ = row.Size_ + "\"";
                //                    }
                //                    break;
                //                case 4:
                //                    row.Size_ = distance.ToStringInEng1();
                //                    break;
                //                case 5:
                //                    row.Size_ = distance.ToStringInEng1();
                //                    break;
                //            }
                //        }
                //    }

                //    if (!row.IsVideoLengthNull())
                //    {
                //        d = new Distance(row.VideoLength);
                //        row.VideoLength = d.ToStringInEng1();
                //    }
                //}
            //}
        }
        protected void cvVideoDistance_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value.Trim() != "")
            {
                // Initialize
                CustomValidator cvDistanceFromUsmh = (CustomValidator)source;
                args.IsValid = true;

                // Control of format
                if (!Distance.IsValidDistance(args.Value))
                {
                    cvDistanceFromUsmh.Text = "Invalid format. (please use X'Y\", or Xft Yin, or X.Y, or X.Ym, or X.Ymm)";
                    args.IsValid = false;
                    hdfErrorFieldList.Value = hdfErrorFieldList.Value + ", Video Length";
                }

                // Control of distance > 0
                if (args.IsValid)
                {
                    Distance distance = new Distance(args.Value);
                    if (distance.ToDoubleInEng3() < 0)
                    {
                        cvDistanceFromUsmh.Text = "Invalid distance. (must be equal or greater than 0)";
                        args.IsValid = false;
                        hdfErrorFieldList.Value = hdfErrorFieldList.Value + ",Video Length";
                    }
                }
            }
        }
 protected void ddlWetOutDataInversionType_SelectedIndexChanged(object sender, EventArgs e)
 {
     tbxWetOutDataDepthOfInversionMH.Text = "0";
     if (tbxM1DataUsmhDepth.Text != "")
     {
         if (ddlWetOutDataInversionType.SelectedValue == "Top")
         {
             Distance usmhDepthDistance = new Distance(tbxM1DataUsmhDepth.Text);
             tbxWetOutDataDepthOfInversionMH.Text = decimal.Round(decimal.Parse(usmhDepthDistance.ToStringInEng3()),1).ToString();
         }
         else
         {
             if (ddlWetOutDataInversionType.SelectedValue == "Bottom")
             {
                 Distance dsmhDepthDistance = new Distance(tbxM1DataDsmhDepth.Text);
                 tbxWetOutDataDepthOfInversionMH.Text = decimal.Round(decimal.Parse(dsmhDepthDistance.ToStringInEng3()), 1).ToString();
             }
         }
     }
 }
        protected void grdJliner2_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("dataEdit");
            if (Page.IsValid)
            {
                Guid id = new Guid(((Label)grdJliner2.Rows[e.RowIndex].Cells[0].FindControl("lblIDEdit")).Text);
                int refId = Int32.Parse(((Label)grdJliner2.Rows[e.RowIndex].Cells[1].FindControl("lblRefIDEdit")).Text);
                int companyId = Int32.Parse(((Label)grdJliner2.Rows[e.RowIndex].Cells[2].FindControl("lblCOMPANY_IDEdit")).Text);
                string detailId = ((TextBox)grdJliner2.Rows[e.RowIndex].Cells[4].FindControl("tbxDetailIdEdit")).Text.Trim();
                string address = ""; if (((TextBox)grdJliner2.Rows[e.RowIndex].Cells[5].FindControl("tbxAddressEdit")).Text.Trim() != "") address = ((TextBox)grdJliner2.Rows[e.RowIndex].Cells[5].FindControl("tbxAddressEdit")).Text.Trim();
                double? distanceFromUSMH = null; if (((TextBox)grdJliner2.Rows[e.RowIndex].Cells[6].FindControl("tbxDistanceFromUSMHEdit")).Text.Trim() != "") distanceFromUSMH = double.Parse(((TextBox)grdJliner2.Rows[e.RowIndex].Cells[6].FindControl("tbxDistanceFromUSMHEdit")).Text.Trim());

                // Calculate fields
                double? distanceFromDSMH = null;
                if (distanceFromUSMH.HasValue)
                {
                    Distance length = new Distance(tbxActualLength.Text.Trim()) - new Distance(distanceFromUSMH.ToString());
                    distanceFromDSMH = length.ToDoubleInEng3();
                }

                JlinerAddJunctionLiner2 model = new JlinerAddJunctionLiner2(jlinerAddTDS);
                model.Update(id, refId, companyId, detailId, address, distanceFromUSMH, distanceFromDSMH );

                Session["jlinerAddTDS"] = jlinerAddTDS;
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void grdLaterals_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("AddLateralsEdit");
            if (Page.IsValid)
            {
                if (((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlLiveEdit")).Visible == true)
                {
                    Page.Validate("AddLateralsEditSpecial");
                }

                if (Page.IsValid)
                {
                    int lateral = int.Parse(((Label)grdLaterals.Rows[e.RowIndex].Cells[1].FindControl("lblLateral")).Text.Trim());
                    string lateralId = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxLateralIdEdit")).Text.Trim();
                    string clientLateralId = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxClientLateralIdEdit")).Text.Trim();
                    string size = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxSizeEdit")).Text.Trim();

                    // Load material
                    string material = "";
                    material = ((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlMaterialEdit")).SelectedValue;

                    // Load lateral state
                    string live = "";
                    if (((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxJlLive")).Visible == true)
                    {
                        live = "Live";
                    }
                    else
                    {
                        if (((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlLiveEdit")).Visible == true)
                        {
                            live = ((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlLiveEdit")).SelectedValue.Trim();
                        }
                    }

                    string videoDistance = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxVideoDistanceEdit")).Text.Trim();
                    string clockPosition = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxClockPositionEdit")).Text.Trim();
                    string distanceToCentre = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxDistanceToCentreEdit")).Text.Trim();
                    string timeOpened = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxTimeOpenedEdit")).Text.Trim();

                    // Reverse Setup calculation
                    string reverseSetup = "";

                    if (videoDistance != "")
                    {
                        Distance videoLength = new Distance(tbxVideoLength.Text.Trim());
                        Distance videoDistanceD = new Distance(videoDistance);
                        Distance reverseSetupD = videoLength - videoDistanceD;

                        switch (videoDistanceD.DistanceType)
                        {
                            case 1:
                                reverseSetup = reverseSetupD.ToStringInEng1();
                                break;
                            case 2:
                                reverseSetup = reverseSetupD.ToStringInEng2();
                                break;
                            case 3:
                                reverseSetup = reverseSetupD.ToStringInEng3();
                                break;
                            case 4:
                                reverseSetup = reverseSetupD.ToStringInMet1();
                                break;
                            case 5:
                                reverseSetup = reverseSetupD.ToStringInMil1();
                                break;
                        }
                    }

                    DateTime? reinstate = null;
                    if (((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpReinstateEdit")).SelectedDate.HasValue)
                    {
                        reinstate = ((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpReinstateEdit")).SelectedDate.Value;
                    }

                    string comments = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxCommentsEdit")).Text.Trim();
                    bool inProject = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[3].FindControl("cbxInProject")).Checked;
                    string connectionType = ""; connectionType = ((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlConnectionTypeEdit")).SelectedValue;
                    string mn = ""; mn = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxMnEdit")).Text.Trim();
                    string clientInspectionNo = ((TextBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tbxclientInspectionNoEdit")).Text.Trim();
                    bool requiredRoboticPrep = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ckbxRequiresRoboticPrepEdit")).Checked;

                    DateTime? requiredRoboticPrepDate = null;
                    if (((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpRequiresRoboticPrepDateEdit")).SelectedDate.HasValue)
                    {
                        requiredRoboticPrepDate = ((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpRequiresRoboticPrepDateEdit")).SelectedDate.Value;
                    }

                    bool holdClientIssue = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ckbxHoldClientIssueEdit")).Checked;
                    bool holdLFSIssue = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ckbxHoldLFSIssueEdit")).Checked;
                    string flange = ((DropDownList)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ddlFlangeEdit")).SelectedValue;
                    bool lineLateral = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("cbxJlEdit")).Checked; ;
                    bool dyeTestReq = ((CheckBox)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("ckbxDyeTestReqEdit")).Checked;

                    DateTime? dyeTestComplete = null;
                    if (((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpDyeTestCompleteEdit")).SelectedDate.HasValue)
                    {
                        dyeTestComplete = ((RadDatePicker)grdLaterals.Rows[e.RowIndex].Cells[2].FindControl("tkrdpDyeTestCompleteEdit")).SelectedDate.Value;
                    }

                    // Update
                    FullLengthLiningLateralDetails lateralModel = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                    lateralModel.Update(lateral, lateralId, size, material, live, videoDistance, clockPosition, distanceToCentre, timeOpened, reverseSetup, reinstate, comments, inProject, clientLateralId, connectionType, mn, clientInspectionNo, requiredRoboticPrep, requiredRoboticPrepDate, holdClientIssue, holdLFSIssue, lineLateral, flange, lineLateral, dyeTestReq, dyeTestComplete);

                    tbxLaterals.Text = lateralModel.GetTotalLaterals().ToString();
                    tbxLiveLaterals.Text = lateralModel.GetLiveLaterals().ToString();

                    // Store dataset
                    Session["fullLengthLiningTDS"] = fullLengthLiningTDS;

                    // Update JL lateral issues
                    FLLateralsSave(lateralId, requiredRoboticPrep, requiredRoboticPrepDate, holdClientIssue, holdLFSIssue, dyeTestReq, dyeTestComplete);
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
        private void GrdJLinerAdd()
        {
            Page.Validate("dataFooter");
            if (Page.IsValid)
            {
                if (ValidateJlinerFooter())
                {
                    Guid id = new Guid(hdfSelectedId.Value);
                    int companyId = Convert.ToInt32(Session["companyID"]);
                    string detailId = ""; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxDetailIdFooter")).Text.Trim() != "") detailId = ((TextBox)grdJliner2.FooterRow.FindControl("tbxDetailIdFooter")).Text.Trim();
                    string address = ""; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxAddressFooter")).Text.Trim() != "") address = ((TextBox)grdJliner2.FooterRow.FindControl("tbxAddressFooter")).Text.Trim();
                    double? distanceFromUSMH = null; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim() != "") distanceFromUSMH = double.Parse(((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim());
                    int buildRebuild = 0;
                    bool inDatabase = false;
                    string issue = "No";

                    // Calculate fields
                    double? distanceFromDSMH = null;
                    if (distanceFromUSMH.HasValue)
                    {
                        Distance length = new Distance(tbxActualLength.Text.Trim()) - new Distance(distanceFromUSMH.ToString());
                        distanceFromDSMH = length.ToDoubleInEng3();
                    }

                    JlinerAddJunctionLiner2 model = new JlinerAddJunctionLiner2(jlinerAddTDS);
                    model.Insert(id, companyId, detailId, address, null, null, null, null, null, null, null, null, null, "", null, null, null, buildRebuild, null, null, null, distanceFromUSMH, distanceFromDSMH, "", issue, null, false, null, false, false, "", false, "", "", null, null, "", "", false, "", null, inDatabase);

                    Session.Remove("jliner2Dummy");
                    Session["jlinerAddTDS"] = jlinerAddTDS;
                    jliner2 = jlinerAddTDS.JunctionLiner2;
                    masterArea = jlinerAddTDS.MasterArea;
                    Session["masterArea"] = masterArea;

                    grdJliner2.DataBind();
                    grdJliner2.PageIndex = grdJliner2.PageCount - 1;
                }
            }
        }
        protected void tbxVideoLength_TextChanged(object sender, EventArgs e)
        {
            int workId = Int32.Parse(hdfWorkId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            string videoLength = tbxVideoLength.Text.Trim();

            // Update distance from dsmh and reverse setup
            FullLengthLiningLateralDetails fullLengthLiningLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
            fullLengthLiningLateralDetails.UpdateLengthReverseSetup(workId, assetId, videoLength);

            // Store dataset
            Session["fullLengthLiningTDS"] = fullLengthLiningTDS;

            for (int i = 0; i < grdLaterals.Rows.Count; i++)
            {
                if ((grdLaterals.Rows[i].RowType == DataControlRowType.DataRow) && ((grdLaterals.Rows[i].RowState == DataControlRowState.Normal) || (grdLaterals.Rows[i].RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
                {
                    // Reverse Setup calculation
                    string videoDistance = ((TextBox)grdLaterals.Rows[i].Cells[2].FindControl("tbxVideoDistance")).Text.Trim();
                    string reverseSetup = "";
                    if (videoDistance != "")
                    {
                        Distance videoLengthD = new Distance(tbxVideoLength.Text.Trim());
                        Distance videoDistanceD = new Distance(videoDistance);
                        Distance reverseSetupD = videoLengthD - videoDistanceD;

                        switch (videoDistanceD.DistanceType)
                        {
                            case 1:
                                reverseSetup = reverseSetupD.ToStringInEng1();
                                break;
                            case 2:
                                reverseSetup = reverseSetupD.ToStringInEng2();
                                break;
                            case 3:
                                reverseSetup = reverseSetupD.ToStringInEng3();
                                break;
                            case 4:
                                reverseSetup = reverseSetupD.ToStringInMet1();
                                break;
                            case 5:
                                reverseSetup = reverseSetupD.ToStringInMil1();
                                break;
                        }
                    }

                    reverseSetup = GetDistance(reverseSetup);

                    ((TextBox)grdLaterals.Rows[i].Cells[2].FindControl("tbxReverseSetup")).Text = reverseSetup;
                }
            }
        }
        protected void btnRectangularShapeOnClick(object sender, EventArgs e)
        {
            Page.Validate("mrRectangularShape");
            if (Page.IsValid)
            {
                if (ckbxRehabilitationDataImperial.Checked)
                {
                    Distance distanceRectangularRectangle1LongSide = new Distance(tbxRehabilitationDataRectangle1LongSide.Text);
                    decimal rectangle1LongSide = GetValueInEng3With2Decimals(distanceRectangularRectangle1LongSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle1LongSide.Text = rectangle1LongSide.ToString();

                    Distance distanceRectangularRectangle1ShortSide = new Distance(tbxRehabilitationDataRectangle1ShortSide.Text);
                    decimal rectangle1ShortSide = GetValueInEng3With2Decimals(distanceRectangularRectangle1ShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle1ShortSide.Text = rectangle1ShortSide.ToString();

                    Distance distanceRectangularRectangle1Depth = new Distance(tbxRehabilitationDataRectangle1Depth.Text);
                    decimal rectangle1Depth = GetValueInEng3With2Decimals(distanceRectangularRectangle1Depth.ToStringInEng3());
                    tbxRehabilitationDataRectangle1Depth.Text = rectangle1Depth.ToString();

                    Distance distanceRectangularRectangle2LongSide = new Distance(tbxRehabilitationDataRectangle2LongSide.Text);
                    decimal rectangle2LongSide = GetValueInEng3With2Decimals(distanceRectangularRectangle2LongSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle2LongSide.Text = rectangle2LongSide.ToString();

                    Distance distanceRectangularRectangle2ShortSide = new Distance(tbxRehabilitationDataRectangle2ShortSide.Text);
                    decimal rectangle2ShortSide = GetValueInEng3With2Decimals(distanceRectangularRectangle2ShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle2ShortSide.Text = rectangle2ShortSide.ToString();

                    Distance distanceRectangularRectangle2Depth = new Distance(tbxRehabilitationDataRectangle2Depth.Text);
                    decimal rectangle2Depth = GetValueInEng3With2Decimals(distanceRectangularRectangle2Depth.ToStringInEng3());
                    tbxRehabilitationDataRectangle2Depth.Text = rectangle2Depth.ToString();

                    // Recalculate Rectangle1 floor
                    decimal rectangle1Floor = 0;
                    tbxRehabilitationDataRectangle1Floor.Text = "";
                    if (ckbxRehabilitationDataRectangle1Floor.Checked)
                    {
                        rectangle1Floor = Decimal.Round((rectangle1LongSide * rectangle1ShortSide), 2);
                        Distance floorDistance = new Distance(rectangle1Floor.ToString());
                        tbxRehabilitationDataRectangle1Floor.Text = floorDistance.ToStringInEng3();
                    }

                    // Recalculate Rectangle1 ceiling
                    decimal rectangle1Ceiling = 0;
                    tbxRehabilitationDataRectangle1Ceiling.Text = "";
                    if (ckbxRehabilitationDataRectangle1Ceiling.Checked)
                    {
                        rectangle1Ceiling = Decimal.Round((rectangle1LongSide * rectangle1ShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangle1Ceiling.ToString());
                        tbxRehabilitationDataRectangle1Ceiling.Text = ceilingDistance.ToStringInEng3();

                        //Graphic
                        lblRectangular1CeilingLabel.Text = tbxRehabilitationDataRectangle1Ceiling.Text;
                    }

                    // Recalculate Rectangle1 benching
                    decimal rectangle1Benching = 0;
                    tbxRehabilitationDataRectangle1Benching.Text = "";
                    if (ckbxRehabilitationDataRectangle1Benching.Checked)
                    {
                        rectangle1Benching = Decimal.Round(((rectangle1LongSide * rectangle1ShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangle1Benching.ToString());
                        tbxRehabilitationDataRectangle1Benching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate rectangle 1 surface area
                    decimal rectangle1SurfaceArea = decimal.Round(((rectangle1LongSide * 2) + (rectangle1ShortSide * 2)) * rectangle1Depth, 2);
                    Distance rectangle1SurfaceAreaDistance = new Distance(rectangle1SurfaceArea.ToString());
                    tbxRehabilitationDataRectangle1SurfaceArea.Text = rectangle1SurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Rectangle2 floor
                    decimal rectangle2Floor = 0;
                    tbxRehabilitationDataRectangle2Floor.Text = "";
                    if (ckbxRehabilitationDataRectangle2Floor.Checked)
                    {
                        rectangle2Floor = Decimal.Round((rectangle2LongSide * rectangle2ShortSide), 2);
                        Distance floorDistance = new Distance(rectangle2Floor.ToString());
                        tbxRehabilitationDataRectangle2Floor.Text = floorDistance.ToStringInEng3();
                    }

                    // Recalculate Rectangle2 ceiling
                    decimal rectangle2Ceiling = 0;
                    tbxRehabilitationDataRectangle2Ceiling.Text = "";
                    if (ckbxRehabilitationDataRectangle2Ceiling.Checked)
                    {
                        rectangle2Ceiling = Decimal.Round((rectangle2LongSide * rectangle2ShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangle2Ceiling.ToString());
                        tbxRehabilitationDataRectangle2Ceiling.Text = ceilingDistance.ToStringInEng3();

                        //Graphic
                        lblRectangular2CeilingLabel.Text = tbxRehabilitationDataRectangle2Ceiling.Text;
                    }

                    // Recalculate Rectangle2 benching
                    decimal rectangle2Benching = 0;
                    tbxRehabilitationDataRectangle2Benching.Text = "";
                    if (ckbxRehabilitationDataRectangle2Benching.Checked)
                    {
                        rectangle2Benching = Decimal.Round(((rectangle2LongSide * rectangle2ShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangle2Benching.ToString());
                        tbxRehabilitationDataRectangle2Benching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate rectangle 2 surface area
                    decimal rectangle2SurfaceArea = decimal.Round(((rectangle2LongSide * 2) + (rectangle2ShortSide * 2)) * rectangle2Depth, 2);
                    Distance rectangle2SurfaceAreaDistance = new Distance(rectangle2SurfaceArea.ToString());
                    tbxRehabilitationDataRectangle2SurfaceArea.Text = rectangle2SurfaceAreaDistance.ToStringInEng3();

                    // Recalculate total depth
                    decimal totalDepth = decimal.Round(rectangle1Depth + rectangle2Depth, 0);
                    Distance totalDepthDistance = new Distance(totalDepth.ToString());
                    tbxRehabilitationDataRectangularTotalDepth.Text = totalDepthDistance.ToStringInEng3();

                    // Recalculate rectangle total surface area
                    decimal totalSurfaceArea = decimal.Round(rectangle1SurfaceArea + rectangle2SurfaceArea + rectangle1Floor + rectangle1Ceiling + rectangle1Benching + rectangle2Floor + rectangle2Ceiling + rectangle2Benching, 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangularTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // Graphic
                    lblRectangular1LongSideLabel.Text = tbxRehabilitationDataRectangle1LongSide.Text;
                    lblRectangular1ShortSideLabel.Text = tbxRehabilitationDataRectangle1ShortSide.Text;
                    lblRectangular1DephtLabel.Text = tbxRehabilitationDataRectangle1Depth.Text;
                    lblRectangle1SurfaceAreaLabel.Text = tbxRehabilitationDataRectangle1SurfaceArea.Text;

                    lblRectangle2LongSideLabel.Text = tbxRehabilitationDataRectangle2LongSide.Text;
                    lblRectangular2ShortSideLabel.Text = tbxRehabilitationDataRectangle2ShortSide.Text;
                    lblRectangular2Depth.Text = tbxRehabilitationDataRectangle2Depth.Text;
                    lblRectangle2SurfaceAreaLabel.Text = tbxRehabilitationDataRectangle2SurfaceArea.Text;

                    lblRectangularTotalDepthLabel.Text = tbxRehabilitationDataRectangularTotalDepth.Text;
                    lblRectangularTotalSurfaceAreaLabel.Text = "Total Surface Area: " + tbxRehabilitationDataRectangularTotalSurfaceArea.Text;

                    // Recalculate Top total surface area
                    decimal rectangle1TotalSurfaceArea = decimal.Round(rectangle1SurfaceArea + rectangle1Floor + rectangle1Ceiling + rectangle1Benching, 2);
                    Distance rectangle1TotalSurfaceAreaDistance = new Distance(rectangle1TotalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangle1TotalSurfaceArea.Text = rectangle1TotalSurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Down total surface area
                    decimal rectangle2TotalSurfaceArea = decimal.Round(rectangle2SurfaceArea + rectangle2Floor + rectangle2Ceiling + rectangle2Benching, 2);
                    Distance rectangle2TotalSurfaceAreaDistance = new Distance(rectangle2TotalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangle2TotalSurfaceArea.Text = rectangle2TotalSurfaceAreaDistance.ToStringInEng3();
                }
                else
                {
                    Distance distanceRectangularRectangle1LongSide = new Distance(tbxRehabilitationDataRectangle1LongSide.Text);
                    decimal rectangle1LongSide = GetValueInEng3With2Decimals(distanceRectangularRectangle1LongSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle1LongSide.Text = distanceRectangularRectangle1LongSide.ToStringInMet2();

                    Distance distanceRectangularRectangle1ShortSide = new Distance(tbxRehabilitationDataRectangle1ShortSide.Text);
                    decimal rectangle1ShortSide = GetValueInEng3With2Decimals(distanceRectangularRectangle1ShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle1ShortSide.Text = distanceRectangularRectangle1ShortSide.ToStringInMet2();

                    Distance distanceRectangularRectangle1Depth = new Distance(tbxRehabilitationDataRectangle1Depth.Text);
                    decimal rectangle1Depth = GetValueInEng3With2Decimals(distanceRectangularRectangle1Depth.ToStringInEng3());
                    tbxRehabilitationDataRectangle1Depth.Text = distanceRectangularRectangle1Depth.ToStringInMet2();

                    Distance distanceRectangularRectangle2LongSide = new Distance(tbxRehabilitationDataRectangle2LongSide.Text);
                    decimal rectangle2LongSide = GetValueInEng3With2Decimals(distanceRectangularRectangle2LongSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle2LongSide.Text = distanceRectangularRectangle2LongSide.ToStringInMet2();

                    Distance distanceRectangularRectangle2ShortSide = new Distance(tbxRehabilitationDataRectangle2ShortSide.Text);
                    decimal rectangle2ShortSide = GetValueInEng3With2Decimals(distanceRectangularRectangle2ShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangle2ShortSide.Text = distanceRectangularRectangle2ShortSide.ToStringInMet2();

                    Distance distanceRectangularRectangle2Depth = new Distance(tbxRehabilitationDataRectangle2Depth.Text);
                    decimal rectangle2Depth = GetValueInEng3With2Decimals(distanceRectangularRectangle2Depth.ToStringInEng3());
                    tbxRehabilitationDataRectangle2Depth.Text = distanceRectangularRectangle2Depth.ToStringInMet2();

                    // Recalculate Rectangle1 floor
                    decimal rectangle1Floor = 0;
                    tbxRehabilitationDataRectangle1Floor.Text = "";
                    if (ckbxRehabilitationDataRectangle1Floor.Checked)
                    {
                        rectangle1Floor = Decimal.Round((rectangle1LongSide * rectangle1ShortSide), 2);
                        Distance floorDistance = new Distance(rectangle1Floor.ToString());
                        tbxRehabilitationDataRectangle1Floor.Text = floorDistance.ToStringInMet2();
                    }

                    // Recalculate Rectangle1 ceiling
                    decimal rectangle1Ceiling = 0;
                    tbxRehabilitationDataRectangle1Ceiling.Text = "";
                    if (ckbxRehabilitationDataRectangle1Ceiling.Checked)
                    {
                        rectangle1Ceiling = Decimal.Round((rectangle1LongSide * rectangle1ShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangle1Ceiling.ToString());
                        tbxRehabilitationDataRectangle1Ceiling.Text = ceilingDistance.ToStringInMet2();

                        //Graphic
                        lblRectangular1CeilingLabel.Text = tbxRehabilitationDataRectangle1Ceiling.Text;
                    }

                    // Recalculate Rectangle1 benching
                    decimal rectangle1Benching = 0;
                    tbxRehabilitationDataRectangle1Benching.Text = "";
                    if (ckbxRehabilitationDataRectangle1Benching.Checked)
                    {
                        rectangle1Benching = Decimal.Round(((rectangle1LongSide * rectangle1ShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangle1Benching.ToString());
                        tbxRehabilitationDataRectangle1Benching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate rectangle 1 surface area
                    decimal rectangle1SurfaceArea = decimal.Round(((rectangle1LongSide * 2) + (rectangle1ShortSide * 2)) * rectangle1Depth, 2);
                    Distance rectangle1SurfaceAreaDistance = new Distance(rectangle1SurfaceArea.ToString());
                    tbxRehabilitationDataRectangle1SurfaceArea.Text = rectangle1SurfaceAreaDistance.ToStringInMet2();

                    // Recalculate Rectangle2 floor
                    decimal rectangle2Floor = 0;
                    tbxRehabilitationDataRectangle2Floor.Text = "";
                    if (ckbxRehabilitationDataRectangle2Floor.Checked)
                    {
                        rectangle2Floor  = Decimal.Round((rectangle2LongSide * rectangle2ShortSide), 2);
                        Distance floorDistance = new Distance(rectangle2Floor.ToString());
                        tbxRehabilitationDataRectangle2Floor.Text = floorDistance.ToStringInMet2();

                    }

                    // Recalculate Rectangle2 ceiling
                    decimal rectangle2Ceiling = 0;
                    tbxRehabilitationDataRectangle2Ceiling.Text = "";
                    if (ckbxRehabilitationDataRectangle2Ceiling.Checked)
                    {
                        rectangle2Ceiling = Decimal.Round((rectangle2LongSide * rectangle2ShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangle2Ceiling.ToString());
                        tbxRehabilitationDataRectangle2Ceiling.Text = ceilingDistance.ToStringInMet2();

                        //Graphic
                        lblRectangular2CeilingLabel.Text = tbxRehabilitationDataRectangle2Ceiling.Text;
                    }

                    // Recalculate Rectangle2 benching
                    decimal rectangle2Benching = 0;
                    tbxRehabilitationDataRectangle2Benching.Text = "";
                    if (ckbxRehabilitationDataRectangle2Benching.Checked)
                    {
                        rectangle2Benching = Decimal.Round(((rectangle2LongSide * rectangle2ShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangle2Benching.ToString());
                        tbxRehabilitationDataRectangle2Benching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate rectangle 2 surface area
                    decimal rectangle2SurfaceArea = decimal.Round(((rectangle2LongSide * 2) + (rectangle2ShortSide * 2)) * rectangle2Depth, 2);
                    Distance rectangle2SurfaceAreaDistance = new Distance(rectangle2SurfaceArea.ToString());
                    tbxRehabilitationDataRectangle2SurfaceArea.Text = rectangle2SurfaceAreaDistance.ToStringInMet2();

                    // Recalculate total depth
                    decimal totalDepth = decimal.Round(rectangle1Depth + rectangle2Depth, 0);
                    Distance totalDepthDistance = new Distance(totalDepth.ToString());
                    tbxRehabilitationDataRectangularTotalDepth.Text = totalDepthDistance.ToStringInMet2();

                    // Recalculate rectangle total surface area
                    decimal totalSurfaceArea = decimal.Round(rectangle1SurfaceArea + rectangle2SurfaceArea + rectangle1Floor + rectangle1Ceiling + rectangle1Benching + rectangle2Floor + rectangle2Ceiling + rectangle2Benching, 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangularTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // Graphic
                    lblRectangular1LongSideLabel.Text = tbxRehabilitationDataRectangle1LongSide.Text;
                    lblRectangular1ShortSideLabel.Text = tbxRehabilitationDataRectangle1ShortSide.Text;
                    lblRectangular1DephtLabel.Text = tbxRehabilitationDataRectangle1Depth.Text;
                    lblRectangle1SurfaceAreaLabel.Text = tbxRehabilitationDataRectangle1SurfaceArea.Text;

                    lblRectangle2LongSideLabel.Text = tbxRehabilitationDataRectangle2LongSide.Text;
                    lblRectangular2ShortSideLabel.Text = tbxRehabilitationDataRectangle2ShortSide.Text;
                    lblRectangular2Depth.Text = tbxRehabilitationDataRectangle2Depth.Text;
                    lblRectangle2SurfaceAreaLabel.Text = tbxRehabilitationDataRectangle2SurfaceArea.Text;

                    lblRectangularTotalDepthLabel.Text = tbxRehabilitationDataRectangularTotalDepth.Text;
                    lblRectangularTotalSurfaceAreaLabel.Text = "Total Surface Area: " + tbxRehabilitationDataRectangularTotalSurfaceArea.Text;

                    // Recalculate Top total surface area
                    decimal rectangle1TotalSurfaceArea = decimal.Round(rectangle1SurfaceArea + rectangle1Floor + rectangle1Ceiling + rectangle1Benching, 2);
                    Distance rectangle1TotalSurfaceAreaDistance = new Distance(rectangle1TotalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangle1TotalSurfaceArea.Text = rectangle1TotalSurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Down total surface area
                    decimal rectangle2TotalSurfaceArea = decimal.Round(rectangle2SurfaceArea + rectangle2Floor + rectangle2Ceiling + rectangle2Benching, 2);
                    Distance rectangle2TotalSurfaceAreaDistance = new Distance(rectangle2TotalSurfaceArea.ToString());
                    tbxRehabilitationDataRectangle2TotalSurfaceArea.Text = rectangle2TotalSurfaceAreaDistance.ToStringInEng3();
                }
            }
        }
        private void LoadWorkData(int workId, int assetId)
        {
            FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway(fullLengthLiningTDS);

            if (fullLengthLiningWorkDetailsGateway.Table.Rows.Count > 0)
            {
                // For Header
                tbxVideoLength.Text = fullLengthLiningWorkDetailsGateway.GetVideoLength(workId);

                // Load full length lining general data
                tbxGeneralClientId.Text = fullLengthLiningWorkDetailsGateway.GetClientId(workId);
                ckbxGeneralIssueIdentified.Checked = fullLengthLiningWorkDetailsGateway.GetIssueIdentified(workId);
                ckbxGeneralLfsIssue.Checked = fullLengthLiningWorkDetailsGateway.GetIssueLFS(workId);
                ckbxGeneralClientIssue.Checked = fullLengthLiningWorkDetailsGateway.GetIssueClient(workId);
                ckbxGeneralSalesIssue.Checked = fullLengthLiningWorkDetailsGateway.GetIssueSales(workId);
                ckbxGeneralIssueGivenToClient.Checked = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClient(workId);
                ckbxGeneralIssueResolved.Checked = fullLengthLiningWorkDetailsGateway.GetIssueResolved(workId);
                ckbxGeneralIssueInvestigation.Checked = fullLengthLiningWorkDetailsGateway.GetIssueInvestigation(workId);

                // ... Load Dates
                if (fullLengthLiningWorkDetailsGateway.GetProposedLiningDate(workId).HasValue)
                {
                    tkrdpGeneralProposedLiningDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetProposedLiningDate(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDate(workId).HasValue)
                {
                    tkrdpGeneralDeadlineLiningDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDate(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetP1Date(workId).HasValue)
                {
                    tkrdpPrepDataP1Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetP1Date(workId);
                    tkrdpGeneralP1Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetP1Date(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetM1Date(workId).HasValue)
                {
                    tkrdpM1DataM1Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetM1Date(workId);
                    tkrdpGeneralM1Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetM1Date(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetM2Date(workId).HasValue)
                {
                    tkrdpGeneralM2Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetM2Date(workId);
                    tkrdpM2DataM2Date.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetM2Date(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetInstallDate(workId).HasValue)
                {
                    tkrdpGeneralInstallDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetInstallDate(workId);
                    tkrdpInstallDataInstallDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetInstallDate(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId).HasValue)
                {
                    tkrdpGeneralFinalVideo.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId);
                    tkrdpInstallDataFinalVideoDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId);
                }

                // ... for RA data
                if (fullLengthLiningWorkDetailsGateway.GetPreFlushDate(workId).HasValue)
                {
                    tkrdpGeneralPreFlushDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetPreFlushDate(workId);
                    tkrdpGeneralPreFlushDateReadOnly.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetPreFlushDate(workId);
                }

                if (fullLengthLiningWorkDetailsGateway.GetPreVideoDate(workId).HasValue)
                {
                    tkrdpGeneralPreVideoDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetPreVideoDate(workId);
                    tkrdpGeneralPreVideoDateReadOnly.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetPreVideoDate(workId);
                }

                // For FullLengthLiningP1 data
                tbxPrepDataCXIsRemoved.Text = ""; if (fullLengthLiningWorkDetailsGateway.GetCxisRemoved(workId).HasValue) tbxPrepDataCXIsRemoved.Text = fullLengthLiningWorkDetailsGateway.GetCxisRemoved(workId).ToString();
                ckbxPrepDataRoboticPrepCompleted.Checked = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                if (fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workId).HasValue)
                {
                    tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate = (DateTime)fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                }
                ckbxPrepDataP1Completed.Checked = fullLengthLiningWorkDetailsGateway.GetP1Completed(workId);

                // For FullLengthLiningM1 data
                // ... for material
                ddlM1DataMaterial.SelectedValue = fullLengthLiningWorkDetailsGateway.GetMaterial(workId);

                // ... form m1 data
                tbxM1DataMeasurementsTakenBy.Text = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenBy(workId);
                ddlM1DataTrafficControl.SelectedValue = fullLengthLiningWorkDetailsGateway.GetTrafficControl(workId);
                if(fullLengthLiningWorkDetailsGateway.GetSiteDetails(workId) == "") ddlM1DataSiteDetails.SelectedIndex = 0; else ddlM1DataSiteDetails.SelectedValue = fullLengthLiningWorkDetailsGateway.GetSiteDetails(workId);
                if (fullLengthLiningWorkDetailsGateway.GetAccessType(workId) == "") ddlM1DataAccessType.SelectedIndex = 0; else ddlM1DataAccessType.SelectedValue = fullLengthLiningWorkDetailsGateway.GetAccessType(workId);
                ckbxM1DataPipeSizeChange.Checked = fullLengthLiningWorkDetailsGateway.GetPipeSizeChange(workId);
                ckbxM1DataStandardBypass.Checked = fullLengthLiningWorkDetailsGateway.GetStandardBypass(workId);
                tbxM1DataStandardBypassComments.Text = fullLengthLiningWorkDetailsGateway.GetStandardBypassComments(workId);
                tbxM1DataTrafficControlDetails.Text = fullLengthLiningWorkDetailsGateway.GetTrafficControlDetails(workId);
                ddlM1DataMeasurementType.SelectedValue = fullLengthLiningWorkDetailsGateway.GetMeasurementType(workId);
                ddlM1DataMeasuredFromMh.SelectedValue = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workId);
                tbxM1DataMeasuredFromMh.Text = ""; fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workId);
                ddlM1DataVideoDoneFromMh.SelectedValue = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMh(workId);
                tbxM1DataVideoDoneFromMh.Text = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMh(workId);
                ddlM1DataVideoDoneToMh.SelectedValue = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMh(workId);
                tbxM1DataVideoDoneToMh.Text = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMh(workId);

                // For FullLengthLiningM2 data
                tbxM2DataMeasurementsTakenBy.Text = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByM2(workId);
                ckbxM2DataDropPipe.Checked = fullLengthLiningWorkDetailsGateway.GetDropPipe(workId);
                tbxM2DataDropPipeInvertdepth.Text = fullLengthLiningWorkDetailsGateway.GetDropPipeInvertDepth(workId);
                tbxM2DataCappedLaterals.Text = ""; if (fullLengthLiningWorkDetailsGateway.GetCappedLaterals(workId).HasValue) tbxM2DataCappedLaterals.Text = fullLengthLiningWorkDetailsGateway.GetCappedLaterals(workId).ToString();
                tbxM2DataLineWidthId.Text = fullLengthLiningWorkDetailsGateway.GetLineWithId(workId);
                tbxM2DataHydrantAddress.Text = fullLengthLiningWorkDetailsGateway.GetHydrantAddress(workId);
                ddlM2DataHydroWireWithin10FtOfInversionMh.SelectedValue = fullLengthLiningWorkDetailsGateway.GetHydroWiredWithin10FtOfInversionMH(workId);
                tbxM2DataDistanceToInversionMH.Text = fullLengthLiningWorkDetailsGateway.GetDistanceToInversionMh(workId);
                if (fullLengthLiningWorkDetailsGateway.GetSurfaceGrade(workId) == "") ddlM2DataSurfaceGrade.SelectedIndex = 0; else ddlM2DataSurfaceGrade.SelectedValue = fullLengthLiningWorkDetailsGateway.GetSurfaceGrade(workId);
                cbxM2DataHydroPulley.Checked = fullLengthLiningWorkDetailsGateway.GetHydroPulley(workId);
                cbxM2DataFridgeCart.Checked = fullLengthLiningWorkDetailsGateway.GetFridgeCart(workId);
                cbxM2DataTwoPump.Checked = fullLengthLiningWorkDetailsGateway.GetTwoPump(workId);
                cbxM2DataSixBypass.Checked = fullLengthLiningWorkDetailsGateway.GetSixBypass(workId);
                cbxM2DataScaffolding.Checked = fullLengthLiningWorkDetailsGateway.GetScaffolding(workId);
                cbxM2DataWinchExtension.Checked = fullLengthLiningWorkDetailsGateway.GetWinchExtension(workId);
                cbxM2DataExtraGenerator.Checked = fullLengthLiningWorkDetailsGateway.GetExtraGenerator(workId);
                cbxM2DataGreyCableExtension.Checked = fullLengthLiningWorkDetailsGateway.GetGreyCableExtension(workId);
                cbxM2DataEasementMats.Checked = fullLengthLiningWorkDetailsGateway.GetEasementMats(workId);
                cbxM2DataRampsRequired.Checked = fullLengthLiningWorkDetailsGateway.GetRampRequired(workId);
                cbxM2DataCameraSkid.Checked = fullLengthLiningWorkDetailsGateway.GetCameraSkid(workId);

                // For FullLengthLiningWetOut data
                int companyId = Int32.Parse(hdfCompanyId.Value);

                // ... ... tube size = confirmed Size
                Distance confirmedSizeDistance = new Distance(tbxConfirmedSize.Text);
                double confirmedSize = 0;
                string[] confirmedSizeString = confirmedSizeDistance.ToStringInEng1().Split('\"');

                if (!confirmedSizeDistance.ToStringInEng1().Contains("'"))
                {
                    if (Validator.IsValidDouble(tbxConfirmedSize.Text))
                    {
                        confirmedSize = double.Parse(tbxConfirmedSize.Text);
                    }
                    else
                    {
                        confirmedSize = double.Parse(confirmedSizeString[0]);
                    }
                }
                else
                {
                    confirmedSize = Math.Ceiling(confirmedSizeDistance.ToDoubleInEng3()*12);
                    tbxConfirmedSize.Text = confirmedSize.ToString();
                }

                // ... Verify if work has wet out information
                WorkFullLengthLiningWetOutGateway workFullLengthLiningWetOutGateway = new WorkFullLengthLiningWetOutGateway();
                workFullLengthLiningWetOutGateway.LoadByWorkId(workId, companyId);

                if (workFullLengthLiningWetOutGateway.Table.Rows.Count > 0)
                {
                    // ... setup data
                    ddlWetOutDataLinerTube.SelectedValue = fullLengthLiningWorkDetailsGateway.GetLinerTube(workId);
                    if (ddlWetOutDataLinerTube.SelectedValue != "(Select)")
                    {
                        ckbxWetOutDataIncludeWetOutInformation.Checked = true;
                    }
                    else
                    {
                        ckbxWetOutDataIncludeWetOutInformation.Checked = false;
                    }

                    ddlWetOutDataResins.SelectedValue = fullLengthLiningWorkDetailsGateway.GetResinId(workId).ToString();
                    tbxWetOutDataExcessResin.Text = fullLengthLiningWorkDetailsGateway.GetExcessResin(workId).ToString();
                    ddlWetOutDataPoundsDrums.SelectedValue = fullLengthLiningWorkDetailsGateway.GetPoundsDrums(workId);
                    tbxWetOutDataDrumDiameter.Text = fullLengthLiningWorkDetailsGateway.GetDrumDiameter(workId).ToString();
                    tbxWetOutDataHoistMaximumHeight.Text = fullLengthLiningWorkDetailsGateway.GetHoistMaximumHeight(workId).ToString();
                    tbxWetOutDataHoistMinimumHeight.Text = fullLengthLiningWorkDetailsGateway.GetHoistMinimumHeight(workId).ToString();
                    tbxWetOutDataDownDropTubeLength.Text = fullLengthLiningWorkDetailsGateway.GetDownDropTubeLenght(workId).ToString();
                    tbxWetOutDataPumpHeightAboveGround.Text = fullLengthLiningWorkDetailsGateway.GetPumpHeightAboveGround(workId).ToString();
                    tbxWetOutDataTubeResinToFeltFactor.Text = fullLengthLiningWorkDetailsGateway.GetTubeResinToFeltFactor(workId).ToString();

                    // ... wet out sheet
                    DateTime wetOutDataDateOfSheet = fullLengthLiningWorkDetailsGateway.GetDateOfSheet(workId);
                    tbxWetOutDataDateOfSheet.Text = wetOutDataDateOfSheet.Month.ToString() + "/" + wetOutDataDateOfSheet.Day.ToString() + "/" + wetOutDataDateOfSheet.Year.ToString();
                    ddlWetOutDataMadeBy.SelectedValue = fullLengthLiningWorkDetailsGateway.GetEmployeeId(workId).ToString();
                    hdfRunDetails.Value = fullLengthLiningWorkDetailsGateway.GetRunDetails(workId);
                    ddlWetOutDataRunDetails2.SelectedValue = fullLengthLiningWorkDetailsGateway.GetRunDetails2(workId);
                    tkrdpWetOutDataWetOutDate.SelectedDate = fullLengthLiningWorkDetailsGateway.GetWetOutDate(workId);

                    tbxWetOutDataInstallDate.Text = "";
                    if (fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId).HasValue)
                    {
                        DateTime? wetOutDataInstallDate = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId);
                        DateTime wetOutDataInstallDateDateTime = (DateTime)wetOutDataInstallDate;
                        tbxWetOutDataInstallDate.Text = wetOutDataInstallDateDateTime.Month.ToString() + "/" + wetOutDataInstallDateDateTime.Day.ToString() + "/" + wetOutDataInstallDateDateTime.Year.ToString();
                    }

                    tbxWetOutDataTubeThickness.Text = fullLengthLiningWorkDetailsGateway.GetInversionThickness(workId);
                    tbxWetOutDataLengthToLine.Text = decimal.Round(decimal.Parse(fullLengthLiningWorkDetailsGateway.GetLengthToLine(workId).ToString()), 1).ToString();
                    tbxWetOutDataPlusExtra.Text = fullLengthLiningWorkDetailsGateway.GetPlusExtra(workId).ToString();
                    tbxWetOutDataForTurnOffset.Text = fullLengthLiningWorkDetailsGateway.GetForTurnOffset(workId).ToString();
                    tbxWetOutDataLengthtToWetOut.Text = fullLengthLiningWorkDetailsGateway.GetLengthToWetOut(workId).ToString();

                    tbxWetOutDataTubeMaxColdHead.Text = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHead(workId).ToString();
                    tbxWetOutDataTubeMaxColdHeadPSI.Text = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHeadPsi(workId).ToString();
                    tbxWetOutDataTubeMaxHotHead.Text = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHead(workId).ToString();
                    tbxWetOutDataTubeMaxHotHeadPSI.Text = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHeadPsi(workId).ToString();
                    tbxWetOutDataTubeIdealHead.Text = fullLengthLiningWorkDetailsGateway.GetTubeIdealHead(workId).ToString();
                    tbxWetOutDataTubeIdealHeadPSI.Text = fullLengthLiningWorkDetailsGateway.GetTubeIdealHeadPsi(workId).ToString();

                    tbxWetOutDataNetResinForTube.Text = fullLengthLiningWorkDetailsGateway.GetNetResinForTube(workId).ToString();
                    tbxWetOutDataNetResinForTubeUsgals.Text = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgals(workId).ToString();
                    tbxWetOutDataNetResinForTubeDrumsIns.Text = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeDrumsIns(workId);
                    tbxWetOutDataNetResinForTubeLbsFt.Text = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeLbsFt(workId).ToString();
                    tbxWetOutDataNetResinForTubeUsgFt.Text = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgFt(workId).ToString();

                    tbxWetOutDataExtraResinForMix.Text = fullLengthLiningWorkDetailsGateway.GetExtraResinForMix(workId).ToString();
                    tbxWetOutDataExtraLbsForMix.Text = fullLengthLiningWorkDetailsGateway.GetExtraLbsForMix(workId).ToString();
                    tbxWetOutDataTotalMixQuantity.Text = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantity(workId).ToString();
                    tbxWetOutDataTotalMixQuantityUsgals.Text = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityUsgals(workId).ToString();
                    tbxWetOutDataTotalMixQuantityDrumsIns.Text = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityDrumsIns(workId);

                    ddlWetOutDataInversionType.SelectedValue = fullLengthLiningWorkDetailsGateway.GetInversionType(workId);
                    tbxWetOutDataDepthOfInversionMH.Text = fullLengthLiningWorkDetailsGateway.GetDepthOfInversionMH(workId).ToString();
                    tbxWetOutDataTubeForColumn.Text = fullLengthLiningWorkDetailsGateway.GetTubeForColumn(workId).ToString();
                    tbxWetOutDataTubeForStartDry.Text = fullLengthLiningWorkDetailsGateway.GetTubeForStartDry(workId).ToString();
                    tbxWetOutDataTotalTube.Text = fullLengthLiningWorkDetailsGateway.GetTotalTube(workId).ToString();
                    tbxWetOutDataDropTubeConnects.Text = fullLengthLiningWorkDetailsGateway.GetDropTubeConnects(workId);
                    tbxWetOutDataAllowsHeadTo.Text = fullLengthLiningWorkDetailsGateway.GetAllowsHeadTo(workId).ToString();
                    tbxWetOutDataRollerGap.Text = fullLengthLiningWorkDetailsGateway.GetRollerGap(workId).ToString();

                    tbxWetOutDataHeightNeeded.Text = fullLengthLiningWorkDetailsGateway.GetHeightNeeded(workId).ToString();
                    tbxWetOutDataAvailable.Text = fullLengthLiningWorkDetailsGateway.GetAvailable(workId);
                    tbxWetOutDataHoistHeight.Text = fullLengthLiningWorkDetailsGateway.GetHoistHeight(workId);
                    hdfResinId.Value = fullLengthLiningWorkDetailsGateway.GetResinId(workId).ToString();
                    hdfMadeBy.Value = fullLengthLiningWorkDetailsGateway.GetEmployeeId(workId).ToString();
                    tbxWetOutDataNotes.Text = fullLengthLiningWorkDetailsGateway.GetCommentsCipp(workId);

                    lblWetOutDataResinGray.Text = fullLengthLiningWorkDetailsGateway.GetResinsLabel(workId);
                    lblWetOutDataDrumContainsGray.Text = fullLengthLiningWorkDetailsGateway.GetDrumContainsLabel(workId);
                    lblWetOutDataLinerTubeGray.Text = fullLengthLiningWorkDetailsGateway.GetLinerTubeLabel(workId);
                    lblWetOutDataLbDrumsGrey.Text = fullLengthLiningWorkDetailsGateway.GetForLbDrumsLabel(workId);
                    lblWetOutDataNetResinGrey.Text = fullLengthLiningWorkDetailsGateway.GetNetResinLabel(workId);
                    lblWetOutDataCatalystGrey.Text = fullLengthLiningWorkDetailsGateway.GetCatalystLabel(workId);

                    // ... ... graphic labels
                    lblWetOutDataDimensionLabel.Text = confirmedSize + " ins x " + ddlThickness.SelectedValue + " mm Tube";
                    lblWetOutDataTotalTubeLengthlabel.Text = "Total Tube Length " + tbxWetOutDataTotalTube.Text + " ft";
                    lblWetOutDataForColumnLabel.Text = tbxWetOutDataTubeForColumn.Text + " ft  for Column";
                    lblWetOutDataDryFtLabel.Text = "Dry " + tbxWetOutDataTubeForStartDry.Text + " ft";
                    lblWetOutDataWetOutLengthlabel.Text = "Wet-Out Length " + tbxWetOutDataLengthtToWetOut.Text + " ft";
                    lblWetOutDataDryFtEndLabel.Text = "Dry " + tbxWetOutDataTubeForColumn.Text + " ft";
                    lblWetOutDataTailEndlabel.Text = "Tail End";
                    lblWetOutDataColumnEndlabel.Text = "Column End";
                    lblWetOutDataRollerGapLabel.Text = "Roller Gap " + tbxWetOutDataRollerGap.Text + " mm";
                }
                else
                {
                    //  Wet Out Data
                    // ... Show current day for new sheets
                    DateTime sheetDate = DateTime.Now;
                    tbxWetOutDataDateOfSheet.Text = sheetDate.Month.ToString() + "/" + sheetDate.Day.ToString() + "/" + sheetDate.Year.ToString();

                    // Set default values.
                    tbxWetOutDataExcessResin.Text = "0.0";
                    ddlWetOutDataPoundsDrums.SelectedIndex = 1;
                    tbxWetOutDataDrumDiameter.Text = "22.5";
                    tbxWetOutDataHoistMaximumHeight.Text = "24";
                    tbxWetOutDataHoistMinimumHeight.Text = "5";
                    tbxWetOutDataDownDropTubeLength.Text = "19";
                    tbxWetOutDataPumpHeightAboveGround.Text = "6";
                    tbxWetOutDataTubeResinToFeltFactor.Text = "87";

                    tbxWetOutDataPlusExtra.Text = "3";
                    tbxWetOutDataForTurnOffset.Text = "0";

                    tbxWetOutDataExtraResinForMix.Text = "0";
                    tbxWetOutDataTubeForColumn.Text = "16";
                    tbxWetOutDataTubeForStartDry.Text = "3";
                    if (ddlWetOutDataInversionType.SelectedValue == "Top")
                    {
                        Distance usmhDepthDistance = new Distance(tbxM1DataUsmhDepth.Text);
                        tbxWetOutDataDepthOfInversionMH.Text = decimal.Round(decimal.Parse(usmhDepthDistance.ToStringInEng3()), 1).ToString();
                    }
                    else
                    {
                        if (ddlWetOutDataInversionType.SelectedValue == "Bottom")
                        {
                            Distance dsmhDepthDistance = new Distance(tbxM1DataDsmhDepth.Text);
                            tbxWetOutDataDepthOfInversionMH.Text = decimal.Round(decimal.Parse(dsmhDepthDistance.ToStringInEng3()), 1).ToString();
                        }
                        else
                        {
                            tbxWetOutDataDepthOfInversionMH.Text = "0";
                        }
                    }

                    tbxWetOutDataRollerGap.Text = "13";
                    tbxWetOutDataNotes.Text = fullLengthLiningWorkDetailsGateway.GetCommentsCipp(workId);

                    // ...Section values
                    // ... ... Length To Line = Steel Tape Length, the first section to consider is the work one in Xft Yin
                    Distance steelTapeLength = new Distance(tbxSteelTapeLength.Text);
                    tbxWetOutDataLengthToLine.Text = decimal.Round(decimal.Parse(steelTapeLength.ToStringInEng3()), 1).ToString();
                    tbxInversionDataRunLength.Text = decimal.Round(decimal.Parse(steelTapeLength.ToStringInEng3()),1).ToString();
                    double lengthToLine = double.Parse(steelTapeLength.ToStringInEng3());

                    // ... Run details
                    if (cbxlSectionId.Items.Count > 1)
                    {
                        hdfRunDetails.Value = hdfSectionId.Value;
                    }

                    // .... Install Date
                    tbxWetOutDataInstallDate.Text = "";
                    if (tkrdpInstallDataInstallDate.SelectedDate.ToString() != "")
                    {
                        DateTime? inversionDataInstalledOn = tkrdpInstallDataInstallDate.SelectedDate;
                        DateTime installedOnDateTime = (DateTime)inversionDataInstalledOn;

                        tbxWetOutDataInstallDate.Text = installedOnDateTime.Month.ToString() + "/" + installedOnDateTime.Day.ToString() + "/" + installedOnDateTime.Year.ToString();
                    }
                }

                // ... Verify if work has inversion information
                WorkFullLengthLiningInversionGateway workFullLengthLiningInversionGateway = new WorkFullLengthLiningInversionGateway();
                workFullLengthLiningInversionGateway.LoadByWorkId(workId, companyId);

                // ... Verify if work has inversion information
                if (workFullLengthLiningInversionGateway.Table.Rows.Count > 0)
                {
                    // ... Inversion data
                    lblInversionDataSubtitle.Text = fullLengthLiningWorkDetailsGateway.GetLinerTube(workId);

                    DateTime inversionDataDateOfSheet = fullLengthLiningWorkDetailsGateway.GetDateOfSheet(workId);
                    tbxInversionDataDateOfSheet.Text = inversionDataDateOfSheet.Month.ToString() + "/" + inversionDataDateOfSheet.Day.ToString() + "/" + inversionDataDateOfSheet.Year.ToString();

                    int employeeId = fullLengthLiningWorkDetailsGateway.GetEmployeeId(workId);
                    EmployeeGateway employeeGateway = new EmployeeGateway();
                    employeeGateway.LoadByEmployeeId(employeeId);
                    tbxInversionDataMadeBy.Text = employeeGateway.GetLastName(employeeId) + " " + employeeGateway.GetFirstName(employeeId);

                    tbxInversionDataInstalledOn.Text = "";
                    if (fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId).HasValue)
                    {
                        DateTime? inversionDataInstalledOn = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId);
                        DateTime inversionDataInstalledOnDateTime = (DateTime)inversionDataInstalledOn;
                        tbxInversionDataInstalledOn.Text = inversionDataInstalledOnDateTime.Month.ToString() + "/" + inversionDataInstalledOnDateTime.Day.ToString() + "/" + inversionDataInstalledOnDateTime.Year.ToString();
                    }

                    tbxInversionDataRunDetails2.Text = fullLengthLiningWorkDetailsGateway.GetRunDetails2(workId);
                    tbxInversionDataCommentsEdit.Text = fullLengthLiningWorkDetailsGateway.GetInversionComment(workId);
                    tbxInversionDataLinerSize.Text = confirmedSizeString + " ins x" + fullLengthLiningWorkDetailsGateway.GetInversionThickness(workId);
                    tbxInversionDataRunLength.Text = decimal.Round(decimal.Parse(fullLengthLiningWorkDetailsGateway.GetLengthToLine(workId).ToString()), 1).ToString();
                    tbxInversionDataWetOutLenght.Text = fullLengthLiningWorkDetailsGateway.GetLengthToWetOut(workId).ToString();

                    ddlInversionDataInversionPipeType.SelectedValue = fullLengthLiningWorkDetailsGateway.GetPipeType(workId);
                    if (ddlInversionDataInversionPipeType.SelectedValue != "(Select)")
                    {
                        ckbxInversionDataIncludeInversionInformation.Checked = true;
                    }
                    else
                    {
                        ckbxInversionDataIncludeInversionInformation.Checked = false;
                    }

                    ddlInversionDataPipeCondition.SelectedValue = fullLengthLiningWorkDetailsGateway.GetPipeCondition(workId);
                    ddlInversionDataGroundMoisture.SelectedValue = fullLengthLiningWorkDetailsGateway.GetGroundMoisture(workId);
                    tbxInversionDataBoilerSize.Text = fullLengthLiningWorkDetailsGateway.GetBoilerSize(workId).ToString();
                    tbxInversionDataPumpsTotalCapacity.Text = fullLengthLiningWorkDetailsGateway.GetPumpTotalCapacity(workId).ToString();
                    tbxInversionDataLayflatSize.Text = fullLengthLiningWorkDetailsGateway.GetLayFlatSize(workId).ToString();
                    tbxInversionDataLayflatQuantityTotal.Text = fullLengthLiningWorkDetailsGateway.GetLayFlatQuantityTotal(workId).ToString();

                    tbxInversionDataWaterStartTempTs.Text = fullLengthLiningWorkDetailsGateway.GetWaterStartTemp(workId).ToString();
                    tbxInversionDataTempT1.Text = fullLengthLiningWorkDetailsGateway.GetTemp1(workId).ToString();
                    tbxInversionDataHoldAtT1For.Text = fullLengthLiningWorkDetailsGateway.GetHoldAtT1(workId).ToString();
                    tbxInversionDataTempT2.Text = fullLengthLiningWorkDetailsGateway.GetTempT2(workId).ToString();
                    tbxInversionDataCookAtT2For.Text = fullLengthLiningWorkDetailsGateway.GetCookAtT2(workId).ToString();
                    tbxInversionDataCoolDownFor.Text = fullLengthLiningWorkDetailsGateway.GetCoolDownFor(workId).ToString();

                    tbxInversionDataCoolToTemp.Text = fullLengthLiningWorkDetailsGateway.GetCoolToTemp(workId).ToString();
                    tbxInversionDataDropInPipeRun.Text = fullLengthLiningWorkDetailsGateway.GetDropInPipeRun(workId).ToString();
                    tbxInversionDataPipeSlopeOf.Text = fullLengthLiningWorkDetailsGateway.GetPipeSlopOf(workId).ToString();

                    lblInversionData45F120F.Text = tbxInversionDataWaterStartTempTs.Text + "°F-" + tbxInversionDataTempT1.Text + "°F (hr)";
                    tbxInversionData45F120F.Text = fullLengthLiningWorkDetailsGateway.GetF45F120(workId).ToString();
                    tbxInversionDataHold.Text = fullLengthLiningWorkDetailsGateway.GetHold(workId).ToString();
                    lblInversionData120F185F.Text = tbxInversionDataTempT1.Text + "°F-" + tbxInversionDataTempT2.Text + "°F (hr)";
                    tbxInversionData120F185F.Text = fullLengthLiningWorkDetailsGateway.GetF120F185(workId).ToString();
                    tbxInversionDataCookTime.Text = fullLengthLiningWorkDetailsGateway.GetCookTime(workId).ToString();
                    tbxInversionDataCoolTime.Text = fullLengthLiningWorkDetailsGateway.GetCoolTime(workId).ToString();
                    tbxInversionDataAproxTotal.Text = fullLengthLiningWorkDetailsGateway.GetAproxTotal(workId).ToString();

                    tbxInversionDataWaterChangesPerHour.Text = fullLengthLiningWorkDetailsGateway.GetWaterChangesPerHour(workId).ToString();
                    tbxInversionDataReturnWaterVelocity.Text = fullLengthLiningWorkDetailsGateway.GetReturnWaterVelocity(workId).ToString();
                    tbxInversionDataLayflatBackPressure.Text = fullLengthLiningWorkDetailsGateway.GetLayflatBackPressure(workId).ToString();
                    tbxInversionDataPumpLiftAtIdealHead.Text = fullLengthLiningWorkDetailsGateway.GetPumpLiftAtIdealHead(workId).ToString();
                    tbxInversionDataWaterToFillLinerColumn.Text = fullLengthLiningWorkDetailsGateway.GetWaterToFillLinerColumn(workId).ToString();
                    tbxInversionDataWaterPerFit.Text = fullLengthLiningWorkDetailsGateway.GetWaterPerFit(workId).ToString();

                    tbxInversionDataNotesAndInstallationResults.Text = fullLengthLiningWorkDetailsGateway.GetInstallationResults(workId);

                    lblInversionDataLinerInfoGrey.Text = fullLengthLiningWorkDetailsGateway.GetInversionLinerTubeLabel(workId);
                    lblInversionDataHeadsGrey.Text = fullLengthLiningWorkDetailsGateway.GetHeadsIdealLabel(workId);
                    lblInversionDataPumpingCirculationSubtitle.Text = fullLengthLiningWorkDetailsGateway.GetPumpingAndCirculationLabel(workId);

                    // ... ... graphic labels
                    lblInversionDataMaxColdForTubeLabel.Text = tbxWetOutDataTubeMaxColdHead.Text + " ft = Max Cold for tube";
                    lblInversionDataMaxHotForTubeLabel.Text = tbxWetOutDataTubeMaxHotHead.Text + " ft = Max Hot for tube";
                    lblInversionDataIdelForTubeLabel.Text = tbxWetOutDataTubeIdealHead.Text + " ft = Ideal for tube";

                    double maxColdForTubeEnd = double.Parse(tbxWetOutDataTubeMaxColdHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                    lblInversionDataMaxColdForTubeEndLabel.Text = decimal.Round(decimal.Parse(maxColdForTubeEnd.ToString()), 1).ToString() + " ft";

                    double maxHotForTubeEnd = double.Parse(tbxWetOutDataTubeMaxHotHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                    lblInversionDataMaxHotForTubeEndLabel.Text = decimal.Round(decimal.Parse(maxHotForTubeEnd.ToString()), 1).ToString() + " ft";

                    double idealForTubeEnd = double.Parse(tbxWetOutDataTubeIdealHead.Text) + double.Parse(tbxInversionDataDropInPipeRun.Text);
                    lblInversionDataIdelForTubeEndLabel.Text = decimal.Round(decimal.Parse(idealForTubeEnd.ToString()), 1).ToString() + " ft";

                    lblInversionDataPumpHeightLabel.Text = "   " + tbxWetOutDataPumpHeightAboveGround.Text + " ft";
                    lblInversionDataLinerSizeLabel.Text = confirmedSize.ToString() + " ins x" + fullLengthLiningWorkDetailsGateway.GetInversionThickness(workId) + " Liner";

                    lblInversionDataRunLengthLabel.Text = "Run Length: " + tbxInversionDataRunLength.Text + " ft; Fall: " + tbxInversionDataDropInPipeRun.Text + " ft";
                    lblInversionDataDepthOfInversionMHLabel.Text = "   " + tbxWetOutDataDepthOfInversionMH.Text + " ft";
                    lblInversionDataEndLabel.Text = "End";
                }
                else
                {
                    //  Wet Out Data
                    // ... Show current day for new sheets
                    DateTime sheetDate = DateTime.Now;
                    tbxInversionDataDateOfSheet.Text = sheetDate.Month.ToString() + "/" + sheetDate.Day.ToString() + "/" + sheetDate.Year.ToString();

                    // Set default values.
                    lblInversionData45F120F.Text = "";
                    lblInversionData120F185F.Text = "";
                    tbxInversionDataBoilerSize.Text = "7000000";
                    tbxInversionDataPumpsTotalCapacity.Text = "300";
                    tbxInversionDataLayflatSize.Text = "4";
                    tbxInversionDataLayflatQuantityTotal.Text = "1";

                    tbxInversionDataWaterStartTempTs.Text = "45";
                    tbxInversionDataTempT1.Text = "120";
                    tbxInversionDataHoldAtT1For.Text = "0.5";
                    tbxInversionDataTempT2.Text = "185";
                    tbxInversionDataCookAtT2For.Text = "2";
                    tbxInversionDataCoolDownFor.Text = "1";
                    tbxInversionDataCoolToTemp.Text = "85";

                    // ...Section values
                    // ... ... Length To Line = Steel Tape Length, the first section to consider is the work one in Xft Yin
                    Distance steelTapeLength = new Distance(tbxSteelTapeLength.Text);
                    tbxInversionDataRunLength.Text = decimal.Round(decimal.Parse(steelTapeLength.ToStringInEng3()), 1).ToString();
                    double lengthToLine = double.Parse(steelTapeLength.ToStringInEng3());

                    // ... Run details
                    if (cbxlSectionId.Items.Count > 1)
                    {
                        hdfRunDetails.Value = hdfSectionId.Value;
                    }

                    // .... Install Date
                    tbxInversionDataInstalledOn.Text = "";
                    if (tkrdpInstallDataInstallDate.SelectedDate.ToString() != "")
                    {
                        DateTime? inversionDataInstalledOn = tkrdpInstallDataInstallDate.SelectedDate;
                        DateTime installedOnDateTime = (DateTime)inversionDataInstalledOn;

                        tbxInversionDataInstalledOn.Text = installedOnDateTime.Month.ToString() + "/" + installedOnDateTime.Day.ToString() + "/" + installedOnDateTime.Year.ToString();
                    }
                 }

                // ... Show FLL Comments + RA Comments
                int flWorkId = workId;

                // ... ... Get raWorkId
                int raWorkId = 0;
                int projectId = Int32.Parse(hdfCurrentProjectId.Value);
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Rehab Assessment", companyId);
                if (workGateway.Table.Rows.Count > 0)
                {
                    raWorkId = workGateway.GetWorkId(assetId, "Rehab Assessment", projectId);
                }

                // ... ... Get comments
                FullLengthLiningAllComments fullLengthLiningAllComments = new FullLengthLiningAllComments(fullLengthLiningTDS);
                fullLengthLiningAllComments.LoadAllByFlWorkIdRaWorkId(flWorkId, raWorkId, companyId);

                // ... ... Store datasets
                Session["fullLengthLiningTDS"] = fullLengthLiningTDS;

                // ... ... Show comments
                tbxCommentsDataComments.Text = fullLengthLiningAllComments.GetFLOrRAComments(companyId, fullLengthLiningAllComments.Table.Rows.Count, "\n");
            }
        }
        protected void btnRoundShapeOnClick(object sender, EventArgs e)
        {
            Page.Validate("mrRoundShape");
            if (Page.IsValid)
            {
                if (ckbxRehabilitationDataImperial.Checked)
                {
                    Distance distanceRoundChimneyDiameter = new Distance(tbxRehabilitationDataChimneyDiameter.Text);
                    decimal chimneyDiameter = GetValueInEng3With2Decimals(distanceRoundChimneyDiameter.ToStringInEng3());
                    tbxRehabilitationDataChimneyDiameter.Text = chimneyDiameter.ToString();

                    Distance distanceRoundChimneyDepth = new Distance(tbxRehabilitationDataChimneyDepth.Text);
                    decimal chimneyDepth = GetValueInEng3With2Decimals(distanceRoundChimneyDepth.ToStringInEng3());
                    tbxRehabilitationDataChimneyDepth.Text = chimneyDepth.ToString();

                    Distance distanceRoundBarrelDiameter = new Distance(tbxRehabilitationDataBarrelDiameter.Text);
                    decimal barrelDiameter = GetValueInEng3With2Decimals(distanceRoundBarrelDiameter.ToStringInEng3());
                    tbxRehabilitationDataBarrelDiameter.Text = barrelDiameter.ToString();

                    Distance distanceRoundBarrelDepth = new Distance(tbxRehabilitationDataBarrelDepth.Text);
                    decimal barrelDepth = GetValueInEng3With2Decimals(distanceRoundBarrelDepth.ToStringInEng3());
                    tbxRehabilitationDataBarrelDepth.Text = barrelDepth.ToString();

                    decimal pi = Decimal.Round(decimal.Parse(Math.PI.ToString()), 4);
                    double chimneyRadius = double.Parse(distanceRoundChimneyDiameter.ToStringInEng3()) / 2;
                    decimal chimneyRadiusSquare = decimal.Parse(Math.Pow(chimneyRadius, 2).ToString());
                    double barrelRadius = double.Parse(distanceRoundBarrelDiameter.ToStringInEng3()) / 2;
                    decimal barrelRadiusSquare = decimal.Parse(Math.Pow(barrelRadius, 2).ToString());

                    // Recalculate chimmney Floor
                    decimal chimneyFloor = 0;
                    tbxRehabilitationDataChimneyFloor.Text = "";
                    if (ckbxRehabilitationDataChimneyFloor.Checked)
                    {
                        chimneyFloor = Decimal.Round(pi * (chimneyRadiusSquare), 2);
                        Distance floorDistance = new Distance(chimneyFloor.ToString());
                        tbxRehabilitationDataChimneyFloor.Text = floorDistance.ToStringInEng3();
                    }

                    // Recalculate Chimney Ceiling
                    decimal chimneyCeiling = 0;
                    tbxRehabilitationDataChimneyCeiling.Text = "";
                    if (ckbxRehabilitationDataChimneyCeiling.Checked)
                    {
                        chimneyCeiling = Decimal.Round(pi * (chimneyRadiusSquare), 2);
                        Distance ceilingDistance = new Distance(chimneyCeiling.ToString());
                        tbxRehabilitationDataChimneyCeiling.Text = ceilingDistance.ToStringInEng3();

                        //Graphic
                        lblRoudChimneyCeilingLabel.Text = tbxRehabilitationDataChimneyCeiling.Text;
                    }

                    // Recalculate chimney Benching
                    decimal chimneyBenching = 0;
                    tbxRehabilitationDataChimneyBenching.Text = "";
                    if (ckbxRehabilitationDataChimneyBenching.Checked)
                    {
                        chimneyBenching = Decimal.Round((pi * (chimneyRadiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(chimneyBenching.ToString());
                        tbxRehabilitationDataChimneyBenching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate chimney surface area
                    decimal chimneyArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * chimneyDiameter) * chimneyDepth), 2);
                    Distance chimneyAreaDistance = new Distance(chimneyArea.ToString());
                    tbxRehabilitationDataChimneySurfaceArea.Text = chimneyAreaDistance.ToStringInEng3();

                    // Recalculate Barrel Floor
                    decimal barrelFloor = 0;
                    tbxRehabilitationDataBarrelFloor.Text = "";

                    if (ckbxRehabilitationDataBarrelFloor.Checked)
                    {
                        barrelFloor = Decimal.Round(pi * (barrelRadiusSquare), 2);
                        Distance floorDistance = new Distance(barrelFloor.ToString());
                        tbxRehabilitationDataBarrelFloor.Text = floorDistance.ToStringInEng3();
                    }

                    // Recalculate Barrel Ceiling
                    decimal barrelCeiling = 0;
                    tbxRehabilitationDataBarrelCeiling.Text = "";
                    if (ckbxRehabilitationDataBarrelCeiling.Checked)
                    {
                        barrelCeiling = Decimal.Round(pi * (barrelRadiusSquare), 2);
                        Distance ceilingDistance = new Distance(barrelCeiling.ToString());
                        tbxRehabilitationDataBarrelCeiling.Text = ceilingDistance.ToStringInEng3();

                        // Graphic
                        lblRoundBarrelCeilingLabel.Text = tbxRehabilitationDataBarrelCeiling.Text;
                    }

                    // Recalculate Barrel Benching
                    decimal barrelBenching = 0;
                    tbxRehabilitationDataBarrelBenching.Text = "";
                    if (ckbxRehabilitationDataBarrelBenching.Checked)
                    {
                        barrelBenching = Decimal.Round((pi * (barrelRadiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(barrelBenching.ToString());
                        tbxRehabilitationDataBarrelBenching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate Barrel surface area
                    decimal barrelArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * barrelDiameter) * barrelDepth), 2);
                    Distance barrelAreaDistance = new Distance(barrelArea.ToString());
                    tbxRehabilitationDataBarrelSurfaceArea.Text = barrelAreaDistance.ToStringInEng3();

                    // Recalculte total depth
                    decimal totalDepth = decimal.Round(chimneyDepth + barrelDepth, 0);
                    Distance totalDepthDistance = new Distance(totalDepth.ToString());
                    tbxRehabilitationDataRoundTotalDepth.Text = totalDepthDistance.ToStringInEng3();

                    // Recalculate total surface area
                    decimal totalSurfaceArea = decimal.Round((chimneyArea + barrelArea + chimneyFloor + chimneyCeiling + chimneyBenching + barrelFloor + barrelCeiling + barrelBenching), 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataRoundTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // For Graphic
                    lblRoudChimneyDiameterLabel.Text = tbxRehabilitationDataChimneyDiameter.Text;
                    lblRoudChimneyDepthLabel.Text = tbxRehabilitationDataChimneyDepth.Text;
                    lblRoundChimneySurfaceAreaLabel.Text = tbxRehabilitationDataChimneySurfaceArea.Text;

                    lblRoudBarrelDiameterLabel.Text = tbxRehabilitationDataBarrelDiameter.Text;
                    lblRoudBarrelDepthLabel.Text = tbxRehabilitationDataBarrelDepth.Text;
                    lblRoundBarrelSurfaceAreaLabel.Text = tbxRehabilitationDataBarrelSurfaceArea.Text;

                    lblRoundTotalDepthLabel.Text = tbxRehabilitationDataRoundTotalDepth.Text;
                    lblRoundTotalSurfaceArea.Text = "Total Surface Area: " + tbxRehabilitationDataRoundTotalSurfaceArea.Text;

                    decimal chimneyTotalSurfaceArea = decimal.Round(chimneyArea + chimneyFloor + chimneyCeiling + chimneyBenching, 2);
                    Distance chimneyTotalSurfaceAreaDistance = new Distance(chimneyTotalSurfaceArea.ToString());
                    tbxRehabilitationDataChimneyTotalSurfaceArea.Text = chimneyTotalSurfaceAreaDistance.ToStringInEng3();

                    decimal barrelTotalSurfaceArea = decimal.Round(barrelArea + barrelFloor + barrelCeiling + barrelBenching, 2);
                    Distance barrelTotalSurfaceAreaDistance = new Distance(barrelTotalSurfaceArea.ToString());
                    tbxRehabilitationDataBarrelTotalSurfaceArea.Text = barrelTotalSurfaceAreaDistance.ToStringInEng3();
                }
                else
                {
                    Distance distanceRoundChimneyDiameter = new Distance(tbxRehabilitationDataChimneyDiameter.Text);
                    decimal chimneyDiameter = decimal.Parse(distanceRoundChimneyDiameter.ToStringInEng3());
                    tbxRehabilitationDataChimneyDiameter.Text = distanceRoundChimneyDiameter.ToStringInMet2();

                    Distance distanceRoundChimneyDepth = new Distance(tbxRehabilitationDataChimneyDepth.Text);
                    decimal chimneyDepth = decimal.Parse(distanceRoundChimneyDepth.ToStringInEng3());
                    tbxRehabilitationDataChimneyDepth.Text = distanceRoundChimneyDepth.ToStringInMet2();

                    Distance distanceRoundBarrelDiameter = new Distance(tbxRehabilitationDataBarrelDiameter.Text);
                    decimal barrelDiameter = decimal.Parse(distanceRoundBarrelDiameter.ToStringInEng3());
                    tbxRehabilitationDataBarrelDiameter.Text = distanceRoundBarrelDiameter.ToStringInMet2();

                    Distance distanceRoundBarrelDepth = new Distance(tbxRehabilitationDataBarrelDepth.Text);
                    decimal barrelDepth = decimal.Parse(distanceRoundBarrelDepth.ToStringInEng3());
                    tbxRehabilitationDataBarrelDepth.Text = distanceRoundBarrelDepth.ToStringInMet2();

                    decimal pi = Decimal.Round(decimal.Parse(Math.PI.ToString()), 4);
                    double chimneyRadius = double.Parse(distanceRoundChimneyDiameter.ToStringInEng3()) / 2;
                    decimal chimneyRadiusSquare = decimal.Parse(Math.Pow(chimneyRadius, 2).ToString());
                    double barrelRadius = double.Parse(distanceRoundBarrelDiameter.ToStringInEng3()) / 2;
                    decimal barrelRadiusSquare = decimal.Parse(Math.Pow(barrelRadius, 2).ToString());

                    // Recalculate chimmney Floor
                    decimal chimneyFloor = 0;
                    tbxRehabilitationDataChimneyFloor.Text = "";
                    if (ckbxRehabilitationDataChimneyFloor.Checked)
                    {
                        chimneyFloor = Decimal.Round(pi * (chimneyRadiusSquare), 2);
                        Distance floorDistance = new Distance(chimneyFloor.ToString());
                        tbxRehabilitationDataChimneyFloor.Text = floorDistance.ToStringInMet2();
                    }

                    // Recalculate Chimney Ceiling
                    decimal chimneyCeiling = 0;
                    tbxRehabilitationDataChimneyCeiling.Text = "";
                    if (ckbxRehabilitationDataChimneyCeiling.Checked)
                    {
                        chimneyCeiling = Decimal.Round(pi * (chimneyRadiusSquare), 2);
                        Distance ceilingDistance = new Distance(chimneyCeiling.ToString());
                        tbxRehabilitationDataChimneyCeiling.Text = ceilingDistance.ToStringInMet2();

                        //Graphic
                        lblRoudChimneyCeilingLabel.Text = tbxRehabilitationDataChimneyCeiling.Text;
                    }

                    // Recalculate chimney Benching
                    decimal chimneyBenching = 0;
                    tbxRehabilitationDataChimneyBenching.Text = "";
                    if (ckbxRehabilitationDataChimneyBenching.Checked)
                    {
                        chimneyBenching = Decimal.Round((pi * (chimneyRadiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(chimneyBenching.ToString());
                        tbxRehabilitationDataChimneyBenching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate chimney surface area
                    decimal chimneyArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * chimneyDiameter) * chimneyDepth), 2);
                    Distance chimneyAreaDistance = new Distance(chimneyArea.ToString());
                    tbxRehabilitationDataChimneySurfaceArea.Text = chimneyAreaDistance.ToStringInMet2();

                    // Recalculate Barrel Floor
                    decimal barrelFloor = 0;
                    tbxRehabilitationDataBarrelFloor.Text = "";
                    if (ckbxRehabilitationDataBarrelFloor.Checked)
                    {
                        barrelFloor = Decimal.Round(pi * (barrelRadiusSquare), 2);
                        Distance floorDistance = new Distance(barrelFloor.ToString());
                        tbxRehabilitationDataBarrelFloor.Text = floorDistance.ToStringInMet2();
                    }

                    // Recalculate Barrel Ceiling
                    decimal barrelCeiling = 0;
                    tbxRehabilitationDataBarrelCeiling.Text = "";
                    if (ckbxRehabilitationDataBarrelCeiling.Checked)
                    {
                        barrelCeiling = Decimal.Round(pi * (barrelRadiusSquare), 2);
                        Distance ceilingDistance = new Distance(barrelCeiling.ToString());
                        tbxRehabilitationDataBarrelCeiling.Text = ceilingDistance.ToStringInMet2();

                        // Graphic
                        lblRoundBarrelCeilingLabel.Text = tbxRehabilitationDataBarrelCeiling.Text;
                    }

                    // Recalculate Barrel Benching
                    decimal barrelBenching = 0;
                    tbxRehabilitationDataBarrelBenching.Text = "";
                    if (ckbxRehabilitationDataBarrelBenching.Checked)
                    {
                        barrelBenching = Decimal.Round((pi * (barrelRadiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(barrelBenching.ToString());
                        tbxRehabilitationDataBarrelBenching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate Barrel surface area
                    decimal barrelArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * barrelDiameter) * barrelDepth), 2);
                    Distance barrelAreaDistance = new Distance(barrelArea.ToString());
                    tbxRehabilitationDataBarrelSurfaceArea.Text = barrelAreaDistance.ToStringInMet2();

                    // Recalculte total depth
                    decimal totalDepth = decimal.Round(chimneyDepth + barrelDepth, 0);
                    Distance totalDepthDistance = new Distance(totalDepth.ToString());
                    tbxRehabilitationDataRoundTotalDepth.Text = totalDepthDistance.ToStringInMet2();

                    // Recalculate total surface area
                    decimal totalSurfaceArea = decimal.Round((chimneyArea + barrelArea + chimneyFloor + chimneyCeiling + chimneyBenching + barrelFloor + barrelCeiling + barrelBenching), 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataRoundTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // For Graphic
                    lblRoudChimneyDiameterLabel.Text = tbxRehabilitationDataChimneyDiameter.Text;
                    lblRoudChimneyDepthLabel.Text = tbxRehabilitationDataChimneyDepth.Text;
                    lblRoundChimneySurfaceAreaLabel.Text = tbxRehabilitationDataChimneySurfaceArea.Text;

                    lblRoudBarrelDiameterLabel.Text = tbxRehabilitationDataBarrelDiameter.Text;
                    lblRoudBarrelDepthLabel.Text = tbxRehabilitationDataBarrelDepth.Text;
                    lblRoundBarrelSurfaceAreaLabel.Text = tbxRehabilitationDataBarrelSurfaceArea.Text;

                    lblRoundTotalDepthLabel.Text = tbxRehabilitationDataRoundTotalDepth.Text;
                    lblRoundTotalSurfaceArea.Text = "Total Surface Area: " + tbxRehabilitationDataRoundTotalSurfaceArea.Text;

                    decimal chimneyTotalSurfaceArea = decimal.Round(chimneyArea + chimneyFloor + chimneyCeiling + chimneyBenching, 2);
                    Distance chimneyTotalSurfaceAreaDistance = new Distance(chimneyTotalSurfaceArea.ToString());
                    tbxRehabilitationDataChimneyTotalSurfaceArea.Text = chimneyTotalSurfaceAreaDistance.ToStringInEng3();

                    decimal barrelTotalSurfaceArea = decimal.Round(barrelArea + barrelFloor + barrelCeiling + barrelBenching, 2);
                    Distance barrelTotalSurfaceAreaDistance = new Distance(barrelTotalSurfaceArea.ToString());
                    tbxRehabilitationDataBarrelTotalSurfaceArea.Text = barrelTotalSurfaceAreaDistance.ToStringInEng3();
                }
            }
        }
        /// <summary>
        /// UpdateFieldsForSections
        /// </summary>
        private void UpdateFieldsForSections()
        {
            foreach (RehabAssessmentTDS.SectionDetailsRow row in (RehabAssessmentTDS.SectionDetailsDataTable)Table)
            {
                if (!row.IsSize_Null())
                {
                    try
                    {
                        if (Distance.IsValidDistance(row.Size_))
                        {
                            Distance distance = new Distance(row.Size_);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    if (Convert.ToDouble(row.Size_) > 99)
                                    {
                                        double newSize_ = 0;
                                        newSize_ = Convert.ToDouble(row.Size_) * 0.03937;
                                        row.Size_ = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                    }
                                    else
                                    {
                                        if (Validator.IsValidInt32(row.Size_))
                                        {
                                            row.Size_ = row.Size_ + "\"";
                                        }
                                    }
                                    break;
                                case 4:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
        protected void btnMixedShapeOnClick(object sender, EventArgs e)
        {
            Page.Validate("mrMixedShape");
            if (Page.IsValid)
            {
                if (ckbxRehabilitationDataImperial.Checked)
                {
                    Distance distanceMixedRoundDiameter = new Distance(tbxRehabilitationDataRoundDiameter.Text);
                    decimal roundDiameter = GetValueInEng3With2Decimals(distanceMixedRoundDiameter.ToStringInEng3());
                    tbxRehabilitationDataRoundDiameter.Text = roundDiameter.ToString();

                    Distance distanceMixedRoundDepth = new Distance(tbxRehabilitationDataRoundDepth.Text);
                    decimal roundDepth = GetValueInEng3With2Decimals(distanceMixedRoundDepth.ToStringInEng3());
                    tbxRehabilitationDataRoundDepth.Text = roundDepth.ToString();

                    Distance distanceMixedRectangleLongSid = new Distance(tbxRehabilitationDataRectangleLongSide.Text);
                    decimal rectangleLongSide = GetValueInEng3With2Decimals(distanceMixedRectangleLongSid.ToStringInEng3());
                    tbxRehabilitationDataRectangleLongSide.Text = rectangleLongSide.ToString();

                    Distance distanceMixedShortSide = new Distance(tbxRehabilitationDataRectangleShortSide.Text);
                    decimal rectangleShortSide = GetValueInEng3With2Decimals(distanceMixedShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangleShortSide.Text = rectangleShortSide.ToString();

                    Distance distanceMixedRectangleDepth = new Distance(tbxRehabilitationDataRectangleDepth.Text);
                    decimal rectangleDepth = GetValueInEng3With2Decimals(distanceMixedRectangleDepth.ToStringInEng3());
                    tbxRehabilitationDataRectangleDepth.Text = rectangleDepth.ToString();

                    decimal pi = Decimal.Round(decimal.Parse(Math.PI.ToString()), 4);
                    double radius = double.Parse(distanceMixedRoundDiameter.ToStringInEng3()) / 2;
                    decimal radiusSquare = decimal.Parse(Math.Pow(radius, 2).ToString());

                    // Recalculate Round Floor
                    decimal roundFloor = 0;
                    tbxRehabilitationDataRoundFloor.Text = "";
                    if (ckbxRehabilitationDataRoundFloor.Checked)
                    {
                        roundFloor = Decimal.Round(pi * (radiusSquare), 2);
                        Distance floorDistance = new Distance(roundFloor.ToString());
                        tbxRehabilitationDataRoundFloor.Text = floorDistance.ToStringInEng3();
                    }

                    // Recalculate Round Ceiling
                    decimal roundCeiling = 0;
                    tbxRehabilitationDataRoundCeiling.Text = "";
                    if (ckbxRehabilitationDataRoundCeiling.Checked)
                    {
                        roundCeiling = Decimal.Round(pi * (radiusSquare), 2);
                        Distance ceilingDistance = new Distance(roundCeiling.ToString());
                        tbxRehabilitationDataRoundCeiling.Text = ceilingDistance.ToStringInEng3(); ;

                        // Graphic
                        lblDataRoundCeilingLabel.Text = tbxRehabilitationDataRoundCeiling.Text;
                    }

                    // Recalculate Round Benching
                    decimal roundBenching = 0;
                    tbxRehabilitationDataRoundBenching.Text = "";
                    if (ckbxRehabilitationDataRoundBenching.Checked)
                    {
                        roundBenching = Decimal.Round((pi * (radiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(roundBenching.ToString());
                        tbxRehabilitationDataRoundBenching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate round surface area
                    decimal roundSurfaceArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * roundDiameter) * roundDepth), 2);
                    Distance roundSurfaceAreaDistance = new Distance(roundSurfaceArea.ToString());
                    tbxRehabilitationDataRoundSurfaceArea.Text = roundSurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Rectangle floor
                    decimal rectangleFloor = 0;
                    tbxRehabilitationDataRectangleFloor.Text = "";
                    if (ckbxRehabilitationDataRectangleFloor.Checked)
                    {
                        rectangleFloor = Decimal.Round((rectangleLongSide * rectangleShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangleFloor.ToString());
                        tbxRehabilitationDataRectangleFloor.Text = ceilingDistance.ToStringInEng3();
                    }

                    // Recalculate Rectangle ceiling
                    decimal rectangleCeiling = 0;
                    tbxRehabilitationDataRectangleCeiling.Text = "";
                    if (ckbxRehabilitationDataRectangleCeiling.Checked)
                    {
                        rectangleCeiling = Decimal.Round((rectangleLongSide * rectangleShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangleCeiling.ToString());
                        tbxRehabilitationDataRectangleCeiling.Text = ceilingDistance.ToStringInEng3();

                        //Graphic
                        lblRectangleCeilingLabel.Text = tbxRehabilitationDataRectangleCeiling.Text;
                    }

                    // Recalculate Rectangle benching
                    decimal rectangleBenching = 0;
                    tbxRehabilitationDataRectangleBenching.Text = "";
                    if (ckbxRehabilitationDataRectangleBenching.Checked)
                    {
                        rectangleBenching = Decimal.Round(((rectangleLongSide * rectangleShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangleBenching.ToString());
                        tbxRehabilitationDataRectangleBenching.Text = benchingDistance.ToStringInEng3();
                    }

                    // Recalculate rectangle  surface area
                    decimal rectangleSurfaceArea = decimal.Round(((rectangleLongSide * 2) + (rectangleShortSide * 2)) * rectangleDepth, 2);
                    Distance rectangleSurfaceAreaDistance = new Distance(rectangleSurfaceArea.ToString());
                    tbxRehabilitationDataRectangleSufaceArea.Text = rectangleSurfaceAreaDistance.ToStringInEng3();

                    // Recalculte total depth
                    decimal totalDetph = decimal.Round((roundDepth + rectangleDepth), 0);
                    Distance totalDetphDistance = new Distance(totalDetph.ToString());
                    tbxRehabilitationDataMixedTotalDepth.Text = totalDetphDistance.ToStringInEng3();

                    // Recalculate total surface area
                    decimal totalSurfaceArea = decimal.Round(rectangleSurfaceArea + roundSurfaceArea + roundFloor + roundCeiling + roundBenching + rectangleFloor + rectangleCeiling + rectangleBenching, 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // Graphic
                    lblDataRoundDiameterLabel.Text = tbxRehabilitationDataRoundDiameter.Text;
                    lblDataRoundDepthLabel.Text = tbxRehabilitationDataRoundDepth.Text;
                    lblDataRoundSurfaceAreaLabel.Text = tbxRehabilitationDataRoundSurfaceArea.Text;

                    lblRectangleLongSideLabel.Text = tbxRehabilitationDataRectangleLongSide.Text;
                    lblRectangleShortSideLabel.Text = tbxRehabilitationDataRectangleShortSide.Text;
                    lblRectangleDephtLabel.Text = tbxRehabilitationDataRectangleDepth.Text;
                    lblRectangleSurfaceAreaLabel.Text = tbxRehabilitationDataRectangleSufaceArea.Text;

                    lblMixedTotalDepthLabel.Text = tbxRehabilitationDataMixedTotalDepth.Text;
                    lblTotalMixedSurfaceAreaLabel.Text = "Total Surface Area: " + tbxRehabilitationDataMixedTotalSurfaceArea.Text;

                    // Recalculate Top total surface area
                    decimal roundTotalSurfaceArea = decimal.Round(roundSurfaceArea + roundFloor + roundCeiling + roundBenching, 2);
                    Distance roundTotalSurfaceAreaDistance = new Distance(roundTotalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedRoundTotalSurfaceArea.Text = roundTotalSurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Down total surface area
                    decimal mixesRectangleTotalSurfaceArea = decimal.Round(rectangleSurfaceArea + rectangleFloor + rectangleCeiling + rectangleBenching, 2);
                    Distance mixesRectangleTotalSurfaceAreaDistance = new Distance(mixesRectangleTotalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedRectangleTotalSurfaceArea.Text = mixesRectangleTotalSurfaceAreaDistance.ToStringInEng3();
                }
                else
                {
                    Distance distanceMixedRoundDiameter = new Distance(tbxRehabilitationDataRoundDiameter.Text);
                    decimal roundDiameter = GetValueInEng3With2Decimals(distanceMixedRoundDiameter.ToStringInEng3());
                    tbxRehabilitationDataRoundDiameter.Text = distanceMixedRoundDiameter.ToStringInMet2();

                    Distance distanceMixedRoundDepth = new Distance(tbxRehabilitationDataRoundDepth.Text);
                    decimal roundDepth = GetValueInEng3With2Decimals(distanceMixedRoundDepth.ToStringInEng3());
                    tbxRehabilitationDataRoundDepth.Text = distanceMixedRoundDepth.ToStringInMet2();

                    Distance distanceMixedRectangleLongSid = new Distance(tbxRehabilitationDataRectangleLongSide.Text);
                    decimal rectangleLongSide = GetValueInEng3With2Decimals(distanceMixedRectangleLongSid.ToStringInEng3());
                    tbxRehabilitationDataRectangleLongSide.Text = distanceMixedRectangleLongSid.ToStringInMet2();

                    Distance distanceMixedShortSide = new Distance(tbxRehabilitationDataRectangleShortSide.Text);
                    decimal rectangleShortSide = GetValueInEng3With2Decimals(distanceMixedShortSide.ToStringInEng3());
                    tbxRehabilitationDataRectangleShortSide.Text = distanceMixedShortSide.ToStringInMet2();

                    Distance distanceMixedRectangleDepth = new Distance(tbxRehabilitationDataRectangleDepth.Text);
                    decimal rectangleDepth = decimal.Parse(distanceMixedRectangleDepth.ToStringInEng3());
                    tbxRehabilitationDataRectangleDepth.Text = distanceMixedRectangleDepth.ToStringInMet2();

                    decimal pi = Decimal.Round(decimal.Parse(Math.PI.ToString()), 4);
                    double radius = double.Parse(distanceMixedRoundDiameter.ToStringInEng3()) / 2;
                    decimal radiusSquare = decimal.Parse(Math.Pow(radius, 2).ToString());

                    // Recalculate Round Floor
                    decimal roundFloor = 0;
                    tbxRehabilitationDataRoundFloor.Text = "";
                    if (ckbxRehabilitationDataRoundFloor.Checked)
                    {
                        roundFloor = Decimal.Round(pi * (radiusSquare), 2);
                        Distance floorDistance = new Distance(roundFloor.ToString());
                        tbxRehabilitationDataRoundFloor.Text = floorDistance.ToStringInMet2();
                    }

                    // Recalculate Round Ceiling
                    decimal roundCeiling = 0;
                    tbxRehabilitationDataRoundCeiling.Text = "";
                    if (ckbxRehabilitationDataRoundCeiling.Checked)
                    {
                        roundCeiling = Decimal.Round(pi * (radiusSquare), 2);
                        Distance ceilingDistance = new Distance(roundCeiling.ToString());
                        tbxRehabilitationDataRoundCeiling.Text = ceilingDistance.ToStringInMet2(); ;

                        // Graphic
                        lblDataRoundCeilingLabel.Text = tbxRehabilitationDataRoundCeiling.Text;
                    }

                    // Recalculate Round Benching
                    decimal roundBenching = 0;
                    tbxRehabilitationDataRoundBenching.Text = "";
                    if (ckbxRehabilitationDataRoundBenching.Checked)
                    {
                        roundBenching = Decimal.Round((pi * (radiusSquare)) * decimal.Parse("0.06"), 2);
                        Distance benchingDistance = new Distance(roundBenching.ToString());
                        tbxRehabilitationDataRoundBenching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate round surface area
                    decimal roundSurfaceArea = Decimal.Round((2 * pi * (decimal.Parse("0.5") * roundDiameter) * roundDepth), 2);
                    Distance roundSurfaceAreaDistance = new Distance(roundSurfaceArea.ToString());
                    tbxRehabilitationDataRoundSurfaceArea.Text = roundSurfaceAreaDistance.ToStringInMet2();

                    // Recalculate Rectangle floor
                    decimal rectangleFloor = 0;
                    tbxRehabilitationDataRectangleFloor.Text = "";
                    if (ckbxRehabilitationDataRectangleFloor.Checked)
                    {
                        rectangleFloor = Decimal.Round((rectangleLongSide * rectangleShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangleFloor.ToString());
                        tbxRehabilitationDataRectangleFloor.Text = ceilingDistance.ToStringInMet2();
                    }

                    // Recalculate Rectangle ceiling
                    decimal rectangleCeiling = 0;
                    tbxRehabilitationDataRectangleCeiling.Text = "";
                    if (ckbxRehabilitationDataRectangleCeiling.Checked)
                    {
                        rectangleCeiling = Decimal.Round((rectangleLongSide * rectangleShortSide), 2);
                        Distance ceilingDistance = new Distance(rectangleCeiling.ToString());
                        tbxRehabilitationDataRectangleCeiling.Text = ceilingDistance.ToStringInMet2();

                        //Graphic
                        lblRectangleCeilingLabel.Text = tbxRehabilitationDataRectangleCeiling.Text;
                    }

                    // Recalculate Rectangle benching
                    decimal rectangleBenching = 0;
                    tbxRehabilitationDataRectangleBenching.Text = "";
                    if (ckbxRehabilitationDataRectangleBenching.Checked)
                    {
                        rectangleBenching = Decimal.Round(((rectangleLongSide * rectangleShortSide) * decimal.Parse("0.06")), 2);
                        Distance benchingDistance = new Distance(rectangleBenching.ToString());
                        tbxRehabilitationDataRectangleBenching.Text = benchingDistance.ToStringInMet2();
                    }

                    // Recalculate rectangle  surface area
                    decimal rectangleSurfaceArea = decimal.Round(((rectangleLongSide * 2) + (rectangleShortSide * 2)) * rectangleDepth, 2);
                    Distance rectangleSurfaceAreaDistance = new Distance(rectangleSurfaceArea.ToString());
                    tbxRehabilitationDataRectangleSufaceArea.Text = rectangleSurfaceAreaDistance.ToStringInMet2();

                    // Recalculte total depth
                    decimal totalDetph = decimal.Round((roundDepth + rectangleDepth), 0);
                    Distance totalDetphDistance = new Distance(totalDetph.ToString());
                    tbxRehabilitationDataMixedTotalDepth.Text = totalDetphDistance.ToStringInMet2();

                    // Recalculate total surface area
                    decimal totalSurfaceArea = decimal.Round(rectangleSurfaceArea + roundSurfaceArea + roundFloor + roundCeiling + roundBenching + rectangleFloor + rectangleCeiling + rectangleBenching, 0);
                    Distance totalSurfaceAreaDistance = new Distance(totalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedTotalSurfaceArea.Text = totalSurfaceAreaDistance.ToStringInEng3();

                    // Graphic
                    lblDataRoundDiameterLabel.Text = tbxRehabilitationDataRoundDiameter.Text;
                    lblDataRoundDepthLabel.Text = tbxRehabilitationDataRoundDepth.Text;
                    lblDataRoundSurfaceAreaLabel.Text = tbxRehabilitationDataRoundSurfaceArea.Text;

                    lblRectangleLongSideLabel.Text = tbxRehabilitationDataRectangleLongSide.Text;
                    lblRectangleShortSideLabel.Text = tbxRehabilitationDataRectangleShortSide.Text;
                    lblRectangleDephtLabel.Text = tbxRehabilitationDataRectangleDepth.Text;
                    lblRectangleSurfaceAreaLabel.Text = tbxRehabilitationDataRectangleSufaceArea.Text;

                    lblMixedTotalDepthLabel.Text = tbxRehabilitationDataMixedTotalDepth.Text;
                    lblTotalMixedSurfaceAreaLabel.Text = "Total Surface Area: " + tbxRehabilitationDataMixedTotalSurfaceArea.Text;

                    // Recalculate Top total surface area
                    decimal roundTotalSurfaceArea = decimal.Round(roundSurfaceArea + roundFloor + roundCeiling + roundBenching, 2);
                    Distance roundTotalSurfaceAreaDistance = new Distance(roundTotalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedRoundTotalSurfaceArea.Text = roundTotalSurfaceAreaDistance.ToStringInEng3();

                    // Recalculate Down total surface area
                    decimal mixesRectangleTotalSurfaceArea = decimal.Round(rectangleSurfaceArea + rectangleFloor + rectangleCeiling + rectangleBenching, 2);
                    Distance mixesRectangleTotalSurfaceAreaDistance = new Distance(mixesRectangleTotalSurfaceArea.ToString());
                    tbxRehabilitationDataMixedRectangleTotalSurfaceArea.Text = mixesRectangleTotalSurfaceAreaDistance.ToStringInEng3();
                }
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        private void ProcessDataForProject(int companyId)
        {
            ArrayList al = new ArrayList();
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;
            int linersAcum = 0;
            double totalHrsAcum = 0;

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepRow row1 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepDataTable)Table)
            {
                if (row1.Phase.Contains("Prep"))
                {
                    int workIdFll = GetWorkId(row1.ProjectID, row1.AssetID, "Full Length Lining", companyId);

                    FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway();
                    fullLengthLiningWorkDetailsGateway.LoadByWorkIdAssetId(workIdFll, row1.AssetID, companyId);

                    if (fullLengthLiningWorkDetailsGateway.Table.Rows.Count > 0)
                    {
                        string totalFt = fullLengthLiningWorkDetailsGateway.GetVideoLength(workIdFll);
                        if (totalFt != "")
                        {
                            Distance distOriginal = new Distance(totalFt);
                            row1.TotalFtDouble = distOriginal.ToDoubleInEng3();
                            row1.RealFt = distOriginal.ToDoubleInEng3();
                        }
                        else
                        {
                            row1.TotalFtDouble = 0;
                            row1.RealFt = 0;
                        }
                    }
                    else
                    {
                        row1.TotalFtDouble = 0;
                        row1.RealFt = 0;
                    }
                }

                if (!alDays.Contains(row1.Date))
                {
                    alDays.Add(row1.Date);
                    totalHrsAcum = totalHrsAcum + row1.Hrs;
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepRow row2 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepDataTable)Table)
            {
                if (row2.Phase.Contains("Prep"))
                {
                    rateAcum = rateAcum + row2.RealFt / row2.Hrs;
                }
                else
                {
                    if (row2.Phase.Contains("Install"))
                    {
                        linersAcum = linersAcum + row2.LinersInstalled;
                        rateAcum = rateAcum + (row2.Hrs / row2.LinersInstalled);
                        //row2.TotalHrs = totalHrsAcum;
                    }
                    else
                    {
                        linersAcum = linersAcum + row2.LinersReinstated;
                        rateAcum = rateAcum + (row2.Hrs / row2.LinersReinstated);
                        //row2.TotalHrs = totalHrsAcum;
                    }
                }

                row2.NumPeriods = alDays.Count;
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepRow row3 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhasePLPrepDataTable)Table)
            {
                if (row3.Phase.Contains("Prep"))
                {
                    row3.AverageRate = rateAcum / alDays.Count;
                }
                else
                {
                    row3.AverageRate = totalHrsAcum / linersAcum;
                }
            }
        }
        protected void cvRehabilitationDataChimneyDiameter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (args.Value.Trim() != "")
            {
                // Initialize
                CustomValidator cvRehabilitationDataChimneyDiameter = (CustomValidator)source;
                string shape = ddlShape.SelectedValue;
                args.IsValid = true;

                // Control of format
                if ((!Distance.IsValidDistance(args.Value)) && (shape == "Round"))
                {
                    cvRehabilitationDataChimneyDiameter.Text = "Invalid format. (please use X'Y\", or X\", or Xft Yin, or X.Y, or X.Ym, or X.Ymm)";
                    args.IsValid = false;
                    hdfErrorFieldList.Value = hdfErrorFieldList.Value + ", Chimney Diameter";
                }

                // Control of distance > 0
                if ((args.IsValid) && (shape == "Round"))
                {
                    Distance distance = new Distance(args.Value);
                    if (distance.ToDoubleInEng3() < 0)
                    {
                        cvRehabilitationDataChimneyDiameter.Text = "Invalid measurement. (must be equal or greater than 0)";
                        args.IsValid = false;
                        hdfErrorFieldList.Value = hdfErrorFieldList.Value + ", Chimney Diameter";
                    }
                }
            }
        }
        /// <summary>
        /// ProcessDataForProject
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <para>Process de data from the original table for the Project Costing report </para>  
        private void ProcessDataForProject(int currentProjectId, string currentPhase, int companyId)
        {
            ArrayList alDays = new ArrayList();
            double rateAcum = 0;
            int numPeriods = 0;

            string projectName = "";
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(currentProjectId);
            projectName = projectGateway.GetName(currentProjectId);

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRARow rowOriginal in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRADataTable)Table)
            {
                if (rowOriginal.ProjectName.Contains(projectName) && rowOriginal.Phase.Contains(currentPhase))
                {
                    if (!rowOriginal.IsTotalFtNull())
                    {
                        Distance distOriginal = new Distance(rowOriginal.TotalFt);
                        rowOriginal.TotalFtDouble = distOriginal.ToDoubleInEng3();
                        rowOriginal.RealFt = distOriginal.ToDoubleInEng3();
                    }
                    else
                    {
                        rowOriginal.TotalFtDouble = 0;
                        rowOriginal.RealFt = 0;
                    }

                    rateAcum = rateAcum + rowOriginal.RealFt / rowOriginal.Hrs;

                    // For get number of periods
                    if (!alDays.Contains(rowOriginal.Date))
                    {
                        alDays.Add(rowOriginal.Date);
                        numPeriods = numPeriods + 1;
                    }
                }
            }

            foreach (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRARow row2 in (PrintManhoursPerPhaseTDS.PrintManHoursPerPhaseRADataTable)Table)
            {
                if (row2.ProjectName.Contains(projectName) && row2.Phase.Contains(currentPhase))
                {
                    row2.AverageRate = rateAcum / numPeriods;
                    row2.NumPeriods = numPeriods;
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        /// <param name="unitType">unitType</param>
        private void UpdateForReport(string unitType)
        {
            FlReinstateLateralReportGateway flReinstateLateralReportGateway = new FlReinstateLateralReportGateway(Data);
            flReinstateLateralReportGateway.ClearBeforeFill = false;
            FlReinstateLateralReport flReinstateLateralReport = new FlReinstateLateralReport(Data);

            foreach (FlReinstateReportTDS.ReinstateSectionRow row in (FlReinstateReportTDS.ReinstateSectionDataTable)Table)
            {
                int workId = row.WorkID;
                FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway();
                fullLengthLiningWorkDetailsGateway.LoadByWorkIdAssetId(workId, row.AssetID, row.COMPANY_ID);
                string measurementFromMH = "USMH"; if (fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workId) != "") measurementFromMH = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workId);

                Distance d;

                if (unitType == "Metric")
                {
                    if (!row.IsSize_Null())
                    {
                        d = new Distance(row.Size_);
                        row.Size_ = d.ToStringInMet1();
                    }

                    if (!row.IsLengthNull())
                    {
                        d = new Distance(row.Length);
                        row.Length = d.ToStringInMet1();
                    }
                }

                if (unitType == "Imperial")
                {
                    if (!row.IsSize_Null())
                    {
                        if (Distance.IsValidDistance(row.Size_))
                        {
                            Distance distance = new Distance(row.Size_);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    if (Convert.ToDouble(row.Size_) > 99)
                                    {
                                        double newSize_ = 0;
                                        newSize_ = Convert.ToDouble(row.Size_) * 0.03937;
                                        row.Size_ = Convert.ToString(Math.Ceiling(newSize_)) + "\"";
                                    }
                                    else
                                    {
                                        row.Size_ = row.Size_ + "\"";
                                    }
                                    break;
                                case 4:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.Size_ = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }

                    if (!row.IsLengthNull())
                    {
                        d = new Distance(row.Length);
                        row.Length = d.ToStringInEng2();
                    }
                }

                flReinstateLateralReportGateway.LoadByAssetId(row.AssetID, row.COMPANY_ID);
                flReinstateLateralReport.UpdateForReport(row.FlowOrderID, unitType, measurementFromMH);
            }
        }