/// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int workId, int companyId)
        {
            WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
            workJunctionLiningSectionGateway.LoadByWorkId(workId, companyId);

            if (workJunctionLiningSectionGateway.Table.Rows.Count > 0)
            {
                WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                workJunctionLiningLateralGateway.LoadBySectionWorkId(workId, companyId);

                // ... Delete Laterals
                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral();

                foreach (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALRow row in (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALDataTable)workJunctionLiningLateralGateway.Table)
                {
                    workJunctionLiningLateral.DeleteDirect(row.WorkID, row.SectionWorkID, companyId);
                }

                // ... Delete WorkJunctionLiningSection
                workJunctionLiningSectionGateway.Delete(workId, companyId);

                // ... Delete work
                Work work = new Work(null);
                work.DeleteDirect(workId, companyId);
            }
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int workId, int sectionWorkId, int companyId)
        {
            // Delete WorkJunctionLiningLateral
            WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway(null);
            workJunctionLiningLateralGateway.Delete(workId, companyId);

            // Delete Work
            Work work = new Work(null);
            work.DeleteDirect(workId, companyId);

            // Update WorkJunctionLiningSection
            UpdateSection(sectionWorkId, workId, companyId);
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// UpdateSection        
        /// <param name="companyId">companyId</param>
        public void UpdateSection(int companyId)
        {
            foreach (Fix1WorkJuntionLiningSectionTDS.LFS_WORK_JUNCTIONLINING_SECTIONRow row in (Fix1WorkJuntionLiningSectionTDS.LFS_WORK_JUNCTIONLINING_SECTIONDataTable)Table)
            {
                WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
                workJunctionLiningSectionGateway.LoadByWorkId(row.WorkID, companyId);

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

                //  get new values of section
                int newAvailableToLine = 0;

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

                int delivered = 0;
                int installed = 0;
                foreach (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALRow row1 in (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALDataTable)workJunctionLiningLateralGateway.Table)
                {
                    if ((!row1.Deleted) && (!row1.OutOfScope))
                    {
                        if (!row1.IsDeliveredNull())  delivered++;
                        if (!row1.IsLinerInstalledNull()) installed++;
                    }
                }

                if (numLats > 0)
                {
                    newAvailableToLine = delivered - installed;
                }

                // Update Work Juntion Lining Section
                WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                workJunctionLiningSection.UpdateDirect(row.WorkID, numLats, notLinedYet, allMeasured, deleted, issueWithLaterals, notMeasuredYet, notDeliveredYet, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, newAvailableToLine);
            }
        }
        /// <summary>
        /// UpdateSection
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="lateralWorkId">lateralWorkId</param>
        /// <param name="companyId">companyId</param>
        public void UpdateSection(int sectionWorkId, int lateralWorkId, int companyId)
        {
            // load section
            WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
            workJunctionLiningSectionGateway.LoadByWorkId(sectionWorkId, companyId);

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

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

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

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

            if (newNumLats == 0) newAllMeasured = false;

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

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

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

            // Update Work Juntion Lining Section
            WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
            workJunctionLiningSection.UpdateDirect(sectionWorkId, numLats, notLinedYet, allMeasured, deleted, issueWithLaterals, notMeasuredYet, notDeliveredYet, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine, newNumLats, newNotLinedYet, newAllMeasured, newIssueWithLaterals, newNotMeasuredYet, newNotDeliveredYet, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, newAvailableToLine);
        }
        /// <summary>
        /// UpdateDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="originalPipeLocated">originalPipeLocated</param>
        /// <param name="originalServicesLocated">originalServicesLocated</param>
        /// <param name="originalCoInstalled">originalCoInstalled</param>
        /// <param name="originalBackfilledConcrete">originalBackfilledConcrete</param>
        /// <param name="originalBackfilledSoil">originalBackfilledSoil</param>
        /// <param name="originalGrouted">originalGrouted</param>
        /// <param name="originalCored">originalCored</param>
        /// <param name="originalPrepped">originalPrepped</param>
        /// <param name="originalMeasured">originalMeasured</param>
        /// <param name="originalLinerSize">originalLinerSize</param>
        /// <param name="originalInProcess">originalInProcess</param>
        /// <param name="originalInStock">originalInStock</param>
        /// <param name="originalDelivered">originalDelivered</param>
        /// <param name="originalBuildRebuild">originalBuildRebuild</param>
        /// <param name="originalPreVideo">originalPreVideo</param>
        /// <param name="originalLinerInstalled">originalLinerInstalled</param>
        /// <param name="originalFinalVideo">originalFinalVideo</param>
        /// <param name="originalCost">originalCost</param>
        /// <param name="originalVideoInspection">originalVideoInspection</param>
        /// <param name="originalCoRequired">originalCoRequired</param>
        /// <param name="originalPitRequired">originalPitRequired</param>
        /// <param name="originalCoPitLocation">originalCoPitLocation</param>
        /// <param name="originalPostContractDigRequired">originalPostContractDigRequired</param>
        /// <param name="originalCoCutDown">originalCoCutDown</param>
        /// <param name="originalFinalRestoration">originalFinalRestoration</param>
        /// <param name="originalDeleted">originalDeleted</param>
        /// <param name="originalCompanyId">originalCompanyId</param>
        /// <param name="originalVideoLengthToPropertyLine">originalVideoLengthToPropertyLine</param>
        /// <param name="originalLiningThruCo">originalLiningThruCo</param>
        /// <param name="originalNoticeDelivered">originalNoticeDelivered</param>
        /// <param name="originalHamiltonInspectionNumber">originalHamiltonInspectionNumber</param>
        /// <param name="originalFlange">originalFlange</param>
        /// <param name="originalGasket">originalGasket</param>
        /// <param name="originalDepthOfLocated">originalDepthOfLocated</param>
        /// <param name="originalDigRequiredPriorToLining">originalDigRequiredPriorToLining</param>
        /// <param name="originalDigRequiredPriorToLiningCompleted">originalDigRequiredPriorToLiningCompleted</param>
        /// <param name="originalDigRequiredAfterLining">originalDigRequiredAfterLining</param>
        /// <param name="originalDigRequiredAfterLiningCompleted">originalDigRequiredAfterLiningCompleted</param>
        /// <param name="originalOutOfScope">originalOutOfScope</param>
        /// <param name="originalHoldClientIssue">originalHoldClientIssue</param>
        /// <param name="originalHoldClientIssueResolved">originalHoldClientIssueResolved</param>
        /// <param name="originalHoldLFSIssue">originalHoldLFSIssue</param>
        /// <param name="originalHoldLFSIssueResolved">originalHoldLFSIssueResolved</param>
        /// <param name="originalRequiresRoboticPrep">originalRequiresRoboticPrep</param>
        /// <param name="originalRequiresRoboticPrep">originalRequiresRoboticPrep</param> 
        /// <param name="originalLinerType">originalLinerType</param>
        /// <param name="originalPrepType">originalPrepType</param>
        /// 
        /// <param name="newPipeLocated">newPipeLocated</param>
        /// <param name="newServicesLocated">newServicesLocated</param>
        /// <param name="newCoInstalled">newCoInstalled</param>
        /// <param name="newBackfilledConcrete">newBackfilledConcrete</param>
        /// <param name="newBackfilledSoil">newBackfilledSoil</param>
        /// <param name="newGrouted">newGrouted</param>
        /// <param name="newCored">newCored</param>
        /// <param name="newPrepped">newPrepped</param>
        /// <param name="newMeasured">newMeasured</param>
        /// <param name="newLinerSize">newLinerSize</param>
        /// <param name="newInProcess">newInProcess</param>
        /// <param name="newInStock">newInStock</param>
        /// <param name="newDelivered">newDelivered</param>
        /// <param name="newBuildRebuild">newBuildRebuild</param>
        /// <param name="newPreVideo">newPreVideo</param>
        /// <param name="newLinerInstalled">newLinerInstalled</param>
        /// <param name="newFinalVideo">newFinalVideo</param>
        /// <param name="newCost">newCost</param>
        /// <param name="newVideoInspection">newVideoInspection</param>
        /// <param name="newCoRequired">newCoRequired</param>
        /// <param name="newPitRequired">newPitRequired</param>
        /// <param name="newCoPitLocation">newCoPitLocation</param>
        /// <param name="newPostContractDigRequired">newPostContractDigRequired</param>
        /// <param name="newCoCutDown">newCoCutDown</param>
        /// <param name="newFinalRestoration">newFinalRestoration</param>
        /// <param name="companyId">companyId</param>
        /// <param name="newVideoLengthToPropertyLine">newVideoLengthToPropertyLine</param>
        /// <param name="newLiningThruCo">newLiningThruCo</param>
        /// <param name="newNoticeDelivered">newNoticeDelivered</param>
        /// <param name="newHamiltonInspectionNumber">newHamiltonInspectionNumber</param>
        /// <param name="newFlange">newFlange</param>
        /// <param name="newGasket">newGasket</param>
        /// <param name="newDepthOfLocated">newDepthOfLocated</param>
        /// <param name="newDigRequiredPriorToLining">newDigRequiredPriorToLining</param>
        /// <param name="newDigRequiredPriorToLiningCompleted">newDigRequiredPriorToLiningCompleted</param>
        /// <param name="newDigRequiredAfterLining">newDigRequiredAfterLining</param>
        /// <param name="newDigRequiredAfterLiningCompleted">newDigRequiredAfterLiningCompleted</param>
        /// <param name="newOutOfScope">newOutOfScope</param>
        /// <param name="newHoldClientIssue">newHoldClientIssue</param>
        /// <param name="newHoldClientIssueResolved">newHoldClientIssueResolved</param>
        /// <param name="newHoldLFSIssue">newHoldLFSIssue</param>
        /// <param name="newHoldLFSIssueResolved">newHoldLFSIssueResolved</param>
        /// <param name="newRequiresRoboticPrep">newRequiresRoboticPrep</param>
        /// <param name="newRequiresRoboticPrep">newRequiresRoboticPrep</param>
        /// <param name="newLinerType">newLinerType</param>
        /// <param name="newPrepType">newPrepType</param>
        /// <param name="dyeTestReq">dyeTestReq</param>
        /// <param name="dyeTestComplete">dyeTestComplete</param>
        public void UpdateDirect(int workId, int sectionWorkId, DateTime? originalPipeLocated, DateTime? originalServicesLocated, DateTime? originalCoInstalled, DateTime? originalBackfilledConcrete, DateTime? originalBackfilledSoil, DateTime? originalGrouted, DateTime? originalCored, DateTime? originalPrepped, DateTime? originalMeasured, string originalLinerSize, DateTime? originalInProcess, DateTime? originalInStock, DateTime? originalDelivered, int? originalBuildRebuild, DateTime? originalPreVideo, DateTime? originalLinerInstalled, DateTime? originalFinalVideo, decimal? originalCost, DateTime? originalVideoInspection, bool originalCoRequired, bool originalPitRequired, string originalCoPitLocation, bool originalPostContractDigRequired, DateTime? originalCoCutDown, DateTime? originalFinalRestoration, bool originalDeleted, int originalCompanyId, string originalVideoLengthToPropertyLine, bool originalLiningThruCo, DateTime? originalNoticeDelivered, string originalHamiltonInspectionNumber, string originalFlange, string originalGasket, string originalDepthOfLocated, bool originalDigRequiredPriorToLining, DateTime? originalDigRequiredPriorToLiningCompleted, bool originalDigRequiredAfterLining, DateTime? originalDigRequiredAfterLiningCompleted, bool originalOutOfScope, bool originalHoldClientIssue, DateTime? originalHoldClientIssueResolved, bool originalHoldLFSIssue, DateTime? originalHoldLFSIssueResolved, bool originalRequiresRoboticPrep, DateTime? originalRequiresRoboticPrepCompleted, string originalLinerType, string originalPrepType, bool originalDyeTestReq, DateTime? originalDyeTestComplete, DateTime? newPipeLocated, DateTime? newServicesLocated, DateTime? newCoInstalled, DateTime? newBackfilledConcrete, DateTime? newBackfilledSoil, DateTime? newGrouted, DateTime? newCored, DateTime? newPrepped, DateTime? newMeasured, string newLinerSize, DateTime? newInProcess, DateTime? newInStock, DateTime? newDelivered, int? newBuildRebuild, DateTime? newPreVideo, DateTime? newLinerInstalled, DateTime? newFinalVideo, decimal? newCost, DateTime? newVideoInspection, bool newCoRequired, bool newPitRequired, string newCoPitLocation, bool newPostContractDigRequired, DateTime? newCoCutDown, DateTime? newFinalRestoration, int companyId, string newVideoLengthToPropertyLine, bool newLiningThruCo, DateTime? newNoticeDelivered, string newHamiltonInspectionNumber, string newFlange, string newGasket, string newDepthOfLocated, bool newDigRequiredPriorToLining, DateTime? newDigRequiredPriorToLiningCompleted, bool newDigRequiredAfterLining, DateTime? newDigRequiredAfterLiningCompleted, bool newOutOfScope, bool newHoldClientIssue, DateTime? newHoldClientIssueResolved, bool newHoldLFSIssue, DateTime? newHoldLFSIssueResolved, bool newRequiresRoboticPrep, DateTime? newRequiresRoboticPrepCompleted, string newLinerType, string newPrepType, bool newDyeTestReq, DateTime? newDyeTestComplete, string originalContractYear, string newContractYear)
        {
            // Update WorkJunctionLiningLateral
            WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway(null);
            workJunctionLiningLateralGateway.Update(workId, sectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, originalDeleted, originalCompanyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, newPipeLocated, newServicesLocated, newCoInstalled, newBackfilledConcrete, newBackfilledSoil, newGrouted, newCored, newPrepped, newMeasured, newLinerSize, newInProcess, newInStock, newDelivered, newBuildRebuild, newPreVideo, newLinerInstalled, newFinalVideo,  newCost, newVideoInspection, newCoRequired, newPitRequired, newCoPitLocation, newPostContractDigRequired, newCoCutDown, newFinalRestoration, newVideoLengthToPropertyLine, newLiningThruCo, newNoticeDelivered, newHamiltonInspectionNumber, newFlange, newGasket, newDepthOfLocated, newDigRequiredPriorToLining, newDigRequiredPriorToLiningCompleted, newDigRequiredAfterLining, newDigRequiredAfterLiningCompleted, newOutOfScope, newHoldClientIssue, newHoldClientIssueResolved, newHoldLFSIssue, newHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, newLinerType, newPrepType, newDyeTestReq, newDyeTestComplete, originalContractYear, newContractYear);

            // Update WorkJunctionLiningSection
            UpdateSection(sectionWorkId, workId, companyId);
        }
        private bool LateralsCouldBeDeletedInJl(int lateral)
        {
            bool delete = false;

            // Get workId
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            string workType = hdfWorkType.Value;
            int projectId = Int32.Parse(hdfCurrentProjectId.Value);

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);

            int workIdJlLateral = GetWorkId(projectId, lateral, "Junction Lining Lateral", companyId);

            WorkJunctionLiningLateralGateway row = new WorkJunctionLiningLateralGateway();
            row.LoadByWorkId(workIdJlLateral, companyId);

            // All fields are empty for deleting a lateral on jl
            if ((!row.GetPipeLocated(workIdJlLateral).HasValue) && (!row.GetServicesLocated(workIdJlLateral).HasValue) && (!row.GetCoInstalled(workIdJlLateral).HasValue) && (!row.GetBackfilledConcrete(workIdJlLateral).HasValue) && (!row.GetBackfilledSoil(workIdJlLateral).HasValue) && (!row.GetGrouted(workIdJlLateral).HasValue) && (!row.GetCored(workIdJlLateral).HasValue) && (!row.GetPrepped(workIdJlLateral).HasValue) && (!row.GetMeasured(workIdJlLateral).HasValue) && (!row.GetInProcess(workIdJlLateral).HasValue) && (!row.GetInStock(workIdJlLateral).HasValue) && (!row.GetDelivered(workIdJlLateral).HasValue) && (!row.GetPreVideo(workIdJlLateral).HasValue) && (!row.GetLinerInstalled(workIdJlLateral).HasValue) && (!row.GetFinalVideo(workIdJlLateral).HasValue) && (!row.GetVideoInspection(workIdJlLateral).HasValue) && (!row.GetCoCutDown(workIdJlLateral).HasValue) && (!row.GetFinalRestoration(workIdJlLateral).HasValue) && (!row.GetNoticeDelivered(workIdJlLateral).HasValue) && (!row.GetHoldClientIssueResolved(workIdJlLateral).HasValue) && (!row.GetDigRequiredPriorToLiningCompleted(workIdJlLateral).HasValue) && (!row.GetHoldLFSIssueResolved(workIdJlLateral).HasValue) && (!row.GetDigRequiredAfterLiningCompleted(workIdJlLateral).HasValue) && (!row.GetLateralRequiresRoboticPrepCompleted(workIdJlLateral).HasValue))
            {
                if ((!row.GetCoRequired(workIdJlLateral)) && (!row.GetPitRequired(workIdJlLateral)) && (!row.GetLiningThruCo(workIdJlLateral)) && (!row.GetPostContractDigRequired(workIdJlLateral)) && (!row.GetDigRequiredPriorToLining(workIdJlLateral)) && (!row.GetDigRequiredAfterLining(workIdJlLateral)) && (!row.GetOutOfScope(workIdJlLateral)) && (!row.GetHoldClientIssue(workIdJlLateral)) && (!row.GetHoldLFSIssue(workIdJlLateral)) && (!row.GetLateralRequiresRoboticPrep(workIdJlLateral)) && (row.GetLinerSize(workIdJlLateral) == "") && (row.GetFlange(workIdJlLateral) == "") && (row.GetHamiltonInspectionNumber(workIdJlLateral) == "") && (row.GetCoPitLocation(workIdJlLateral) == "") && (row.GetPrepType(workIdJlLateral) == "") && (row.GetGasket(workIdJlLateral) == "") && (row.GetDepthOfLocated(workIdJlLateral) == "") && (row.GetLinerType(workIdJlLateral) == "") && (row.GetVideoLengthToPropertyLine(workIdJlLateral) == ""))
                {
                    if ((row.GetBuildRebuild(workIdJlLateral) == 0) && (row.GetCost(workIdJlLateral) == 0.00m))
                    {
                        delete = true;
                    }
                }
            }

            return delete;
        }
        /// <summary>
        /// Save a Previous JL work
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="companyId">companyId</param>
        private void SavePreviousJLWork(int projectId, int section_assetId, int companyId)
        {
            // Load Previous work  -  Junction Lining section data (last sections work)
            string workType = "Junction Lining Section";
            WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
            workJunctionLiningSectionGateway.LoadTop1ByProjectIdAssetIdWorkType(projectId, section_assetId, workType, companyId);

            int workId = workJunctionLiningSectionGateway.GetWorkIdTop1();
            int numLats = workJunctionLiningSectionGateway.GetNumLats(workId);
            int notLinedYet = workJunctionLiningSectionGateway.GetNotLinedYet(workId);
            Boolean allMeasured = workJunctionLiningSectionGateway.GetAllMeasured(workId);
            string issueWithLaterals = workJunctionLiningSectionGateway.GetIssueWithLaterals(workId);
            int notMeasuredYet = workJunctionLiningSectionGateway.GetNotMeasuredYet(workId);
            int notDeliveredYet = workJunctionLiningSectionGateway.GetNotDeliveredYet(workId);
            string trafficControl = ""; if (workJunctionLiningSectionGateway.GetTrafficControl(workId) != "") trafficControl = workJunctionLiningSectionGateway.GetTrafficControl(workId);
            string trafficControlDetails = ""; if (workJunctionLiningSectionGateway.GetTrafficControlDetails(workId) != "") trafficControlDetails = workJunctionLiningSectionGateway.GetTrafficControlDetails(workId);
            Boolean standardBypass = workJunctionLiningSectionGateway.GetStandardBypass(workId);
            string standardBypassComments = ""; if (workJunctionLiningSectionGateway.GetStandardBypassComments(workId) != "") standardBypassComments = workJunctionLiningSectionGateway.GetStandardBypassComments(workId);
            int availableToLine = workJunctionLiningSectionGateway.GetAvailableToLine(workId);

            // Load Previous work  -  General work data
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);

            int? libraryCategoriesId = null; if (workGateway.GetLibraryCategoriesId(workId).HasValue) libraryCategoriesId = workGateway.GetLibraryCategoriesId(workId);
            string comments = workGateway.GetComments(workId);
            string history = workGateway.GetHistory(workId);

            // Save new work
            WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
            int newSectionWorkId = workJunctionLiningSection.InsertDirect(projectId, section_assetId, libraryCategoriesId, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, false, companyId, comments, history, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine);

            // Load Previous work  - Junction Lining Lateral data
            WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
            workJunctionLiningLateralGateway.LoadBySectionWorkId(workId, companyId);

            foreach (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALRow lateralRow in (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALDataTable)workJunctionLiningLateralGateway.Table)
            {
                WorkGateway workGatewayForLateral = new WorkGateway();
                workGatewayForLateral.LoadByWorkId(lateralRow.WorkID, companyId);
                int lateral_assetId = workGatewayForLateral.GetAssetId(lateralRow.WorkID);

                DateTime? pipeLocated = null; if (!lateralRow.IsPipeLocatedNull()) pipeLocated = lateralRow.PipeLocated;
                DateTime? sevicesLocated = null; if (!lateralRow.IsServicesLocatedNull()) sevicesLocated = lateralRow.ServicesLocated;
                DateTime? coInstalled = null; if (!lateralRow.IsCoInstalledNull()) coInstalled = lateralRow.CoInstalled;
                DateTime? backfilledConcrete = null; if (!lateralRow.IsBackfilledConcreteNull()) backfilledConcrete = lateralRow.BackfilledConcrete;
                DateTime? backfilledSoil = null; if (!lateralRow.IsBackfilledSoilNull()) backfilledSoil = lateralRow.BackfilledSoil;
                DateTime? grouted = null; if (!lateralRow.IsGroutedNull()) grouted = lateralRow.Grouted;
                DateTime? cored = null; if (!lateralRow.IsCoredNull()) cored = lateralRow.Cored;
                DateTime? prepped = null; if (!lateralRow.IsPreppedNull()) prepped = lateralRow.Prepped;
                DateTime? measured = null; if (!lateralRow.IsMeasuredNull()) measured = lateralRow.Measured;
                string linerSize = ""; if (!lateralRow.IsLinerSizeNull()) linerSize = lateralRow.LinerSize;
                DateTime? inProcess = null; if (!lateralRow.IsInProcessNull()) inProcess = lateralRow.InProcess;
                DateTime? inStock = null; if (!lateralRow.IsInStockNull()) inStock = lateralRow.InStock;
                DateTime? delivered = null; if (!lateralRow.IsDeliveredNull()) delivered = lateralRow.Delivered;
                int? buildRebuild = null; if (!lateralRow.IsBuildRebuildNull()) buildRebuild = lateralRow.BuildRebuild;
                DateTime? preVideo = null; if (!lateralRow.IsPreVideoNull()) preVideo = lateralRow.PreVideo;
                DateTime? linerInstalled = null; if (!lateralRow.IsLinerInstalledNull()) linerInstalled = lateralRow.LinerInstalled;
                DateTime? finalVideo = null; if (!lateralRow.IsFinalVideoNull()) finalVideo = lateralRow.FinalVideo;
                decimal? cost = null; if (!lateralRow.IsCostNull()) cost = lateralRow.Cost;
                DateTime? videoInspection = null; if (!lateralRow.IsVideoInspectionNull()) videoInspection = lateralRow.VideoInspection;
                bool coRequired = lateralRow.CoRequired;
                bool pitRequired = lateralRow.PitRequired;
                string coPitLocation = ""; if (!lateralRow.IsCoPitLocationNull()) coPitLocation = lateralRow.CoPitLocation;
                bool postContractDigRequired = lateralRow.PostContractDigRequired;
                DateTime? coCutDown = null; if (!lateralRow.IsCoCutDownNull()) coCutDown = lateralRow.CoCutDown;
                DateTime? finalRestoration = null; if (!lateralRow.IsFinalRestorationNull()) finalRestoration = lateralRow.FinalRestoration;
                string videoLengthToPropertyLine = ""; if (!lateralRow.IsVideoLengthToPropertyLineNull()) videoLengthToPropertyLine = lateralRow.VideoLengthToPropertyLine;
                bool liningThruCo = lateralRow.LiningThruCo;
                DateTime? noticeDelivered = null; if (!lateralRow.IsNoticeDeliveredNull()) noticeDelivered = lateralRow.NoticeDelivered;
                string hamiltonInspectionNumber = ""; if (!lateralRow.IsHamiltonInspectionNumberNull()) hamiltonInspectionNumber = lateralRow.HamiltonInspectionNumber;
                string flange = ""; if (!lateralRow.IsFlangeNull()) flange = lateralRow.Flange;
                string gasket = ""; if (!lateralRow.IsGasketNull()) gasket = lateralRow.Gasket;
                string depthOfLocated = ""; if (!lateralRow.IsDepthOfLocatedNull()) depthOfLocated = lateralRow.DepthOfLocated;
                bool digRequiredPriorToLining = lateralRow.DigRequiredPriorToLining;
                DateTime? digRequiredPriorToLiningCompleted = null; if (!lateralRow.IsDigRequiredPriorToLiningCompletedNull()) digRequiredPriorToLiningCompleted = lateralRow.DigRequiredPriorToLiningCompleted;
                bool digRequiredAfterLining = lateralRow.DigRequiredAfterLining;
                DateTime? digRequiredAfterLiningCompleted = null; if (!lateralRow.IsDigRequiredAfterLiningCompletedNull()) digRequiredAfterLiningCompleted = lateralRow.DigRequiredAfterLiningCompleted;
                bool outOfScope = lateralRow.OutOfScope;
                bool holdClientIssue = lateralRow.HoldClientIssue;
                DateTime? holdClientIssueResolved = null; if (!lateralRow.IsHoldClientIssueResolvedNull()) holdClientIssueResolved = lateralRow.HoldClientIssueResolved;
                bool holdLFSIssue = lateralRow.HoldLFSIssue;
                DateTime? holdLFSIssueResolved = null; if (!lateralRow.IsHoldLFSIssueResolvedNull()) holdLFSIssueResolved = lateralRow.HoldLFSIssueResolved;
                bool requiresRoboticPrep = lateralRow.LateralRequiresRoboticPrep;
                DateTime? requiresRoboticPrepCompleted = null; if (!lateralRow.IsLateralRequiresRoboticPrepCompletedNull()) requiresRoboticPrepCompleted = lateralRow.LateralRequiresRoboticPrepCompleted;
                string linerType = ""; if (!lateralRow.IsLinerTypeNull()) linerType = lateralRow.LinerType;
                string prepType = ""; if (!lateralRow.IsPrepTypeNull()) prepType = lateralRow.PrepType;
                bool dyeTestReq = lateralRow.DyeTestReq;
                DateTime? dyeTestComplete = null; if (!lateralRow.IsDyeTestCompleteNull()) dyeTestComplete = lateralRow.DyeTestComplete;
                string contractYear = ""; if (!lateralRow.IsContractYearNull()) contractYear = lateralRow.ContractYear;

                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                workJunctionLiningLateral.InsertDirect(projectId, lateral_assetId, newSectionWorkId, pipeLocated, sevicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, delivered, buildRebuild, preVideo, linerInstalled, finalVideo, cost, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, false, companyId, comments, history, videoLengthToPropertyLine, liningThruCo, noticeDelivered, hamiltonInspectionNumber, flange, gasket, depthOfLocated, digRequiredPriorToLining, digRequiredPriorToLiningCompleted, digRequiredAfterLining, digRequiredAfterLiningCompleted, outOfScope, holdClientIssue, holdClientIssueResolved, holdLFSIssue, holdLFSIssueResolved, requiresRoboticPrep, requiresRoboticPrepCompleted, linerType, prepType, dyeTestReq, dyeTestComplete, contractYear);
            }

            // Load Previous work  - Comments and History
            SavePreviousComments(workId, workType, companyId, newSectionWorkId);
            SavePreviousHistory(workId, workType, companyId, newSectionWorkId);
        }
        /// <summary>
        /// UpdateForReport
        /// </summary>
        public void UpdateForReport()
        {
            foreach (JltoBuildReportTDS.JLToBuildRow jlToBuildRow in ((JltoBuildReportTDS.JLToBuildDataTable)Table))
            {
                // Load work
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByProjectIdAssetIdWorkType(jlToBuildRow.ProjectID, jlToBuildRow.AssetID, "Junction Lining Lateral", jlToBuildRow.COMPANY_ID);
                int workId = workGateway.GetWorkId(jlToBuildRow.AssetID, "Junction Lining Lateral", jlToBuildRow.ProjectID);

                // Load Laterals in work
                WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                workJunctionLiningLateralGateway.LoadByWorkId(workId, jlToBuildRow.COMPANY_ID);

                // Load original data
                DateTime? originalPipeLocated = workJunctionLiningLateralGateway.GetPipeLocated(workId);
                int sectionWorkId = workJunctionLiningLateralGateway.GetSectionWorkID(workId);
                DateTime? originalServicesLocated = workJunctionLiningLateralGateway.GetServicesLocated(workId);
                DateTime? originalCoInstalled = workJunctionLiningLateralGateway.GetCoInstalled(workId);
                DateTime? originalBackfilledConcrete = workJunctionLiningLateralGateway.GetBackfilledConcrete(workId);
                DateTime? originalBackfilledSoil = workJunctionLiningLateralGateway.GetBackfilledSoil(workId);
                DateTime? originalGrouted = workJunctionLiningLateralGateway.GetGrouted(workId);
                DateTime? originalCored = workJunctionLiningLateralGateway.GetCored(workId);
                DateTime? originalPrepped = workJunctionLiningLateralGateway.GetPrepped(workId);
                DateTime? originalMeasured = workJunctionLiningLateralGateway.GetMeasured(workId);
                string originalLinerSize = workJunctionLiningLateralGateway.GetLinerSize(workId);
                DateTime? originalInProcess = workJunctionLiningLateralGateway.GetInProcess(workId);
                DateTime? originalInStock = workJunctionLiningLateralGateway.GetInStock(workId);
                DateTime? originalDelivered = workJunctionLiningLateralGateway.GetDelivered(workId);
                int? originalBuildRebuild = workJunctionLiningLateralGateway.GetBuildRebuild(workId);
                DateTime? originalPreVideo = workJunctionLiningLateralGateway.GetPreVideo(workId);
                DateTime? originalLinerInstalled = workJunctionLiningLateralGateway.GetLinerInstalled(workId);
                DateTime? originalFinalVideo = workJunctionLiningLateralGateway.GetFinalVideo(workId);
                decimal? originalCost = workJunctionLiningLateralGateway.GetCost(workId);
                DateTime? originalVideoInspection = workJunctionLiningLateralGateway.GetVideoInspection(workId);
                bool originalCoRequired = workJunctionLiningLateralGateway.GetCoRequired(workId);
                bool originalPitRequired = workJunctionLiningLateralGateway.GetPitRequired(workId);
                string originalCoPitLocation = workJunctionLiningLateralGateway.GetCoPitLocation(workId);
                bool originalPostContractDigRequired = workJunctionLiningLateralGateway.GetPostContractDigRequired(workId);
                DateTime? originalCoCutDown = workJunctionLiningLateralGateway.GetCoCutDown(workId);
                DateTime? originalFinalRestoration = workJunctionLiningLateralGateway.GetFinalRestoration(workId);
                string originalVideoLengthToPropertyLine = workJunctionLiningLateralGateway.GetVideoLengthToPropertyLine(workId);
                bool originalLiningThruCo = workJunctionLiningLateralGateway.GetLiningThruCo(workId);
                DateTime? originalNoticeDelivered = workJunctionLiningLateralGateway.GetNoticeDelivered(workId);
                string originalHamiltonInspectionNumber = workJunctionLiningLateralGateway.GetHamiltonInspectionNumber(workId);
                string originalFlange = workJunctionLiningLateralGateway.GetFlange(workId);
                string originalGasket = workJunctionLiningLateralGateway.GetGasket(workId);
                string originalDepthOfLocated = workJunctionLiningLateralGateway.GetDepthOfLocated(workId);
                bool originalDigRequiredPriorToLining = workJunctionLiningLateralGateway.GetDigRequiredPriorToLining(workId);
                DateTime? originalDigRequiredPriorToLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredPriorToLiningCompleted(workId);
                bool originalDigRequiredAfterLining = workJunctionLiningLateralGateway.GetDigRequiredAfterLining(workId);
                DateTime? originalDigRequiredAfterLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredAfterLiningCompleted(workId);
                bool originalOutOfScope = workJunctionLiningLateralGateway.GetOutOfScope(workId);
                bool originalHoldClientIssue = workJunctionLiningLateralGateway.GetHoldClientIssue(workId);
                DateTime? originalHoldClientIssueResolved = workJunctionLiningLateralGateway.GetHoldClientIssueResolved(workId);
                bool originalHoldLFSIssue = workJunctionLiningLateralGateway.GetHoldLFSIssue(workId);
                DateTime? originalHoldLFSIssueResolved = workJunctionLiningLateralGateway.GetHoldLFSIssueResolved(workId);
                bool originalRequiresRoboticPrep = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrep(workId);
                DateTime? originalRequiresRoboticPrepCompleted = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrepCompleted(workId);
                string originalLinerType = workJunctionLiningLateralGateway.GetLinerType(workId);
                string originalPrepType = workJunctionLiningLateralGateway.GetPrepType(workId);
                bool originalDyeTestReq = workJunctionLiningLateralGateway.GetDyeTestReq(workId);
                DateTime? originalDyeTestComplete = workJunctionLiningLateralGateway.GetDyeTestComplete(workId);
                string originalContractYear = workJunctionLiningLateralGateway.GetContractYear(workId);

                // New data
                DateTime? newPipeLocated = originalPipeLocated;
                DateTime? newServicesLocated = originalServicesLocated;
                DateTime? newCoInstalled = originalCoInstalled;
                DateTime? newBackfilledConcrete = originalBackfilledConcrete;
                DateTime? newBackfilledSoil = originalBackfilledSoil;
                DateTime? newGrouted = originalGrouted;
                DateTime? newCored = originalCored;
                DateTime? newPrepped = originalPrepped;
                DateTime? newMeasured = originalMeasured;
                string newLinerSize = originalLinerSize;
                DateTime? newInProcess = DateTime.Now;
                DateTime? newInStock = originalInStock;
                DateTime? newDelivered = originalDelivered;
                DateTime? newPreVideo = originalPreVideo;
                DateTime? newLinerInstalled = originalLinerInstalled;
                DateTime? newFinalVideo = originalFinalVideo;
                decimal? newCost = originalCost;
                DateTime? newVideoInspection = originalVideoInspection;
                bool newCoRequired = originalCoRequired;
                bool newPitRequired = originalPitRequired;
                string newCoPitLocation = originalCoPitLocation;
                bool newPostContractDigRequired = originalPostContractDigRequired;
                DateTime? newCoCutDown = originalCoCutDown;
                DateTime? newFinalRestoration = originalFinalRestoration;
                int? newBuildRebuild = (int)originalBuildRebuild + 1;
                string newVideoLengthToPropertyLine = originalVideoLengthToPropertyLine;
                bool newLiningThruCo = originalLiningThruCo;
                DateTime? newNoticeDelivered = originalNoticeDelivered;
                string newHamiltonInspectionNumber = originalHamiltonInspectionNumber;
                string newFlange = originalFlange;
                string newGasket = originalGasket;
                string newDepthOfLocated = originalDepthOfLocated;
                bool newDigRequiredPriorToLining = originalDigRequiredPriorToLining;
                DateTime? newDigRequiredPriorToLiningCompleted = originalDigRequiredPriorToLiningCompleted;
                bool newDigRequiredAfterLining = originalDigRequiredAfterLining;
                DateTime? newDigRequiredAfterLiningCompleted = originalDigRequiredAfterLiningCompleted;
                bool newOutOfScope = originalOutOfScope;
                bool newHoldClientIssue = originalHoldClientIssue;
                DateTime? newHoldClientIssueResolved = originalHoldClientIssueResolved;
                bool newHoldLFSIssue = originalHoldLFSIssue;
                DateTime? newHoldLFSIssueResolved = originalHoldLFSIssueResolved;
                bool newRequiresRoboticPrep = originalRequiresRoboticPrep;
                DateTime? newRequiresRoboticPrepCompleted = originalRequiresRoboticPrepCompleted;
                string newLinerType = originalLinerType;
                string newPrepType = originalPrepType;
                bool newDyeTestReq = originalDyeTestReq;
                DateTime? newDyeTestComplete = originalDyeTestComplete;
                string newContractYear = originalContractYear;

                // Update Lateral
                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                workJunctionLiningLateral.UpdateDirect(workId, sectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, false, jlToBuildRow.COMPANY_ID, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, newPipeLocated, newServicesLocated, newCoInstalled, newBackfilledConcrete, newBackfilledSoil, newGrouted, newCored, newPrepped, newMeasured, newLinerSize, newInProcess, newInStock, newDelivered, newBuildRebuild, newPreVideo, newLinerInstalled, newFinalVideo, newCost, newVideoInspection, newCoRequired, newPitRequired, newCoPitLocation, newPostContractDigRequired, newCoCutDown, newFinalRestoration, jlToBuildRow.COMPANY_ID, newVideoLengthToPropertyLine, newLiningThruCo, newNoticeDelivered, newHamiltonInspectionNumber, newFlange, newGasket, newDepthOfLocated, newDigRequiredPriorToLining, newDigRequiredPriorToLiningCompleted, newDigRequiredAfterLining, newDigRequiredAfterLiningCompleted, newOutOfScope, newHoldClientIssue, newHoldClientIssueResolved, newHoldLFSIssue, newHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, newLinerType, newPrepType, newDyeTestReq, newDyeTestComplete, originalContractYear, newContractYear);
            }
        }
        /// <summary>
        /// UpdateJLLaterals
        /// </summary>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="lateral_assetId">lateral_assetId</param>
        /// <param name="companyId">companyId</param>        
        /// <param name="clientInspectionNo">clientInspectionNo</param>
        /// <param name="requiresRoboticPrep">requiresRoboticPrep</param>
        /// <param name="requiresRoboticPrepDate">requiresRoboticPrepDate</param>
        /// <param name="holdClientIssue">holdClientIssue</param>
        /// <param name="holdLFSIssue">holdLFSIssue</param>
        /// <param name="flange">flange</param>
        /// <param name="dyeTestReq">dyeTestReq</param>
        /// <param name="dyeTestComplete">dyeTestComplete</param>
        private void UpdateJLLaterals(int currentProjectId, int lateral_assetId, int companyId, string clientInspectionNo, bool requiresRoboticPrep, DateTime? requiresRoboticPrepDate, bool holdClientIssue, bool holdLFSIssue, string flange, bool dyeTestReq, DateTime? dyeTestComplete, string contractYear)
        {
            // Load work id
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, lateral_assetId, "Junction Lining Lateral", companyId);
            if (workGateway.Table.Rows.Count > 0)
            {
                int workId = workGateway.GetWorkId(lateral_assetId, "Junction Lining Lateral", currentProjectId);

                if (workId > 0)
                {
                    WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                    workJunctionLiningLateralGateway.LoadByWorkId(workId, companyId);

                    // Load original data
                    int originalSectionWorkId = workJunctionLiningLateralGateway.GetSectionWorkID(workId);
                    DateTime? originalPipeLocated = workJunctionLiningLateralGateway.GetPipeLocated(workId);
                    DateTime? originalServicesLocated = workJunctionLiningLateralGateway.GetServicesLocated(workId);
                    DateTime? originalCoInstalled = workJunctionLiningLateralGateway.GetCoInstalled(workId);
                    DateTime? originalBackfilledConcrete = workJunctionLiningLateralGateway.GetBackfilledConcrete(workId);
                    DateTime? originalBackfilledSoil = workJunctionLiningLateralGateway.GetBackfilledSoil(workId);
                    DateTime? originalGrouted = workJunctionLiningLateralGateway.GetGrouted(workId);
                    DateTime? originalCored = workJunctionLiningLateralGateway.GetCored(workId);
                    DateTime? originalPrepped = workJunctionLiningLateralGateway.GetPrepped(workId);
                    DateTime? originalMeasured = workJunctionLiningLateralGateway.GetMeasured(workId);
                    string originalLinerSize = workJunctionLiningLateralGateway.GetLinerSize(workId);
                    DateTime? originalInProcess = workJunctionLiningLateralGateway.GetInProcess(workId);
                    DateTime? originalInStock = workJunctionLiningLateralGateway.GetInStock(workId);
                    DateTime? originalDelivered = workJunctionLiningLateralGateway.GetDelivered(workId);
                    int? originalBuildRebuild = workJunctionLiningLateralGateway.GetBuildRebuild(workId);
                    DateTime? originalPreVideo = workJunctionLiningLateralGateway.GetPreVideo(workId);
                    DateTime? originalLinerInstalled = workJunctionLiningLateralGateway.GetLinerInstalled(workId);
                    DateTime? originalFinalVideo = workJunctionLiningLateralGateway.GetFinalVideo(workId);
                    decimal? originalCost = workJunctionLiningLateralGateway.GetCost(workId);
                    DateTime? originalVideoInspection = workJunctionLiningLateralGateway.GetVideoInspection(workId);
                    bool originalCoRequired = workJunctionLiningLateralGateway.GetCoRequired(workId);
                    bool originalPitRequired = workJunctionLiningLateralGateway.GetPitRequired(workId);
                    string originalCoPitLocation = workJunctionLiningLateralGateway.GetCoPitLocation(workId);
                    bool originalPostContractDigRequired = workJunctionLiningLateralGateway.GetPostContractDigRequired(workId);
                    DateTime? originalCoCutDown = workJunctionLiningLateralGateway.GetCoCutDown(workId);
                    DateTime? originalFinalRestoration = workJunctionLiningLateralGateway.GetFinalRestoration(workId);
                    string originalVideoLengthToPropertyLine = workJunctionLiningLateralGateway.GetVideoLengthToPropertyLine(workId);
                    bool originalLiningThruCo = workJunctionLiningLateralGateway.GetLiningThruCo(workId);
                    DateTime? originalNoticeDelivered = workJunctionLiningLateralGateway.GetNoticeDelivered(workId);
                    string originalHamiltonInspectionNumber = workJunctionLiningLateralGateway.GetHamiltonInspectionNumber(workId);
                    string originalFlange = workJunctionLiningLateralGateway.GetFlange(workId);
                    string originalGasket = workJunctionLiningLateralGateway.GetGasket(workId);
                    string originalDepthOfLocated = workJunctionLiningLateralGateway.GetDepthOfLocated(workId);
                    bool originalDigRequiredPriorToLining = workJunctionLiningLateralGateway.GetDigRequiredPriorToLining(workId);
                    DateTime? originalDigRequiredPriorToLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredPriorToLiningCompleted(workId);
                    bool originalDigRequiredAfterLining = workJunctionLiningLateralGateway.GetDigRequiredAfterLining(workId);
                    DateTime? originalDigRequiredAfterLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredAfterLiningCompleted(workId);
                    bool originalOutOfScope = workJunctionLiningLateralGateway.GetOutOfScope(workId);
                    bool originalHoldClientIssue = workJunctionLiningLateralGateway.GetHoldClientIssue(workId);
                    DateTime? originalHoldClientIssueResolved = workJunctionLiningLateralGateway.GetHoldClientIssueResolved(workId);
                    bool originalHoldLFSIssue = workJunctionLiningLateralGateway.GetHoldLFSIssue(workId);
                    DateTime? originalHoldLFSIssueResolved = workJunctionLiningLateralGateway.GetHoldLFSIssueResolved(workId);
                    bool originalRequiresRoboticPrep = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrep(workId);
                    DateTime? originalRequiresRoboticPrepCompleted = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrepCompleted(workId);
                    string originalLinerType = workJunctionLiningLateralGateway.GetLinerType(workId);
                    string originalPrepType = workJunctionLiningLateralGateway.GetPrepType(workId);
                    bool originalDyeTestReq = workJunctionLiningLateralGateway.GetDyeTestReq(workId);
                    DateTime? originalDyeTestComplete = null; if (workJunctionLiningLateralGateway.GetDyeTestComplete(workId).HasValue) originalDyeTestComplete = workJunctionLiningLateralGateway.GetDyeTestComplete(workId);
                    string originalContractYear = workJunctionLiningLateralGateway.GetContractYear(workId);

                    // New data
                    string newClientInspectionNo = clientInspectionNo;
                    bool newRequiresRoboticPrep = requiresRoboticPrep;
                    DateTime? newRequiresRoboticPrepCompleted = null; if (requiresRoboticPrepDate.HasValue) newRequiresRoboticPrepCompleted = requiresRoboticPrepDate;
                    bool newHoldClientIssue = holdClientIssue;
                    bool newHoldLFSIssue = holdLFSIssue;
                    bool newDyeTetRepair = dyeTestReq;
                    DateTime? newDyeTestComplete = null; if (dyeTestComplete.HasValue) newDyeTestComplete = dyeTestComplete;
                    string newContractYear = contractYear;

                    // Update work
                    WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                    workJunctionLiningLateral.UpdateDirect(workId, originalSectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, false, companyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, companyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, newClientInspectionNo, flange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, newHoldClientIssue, originalHoldClientIssueResolved,  newHoldLFSIssue, originalHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, newDyeTetRepair, newDyeTestComplete, originalContractYear, newContractYear);
                }
            }
        }
        /// <summary>
        /// Save all sections & works to database (direct)
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="videoLength">videoLength</param>
        /// <param name="companyId">companyId</param>
        /// <param name="isNewMeasuredFromDsmh">isNewMeasuredFromDsmh</param>
        public void Save(int workId, int projectId, int sectionAssetId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string videoLength, int companyId, bool isNewMeasuredFromDsmh, bool prepDataRoboticPrep, DateTime? prepDataRoboticPrepCompleted)
        {
            FullLengthLiningTDS fullLengthLiningChanges = (FullLengthLiningTDS)Data.GetChanges();

            if (fullLengthLiningChanges.LateralDetails.Rows.Count > 0)
            {
                FullLengthLiningLateralDetailsGateway fullLengthLiningLateralDetailsGateway = new FullLengthLiningLateralDetailsGateway(fullLengthLiningChanges);

                foreach (FullLengthLiningTDS.LateralDetailsRow row in (FullLengthLiningTDS.LateralDetailsDataTable)fullLengthLiningChanges.LateralDetails)
                {
                    // Process modified rows
                    if (row.ToProcess)
                    {
                        // Insert new laterals
                        if ((!row.Deleted) && (row.InProject) && (!row.InProjectDatabase))
                        {
                            // Insert asset
                            int lateral_assetId = SaveLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, companyId, isNewMeasuredFromDsmh);
                            int lateral = row.Lateral;

                            // Insert work
                            string videoDistance = fullLengthLiningLateralDetailsGateway.GetVideoDistance(lateral);
                            string clockPosition = fullLengthLiningLateralDetailsGateway.GetClockPosition(lateral);
                            string distanceToCentre = fullLengthLiningLateralDetailsGateway.GetDistanceToCentre(lateral);
                            string timeOpened = fullLengthLiningLateralDetailsGateway.GetTimeOpened(lateral);
                            string reverseSetup = fullLengthLiningLateralDetailsGateway.GetReverseSetup(lateral);
                            DateTime? reinstate = fullLengthLiningLateralDetailsGateway.GetReinstate(lateral);
                            string comments = fullLengthLiningLateralDetailsGateway.GetComments(lateral);
                            string clientInspectionNo = fullLengthLiningLateralDetailsGateway.GetClientInspectionNo(lateral);
                            DateTime? v1Inspection = null;
                            bool requiresRoboticPrep = fullLengthLiningLateralDetailsGateway.GetRequiresRoboticPrep(lateral);
                            DateTime? requiresRoboticPrepDate = null;
                            bool holdClientIssue = fullLengthLiningLateralDetailsGateway.GetHoldClientIssue(lateral);
                            bool holdLFSIssue = fullLengthLiningLateralDetailsGateway.GetHoldLFSIssue(lateral);
                            bool lineLateral = fullLengthLiningLateralDetailsGateway.GetLineLateral(lateral);
                            string flange = fullLengthLiningLateralDetailsGateway.GetFlange(lateral);
                            bool dyeTestReq = fullLengthLiningLateralDetailsGateway.GetDyeTestReq(lateral);
                            DateTime? dyeTestComplete = null; if (fullLengthLiningLateralDetailsGateway.GetDyeTestComplete(lateral).HasValue) dyeTestComplete = fullLengthLiningLateralDetailsGateway.GetDyeTestComplete(lateral);
                            string contractYear = fullLengthLiningLateralDetailsGateway.GetContractYear(lateral);

                            WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateay = new WorkFullLengthLiningM1LateralGateway();
                            workFullLengthLiningM1LateralGateay.LoadAllByWorkIdLateral(workId, lateral_assetId, companyId);

                            if (workFullLengthLiningM1LateralGateay.Table.Rows.Count == 0)
                            {
                                InsertFLLLateral(workId, lateral_assetId, videoDistance, clockPosition, distanceToCentre, timeOpened, reverseSetup, reinstate, comments, row.Deleted, companyId, clientInspectionNo, v1Inspection, requiresRoboticPrep, requiresRoboticPrepDate, holdClientIssue, holdLFSIssue, lineLateral, dyeTestReq, dyeTestComplete, contractYear);
                            }

                            // ... ... If lateral will be in Junction Lining
                            if ((row.LineLateral) && (!row.InJlDatabase))
                            {
                                if (((!prepDataRoboticPrep) && (!prepDataRoboticPrepCompleted.HasValue)) || ((prepDataRoboticPrep) && (prepDataRoboticPrepCompleted.HasValue)))
                                {
                                    // ... ... Load work id
                                    int sectionWorkId = 0;
                                    WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                    sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                    WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                                    WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(workJunctionLiningLateralGateway.Data);
                                    workJunctionLiningLateral.InsertDirect(projectId, lateral_assetId, sectionWorkId, null, null, null, null, null, null, null, null, null, "", null, null, null, 0, null, null, null, 0, null, true, false, "", false, null, null, false, companyId, "", "", "", false, null, "", flange, "", "", false, null, false, null, false, holdClientIssue, null, holdLFSIssue, null, requiresRoboticPrep, requiresRoboticPrepDate, "", "", dyeTestReq, dyeTestComplete, contractYear);
                                }
                            }

                            //... Insert material for m1 lateral
                            string material = fullLengthLiningLateralDetailsGateway.GetMaterialType(lateral);
                            if (material != "")
                            {
                                InsertMaterial(lateral_assetId, material, companyId);
                            }

                            //... Insert client lateral id
                            string clientLateralId = fullLengthLiningLateralDetailsGateway.GetClientLateralId(lateral);

                            if (clientLateralId.Trim() != "")
                            {
                                ProjectGateway projectGateway = new ProjectGateway();
                                projectGateway.LoadByProjectId(projectId);
                                int clientId = projectGateway.GetClientID(projectId);

                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                lfsAssetSewerLateralClient.InsertDirect(lateral_assetId, clientId, clientLateralId, false, companyId);
                            }

                            // Change row process state
                            NotProcess(lateral);
                        }

                        // Update laterals
                        if ((!row.Deleted) && (row.InProject) && (row.InProjectDatabase))
                        {
                            int lateral = row.Lateral;

                            // original values
                            string originalVideoDistance = fullLengthLiningLateralDetailsGateway.GetVideoDistanceOriginal(lateral);
                            string originalClockPosition = fullLengthLiningLateralDetailsGateway.GetClockPositionOriginal(lateral);
                            string originalDistanceToCentre = fullLengthLiningLateralDetailsGateway.GetDistanceToCentreOriginal(lateral);
                            string originalTimeOpened = fullLengthLiningLateralDetailsGateway.GetTimeOpenedOriginal(lateral);
                            string originalReverseSetup = fullLengthLiningLateralDetailsGateway.GetReverseSetupOriginal(lateral);
                            DateTime? originalReinstate = fullLengthLiningLateralDetailsGateway.GetReinstateOriginal(lateral);
                            string originalComments = fullLengthLiningLateralDetailsGateway.GetCommentsOriginal(lateral);
                            string originalClientFullLateralId = fullLengthLiningLateralDetailsGateway.GetClientLateralIdOriginal(lateral);
                            string originalClientLateralId = ""; if (originalClientFullLateralId != "") originalClientLateralId = originalClientFullLateralId;
                            string originalClientInspectionNo = fullLengthLiningLateralDetailsGateway.GetClientInspectionNoOriginal(lateral);
                            DateTime? originalV1Inspection = fullLengthLiningLateralDetailsGateway.GetV1InspectionOriginal(lateral);
                            bool originalRequiresRoboticPrep = fullLengthLiningLateralDetailsGateway.GetRequiresRoboticPrepOriginal(lateral);
                            DateTime? originalRequiresRoboticPrepDate = fullLengthLiningLateralDetailsGateway.GetRequiresRoboticPrepDateOriginal(lateral);
                            bool originalHoldClientIssue = fullLengthLiningLateralDetailsGateway.GetHoldClientIssueOriginal(lateral);
                            bool originalHoldLFSIssue = fullLengthLiningLateralDetailsGateway.GetHoldLFSIssueOriginal(lateral);
                            bool originalLineLateral = fullLengthLiningLateralDetailsGateway.GetLineLateralOriginal(lateral);
                            bool originalDyeTestReq = fullLengthLiningLateralDetailsGateway.GetDyeTestReqOriginal(lateral);
                            DateTime? originalDyeTestComplete = null; if (fullLengthLiningLateralDetailsGateway.GetDyeTestCompleteOriginal(lateral).HasValue) originalDyeTestComplete = fullLengthLiningLateralDetailsGateway.GetDyeTestCompleteOriginal(lateral);
                            string originalContractYear = fullLengthLiningLateralDetailsGateway.GetContractYearOriginal(lateral);

                            // new values
                            string newVideoDistance = fullLengthLiningLateralDetailsGateway.GetVideoDistance(lateral);
                            string newClockPosition = fullLengthLiningLateralDetailsGateway.GetClockPosition(lateral);
                            string newDistanceToCentre = fullLengthLiningLateralDetailsGateway.GetDistanceToCentre(lateral);
                            string newTimeOpened = fullLengthLiningLateralDetailsGateway.GetTimeOpened(lateral);
                            string newReverseSetup = fullLengthLiningLateralDetailsGateway.GetReverseSetup(lateral);
                            DateTime? newReinstate = fullLengthLiningLateralDetailsGateway.GetReinstate(lateral);
                            string newComments = fullLengthLiningLateralDetailsGateway.GetComments(lateral);
                            string newClientFullLateralId = fullLengthLiningLateralDetailsGateway.GetClientLateralId(lateral);
                            string newClientLateralId = ""; if (newClientFullLateralId != "") newClientLateralId = newClientFullLateralId;
                            string newClientInspectionNo = fullLengthLiningLateralDetailsGateway.GetClientInspectionNo(lateral);
                            bool newRequiresRoboticPrep = fullLengthLiningLateralDetailsGateway.GetRequiresRoboticPrep(lateral);
                            DateTime? newRequiresRoboticPrepDate = fullLengthLiningLateralDetailsGateway.GetRequiresRoboticPrepDate(lateral);
                            bool newHoldClientIssue = fullLengthLiningLateralDetailsGateway.GetHoldClientIssue(lateral);
                            bool newHoldLFSIssue = fullLengthLiningLateralDetailsGateway.GetHoldLFSIssue(lateral);
                            bool newLineLateral = fullLengthLiningLateralDetailsGateway.GetLineLateral(lateral);
                            string newFlange = fullLengthLiningLateralDetailsGateway.GetFlange(lateral);
                            bool newDyeTestReq = fullLengthLiningLateralDetailsGateway.GetDyeTestReq(lateral);
                            DateTime? newDyeTestComplete = null; if (fullLengthLiningLateralDetailsGateway.GetDyeTestComplete(lateral).HasValue) newDyeTestComplete = fullLengthLiningLateralDetailsGateway.GetDyeTestComplete(lateral);
                            string newContractYear = fullLengthLiningLateralDetailsGateway.GetContractYear(lateral);

                            // ... Update fll laterals
                            int lateral_assetId = SaveLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, companyId, isNewMeasuredFromDsmh);
                            UpdateLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, videoLength, companyId);
                            UpdateFLLLateral(workId, lateral_assetId, originalVideoDistance, originalClockPosition, originalDistanceToCentre, originalTimeOpened, originalReverseSetup, originalReinstate, originalComments, false, companyId, originalClientInspectionNo, originalV1Inspection, originalRequiresRoboticPrep, originalRequiresRoboticPrepDate, originalHoldClientIssue, originalHoldLFSIssue, originalLineLateral, originalDyeTestReq, originalDyeTestComplete, originalContractYear, workId, lateral_assetId, newVideoDistance, newClockPosition, newDistanceToCentre, newTimeOpened, newReverseSetup, newReinstate, newComments, false, companyId, newClientInspectionNo, originalV1Inspection, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newLineLateral, newDyeTestReq, newDyeTestComplete, newContractYear);

                            // ... Update if lateral is in Junction Lining
                            if (row.InJlDatabase)
                            {
                                if (originalLineLateral == newLineLateral)
                                {
                                    // ... ... Update jl lateral (clientInspectionNo, v1Inspection, requiredRoboticPrep, requiredRoboticPrepDate, holdClientIssue, holdLFSIssue, flange)
                                    UpdateJLLaterals(projectId, lateral_assetId, companyId, newClientInspectionNo, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newFlange, newDyeTestReq, newDyeTestComplete, newContractYear);
                                }
                                else
                                {
                                    int sectionWorkId = 0;
                                    WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                    sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                    // Delete empty lateral form jl.
                                    DeleteJLLaterals(projectId, lateral_assetId, companyId, sectionWorkId);
                                }
                            }
                            else
                            {
                                // ... ... Insert if should be in junction Lining
                                if (row.LineLateral)
                                {
                                    if (((!prepDataRoboticPrep) && (!prepDataRoboticPrepCompleted.HasValue)) || ((prepDataRoboticPrep) && (prepDataRoboticPrepCompleted.HasValue)))
                                    {
                                        int sectionWorkId = 0;

                                        // Insert to jl laterals
                                        WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                        sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                        WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                                        WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(workJunctionLiningLateralGateway.Data);
                                        workJunctionLiningLateral.InsertDirect(projectId, lateral_assetId, sectionWorkId, null, null, null, null, null, null, null, null, null, "", null, null, null, 0, null, null, null, 0, null, false, false, "", false, null, null, false, companyId, "", "", "", false, null, newClientInspectionNo, newFlange, "", "", false, null, false, null, false, newHoldClientIssue, null, newHoldLFSIssue, null, newRequiresRoboticPrep, newRequiresRoboticPrepDate, "", "", newDyeTestReq, newDyeTestComplete, newContractYear);
                                    }
                                }
                            }

                            //... Insert material for m1 lateral
                            string material = fullLengthLiningLateralDetailsGateway.GetMaterialType(lateral);
                            if (material != "")
                            {
                                InsertMaterial(lateral_assetId, material, companyId);
                            }

                            ProjectGateway projectGateway = new ProjectGateway();
                            projectGateway.LoadByProjectId(projectId);
                            int clientId = projectGateway.GetClientID(projectId);

                            LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                            lfsAssetSewerLateralClientGateway.LoadAllByAssetIdClientId(lateral_assetId, clientId, companyId);

                            if (lfsAssetSewerLateralClientGateway.Table.Rows.Count == 0)
                            {
                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                lfsAssetSewerLateralClient.InsertDirect(lateral_assetId, clientId, originalClientLateralId, false, companyId);
                            }
                            else
                            {
                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                string originalFullClientLateralId = lfsAssetSewerLateralClientGateway.GetClientLateralId(lateral_assetId, clientId);

                                lfsAssetSewerLateralClient.UpdateDirect(lateral_assetId, clientId, originalClientLateralId, false, companyId, lateral_assetId, clientId, newClientLateralId, false, companyId);
                            }

                            // Change row process state
                            NotProcess(lateral);
                        }

                        // Deleted laterals or exclude them from fulllength lining work
                        if (((row.Deleted) && (row.InProject) && (row.InProjectDatabase)) || ((!row.Deleted) && (!row.InProject) && (row.InProjectDatabase)))
                        {
                            DeleteFLLLateral(workId, row.Lateral, companyId, projectId);

                            // Change row process state
                            NotProcess(row.Lateral);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Save a Previous RA work
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="companyId">companyId</param>
        private void SavePreviousWork(int parentProjectId, int childProjectId, int assetId, string workType, int companyId)
        {
            int parentWorkId = 0;
            int childWorkId = 0;
            int childJLLWorkId = 0;
            int parentJLLWorkID = 0;

            // Load Previous work  - Rehab assessment data (last sections work)
            WorkGateway parentWorkGateway = new WorkGateway();
            WorkGateway childWorkGateway = new WorkGateway();
            WorkGateway childJLLWorkGateway = new WorkGateway();

            parentWorkGateway.LoadByProjectIdAssetIdWorkType(parentProjectId, assetId, workType, companyId);

            if (parentWorkGateway.Table.Rows.Count > 0)
            {
                parentWorkId = parentWorkGateway.GetWorkId(assetId, workType, parentProjectId);

                childWorkGateway.LoadByProjectIdAssetIdWorkType(childProjectId, assetId, workType, companyId);
                childWorkId = childWorkGateway.GetWorkId(assetId, workType, childProjectId);

                // Load Previous work  - Comments and History
                SavePreviousComments(parentWorkId, workType, companyId, childWorkId);
                SavePreviousHistory(parentWorkId, workType, companyId, childWorkId);

                if (workType == "Junction Lining Section")
                {
                    // Load Previous work  - Junction Lining Lateral data
                    WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                    workJunctionLiningLateralGateway.LoadBySectionWorkId(parentWorkId, companyId);

                    foreach (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALRow lateralRow in (WorkTDS.LFS_WORK_JUNCTIONLINING_LATERALDataTable)workJunctionLiningLateralGateway.Table)
                    {
                        try
                        {
                            WorkGateway workGatewayForLateral = new WorkGateway();
                            workGatewayForLateral.LoadByWorkId(lateralRow.WorkID, companyId);

                            int lateral_assetId = workGatewayForLateral.GetAssetId(lateralRow.WorkID);
                            parentJLLWorkID = lateralRow.WorkID;

                            childJLLWorkGateway.LoadByProjectIdAssetIdWorkType(childProjectId, lateral_assetId, "Junction Lining Lateral", companyId);
                            childJLLWorkId = childJLLWorkGateway.GetWorkId(lateral_assetId, "Junction Lining Lateral", childProjectId);

                            // Load Previous work  - Comments and History
                            SavePreviousComments(parentJLLWorkID, "Junction Lining Lateral", companyId, childJLLWorkId);
                            SavePreviousHistory(parentJLLWorkID, "Junction Lining Lateral", companyId, childJLLWorkId);

                            workUpdate(childJLLWorkId, childProjectId, lateral_assetId, companyId, "Junction Lining Lateral");
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    workUpdate(childWorkId, childProjectId, assetId, companyId, workType);
                }
            }
        }
        /// <summary>
        /// WorkUpdate
        /// </summary>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="workType">workType</param>
        /// <param name="assetId">assetId</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="pipeLocated">pipeLocated</param>
        /// <param name="servicesLocated">servicesLocated</param>
        /// <param name="coInstalled">coInstalled</param>
        /// <param name="backfilledConcrete">backfilledConcrete</param>
        /// <param name="backfilledSoil">backfilledSoil</param>
        /// <param name="grouted">grouted</param>
        /// <param name="cored">cored</param>
        /// <param name="prepped">prepped</param>
        /// <param name="measured">measured</param>
        /// <param name="linerSize">linerSize</param>
        /// <param name="inProcess">inProcess</param>
        /// <param name="inStock">inStock</param>
        /// <param name="delivered">delivered</param>
        /// <param name="buildRebuild">buildRebuild</param>
        /// <param name="preVideo">preVideo</param>
        /// <param name="linerInstalled">linerInstalled</param>
        /// <param name="finalVideo">finalVideo</param>
        /// <param name="cost">cost</param>
        /// <param name="videoInspection">videoInspection</param>
        /// <param name="coRequired">coRequired</param>
        /// <param name="pitRequired">pitRequired</param>
        /// <param name="coPitLocation">coPitLocation</param>
        /// <param name="postContractDigRequired">postContractDigRequired</param>
        /// <param name="coCutDown">coCutDown</param>
        /// <param name="finalRestoration">finalRestoration</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="videoLengthToPropertyLine">videoLengthToPropertyLine</param>
        /// <param name="liningThruCo">liningThruCo</param>
        /// <param name="noticeDelivered">noticeDelivered</param>
        /// <param name="hamiltonInspectionNumber">hamiltonInspectionNumber</param>
        /// <param name="flange">flange</param>
        /// <param name="gasket">gasket</param>
        /// <param name="depthOfLocated">depthOfLocated</param>
        /// <param name="digRequiredPriorToLining">digRequiredPriorToLining</param>
        /// <param name="digRequiredPriorToLiningCompleted">digRequiredPriorToLiningCompleted</param>
        /// <param name="digRequiredAfterLining">digRequiredAfterLining</param>
        /// <param name="digRequiredAfterLiningCompleted">digRequiredAfterLiningCompleted</param>
        /// <param name="outOfScope">outOfScope</param>
        /// <param name="holdClientIssue">holdClientIssue</param>
        /// <param name="holdClientIssueResolved">holdClientIssueResolved</param>
        /// <param name="holdLFSIssue">holdLFSIssue</param>
        /// <param name="holdLFSIssueResolved">holdLFSIssueResolved</param>
        /// <param name="requiresRoboticPrep">requiresRoboticPrep</param>
        /// <param name="requiresRoboticPrepCompleted">requiresRoboticPrepCompleted</param>
        /// <param name="linerType">linerType</param>
        /// <param name="prepType">prepType</param>
        /// <param name="dyeTestReq">dyeTestReq</param>
        /// <param name="dyeTestComplete">dyeTestComplete</param>
        private void WorkUpdate(int currentProjectId, int assetId, int sectionWorkId, DateTime? pipeLocated, DateTime? servicesLocated, DateTime? coInstalled, DateTime? backfilledConcrete, DateTime? backfilledSoil, DateTime? grouted, DateTime? cored, DateTime? prepped, DateTime? measured, string linerSize, DateTime? inProcess, DateTime? inStock, DateTime? delivered, int? buildRebuild, DateTime? preVideo, DateTime? linerInstalled, DateTime? finalVideo, decimal? cost, DateTime? videoInspection, bool coRequired, bool pitRequired, string coPitLocation, bool postContractDigRequired, DateTime? coCutDown, DateTime? finalRestoration, bool deleted, int companyId, string videoLengthToPropertyLine, bool liningThruCo, DateTime? noticeDelivered, string hamiltonInspectionNumber, string flange, string gasket, string depthOfLocated, bool digRequiredPriorToLining, DateTime? digRequiredPriorToLiningCompleted, bool digRequiredAfterLining, DateTime? digRequiredAfterLiningCompleted, bool outOfScope, bool holdClientIssue, DateTime? holdClientIssueResolved, bool holdLFSIssue, DateTime? holdLFSIssueResolved, bool requiresRoboticPrep, DateTime? requiresRoboticPrepCompleted, string linerType, string prepType, bool dyeTestReq, DateTime? dyeTestComplete, string contractYear)
        {
            // Load work id
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, assetId, "Junction Lining Lateral", companyId);
            int workId = workGateway.GetWorkId(assetId, "Junction Lining Lateral", currentProjectId);

            WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
            workJunctionLiningLateralGateway.LoadByWorkId(workId, companyId);

            // Load original data
            DateTime? originalPipeLocated = workJunctionLiningLateralGateway.GetPipeLocated(workId);
            DateTime? originalServicesLocated = workJunctionLiningLateralGateway.GetServicesLocated(workId);
            DateTime? originalCoInstalled = workJunctionLiningLateralGateway.GetCoInstalled(workId);
            DateTime? originalBackfilledConcrete = workJunctionLiningLateralGateway.GetBackfilledConcrete(workId);
            DateTime? originalBackfilledSoil = workJunctionLiningLateralGateway.GetBackfilledSoil(workId);
            DateTime? originalGrouted = workJunctionLiningLateralGateway.GetGrouted(workId);
            DateTime? originalCored = workJunctionLiningLateralGateway.GetCored(workId);
            DateTime? originalPrepped = workJunctionLiningLateralGateway.GetPrepped(workId);
            DateTime? originalMeasured = workJunctionLiningLateralGateway.GetMeasured(workId);
            string originalLinerSize = workJunctionLiningLateralGateway.GetLinerSize(workId);
            DateTime? originalInProcess = workJunctionLiningLateralGateway.GetInProcess(workId);
            DateTime? originalInStock = workJunctionLiningLateralGateway.GetInStock(workId);
            DateTime? originalDelivered = workJunctionLiningLateralGateway.GetDelivered(workId);
            int? originalBuildRebuild = workJunctionLiningLateralGateway.GetBuildRebuild(workId);
            DateTime? originalPreVideo = workJunctionLiningLateralGateway.GetPreVideo(workId);
            DateTime? originalLinerInstalled = workJunctionLiningLateralGateway.GetLinerInstalled(workId);
            DateTime? originalFinalVideo = workJunctionLiningLateralGateway.GetFinalVideo(workId);
            decimal? originalCost = workJunctionLiningLateralGateway.GetCost(workId);
            DateTime? originalVideoInspection = workJunctionLiningLateralGateway.GetVideoInspection(workId);
            bool originalCoRequired = workJunctionLiningLateralGateway.GetCoRequired(workId);
            bool originalPitRequired = workJunctionLiningLateralGateway.GetPitRequired(workId);
            string originalCoPitLocation = workJunctionLiningLateralGateway.GetCoPitLocation(workId);
            bool originalPostContractDigRequired = workJunctionLiningLateralGateway.GetPostContractDigRequired(workId);
            DateTime? originalCoCutDown = workJunctionLiningLateralGateway.GetCoCutDown(workId);
            DateTime? originalFinalRestoration = workJunctionLiningLateralGateway.GetFinalRestoration(workId);
            string originalVideoLengthToPropertyLine = workJunctionLiningLateralGateway.GetVideoLengthToPropertyLine(workId);
            bool originalLiningThruCo = workJunctionLiningLateralGateway.GetLiningThruCo(workId);
            DateTime? originalNoticeDelivered = workJunctionLiningLateralGateway.GetNoticeDelivered(workId);
            string originalHamiltonInspectionNumber = workJunctionLiningLateralGateway.GetHamiltonInspectionNumber(workId);
            string originalFlange = workJunctionLiningLateralGateway.GetFlange(workId);
            string originalGasket = workJunctionLiningLateralGateway.GetGasket(workId);
            string originalDepthOfLocated = workJunctionLiningLateralGateway.GetDepthOfLocated(workId);
            bool originalDigRequiredPriorToLining = workJunctionLiningLateralGateway.GetDigRequiredPriorToLining(workId);
            DateTime? originalDigRequiredPriorToLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredPriorToLiningCompleted(workId);
            bool originalDigRequiredAfterLining = workJunctionLiningLateralGateway.GetDigRequiredAfterLining(workId);
            DateTime? originalDigRequiredAfterLiningCompleted = workJunctionLiningLateralGateway.GetDigRequiredAfterLiningCompleted(workId);
            bool originalOutOfScope = workJunctionLiningLateralGateway.GetOutOfScope(workId);
            bool originalHoldClientIssue = workJunctionLiningLateralGateway.GetHoldClientIssue(workId);
            DateTime? originalHoldClientIssueResolved = workJunctionLiningLateralGateway.GetHoldClientIssueResolved(workId);
            bool originalHoldLFSIssue = workJunctionLiningLateralGateway.GetHoldLFSIssue(workId);
            DateTime? originalHoldLFSIssueResolved = workJunctionLiningLateralGateway.GetHoldLFSIssueResolved(workId);
            bool originalRequiresRoboticPrep = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrep(workId);
            DateTime? originalRequiresRoboticPrepCompleted = workJunctionLiningLateralGateway.GetLateralRequiresRoboticPrepCompleted(workId);
            string originalLinerType = workJunctionLiningLateralGateway.GetLinerType(workId);
            string originalPrepType = workJunctionLiningLateralGateway.GetPrepType(workId);
            bool originalDyeTestReq = workJunctionLiningLateralGateway.GetDyeTestReq(workId);
            DateTime? originalDyeTestComplete = null; if (workJunctionLiningLateralGateway.GetDyeTestComplete(workId).HasValue) originalDyeTestComplete = workJunctionLiningLateralGateway.GetDyeTestComplete(workId);
            string originalContractYear = workJunctionLiningLateralGateway.GetContractYear(workId);

            // New data
            DateTime? newPipeLocated = pipeLocated;
            DateTime? newServicesLocated = servicesLocated;
            DateTime? newCoInstalled = coInstalled;
            DateTime? newBackfilledConcrete = backfilledConcrete;
            DateTime? newBackfilledSoil = backfilledSoil;
            DateTime? newGrouted = grouted;
            DateTime? newCored = cored;
            DateTime? newPrepped = prepped;
            DateTime? newMeasured = measured;
            string newLinerSize = linerSize;
            DateTime? newInProcess = inProcess;
            DateTime? newInStock = inStock;
            DateTime? newDelivered = delivered;
            int? newBuildRebuild = buildRebuild;
            DateTime? newPreVideo = preVideo;
            DateTime? newLinerInstalled = linerInstalled;
            DateTime? newFinalVideo = finalVideo;
            decimal? newCost = cost;
            DateTime? newVideoInspection = videoInspection;
            bool newCoRequired = coRequired;
            bool newPitRequired = pitRequired;
            string newCoPitLocation = coPitLocation;
            bool newPostContractDigRequired = postContractDigRequired;
            DateTime? newCoCutDown = coCutDown;
            DateTime? newFinalRestoration = finalRestoration;
            string newVideoLengthToPropertyLine = videoLengthToPropertyLine;
            bool newLiningThruCo = liningThruCo;
            DateTime? newNoticeDelivered = noticeDelivered;
            string newHamiltonInspectionNumber = hamiltonInspectionNumber;
            string newFlange = flange;
            string newGasket = gasket;
            string newDepthOfLocated = depthOfLocated;
            bool newDigRequiredPriorToLining = digRequiredPriorToLining;
            DateTime? newDigRequiredPriorToLiningCompleted = digRequiredPriorToLiningCompleted;
            bool newDigRequiredAfterLining = digRequiredAfterLining;
            DateTime? newDigRequiredAfterLiningCompleted = digRequiredAfterLiningCompleted;
            bool newOutOfScope = outOfScope;
            bool newHoldClientIssue = holdClientIssue;
            DateTime? newHoldClientIssueResolved = holdClientIssueResolved;
            bool newHoldLFSIssue = holdLFSIssue;
            DateTime? newHoldLFSIssueResolved = holdLFSIssueResolved;
            bool newRequiresRoboticPrep = requiresRoboticPrep;
            DateTime? newRequiresRoboticPrepCompleted = requiresRoboticPrepCompleted;
            string newLinerType = linerType;
            string newPrepType = prepType;
            bool newDyeTestReq = dyeTestReq;
            DateTime? newDyeTestComplete = null; if (dyeTestComplete.HasValue) newDyeTestComplete = dyeTestComplete;
            string newContractYear = contractYear;

            // Update work
            WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
            workJunctionLiningLateral.UpdateDirect(workId, sectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, false, companyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, newPipeLocated, newServicesLocated, newCoInstalled, newBackfilledConcrete, newBackfilledSoil, newGrouted, newCored, newPrepped, newMeasured, newLinerSize, newInProcess, newInStock, newDelivered, newBuildRebuild, newPreVideo, newLinerInstalled, newFinalVideo, newCost, newVideoInspection, newCoRequired, newPitRequired, newCoPitLocation, newPostContractDigRequired, newCoCutDown, newFinalRestoration, companyId, newVideoLengthToPropertyLine, newLiningThruCo, newNoticeDelivered, newHamiltonInspectionNumber, newFlange, newGasket, newDepthOfLocated, newDigRequiredPriorToLining, newDigRequiredPriorToLiningCompleted, newDigRequiredAfterLining, newDigRequiredAfterLiningCompleted, newOutOfScope, newHoldClientIssue, newHoldClientIssueResolved, newHoldLFSIssue, newHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, newLinerType, newPrepType, newDyeTestReq, newDyeTestComplete, originalContractYear, newContractYear);
        }
        /// <summary>
        /// Save all sections & works to database (direct)
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="length">length</param>
        /// <param name="companyId">companyId</param>
        /// <param name="isNewMeasuredFromDsmh">isNewMeasuredFromDsmh</param>
        /// <param name="prepDataRoboticPrep">prepDataRoboticPrep</param>
        /// <param name="prepDataRoboticPrepCompleted">prepDataRoboticPrepCompleted</param>
        public void Save(int workId, int projectId, int sectionAssetId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string length, int companyId, bool isNewMeasuredFromDsmh, bool prepDataRoboticPrep, DateTime? prepDataRoboticPrepCompleted)
        {
            // Update Laterals
            RehabAssessmentLateralDetailsGateway rehabAssessmentLateralDetailsGateway = new RehabAssessmentLateralDetailsGateway(Data);

            if (rehabAssessmentLateralDetailsGateway.Table.Rows.Count > 0)
            {
                // Get WorkId
                if (workId == 0)
                {
                    WorkFullLengthLining workFullLengthLining = new WorkFullLengthLining(null);
                    workId = workFullLengthLining.InsertDirectEmptyWorks(projectId, sectionAssetId, null, "", null, null, null, null, null, null, null, false, false, false, false, false, false, false, companyId, false, "", "");
                }

                foreach (RehabAssessmentTDS.LateralDetailsRow row in (RehabAssessmentTDS.LateralDetailsDataTable)Table)
                {
                    int lateral = row.Lateral;

                    ProjectGateway projectGateway = new ProjectGateway();
                    projectGateway.LoadByProjectId(projectId);
                    int clientId = projectGateway.GetClientID(projectId);

                    // ... Insert lateral
                    if ((!row.InDatabase) && (!row.Deleted))
                    {
                        string videoDistance = rehabAssessmentLateralDetailsGateway.GetVideoDistance(lateral);
                        string clockPosition = rehabAssessmentLateralDetailsGateway.GetClockPosition(lateral);
                        string distanceToCentre = rehabAssessmentLateralDetailsGateway.GetDistanceToCentre(lateral);
                        string timeOpened = rehabAssessmentLateralDetailsGateway.GetTimeOpened(lateral);
                        string reverseSetup = rehabAssessmentLateralDetailsGateway.GetReverseSetup(lateral);
                        DateTime? reinstate = rehabAssessmentLateralDetailsGateway.GetReinstate(lateral);
                        string comments = rehabAssessmentLateralDetailsGateway.GetComments(lateral);
                        string clientLateralId = rehabAssessmentLateralDetailsGateway.GetClientLateralId(lateral);
                        string clientInspectionNo = rehabAssessmentLateralDetailsGateway.GetClientInspectionNo(lateral);
                        DateTime? v1Inspection = rehabAssessmentLateralDetailsGateway.GetV1Inspection(lateral);
                        bool requiredRoboticPrep = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrep(lateral);
                        DateTime? requiredRoboticPrepDate = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrepDate(lateral);
                        bool holdClientIssue = rehabAssessmentLateralDetailsGateway.GetHoldClientIssue(lateral);
                        bool holdLFSIssue = rehabAssessmentLateralDetailsGateway.GetHoldLFSIssue(lateral);
                        bool lineLateral = rehabAssessmentLateralDetailsGateway.GetLineLateral(lateral);
                        string flange = rehabAssessmentLateralDetailsGateway.GetFlange(lateral);
                        bool dyeTestReq = rehabAssessmentLateralDetailsGateway.GetDyeTestReq(lateral);
                        DateTime? dyeTestComplete = null; if (rehabAssessmentLateralDetailsGateway.GetDyeTestComplete(lateral).HasValue) dyeTestComplete = rehabAssessmentLateralDetailsGateway.GetDyeTestComplete(lateral);
                        string contractYear = rehabAssessmentLateralDetailsGateway.GetContractYear(lateral);

                        // ... ... Insert asset
                        int lateral_assetId = SaveLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, companyId, isNewMeasuredFromDsmh);

                        // ... ... Insert lateral to FulllengthLining
                        InsertFLLLateral(workId, lateral_assetId, videoDistance, clockPosition, distanceToCentre, timeOpened, reverseSetup, reinstate, comments, false, companyId, clientInspectionNo, v1Inspection, requiredRoboticPrep, requiredRoboticPrepDate, holdClientIssue, holdLFSIssue, lineLateral, dyeTestReq, dyeTestComplete, contractYear);

                        // ... ... If lateral will be in Junction Lining
                        if ((row.LineLateral) && (!row.InJlDatabase))
                        {
                            if (((!prepDataRoboticPrep) && (!prepDataRoboticPrepCompleted.HasValue)) || ((prepDataRoboticPrep) && (prepDataRoboticPrepCompleted.HasValue)))
                            {
                                // ... ... Load work id
                                int sectionWorkId = 0;
                                WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(workJunctionLiningLateralGateway.Data);
                                workJunctionLiningLateral.InsertDirect(projectId, lateral_assetId, sectionWorkId, null, null, null, null, null, null, null, null, null, "", null, null, null, 0, null, null, null, 0, v1Inspection, true, false, "", false, null, null, false, companyId, "", "", "", false, null, "", flange, "", "", false, null, false, null, false, holdClientIssue, null, holdLFSIssue, null, requiredRoboticPrep, requiredRoboticPrepDate, "", "", dyeTestReq, dyeTestComplete, contractYear);
                            }
                        }

                        // ... Insert material for M1 lateral
                        try
                        {
                            string material = rehabAssessmentLateralDetailsGateway.GetMaterialType(lateral);
                            if (material != "")
                            {
                                InsertMaterial(lateral_assetId, material, companyId);
                            }
                        }
                        catch { }

                        //... Insert client lateral id
                        try
                        {
                            if (clientLateralId.Trim() != "")
                            {
                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                lfsAssetSewerLateralClient.InsertDirect(lateral_assetId, clientId, clientLateralId, false, companyId);
                            }
                        }
                        catch { }
                    }

                    // ... Edit laterals
                    if ((row.InDatabase) && (!row.Deleted))
                    {
                        // original values
                        string originalVideoDistance = rehabAssessmentLateralDetailsGateway.GetVideoDistanceOriginal(lateral);
                        string originalClockPosition = rehabAssessmentLateralDetailsGateway.GetClockPositionOriginal(lateral);
                        string originalDistanceToCentre = rehabAssessmentLateralDetailsGateway.GetDistanceToCentreOriginal(lateral);
                        string originalTimeOpened = rehabAssessmentLateralDetailsGateway.GetTimeOpenedOriginal(lateral);
                        string originalReverseSetup = rehabAssessmentLateralDetailsGateway.GetReverseSetupOriginal(lateral);
                        DateTime? originalReinstate = rehabAssessmentLateralDetailsGateway.GetReinstateOriginal(lateral);
                        string originalComments = rehabAssessmentLateralDetailsGateway.GetCommentsOriginal(lateral);
                        string originalClientLateralId = rehabAssessmentLateralDetailsGateway.GetClientLateralIdOriginal(lateral);
                        string originalClientInspectionNo = rehabAssessmentLateralDetailsGateway.GetClientInspectionNoOriginal(lateral);
                        DateTime? originalV1Inspection = rehabAssessmentLateralDetailsGateway.GetV1InspectionOriginal(lateral);
                        bool originalRequiresRoboticPrep = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrepOriginal(lateral);
                        DateTime? originalRequiresRoboticPrepDate = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrepDateOriginal(lateral);
                        bool originalHoldClientIssue = rehabAssessmentLateralDetailsGateway.GetHoldClientIssueOriginal(lateral);
                        bool originalHoldLFSIssue = rehabAssessmentLateralDetailsGateway.GetHoldLFSIssueOriginal(lateral);
                        bool originalLineLateral = rehabAssessmentLateralDetailsGateway.GetLineLateralOriginal(lateral);
                        bool originalDyeTestReq = rehabAssessmentLateralDetailsGateway.GetDyeTestReqOriginal(lateral);
                        DateTime? originalDyeTestComplete = null; if (rehabAssessmentLateralDetailsGateway.GetDyeTestCompleteOriginal(lateral).HasValue) originalDyeTestComplete = rehabAssessmentLateralDetailsGateway.GetDyeTestCompleteOriginal(lateral);
                        string originalContractYear = rehabAssessmentLateralDetailsGateway.GetContractYearOriginal(lateral);

                        // new values
                        string newVideoDistance = rehabAssessmentLateralDetailsGateway.GetVideoDistance(lateral);
                        string newClockPosition = rehabAssessmentLateralDetailsGateway.GetClockPosition(lateral);
                        string newDistanceToCentre = rehabAssessmentLateralDetailsGateway.GetDistanceToCentre(lateral);
                        string newTimeOpened = rehabAssessmentLateralDetailsGateway.GetTimeOpened(lateral);
                        string newReverseSetup = rehabAssessmentLateralDetailsGateway.GetReverseSetup(lateral);
                        DateTime? newReinstate = rehabAssessmentLateralDetailsGateway.GetReinstate(lateral);
                        string newComments = rehabAssessmentLateralDetailsGateway.GetComments(lateral);
                        string newClientLateralId = rehabAssessmentLateralDetailsGateway.GetClientLateralId(lateral);
                        string newClientInspectionNo = rehabAssessmentLateralDetailsGateway.GetClientInspectionNo(lateral);
                        DateTime? newV1Inspection = rehabAssessmentLateralDetailsGateway.GetV1Inspection(lateral);
                        bool newRequiresRoboticPrep = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrep(lateral);
                        DateTime? newRequiresRoboticPrepDate = rehabAssessmentLateralDetailsGateway.GetRequiresRoboticPrepDate(lateral);
                        bool newHoldClientIssue = rehabAssessmentLateralDetailsGateway.GetHoldClientIssue(lateral);
                        bool newHoldLFSIssue = rehabAssessmentLateralDetailsGateway.GetHoldLFSIssue(lateral);
                        bool newLineLateral = rehabAssessmentLateralDetailsGateway.GetLineLateral(lateral);
                        string newFlange = rehabAssessmentLateralDetailsGateway.GetFlange(lateral);
                        bool newDyeTestReq = rehabAssessmentLateralDetailsGateway.GetDyeTestReq(lateral);
                        DateTime? newDyeTestComplete = null; if (rehabAssessmentLateralDetailsGateway.GetDyeTestComplete(lateral).HasValue) newDyeTestComplete = rehabAssessmentLateralDetailsGateway.GetDyeTestComplete(lateral);
                        string newContractYear = rehabAssessmentLateralDetailsGateway.GetContractYear(lateral);

                        // ... Update laterals
                        int lateral_assetId = SaveLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, companyId, isNewMeasuredFromDsmh);
                        UpdateLateral(row, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, length, companyId);

                        // ... Update if lateral is in FulllenghtLining
                        if (!row.InFllDatabase)
                        {
                            WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateay = new WorkFullLengthLiningM1LateralGateway();
                            workFullLengthLiningM1LateralGateay.LoadAllByWorkIdLateral(workId, lateral_assetId, companyId);

                            if (workFullLengthLiningM1LateralGateay.Table.Rows.Count == 0)
                            {
                                InsertFLLLateral(workId, lateral_assetId, newVideoDistance, newClockPosition, newDistanceToCentre, newTimeOpened, newReverseSetup, newReinstate, newComments, false, companyId, newClientInspectionNo, newV1Inspection, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newLineLateral, newDyeTestReq, newDyeTestComplete, newContractYear);
                            }
                            else
                            {
                                UpdateFLLLateral(workId, lateral_assetId, originalVideoDistance, originalClockPosition, originalDistanceToCentre, originalTimeOpened, originalReverseSetup, originalReinstate, originalComments, true, companyId, originalClientInspectionNo, originalV1Inspection, originalRequiresRoboticPrep, originalRequiresRoboticPrepDate, originalHoldClientIssue, originalHoldLFSIssue, originalLineLateral, originalDyeTestReq, originalDyeTestComplete, originalContractYear, workId, lateral_assetId, newVideoDistance, newClockPosition, newDistanceToCentre, newTimeOpened, newReverseSetup, newReinstate, newComments, false, companyId, newClientInspectionNo, newV1Inspection, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newLineLateral, newDyeTestReq, newDyeTestComplete, newContractYear);
                            }
                        }
                        else
                        {
                            UpdateFLLLateral(workId, lateral_assetId, originalVideoDistance, originalClockPosition, originalDistanceToCentre, originalTimeOpened, originalReverseSetup, originalReinstate, originalComments, false, companyId, originalClientInspectionNo, originalV1Inspection, originalRequiresRoboticPrep, originalRequiresRoboticPrepDate, originalHoldClientIssue, originalHoldLFSIssue, originalLineLateral, originalDyeTestReq, originalDyeTestComplete, originalContractYear,workId, lateral_assetId, newVideoDistance, newClockPosition, newDistanceToCentre, newTimeOpened, newReverseSetup, newReinstate, newComments, false, companyId, newClientInspectionNo, newV1Inspection, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newLineLateral, newDyeTestReq, newDyeTestComplete, newContractYear);
                        }

                        // ... Update if lateral is in Junction Lining
                        if (row.InJlDatabase)
                        {
                            if (originalLineLateral == newLineLateral)
                            {
                                // ... ... Update jl lateral (clientInspectionNo, v1Inspection, requiredRoboticPrep, requiredRoboticPrepDate, holdClientIssue, holdLFSIssue, flange)
                                UpdateJLLaterals(projectId, lateral_assetId, companyId, newV1Inspection, newClientInspectionNo, newRequiresRoboticPrep, newRequiresRoboticPrepDate, newHoldClientIssue, newHoldLFSIssue, newFlange, newDyeTestReq, newDyeTestComplete, newContractYear);
                            }
                            else
                            {
                                int sectionWorkId = 0;
                                WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                // Delete empty lateral form jl.
                                DeleteJLLaterals(projectId, lateral_assetId, companyId, sectionWorkId);
                            }
                        }
                        else
                        {
                            // ... ... Insert if should be in junction Lining
                            if (row.LineLateral)
                            {
                                if (((!prepDataRoboticPrep) && (!prepDataRoboticPrepCompleted.HasValue)) || ((prepDataRoboticPrep) && (prepDataRoboticPrepCompleted.HasValue)))
                                {
                                    int sectionWorkId = 0;

                                    // Insert to jl laterals
                                    WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                                    sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, sectionAssetId, null, 0, 0, false, "No", 0, 0, false, companyId, "", "", "", "", false, "", 0);

                                    WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                                    WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(workJunctionLiningLateralGateway.Data);
                                    workJunctionLiningLateral.InsertDirect(projectId, lateral_assetId, sectionWorkId, null, null, null, null, null, null, null, null, null, "", null, null, null, 0, null, null, null, 0, newV1Inspection, false, false, "", false, null, null, false, companyId, "", "", "", false, null, newClientInspectionNo, newFlange, "", "", false, null, false, null, false, newHoldClientIssue, null, newHoldLFSIssue, null, newRequiresRoboticPrep, newRequiresRoboticPrepDate, "", "", newDyeTestReq, newDyeTestComplete, newContractYear);
                                }
                            }
                        }

                        string material = rehabAssessmentLateralDetailsGateway.GetMaterialType(lateral);
                        if (material != "")
                        {
                            InsertMaterial(lateral_assetId, material, companyId);
                        }

                        try
                        {
                            LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                            lfsAssetSewerLateralClientGateway.LoadAllByAssetIdClientId(lateral_assetId, clientId, companyId);

                            if (lfsAssetSewerLateralClientGateway.Table.Rows.Count == 0)
                            {
                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                lfsAssetSewerLateralClient.InsertDirect(lateral_assetId, clientId, originalClientLateralId, false, companyId);
                            }
                            else
                            {
                                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                                string originalClientLateralId2 = lfsAssetSewerLateralClientGateway.GetClientLateralId(lateral_assetId, clientId);

                                lfsAssetSewerLateralClient.UpdateDirect(lateral_assetId, clientId, originalClientLateralId, false, companyId, lateral_assetId, clientId, newClientLateralId, false, companyId);
                            }
                        }
                        catch
                        { }
                    }

                    // ... Delete laterals
                    if ((row.InDatabase) && (row.Deleted))
                    {
                        DeleteFLLLateral(workId, row.Lateral, companyId, clientId);
                    }
                }
            }
        }
        /// <summary>
        /// UpdateForReportForJunctionLining
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="workId">workId</param>
        /// <param name="projectId">projectId</param>        
        /// <param name="measuredFrom">measuredFrom</param>
        /// /// <param name="companyId">companyId</param>
        private int UpdateForReportForJunctionLining(int assetId, int workId, int projectId, string measuredFrom, int companyId)
        {
            int lateralsTot = 0;

            foreach (LateralLocationSheetReportTDS.LateralLocationSheetRow row in (LateralLocationSheetReportTDS.LateralLocationSheetDataTable)Table)
            {
                if (row.AssetID == assetId)
                {
                    int lateralNumber = 0;

                    LateralLocationSheetLateralDetailsReport lateralLocationSheetLateralDetailsReportSorted;

                    LateralLocationSheetLateralDetailsReport lateralLocationSheetLateralDetailsReport = new LateralLocationSheetLateralDetailsReport();
                    lateralLocationSheetLateralDetailsReport.LoadBySectionIdWorkIdProjectId(assetId, workId, projectId, companyId);
                    lateralsTot = lateralLocationSheetLateralDetailsReport.Table.Rows.Count;

                    if (lateralLocationSheetLateralDetailsReport.Table.Rows.Count > 0)
                    {
                        int totalLaterals = 0;
                        totalLaterals = lateralLocationSheetLateralDetailsReport.Table.Rows.Count;
                        decimal div;
                        decimal interval;

                        if (totalLaterals > 26)
                        {
                            interval = 1;
                        }
                        else
                        {
                            div = 26 / totalLaterals;
                            interval = Math.Truncate(div);
                        }

                        lateralLocationSheetLateralDetailsReportSorted = Sort(lateralLocationSheetLateralDetailsReport, measuredFrom);

                        foreach (LateralLocationSheetReportTDS.LateralLocationSheetLateralDetailsRow lateralRow in (LateralLocationSheetReportTDS.LateralLocationSheetLateralDetailsDataTable)lateralLocationSheetLateralDetailsReportSorted.Table)
                        {
                            lateralNumber = lateralNumber + (int)interval;

                            if (totalLaterals == 1)
                            {
                                lateralNumber = 13;
                            }

                            // Determine position
                            string clock = ""; if (!lateralRow.IsClockPositionNull()) clock = lateralRow.ClockPosition;
                            string clockPosition = "N";
                            Distance d;
                            string distance = "";

                            if (measuredFrom == "DSMH")
                            {
                                clockPosition = "S";

                                if (clock != "")
                                {
                                    if (clock == "1" || clock == "1:00" || clock == "01:00" || clock == "2" || clock == "2:00" || clock == "02:00" || clock == "3" || clock == "3:00" || clock == "03:00" || clock == "4" || clock == "4:00" || clock == "04:00" || clock == "5" || clock == "5:00" || clock == "05:00" || clock == "6" && clock != "6:00" && clock != "06:00")
                                    {
                                        clockPosition = "N";
                                    }
                                }

                                if (!lateralRow.IsReverseSetupNull()) d = new Distance(lateralRow.ReverseSetup); else d = new Distance();
                                distance = (!lateralRow.IsReverseSetupNull()) ? d.ToStringInMet3() + "/" + ((decimal)Math.Round(d.ToDoubleInEng3(), 1)).ToString() + "ft  " : "Distance not defined.  ";
                            }
                            else
                            {
                                clockPosition = "N";

                                if (clock != "")
                                {
                                    if (clock == "1" || clock == "1:00" || clock == "01:00" || clock == "2" || clock == "2:00" || clock == "02:00" || clock == "3" || clock == "3:00" || clock == "03:00" || clock == "4" || clock == "4:00" || clock == "04:00" || clock == "5" || clock == "5:00" || clock == "05:00" || clock == "6" && clock != "6:00" && clock != "06:00")
                                    {
                                        clockPosition = "S";
                                    }
                                }

                                if (!lateralRow.IsVideoDistanceNull()) d = new Distance(lateralRow.VideoDistance); else d = new Distance();
                                distance = (!lateralRow.IsVideoDistanceNull()) ? d.ToStringInMet3() + "/" + ((decimal)Math.Round(d.ToDoubleInEng3(), 1)).ToString() + "ft  " : "Distance not defined.  ";
                            }

                            // Determine address
                            string address = ""; if (!lateralRow.IsAddressNull()) address = lateralRow.Address;
                            string connection = "";
                            string connectionType = ""; if (!lateralRow.IsConnectionTypeNull()) connectionType = lateralRow.ConnectionType;
                            if (connectionType != "")
                            {
                                connection += " (" + connectionType + ")    ";
                            }
                            else
                            {
                                connection += "    ";
                            }

                            // Determine state
                            string state = ""; if (!lateralRow.IsStateNull())
                            {
                                if (lateralRow.State == "Visibly Plugged")
                                {
                                    state = "- VP ";
                                }
                                else
                                {
                                    state = "- " + lateralRow.State + "  ";
                                }
                            }

                            // Determine color, flange and out of scope
                            DateTime? linerInstalled = null;
                            string flange = "";
                            bool outOfScope = false;

                            int workIdJl = GetWorkId(projectId, lateralRow.AssetID, "Junction Lining Lateral", companyId);
                            if (workIdJl > 0)
                            {
                                WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
                                workJunctionLiningLateralGateway.LoadByWorkId(workIdJl, companyId);
                                linerInstalled = workJunctionLiningLateralGateway.GetLinerInstalled(workIdJl);
                                flange = workJunctionLiningLateralGateway.GetFlange(workIdJl);
                                outOfScope = workJunctionLiningLateralGateway.GetOutOfScope(workIdJl);
                            }

                            string color = "";

                            if (linerInstalled.HasValue)
                            {
                                color = "blue";
                            }
                            else
                            {
                                if (outOfScope)
                                {
                                    color = "red";
                                }
                                else
                                {
                                    if (lateralRow.LineLateral)
                                    {
                                        color = "green";
                                    }
                                    else
                                    {
                                        if ((!lateralRow.IsStateNull()) && (lateralRow.State == "Visibly Plugged") || (!lateralRow.LineLateral))
                                        {
                                            color = "red";
                                        }
                                    }
                                }
                            }

                            // Set distance
                            if ((distance == "0.00m/0ft") && (flange == "MH Shot"))
                            {
                                distance = " " + connection + distance + "MH Shot  " + state + "  ";
                            }
                            else
                            {
                                distance = " " + connection + distance + state + "  ";
                            }

                            // Set values
                            switch (lateralNumber)
                            {
                                case 1:
                                    row.ID1 = lateralRow.LateralID;
                                    row.A1 = address;
                                    row.D1 = distance;
                                    row.CP1 = clockPosition;
                                    row.C1 = color;
                                    break;

                                case 2:
                                    row.ID2 = lateralRow.LateralID;
                                    row.A2 = address;
                                    row.D2 = distance;
                                    row.CP2 = clockPosition;
                                    row.C2 = color;
                                    break;

                                case 3:
                                    row.ID3 = lateralRow.LateralID;
                                    row.A3 = address;
                                    row.D3 = distance;
                                    row.CP3 = clockPosition;
                                    row.C3 = color;
                                    break;

                                case 4:
                                    row.ID4 = lateralRow.LateralID;
                                    row.A4 = address;
                                    row.D4 = distance;
                                    row.CP4 = clockPosition;
                                    row.C4 = color;
                                    break;

                                case 5:
                                    row.ID5 = lateralRow.LateralID;
                                    row.A5 = address;
                                    row.D5 = distance;
                                    row.CP5 = clockPosition;
                                    row.C5 = color;
                                    break;

                                case 6:
                                    row.ID6 = lateralRow.LateralID;
                                    row.A6 = address;
                                    row.D6 = distance;
                                    row.CP6 = clockPosition;
                                    row.C6 = color;
                                    break;

                                case 7:
                                    row.ID7 = lateralRow.LateralID;
                                    row.A7 = address;
                                    row.D7 = distance;
                                    row.CP7 = clockPosition;
                                    row.C7 = color;
                                    break;

                                case 8:
                                    row.ID8 = lateralRow.LateralID;
                                    row.A8 = address;
                                    row.D8 = distance;
                                    row.CP8 = clockPosition;
                                    row.C8 = color;
                                    break;

                                case 9:
                                    row.ID9 = lateralRow.LateralID;
                                    row.A9 = address;
                                    row.D9 = distance;
                                    row.CP9 = clockPosition;
                                    row.C9 = color;
                                    break;

                                case 10:
                                    row.ID10 = lateralRow.LateralID;
                                    row.A10 = address;
                                    row.D10 = distance;
                                    row.CP10 = clockPosition;
                                    row.C10 = color;
                                    break;

                                case 11:
                                    row.ID11 = lateralRow.LateralID;
                                    row.A11 = address;
                                    row.D11 = distance;
                                    row.CP11 = clockPosition;
                                    row.C11 = color;
                                    break;

                                case 12:
                                    row.ID12 = lateralRow.LateralID;
                                    row.A12 = address;
                                    row.D12 = distance;
                                    row.CP12 = clockPosition;
                                    row.C12 = color;
                                    break;

                                case 13:
                                    row.ID13 = lateralRow.LateralID;
                                    row.A13 = address;
                                    row.D13 = distance;
                                    row.CP13 = clockPosition;
                                    row.C13 = color;
                                    break;

                                case 14:
                                    row.ID14 = lateralRow.LateralID;
                                    row.A14 = address;
                                    row.D14 = distance;
                                    row.CP14 = clockPosition;
                                    row.C14 = color;
                                    break;

                                case 15:
                                    row.ID15 = lateralRow.LateralID;
                                    row.A15 = address;
                                    row.D15 = distance;
                                    row.CP15 = clockPosition;
                                    row.C15 = color;
                                    break;

                                case 16:
                                    row.ID16 = lateralRow.LateralID;
                                    row.A16 = address;
                                    row.D16 = distance;
                                    row.CP16 = clockPosition;
                                    row.C16 = color;
                                    break;

                                case 17:
                                    row.ID17 = lateralRow.LateralID;
                                    row.A17 = address;
                                    row.D17 = distance;
                                    row.CP17 = clockPosition;
                                    row.C17 = color;
                                    break;

                                case 18:
                                    row.ID18 = lateralRow.LateralID;
                                    row.A18 = address;
                                    row.D18 = distance;
                                    row.CP18 = clockPosition;
                                    row.C18 = color;
                                    break;

                                case 19:
                                    row.ID19 = lateralRow.LateralID;
                                    row.A19 = address;
                                    row.D19 = distance;
                                    row.CP19 = clockPosition;
                                    row.C19 = color;
                                    break;

                                case 20:
                                    row.ID20 = lateralRow.LateralID;
                                    row.A20 = address;
                                    row.D20 = distance;
                                    row.CP20 = clockPosition;
                                    row.C20 = color;
                                    break;

                                case 21:
                                    row.ID21 = lateralRow.LateralID;
                                    row.A21 = address;
                                    row.D21 = distance;
                                    row.CP21 = clockPosition;
                                    row.C21 = color;
                                    break;

                                case 22:
                                    row.ID22 = lateralRow.LateralID;
                                    row.A22 = address;
                                    row.D22 = distance;
                                    row.CP22 = clockPosition;
                                    row.C22 = color;
                                    break;

                                case 23:
                                    row.ID23 = lateralRow.LateralID;
                                    row.A23 = address;
                                    row.D23 = distance;
                                    row.CP23 = clockPosition;
                                    row.C23 = color;
                                    break;

                                case 24:
                                    row.ID24 = lateralRow.LateralID;
                                    row.A24 = address;
                                    row.D24 = distance;
                                    row.CP24 = clockPosition;
                                    row.C24 = color;
                                    break;

                                case 25:
                                    row.ID25 = lateralRow.LateralID;
                                    row.A25 = address;
                                    row.D25 = distance;
                                    row.CP25 = clockPosition;
                                    row.C25 = color;
                                    break;

                                case 26:
                                    row.ID26 = lateralRow.LateralID;
                                    row.A26 = address;
                                    row.D26 = distance;
                                    row.CP26 = clockPosition;
                                    row.C26 = color;
                                    break;

                                case 27:
                                    row.ID27 = lateralRow.LateralID;
                                    row.A27 = address;
                                    row.D27 = distance;
                                    row.CP27 = clockPosition;
                                    row.C27 = color;
                                    break;

                                case 28:
                                    row.ID28 = lateralRow.LateralID;
                                    row.A28 = address;
                                    row.D28 = distance;
                                    row.CP28 = clockPosition;
                                    row.C28 = color;
                                    break;

                                case 29:
                                    row.ID29 = lateralRow.LateralID;
                                    row.A29 = address;
                                    row.D29 = distance;
                                    row.CP29 = clockPosition;
                                    row.C29 = color;
                                    break;

                                case 30:
                                    row.ID30 = lateralRow.LateralID;
                                    row.A30 = address;
                                    row.D30 = distance;
                                    row.CP30 = clockPosition;
                                    row.C30 = color;
                                    break;

                                case 31:
                                    row.ID31 = lateralRow.LateralID;
                                    row.A31 = address;
                                    row.D31 = distance;
                                    row.CP31 = clockPosition;
                                    row.C31 = color;
                                    break;

                                case 32:
                                    row.ID32 = lateralRow.LateralID;
                                    row.A32 = address;
                                    row.D32 = distance;
                                    row.CP32 = clockPosition;
                                    row.C32 = color;
                                    break;

                                case 33:
                                    row.ID33 = lateralRow.LateralID;
                                    row.A33 = address;
                                    row.D33 = distance;
                                    row.CP33 = clockPosition;
                                    row.C33 = color;
                                    break;

                                case 34:
                                    row.ID34 = lateralRow.LateralID;
                                    row.A34 = address;
                                    row.D34 = distance;
                                    row.CP34 = clockPosition;
                                    row.C34 = color;
                                    break;

                                case 35:
                                    row.ID35 = lateralRow.LateralID;
                                    row.A35 = address;
                                    row.D35 = distance;
                                    row.CP35 = clockPosition;
                                    row.C35 = color;
                                    break;

                                case 36:
                                    row.ID36 = lateralRow.LateralID;
                                    row.A36 = address;
                                    row.D36 = distance;
                                    row.CP36 = clockPosition;
                                    row.C36 = color;
                                    break;

                                case 37:
                                    row.ID37 = lateralRow.LateralID;
                                    row.A37 = address;
                                    row.D37 = distance;
                                    row.CP37 = clockPosition;
                                    row.C37 = color;
                                    break;

                                case 38:
                                    row.ID38 = lateralRow.LateralID;
                                    row.A38 = address;
                                    row.D38 = distance;
                                    row.CP38 = clockPosition;
                                    row.C38 = color;
                                    break;

                                case 39:
                                    row.ID39 = lateralRow.LateralID;
                                    row.A39 = address;
                                    row.D39 = distance;
                                    row.CP39 = clockPosition;
                                    row.C39 = color;
                                    break;

                                case 40:
                                    row.ID40 = lateralRow.LateralID;
                                    row.A40 = address;
                                    row.D40 = distance;
                                    row.CP40 = clockPosition;
                                    row.C40 = color;
                                    break;

                                case 41:
                                    row.ID41 = lateralRow.LateralID;
                                    row.A41 = address;
                                    row.D41 = distance;
                                    row.CP41 = clockPosition;
                                    row.C41 = color;
                                    break;

                                case 42:
                                    row.ID42 = lateralRow.LateralID;
                                    row.A42 = address;
                                    row.D42 = distance;
                                    row.CP42 = clockPosition;
                                    row.C42 = color;
                                    break;

                                case 43:
                                    row.ID43 = lateralRow.LateralID;
                                    row.A43 = address;
                                    row.D43 = distance;
                                    row.CP43 = clockPosition;
                                    row.C43 = color;
                                    break;

                                case 44:
                                    row.ID44 = lateralRow.LateralID;
                                    row.A44 = address;
                                    row.D44 = distance;
                                    row.CP44 = clockPosition;
                                    row.C44 = color;
                                    break;

                                case 45:
                                    row.ID45 = lateralRow.LateralID;
                                    row.A45 = address;
                                    row.D45 = distance;
                                    row.CP45 = clockPosition;
                                    row.C45 = color;
                                    break;

                                case 46:
                                    row.ID46 = lateralRow.LateralID;
                                    row.A46 = address;
                                    row.D46 = distance;
                                    row.CP46 = clockPosition;
                                    row.C46 = color;
                                    break;

                                case 47:
                                    row.ID47 = lateralRow.LateralID;
                                    row.A47 = address;
                                    row.D47 = distance;
                                    row.CP47 = clockPosition;
                                    row.C47 = color;
                                    break;

                                case 48:
                                    row.ID48 = lateralRow.LateralID;
                                    row.A48 = address;
                                    row.D48 = distance;
                                    row.CP48 = clockPosition;
                                    row.C48 = color;
                                    break;

                                case 49:
                                    row.ID49 = lateralRow.LateralID;
                                    row.A49 = address;
                                    row.D49 = distance;
                                    row.CP49 = clockPosition;
                                    row.C49 = color;
                                    break;

                                case 50:
                                    row.ID50 = lateralRow.LateralID;
                                    row.A50 = address;
                                    row.D50 = distance;
                                    row.CP50 = clockPosition;
                                    row.C50 = color;
                                    break;

                                case 51:
                                    row.ID51 = lateralRow.LateralID;
                                    row.A51 = address;
                                    row.D51 = distance;
                                    row.CP51 = clockPosition;
                                    row.C51 = color;
                                    break;

                                case 52:
                                    row.ID52 = lateralRow.LateralID;
                                    row.A52 = address;
                                    row.D52 = distance;
                                    row.CP52 = clockPosition;
                                    row.C52 = color;
                                    break;

                                default:
                                    break;
                            }
                        }
                    }
                }
            }

            return lateralsTot;
        }
 /// <summary>
 /// Save a lateral work
 /// </summary>
 /// <param name="projectId">projectId</param>
 /// <param name="lateralAssetId">lateralAssetId</param>
 /// <param name="sectionWorkId">sectionWorkId</param>
 /// <param name="companyId">companyId</param>
 private void SaveJLLWork(int projectId, int lateralAssetId, int sectionWorkId, int companyId)
 {
     WorkJunctionLiningLateralGateway workJunctionLiningLateralGateway = new WorkJunctionLiningLateralGateway();
     WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(workJunctionLiningLateralGateway.Data);
     workJunctionLiningLateral.InsertDirect(projectId, lateralAssetId, sectionWorkId, null, null, null, null, null, null, null, null, null, "", null, null, null, 0, null, null, null, 0, null, false, false, "", false, null, null, false, companyId, "", "", "", false, null, "", "", "", "", false, null, false, null, false, false, null, false, null, false, null, "", "", false, DateTime.Now, "");
 }