/// <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="companyId">companyId</param>
        public void DeleteDirect(int workId, int companyId)
        {
            WorkRehabAssessmentGateway workRehabAssessmentGateway = new WorkRehabAssessmentGateway(null);
            workRehabAssessmentGateway.Delete(workId, companyId);

            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);
        }
        /// <summary>
        /// InsertDirect a rehabilitation
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="preppredDate">preppredDate</param>
        /// <param name="sprayedDate">sprayedDate</param>
        /// <param name="batchId">batchId</param>
        /// <param name="deleted">deleted</param>       
        /// <param name="companyId">companyId</param>        
        public int InsertDirectEmptyWorks(int projectId, int assetId, DateTime? preppredDate, DateTime? sprayedDate, int? batchId, bool deleted, int companyId)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Manhole Rehabilitation", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Manhole Rehabilitation", null, deleted, companyId, "", "");
                new WorkManholeRehabilitationGateway(null).Insert(workId, preppredDate, sprayedDate, batchId, deleted, companyId);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Manhole Rehabilitation", projectId);
            }

            return workId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="projectId">projectId></param>
        /// <param name="assetId">assetId</param>
        /// <param name="libraryCategoriesId">libraryCategoriesId</param>
        /// <param name="preFlushDate">preFlushDate</param>
        /// <param name="preVideoDate">preVideoDate</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        public int InsertDirect(int projectId, int assetId, int? libraryCategoriesId, DateTime? preFlushDate, DateTime? preVideoDate, bool deleted, int companyId, string comments, string history)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Rehab Assessment", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Rehab Assessment", libraryCategoriesId, deleted, companyId, comments, history);
                new WorkRehabAssessmentGateway(null).Insert(workId, preFlushDate, preVideoDate, deleted, companyId);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Rehab Assessment", projectId);
            }

            return workId;
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int workId, int companyId)
        {
            WorkPointRepairsGateway workPointRepairsGateway = new WorkPointRepairsGateway();
            workPointRepairsGateway.LoadByWorkId(workId, companyId);

            if (workPointRepairsGateway.Table.Rows.Count > 0)
            {
                // Delete WorkPointRepairsRepair
                WorkPointRepairsRepair workPointRepairsRepair = new WorkPointRepairsRepair();
                workPointRepairsRepair.Delete(workId, companyId);

                // Delete WorkPointRepairs
                workPointRepairsGateway.Delete(workId, companyId);

                // Delete work
                Work work = new Work(null);
                work.DeleteDirect(workId, companyId);
            }
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int workId, int companyId)
        {
            WorkFullLengthLiningGateway workFullLengthLiningGateway = new WorkFullLengthLiningGateway();
            workFullLengthLiningGateway.LoadByWorkId(workId, companyId);

            if (workFullLengthLiningGateway.Table.Rows.Count > 0)
            {
                // Delete P1
                WorkFullLengthLiningP1 workFullLengthLiningP1 = new WorkFullLengthLiningP1(null);
                workFullLengthLiningP1.DeleteDirect(workId, companyId);

                // Delete M1
                WorkFullLengthLiningM1 workFullLengthLiningM1 = new WorkFullLengthLiningM1(null);
                workFullLengthLiningM1.DeleteDirect(workId, companyId);

                // Delete M2
                WorkFullLengthLiningM2 workFullLengthLiningM2 = new WorkFullLengthLiningM2(null);
                workFullLengthLiningM2.DeleteDirect(workId, companyId);

                // Delete WorkComments
                WorkComments workComments = new WorkComments(null);
                workComments.DeleteAllDirect(workId, companyId);

                // Delete Catalysts

                // Delete wet out data

                // delete inversion data

                // Delete WorkFullLengthLining
                workFullLengthLiningGateway.Delete(workId, companyId);

                // Delete work
                Work work = new Work(null);
                work.DeleteDirect(workId, companyId);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateWork
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="originalPreppedDate">originalPreppedDate</param>
        /// <param name="originalSprayedDate">originalSprayedDate</param>
        /// <param name="originalBatchId">originalBatchId</param>        
        /// <param name="originalComments">originalComments</param>
        /// <param name="originalDeleted">originalDeleted</param>
        /// <param name="originalCompanyId">originalCompanyId</param>
        /// 
        /// <param name="newPreppedDate">newPreppedDate</param>
        /// <param name="newSprayedDate">newSprayedDate</param>
        /// <param name="newBatchId">newBatchId</param>        
        /// <param name="newComments">newComments</param>
        /// <param name="newDeleted">newDeleted</param>
        private void UpdateWork(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int assetId, DateTime? originalPreppedDate, DateTime? originalSprayedDate, int originalBatchId, string originalComments, bool originalDeleted, int originalCompanyId, DateTime? newPreppedDate, DateTime? newSprayedDate, int newBatchId, string newComments, bool newDeleted)
        {
            int newWorkId = 0;

            // Loading workId
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Manhole Rehabilitation", originalCompanyId);

            if (workGateway.Table.Rows.Count > 0)
            {
                newWorkId = workGateway.GetWorkId(assetId, "Manhole Rehabilitation", projectId);

                int? libraryCategoriesId = workGateway.GetLibraryCategoriesId(newWorkId);
                string history = workGateway.GetHistory(newWorkId);

                // Updating work
                Work work = new Work();
                work.UpdateDirect(newWorkId, projectId, assetId, "Manhole Rehabilitation", libraryCategoriesId, originalDeleted, originalCompanyId, originalComments, history, newWorkId, projectId, assetId, "Manhole Rehabilitation", libraryCategoriesId, originalDeleted, originalCompanyId, newComments, history);

                // Update manhole rehabilitation work
                WorkManholeRehabilitation workManholeRehabilitation = new WorkManholeRehabilitation();
                workManholeRehabilitation.UpdateDirect(newWorkId, originalPreppedDate, originalSprayedDate, originalBatchId, originalDeleted, originalCompanyId, newWorkId, newPreppedDate, newSprayedDate, newBatchId, newDeleted, originalCompanyId);
            }
        }
        /// <summary>
        /// UpdateDirect
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="companyId">companyId</param>
        public void Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int sectionAssetId, int companyId)
        {
            PointRepairsTDS pointRepairsChanges = (PointRepairsTDS)Data.GetChanges();

            if (pointRepairsChanges.WorkDetails.Rows.Count > 0)
            {
                PointRepairsWorkDetailsGateway pointRepairsWorkDetailsGateway = new PointRepairsWorkDetailsGateway(pointRepairsChanges);

                // Update sections
                foreach (PointRepairsTDS.WorkDetailsRow workDetailsRow in (PointRepairsTDS.WorkDetailsDataTable)pointRepairsChanges.WorkDetails)
                {
                    // Unchanged values
                    int workId = workDetailsRow.WorkID;

                    // Original values
                    string originalClientId = pointRepairsWorkDetailsGateway.GetClientIdOriginal(workId);
                    string originalMeasurementTakenBy = pointRepairsWorkDetailsGateway.GetMeasurementTakenByOriginal(workId);
                    DateTime? originalRepairConfirmationDate = pointRepairsWorkDetailsGateway.GetRepairConfirmationDateOriginal(workId);
                    bool originalBypassRequired = pointRepairsWorkDetailsGateway.GetBypassRequiredOriginal(workId);
                    string originalRoboticDistances = pointRepairsWorkDetailsGateway.GetRoboticDistancesOriginal(workId);
                    DateTime? originalProposedLiningDate = pointRepairsWorkDetailsGateway.GetProposedLiningDateOriginal(workId);
                    DateTime? originalDeadlineLiningDate = pointRepairsWorkDetailsGateway.GetDeadlineLiningDateOriginal(workId);
                    DateTime? originalFinalVideoDate = pointRepairsWorkDetailsGateway.GetFinalVideoDateOriginal(workId);
                    int? originalEstimatedJoints = pointRepairsWorkDetailsGateway.GetEstimatedJointsOriginal(workId);
                    int? originalJointsTestSealed = pointRepairsWorkDetailsGateway.GetJointsTestSealedOriginal(workId);
                    bool originalIssueIdentified = pointRepairsWorkDetailsGateway.GetIssueIdentifiedOriginal(workId);
                    bool originalIssueLFS = pointRepairsWorkDetailsGateway.GetIssueLFSOriginal(workId);
                    bool originalIssueClient = pointRepairsWorkDetailsGateway.GetIssueClientOriginal(workId);
                    bool originalIssueSales = pointRepairsWorkDetailsGateway.GetIssueSalesOriginal(workId);
                    bool originalIssueGivenToClient = pointRepairsWorkDetailsGateway.GetIssueGivenToClientOriginal(workId);
                    bool originalIssueResolved = pointRepairsWorkDetailsGateway.GetIssueResolvedOriginal(workId);
                    bool originalIssueInvestigation = pointRepairsWorkDetailsGateway.GetIssueInvestigationOriginal(workId);

                    // New variables
                    string newClientId = pointRepairsWorkDetailsGateway.GetClientId(workId);
                    string newMeasurementTakenBy = pointRepairsWorkDetailsGateway.GetMeasurementTakenBy(workId);
                    DateTime? newRepairConfirmationDate = pointRepairsWorkDetailsGateway.GetRepairConfirmationDate(workId);
                    bool newBypassRequired = pointRepairsWorkDetailsGateway.GetBypassRequired(workId);
                    string newRoboticDistances = pointRepairsWorkDetailsGateway.GetRoboticDistances(workId);
                    DateTime? newProposedLiningDate = pointRepairsWorkDetailsGateway.GetProposedLiningDate(workId);
                    DateTime? newDeadlineLiningDate = pointRepairsWorkDetailsGateway.GetDeadlineLiningDate(workId);
                    DateTime? newFinalVideoDate = pointRepairsWorkDetailsGateway.GetFinalVideoDate(workId);
                    int? newEstimatedJoints = pointRepairsWorkDetailsGateway.GetEstimatedJoints(workId);
                    int? newJointsTestSealed = pointRepairsWorkDetailsGateway.GetJointsTestSealed(workId);
                    bool newIssueIdentified = pointRepairsWorkDetailsGateway.GetIssueIdentified(workId);
                    bool newIssueLFS = pointRepairsWorkDetailsGateway.GetIssueLFS(workId);
                    bool newIssueClient = pointRepairsWorkDetailsGateway.GetIssueClient(workId);
                    bool newIssueSales = pointRepairsWorkDetailsGateway.GetIssueSales(workId);
                    bool newIssueGivenToClient = pointRepairsWorkDetailsGateway.GetIssueGivenToClient(workId);
                    bool newIssueResolved = pointRepairsWorkDetailsGateway.GetIssueResolved(workId);
                    bool newIssueInvestigation = pointRepairsWorkDetailsGateway.GetIssueInvestigation(workId);

                    // ... RA
                    DateTime? originalPreFlushDate = pointRepairsWorkDetailsGateway.GetPreFlushDateOriginal(workId);
                    DateTime? originalPreVideoDate = pointRepairsWorkDetailsGateway.GetPreVideoDateOriginal(workId);

                    // ... FLL P1
                    DateTime? originalP1Date = pointRepairsWorkDetailsGateway.GetP1DateOriginal(workId);
                    int? originalCxisRemoved = pointRepairsWorkDetailsGateway.GetCxisRemovedOriginal(workId);

                    // ... FLL M1
                    string originalTrafficControl = pointRepairsWorkDetailsGateway.GetTrafficControlOriginal(workId);
                    string originalMaterial = pointRepairsWorkDetailsGateway.GetMaterialOriginal(workId);

                    // ... FLL M2
                    string originalVideoLength = pointRepairsWorkDetailsGateway.GetVideoLengthOriginal(workId);

                    // ... P1
                    DateTime? newP1Date = pointRepairsWorkDetailsGateway.GetP1Date(workId);
                    int? newCxisRemoved = pointRepairsWorkDetailsGateway.GetCxisRemoved(workId);
                    string newTrafficControl = pointRepairsWorkDetailsGateway.GetTrafficControl(workId);
                    string newMaterial = pointRepairsWorkDetailsGateway.GetMaterial(workId);

                    // ... M2
                    string newVideoLength = pointRepairsWorkDetailsGateway.GetVideoLength(workId);

                    // ... RA
                    DateTime? newPreFlushDate = pointRepairsWorkDetailsGateway.GetPreFlushDate(workId);
                    DateTime? newPreVideoDate = pointRepairsWorkDetailsGateway.GetPreVideoDate(workId);

                    // ... FLL WorkID
                    int workIdFll = 0; if (!workDetailsRow.IsWorkIDFLLNull()) workIdFll = workDetailsRow.WorkIDFLL;
                    int workIdRa = 0; if (!workDetailsRow.IsWorkIDRANull()) workIdRa = workDetailsRow.WorkIDRA;

                    if (workIdFll != 0) // ... Has Fll work
                    {
                        FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway();
                        fullLengthLiningWorkDetailsGateway.LoadByWorkIdAssetId(workIdFll, sectionAssetId, companyId);

                        // Original values
                        string originalClientIdFLL = fullLengthLiningWorkDetailsGateway.GetClientIdOriginal(workIdFll);
                        DateTime? originalProposedLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetProposedLiningDateOriginal(workIdFll);
                        DateTime? originalDeadlineLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDateOriginal(workIdFll);
                        DateTime? originalM1Date = fullLengthLiningWorkDetailsGateway.GetM1DateOriginal(workIdFll);
                        DateTime? originalM2Date = fullLengthLiningWorkDetailsGateway.GetM2DateOriginal(workIdFll);
                        DateTime? originalInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDateOriginal(workIdFll);
                        DateTime? originalFinalVideoDateFLL = fullLengthLiningWorkDetailsGateway.GetFinalVideoDateOriginal(workIdFll);
                        bool originalIssueIdentifiedFLL = fullLengthLiningWorkDetailsGateway.GetIssueIdentifiedOriginal(workIdFll);
                        bool originalIssueLFSFLL = fullLengthLiningWorkDetailsGateway.GetIssueLFSOriginal(workIdFll);
                        bool originalIssueClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueClientOriginal(workIdFll);
                        bool originalIssueSalesFLL = fullLengthLiningWorkDetailsGateway.GetIssueSalesOriginal(workIdFll);
                        bool originalIssueGivenToClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClientOriginal(workIdFll);
                        bool originalIssueResolvedFLL = fullLengthLiningWorkDetailsGateway.GetIssueResolvedOriginal(workIdFll);
                        bool originalIssueInvestigationFLL = fullLengthLiningWorkDetailsGateway.GetIssueInvestigationOriginal(workIdFll);
                        bool originalRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedOriginal(workIdFll);
                        DateTime? originalRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDateOriginal(workIdFll);
                        bool originalP1Completed = fullLengthLiningWorkDetailsGateway.GetP1CompletedOriginal(workIdFll);

                        // M1 data
                        string originalMeasurementTakenByFLL = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByOriginal(workIdFll);
                        string originalSiteDetails = fullLengthLiningWorkDetailsGateway.GetSiteDetailsOriginal(workIdFll);
                        bool originalPipeSizeChange = fullLengthLiningWorkDetailsGateway.GetPipeSizeChangeOriginal(workIdFll);
                        bool originalStandardBypass = fullLengthLiningWorkDetailsGateway.GetStandardBypassOriginal(workIdFll);
                        string originalStandardBypassComments = fullLengthLiningWorkDetailsGateway.GetStandardBypassCommentsOriginal(workIdFll);
                        string originalTrafficControlDetails = fullLengthLiningWorkDetailsGateway.GetTrafficControlDetailsOriginal(workIdFll);
                        string originalMeasurementType = fullLengthLiningWorkDetailsGateway.GetMeasurementTypeOriginal(workIdFll);
                        string originalMeasurementFromMh = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMhOriginal(workIdFll);
                        string originalVideoDoneFromMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMhOriginal(workIdFll);
                        string originalVideoDoneToMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMhOriginal(workIdFll);
                        string originalAccessType = fullLengthLiningWorkDetailsGateway.GetAccessTypeOriginal(workIdFll);

                        // M2 data
                        string originalMeasurementTakenByM2 = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByM2Original(workIdFll);
                        bool originalDropPipe = fullLengthLiningWorkDetailsGateway.GetDropPipeOriginal(workIdFll);
                        string originalDropPipeInvertDepth = fullLengthLiningWorkDetailsGateway.GetDropPipeInvertDepthOriginal(workIdFll);
                        int? originalCappedLaterals = fullLengthLiningWorkDetailsGateway.GetCappedLateralsOriginal(workIdFll);
                        string originalLineWithId = fullLengthLiningWorkDetailsGateway.GetLineWithIdOriginal(workIdFll);
                        string originalHydrantAddress = fullLengthLiningWorkDetailsGateway.GetHydrantAddressOriginal(workIdFll);
                        string originalHydroWireWithin10FtOfInversionMH = fullLengthLiningWorkDetailsGateway.GetHydroWiredWithin10FtOfInversionMHOriginal(workIdFll);
                        string originalDistanceToInversionMh = fullLengthLiningWorkDetailsGateway.GetDistanceToInversionMhOriginal(workIdFll);
                        string originalSurfaceGrade = fullLengthLiningWorkDetailsGateway.GetSurfaceGradeOriginal(workIdFll);
                        bool originalHydroPulley = fullLengthLiningWorkDetailsGateway.GetHydroPulleyOriginal(workIdFll);
                        bool originalFridgeCart = fullLengthLiningWorkDetailsGateway.GetFridgeCartOriginal(workIdFll);
                        bool originalTwoPump = fullLengthLiningWorkDetailsGateway.GetTwoPumpOriginal(workIdFll);
                        bool originalSixBypass = fullLengthLiningWorkDetailsGateway.GetSixBypassOriginal(workIdFll);
                        bool originalScaffolding = fullLengthLiningWorkDetailsGateway.GetScaffoldingOriginal(workIdFll);
                        bool originalWinchExtension = fullLengthLiningWorkDetailsGateway.GetWinchExtensionOriginal(workIdFll);
                        bool originalExtraGenerator = fullLengthLiningWorkDetailsGateway.GetExtraGeneratorOriginal(workIdFll);
                        bool originalGreyCableExtension = fullLengthLiningWorkDetailsGateway.GetGreyCableExtensionOriginal(workIdFll);
                        bool originalEasementMats = fullLengthLiningWorkDetailsGateway.GetEasementMatsOriginal(workIdFll);
                        bool originalRampRequired = fullLengthLiningWorkDetailsGateway.GetRampRequiredOriginal(workIdFll);
                        bool originalCameraSkid = fullLengthLiningWorkDetailsGateway.GetCameraSkidOriginal(workIdFll);

                        // Comments
                        string originalComments = fullLengthLiningWorkDetailsGateway.GetCommentsOriginal(workIdFll);

                        // New variables
                        string newClientIdFLL = fullLengthLiningWorkDetailsGateway.GetClientId(workIdFll);
                        DateTime? newProposedLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetProposedLiningDate(workIdFll);
                        DateTime? newDeadlineLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDate(workIdFll);
                        DateTime? newM1Date = fullLengthLiningWorkDetailsGateway.GetM1Date(workIdFll);
                        DateTime? newM2Date = fullLengthLiningWorkDetailsGateway.GetM2Date(workIdFll);
                        DateTime? newInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDate(workIdFll);
                        DateTime? newFinalVideoDateFLL = fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workIdFll);
                        bool newIssueIdentifiedFLL = fullLengthLiningWorkDetailsGateway.GetIssueIdentified(workIdFll);
                        bool newIssueLFSFLL = fullLengthLiningWorkDetailsGateway.GetIssueLFS(workIdFll);
                        bool newIssueClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueClient(workIdFll);
                        bool newIssueSalesFLL = fullLengthLiningWorkDetailsGateway.GetIssueSales(workIdFll);
                        bool newIssueGivenToClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClient(workIdFll);
                        bool newIssueResolvedFLL = fullLengthLiningWorkDetailsGateway.GetIssueResolved(workIdFll);
                        bool newIssueInvestigationFLL = fullLengthLiningWorkDetailsGateway.GetIssueInvestigation(workIdFll);
                        bool newRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompleted(workIdFll);
                        DateTime? newRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workIdFll);
                        bool newP1Completed = fullLengthLiningWorkDetailsGateway.GetP1Completed(workIdFll);

                        // M1
                        string newMeasurementTakenByFLL = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenBy(workIdFll);
                        string newSiteDetails = fullLengthLiningWorkDetailsGateway.GetSiteDetails(workIdFll);
                        bool newPipeSizeChange = fullLengthLiningWorkDetailsGateway.GetPipeSizeChange(workIdFll);
                        bool newStandardBypass = fullLengthLiningWorkDetailsGateway.GetStandardBypass(workIdFll);
                        string newStandardBypassComments = fullLengthLiningWorkDetailsGateway.GetStandardBypassComments(workIdFll);
                        string newTrafficControlDetails = fullLengthLiningWorkDetailsGateway.GetTrafficControlDetails(workIdFll);
                        string newMeasurementType = fullLengthLiningWorkDetailsGateway.GetMeasurementType(workIdFll);
                        string newMeasurementFromMh = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workIdFll);
                        string newVideoDoneFromMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMh(workIdFll);
                        string newVideoDoneToMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMh(workIdFll);
                        string newAccessType = fullLengthLiningWorkDetailsGateway.GetAccessType(workIdFll);

                        // M2
                        string newMeasurementTakenByM2 = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByM2(workIdFll);
                        bool newDropPipe = fullLengthLiningWorkDetailsGateway.GetDropPipe(workIdFll);
                        string newDropPipeInvertDepth = fullLengthLiningWorkDetailsGateway.GetDropPipeInvertDepth(workIdFll);
                        int? newCappedLaterals = fullLengthLiningWorkDetailsGateway.GetCappedLaterals(workIdFll);
                        string newLineWithId = fullLengthLiningWorkDetailsGateway.GetLineWithId(workIdFll);
                        string newHydrantAddress = fullLengthLiningWorkDetailsGateway.GetHydrantAddress(workIdFll);
                        string newHydroWireWithin10FtOfInversionMH = fullLengthLiningWorkDetailsGateway.GetHydroWiredWithin10FtOfInversionMH(workIdFll);
                        string newDistanceToInversionMh = fullLengthLiningWorkDetailsGateway.GetDistanceToInversionMh(workIdFll);
                        string newSurfaceGrade = fullLengthLiningWorkDetailsGateway.GetSurfaceGrade(workIdFll);
                        bool newHydroPulley = fullLengthLiningWorkDetailsGateway.GetHydroPulley(workIdFll);
                        bool newFridgeCart = fullLengthLiningWorkDetailsGateway.GetFridgeCart(workIdFll);
                        bool newTwoPump = fullLengthLiningWorkDetailsGateway.GetTwoPump(workIdFll);
                        bool newSixBypass = fullLengthLiningWorkDetailsGateway.GetSixBypass(workIdFll);
                        bool newScaffolding = fullLengthLiningWorkDetailsGateway.GetScaffolding(workIdFll);
                        bool newWinchExtension = fullLengthLiningWorkDetailsGateway.GetWinchExtension(workIdFll);
                        bool newExtraGenerator = fullLengthLiningWorkDetailsGateway.GetExtraGenerator(workIdFll);
                        bool newGreyCableExtension = fullLengthLiningWorkDetailsGateway.GetGreyCableExtension(workIdFll);
                        bool newEasementMats = fullLengthLiningWorkDetailsGateway.GetEasementMats(workIdFll);
                        bool newRampRequired = fullLengthLiningWorkDetailsGateway.GetRampRequired(workIdFll);
                        bool newCameraSkid = fullLengthLiningWorkDetailsGateway.GetCameraSkid(workIdFll);

                        // comments
                        string newComments = fullLengthLiningWorkDetailsGateway.GetComments(workIdFll);

                        // ... Update work
                        UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientIdFLL, originalProposedLiningDateFLL, originalDeadlineLiningDateFLL, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDateFLL, originalIssueIdentifiedFLL, originalIssueLFSFLL, originalIssueClientFLL, originalIssueSalesFLL, originalIssueGivenToClientFLL, originalIssueResolvedFLL, originalIssueInvestigationFLL, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenByFLL, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoLength, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientIdFLL, originalProposedLiningDateFLL, originalDeadlineLiningDateFLL, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDateFLL, originalIssueIdentifiedFLL, originalIssueLFSFLL, originalIssueClientFLL, originalIssueSalesFLL, originalIssueGivenToClientFLL, originalIssueResolvedFLL, originalIssueInvestigationFLL, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenByFLL, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoLength, newComments, false, companyId, newAccessType, newP1Completed);
                    }
                    else
                    {
                        if (newP1Date.HasValue || newCxisRemoved.HasValue || newMaterial != "" || newTrafficControl != "" || newVideoLength != "") // Insert Fll work
                        {
                            WorkFullLengthLining workFullLengthLining = new WorkFullLengthLining(null);
                            workIdFll = workFullLengthLining.InsertDirectEmptyWorks(projectId, sectionAssetId, null, "", null, null, null, null, null, null, null, false, false, false, false, false, false, false, companyId, false, "", "");

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

                            // Original values
                            string originalClientIdFLL = fullLengthLiningWorkDetailsGateway.GetClientIdOriginal(workIdFll);
                            DateTime? originalProposedLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetProposedLiningDateOriginal(workIdFll);
                            DateTime? originalDeadlineLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDateOriginal(workIdFll);
                            DateTime? originalM1Date = fullLengthLiningWorkDetailsGateway.GetM1DateOriginal(workIdFll);
                            DateTime? originalM2Date = fullLengthLiningWorkDetailsGateway.GetM2DateOriginal(workIdFll);
                            DateTime? originalInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDateOriginal(workIdFll);
                            DateTime? originalFinalVideoDateFLL = fullLengthLiningWorkDetailsGateway.GetFinalVideoDateOriginal(workIdFll);
                            bool originalIssueIdentifiedFLL = fullLengthLiningWorkDetailsGateway.GetIssueIdentifiedOriginal(workIdFll);
                            bool originalIssueLFSFLL = fullLengthLiningWorkDetailsGateway.GetIssueLFSOriginal(workIdFll);
                            bool originalIssueClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueClientOriginal(workIdFll);
                            bool originalIssueSalesFLL = fullLengthLiningWorkDetailsGateway.GetIssueSalesOriginal(workIdFll);
                            bool originalIssueGivenToClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClientOriginal(workIdFll);
                            bool originalIssueResolvedFLL = fullLengthLiningWorkDetailsGateway.GetIssueResolvedOriginal(workIdFll);
                            bool originalIssueInvestigationFLL = fullLengthLiningWorkDetailsGateway.GetIssueInvestigationOriginal(workIdFll);
                            bool originalRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedOriginal(workIdFll);
                            DateTime? originalRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDateOriginal(workIdFll);
                            bool originalP1Completed = fullLengthLiningWorkDetailsGateway.GetP1CompletedOriginal(workIdFll);

                            // M1 data
                            string originalMeasurementTakenByFLL = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByOriginal(workIdFll);
                            string originalSiteDetails = fullLengthLiningWorkDetailsGateway.GetSiteDetailsOriginal(workIdFll);
                            bool originalPipeSizeChange = fullLengthLiningWorkDetailsGateway.GetPipeSizeChangeOriginal(workIdFll);
                            bool originalStandardBypass = fullLengthLiningWorkDetailsGateway.GetStandardBypassOriginal(workIdFll);
                            string originalStandardBypassComments = fullLengthLiningWorkDetailsGateway.GetStandardBypassCommentsOriginal(workIdFll);
                            string originalTrafficControlDetails = fullLengthLiningWorkDetailsGateway.GetTrafficControlDetailsOriginal(workIdFll);
                            string originalMeasurementType = fullLengthLiningWorkDetailsGateway.GetMeasurementTypeOriginal(workIdFll);
                            string originalMeasurementFromMh = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMhOriginal(workIdFll);
                            string originalVideoDoneFromMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMhOriginal(workIdFll);
                            string originalVideoDoneToMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMhOriginal(workIdFll);
                            string originalAccessType = fullLengthLiningWorkDetailsGateway.GetAccessTypeOriginal(workIdFll);

                            // M2 data
                            string originalMeasurementTakenByM2 = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByM2Original(workIdFll);
                            bool originalDropPipe = fullLengthLiningWorkDetailsGateway.GetDropPipeOriginal(workIdFll);
                            string originalDropPipeInvertDepth = fullLengthLiningWorkDetailsGateway.GetDropPipeInvertDepthOriginal(workIdFll);
                            int? originalCappedLaterals = fullLengthLiningWorkDetailsGateway.GetCappedLateralsOriginal(workIdFll);
                            string originalLineWithId = fullLengthLiningWorkDetailsGateway.GetLineWithIdOriginal(workIdFll);
                            string originalHydrantAddress = fullLengthLiningWorkDetailsGateway.GetHydrantAddressOriginal(workIdFll);
                            string originalHydroWireWithin10FtOfInversionMH = fullLengthLiningWorkDetailsGateway.GetHydroWiredWithin10FtOfInversionMHOriginal(workIdFll);
                            string originalDistanceToInversionMh = fullLengthLiningWorkDetailsGateway.GetDistanceToInversionMhOriginal(workIdFll);
                            string originalSurfaceGrade = fullLengthLiningWorkDetailsGateway.GetSurfaceGradeOriginal(workIdFll);
                            bool originalHydroPulley = fullLengthLiningWorkDetailsGateway.GetHydroPulleyOriginal(workIdFll);
                            bool originalFridgeCart = fullLengthLiningWorkDetailsGateway.GetFridgeCartOriginal(workIdFll);
                            bool originalTwoPump = fullLengthLiningWorkDetailsGateway.GetTwoPumpOriginal(workIdFll);
                            bool originalSixBypass = fullLengthLiningWorkDetailsGateway.GetSixBypassOriginal(workIdFll);
                            bool originalScaffolding = fullLengthLiningWorkDetailsGateway.GetScaffoldingOriginal(workIdFll);
                            bool originalWinchExtension = fullLengthLiningWorkDetailsGateway.GetWinchExtensionOriginal(workIdFll);
                            bool originalExtraGenerator = fullLengthLiningWorkDetailsGateway.GetExtraGeneratorOriginal(workIdFll);
                            bool originalGreyCableExtension = fullLengthLiningWorkDetailsGateway.GetGreyCableExtensionOriginal(workIdFll);
                            bool originalEasementMats = fullLengthLiningWorkDetailsGateway.GetEasementMatsOriginal(workIdFll);
                            bool originalRampRequired = fullLengthLiningWorkDetailsGateway.GetRampRequiredOriginal(workIdFll);
                            bool originalCameraSkid = fullLengthLiningWorkDetailsGateway.GetCameraSkidOriginal(workIdFll);

                            // Comments
                            string originalComments = fullLengthLiningWorkDetailsGateway.GetCommentsOriginal(workIdFll);

                            // New variables
                            string newClientIdFLL = fullLengthLiningWorkDetailsGateway.GetClientId(workIdFll);
                            DateTime? newProposedLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetProposedLiningDate(workIdFll);
                            DateTime? newDeadlineLiningDateFLL = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDate(workIdFll);
                            DateTime? newM1Date = fullLengthLiningWorkDetailsGateway.GetM1Date(workIdFll);
                            DateTime? newM2Date = fullLengthLiningWorkDetailsGateway.GetM2Date(workIdFll);
                            DateTime? newInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDate(workIdFll);
                            DateTime? newFinalVideoDateFLL = fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workIdFll);
                            bool newIssueIdentifiedFLL = fullLengthLiningWorkDetailsGateway.GetIssueIdentified(workIdFll);
                            bool newIssueLFSFLL = fullLengthLiningWorkDetailsGateway.GetIssueLFS(workIdFll);
                            bool newIssueClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueClient(workIdFll);
                            bool newIssueSalesFLL = fullLengthLiningWorkDetailsGateway.GetIssueSales(workIdFll);
                            bool newIssueGivenToClientFLL = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClient(workIdFll);
                            bool newIssueResolvedFLL = fullLengthLiningWorkDetailsGateway.GetIssueResolved(workIdFll);
                            bool newIssueInvestigationFLL = fullLengthLiningWorkDetailsGateway.GetIssueInvestigation(workIdFll);
                            bool newRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompleted(workIdFll);
                            DateTime? newRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workIdFll);
                            bool newP1Completed = fullLengthLiningWorkDetailsGateway.GetP1Completed(workIdFll);

                            // M1
                            string newMeasurementTakenByFLL = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenBy(workIdFll);
                            string newSiteDetails = fullLengthLiningWorkDetailsGateway.GetSiteDetails(workIdFll);
                            bool newPipeSizeChange = fullLengthLiningWorkDetailsGateway.GetPipeSizeChange(workIdFll);
                            bool newStandardBypass = fullLengthLiningWorkDetailsGateway.GetStandardBypass(workIdFll);
                            string newStandardBypassComments = fullLengthLiningWorkDetailsGateway.GetStandardBypassComments(workIdFll);
                            string newTrafficControlDetails = fullLengthLiningWorkDetailsGateway.GetTrafficControlDetails(workIdFll);
                            string newMeasurementType = fullLengthLiningWorkDetailsGateway.GetMeasurementType(workIdFll);
                            string newMeasurementFromMh = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workIdFll);
                            string newVideoDoneFromMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneFromMh(workIdFll);
                            string newVideoDoneToMh = fullLengthLiningWorkDetailsGateway.GetVideoDoneToMh(workIdFll);
                            string newAccessType = fullLengthLiningWorkDetailsGateway.GetAccessType(workIdFll);

                            // M2
                            string newMeasurementTakenByM2 = fullLengthLiningWorkDetailsGateway.GetMeasurementTakenByM2(workIdFll);
                            bool newDropPipe = fullLengthLiningWorkDetailsGateway.GetDropPipe(workIdFll);
                            string newDropPipeInvertDepth = fullLengthLiningWorkDetailsGateway.GetDropPipeInvertDepth(workIdFll);
                            int? newCappedLaterals = fullLengthLiningWorkDetailsGateway.GetCappedLaterals(workIdFll);
                            string newLineWithId = fullLengthLiningWorkDetailsGateway.GetLineWithId(workIdFll);
                            string newHydrantAddress = fullLengthLiningWorkDetailsGateway.GetHydrantAddress(workIdFll);
                            string newHydroWireWithin10FtOfInversionMH = fullLengthLiningWorkDetailsGateway.GetHydroWiredWithin10FtOfInversionMH(workIdFll);
                            string newDistanceToInversionMh = fullLengthLiningWorkDetailsGateway.GetDistanceToInversionMh(workIdFll);
                            string newSurfaceGrade = fullLengthLiningWorkDetailsGateway.GetSurfaceGrade(workIdFll);
                            bool newHydroPulley = fullLengthLiningWorkDetailsGateway.GetHydroPulley(workIdFll);
                            bool newFridgeCart = fullLengthLiningWorkDetailsGateway.GetFridgeCart(workIdFll);
                            bool newTwoPump = fullLengthLiningWorkDetailsGateway.GetTwoPump(workIdFll);
                            bool newSixBypass = fullLengthLiningWorkDetailsGateway.GetSixBypass(workIdFll);
                            bool newScaffolding = fullLengthLiningWorkDetailsGateway.GetScaffolding(workIdFll);
                            bool newWinchExtension = fullLengthLiningWorkDetailsGateway.GetWinchExtension(workIdFll);
                            bool newExtraGenerator = fullLengthLiningWorkDetailsGateway.GetExtraGenerator(workIdFll);
                            bool newGreyCableExtension = fullLengthLiningWorkDetailsGateway.GetGreyCableExtension(workIdFll);
                            bool newEasementMats = fullLengthLiningWorkDetailsGateway.GetEasementMats(workIdFll);
                            bool newRampRequired = fullLengthLiningWorkDetailsGateway.GetRampRequired(workIdFll);
                            bool newCameraSkid = fullLengthLiningWorkDetailsGateway.GetCameraSkid(workIdFll);

                            // comments
                            string newComments = fullLengthLiningWorkDetailsGateway.GetComments(workIdFll);

                            // ... Update work
                            UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientIdFLL, originalProposedLiningDateFLL, originalDeadlineLiningDateFLL, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDateFLL, originalIssueIdentifiedFLL, originalIssueLFSFLL, originalIssueClientFLL, originalIssueSalesFLL, originalIssueGivenToClientFLL, originalIssueResolvedFLL, originalIssueInvestigationFLL, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenByFLL, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoLength, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientIdFLL, originalProposedLiningDateFLL, originalDeadlineLiningDateFLL, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDateFLL, originalIssueIdentifiedFLL, originalIssueLFSFLL, originalIssueClientFLL, originalIssueSalesFLL, originalIssueGivenToClientFLL, originalIssueResolvedFLL, originalIssueInvestigationFLL, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenByFLL, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoLength, newComments, false, companyId, newAccessType, newP1Completed);
                        }
                    }

                    if (workIdRa != 0) // ... Has Fll work
                    {
                        UpdateRaWork(workIdRa, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                    }
                    else
                    {
                        if (newPreFlushDate.HasValue || newPreVideoDate.HasValue) // Insert RA work
                        {
                            WorkRehabAssessment workRehabAssessment = new WorkRehabAssessment(null);
                            workIdRa = workRehabAssessment.InsertDirect(projectId, sectionAssetId, null, newPreFlushDate, newPreVideoDate, false, companyId, "", "");

                            UpdateRaWork(workIdRa, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                        }
                    }

                    // Update work
                    WorkPointRepairs workPointRepairs = new WorkPointRepairs(null);
                    workPointRepairs.UpdateDirect(sectionAssetId, workId, originalClientId, originalMeasurementTakenBy, originalRepairConfirmationDate, originalBypassRequired, originalRoboticDistances, originalProposedLiningDate, originalDeadlineLiningDate, originalFinalVideoDate, originalEstimatedJoints, originalJointsTestSealed, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, "", false, companyId, workId, newClientId, newMeasurementTakenBy, newRepairConfirmationDate, newBypassRequired, newRoboticDistances, newProposedLiningDate, newDeadlineLiningDate, newFinalVideoDate, newEstimatedJoints, newJointsTestSealed, newIssueIdentified, newIssueLFS, newIssueClient, newIssueSales, newIssueGivenToClient, newIssueResolved, newIssueInvestigation, "", false, companyId);

                    // Get original variables
                    WorkGateway workGateway = new WorkGateway();
                    workGateway.LoadByWorkId(workId, companyId);

                    string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
                    int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
                    string originalComment = workGateway.GetCommentsOriginal(workId);
                    string originalHistory = workGateway.GetHistoryOriginal(workId);

                    //Get new comment
                    WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                    workCommentsGateway.LoadByAssetIdWorkTypeProjectId(sectionAssetId, companyId, "Point Repairs", projectId);
                    WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                    string newComment = workComments.GetCommentsSummary(companyId, workCommentsGateway.Table.Rows.Count, "\n");

                    Work work = new Work(null);
                    work.UpdateDirect(workId, projectId, sectionAssetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, sectionAssetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComment, originalHistory);
                }
            }
        }
        /// <summary>
        /// Insert a new Full Length Lining Work (direct to DB), full Data
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="libraryCategoriesId">libraryCategoriesId</param>
        /// <param name="clientId">clientId</param>
        /// <param name="proposedLiningDate">proposedLiningDate</param>
        /// <param name="deadlineLiningDate">deadlineLiningDate</param>
        /// <param name="p1Date">p1Date</param>
        /// <param name="m1Date">m1Date</param>
        /// <param name="m2Date">m2Date</param>
        /// <param name="installDate">installDate</param>
        /// <param name="finalVideoDate">finalVideoDate</param>
        /// <param name="issueIdentified">issueIdentified</param>
        /// <param name="issueLfs">issueLfs</param>
        /// <param name="issueClient">issueClient</param>
        /// <param name="issueSales">issueSales</param>
        /// <param name="issueGivenToClient">issueGivenToClient</param>
        /// <param name="issueResolved">issueResolved</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="issueInvestigation">issueInvestigation</param>
        /// <param name="comments">comments</param>
        /// <param name="history">history</param>
        /// <param name="cxisRemoved">cxisRemoved</param>
        /// <param name="roboticPrepCompleted">roboticPrepCompleted</param>
        /// <param name="roboticPrepCompletedDate">roboticPrepCompletedDate</param>
        /// <param name="measurementTakenBy">measurementTakenBy</param>
        /// <param name="trafficControl">trafficControl</param>
        /// <param name="siteDetails">siteDetails</param>
        /// <param name="pipeSizeChange">pipeSizeChange</param>
        /// <param name="standardByPass">standardByPass</param>        
        /// <param name="standardByPassComments">standardByPassComments</param>
        /// <param name="trafficControlDetails">trafficControlDetails</param>
        /// <param name="measurementType">measurementType</param>
        /// <param name="measurementFromMH">measurementFromMH</param>
        /// <param name="videoDoneFromMH">videoDoneFromMH</param>
        /// <param name="videoDoneToMH">videoDoneToMH</param>
        /// <param name="videoLength">videoLength</param>
        /// <param name="measurementTakenBy2">measurementTakenBy2</param>
        /// <param name="dropPipe">dropPipe</param>
        /// <param name="dropPipeInvertDepth">dropPipeInvertDepth</param>
        /// <param name="cappedLaterals">cappedLaterals</param>
        /// <param name="lineWithID">lineWithID</param>
        /// <param name="hydrantAddress">hydrantAddress</param>
        /// <param name="hydroWireWithin10FtOfInversionMH">hydroWireWithin10FtOfInversionMH</param>
        /// <param name="distanceToInversionMH">distanceToInversionMH</param>
        /// <param name="surfaceGrade">surfaceGrade</param>
        /// <param name="hydroPulley">hydroPulley</param>
        /// <param name="fridgeCart">fridgeCart</param>
        /// <param name="twoPump">twoPump</param>
        /// <param name="sixBypass">sixBypass</param>
        /// <param name="scaffolding">scaffolding</param>
        /// <param name="winchExtention">winchExtention</param>
        /// <param name="extraGenerator">extraGenerator</param>
        /// <param name="greyCableExtension">greyCableExtension</param>
        /// <param name="easementMats">easementMats</param>
        /// <param name="rampRequired">rampRequired</param>
        /// <param name="cameraSkid">cameraSkid</param>
        /// <param name="accessType">accessType</param>
        /// <param name="p1Completed">p1Completed</param>
        /// <returns>int</returns>
        public int InsertDirectFullWork(int projectId, int assetId, int? libraryCategoriesId, string clientId, DateTime? proposedLiningDate, DateTime? deadlineLiningDate, DateTime? p1Date, DateTime? m1Date, DateTime? m2Date, DateTime? installDate, DateTime? finalVideoDate, bool issueIdentified, bool issueLfs, bool issueClient, bool issueSales, bool issueGivenToClient, bool issueResolved, bool deleted, int companyId, bool issueInvestigation, string comments, string history, int? cxisRemoved, bool roboticPrepCompleted, DateTime? roboticPrepCompletedDate, string measurementTakenBy, string trafficControl, string siteDetails, bool pipeSizeChange, bool standardByPass, string standardByPassComments, string trafficControlDetails, string  measurementType, string  measurementFromMH, string videoDoneFromMH, string videoDoneToMH, string videoLength, string  measurementTakenBy2,bool dropPipe, string dropPipeInvertDepth, int? cappedLaterals, string lineWithID,string hydrantAddress, string hydroWireWithin10FtOfInversionMH, string distanceToInversionMH, string surfaceGrade, bool hydroPulley, bool fridgeCart, bool twoPump, bool sixBypass, bool scaffolding, bool winchExtention, bool extraGenerator, bool greyCableExtension, bool easementMats, bool rampRequired, bool cameraSkid, string accessType, bool p1Completed)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Full Length Lining", libraryCategoriesId, deleted, companyId, comments, history);
                new WorkFullLengthLiningGateway(null).Insert(workId, clientId, proposedLiningDate, deadlineLiningDate, p1Date, m1Date, m2Date, installDate, finalVideoDate, issueIdentified, issueLfs, issueClient, issueSales, issueGivenToClient, issueResolved, deleted, companyId, issueInvestigation);
                new WorkFullLengthLiningP1Gateway(null).Insert(workId, cxisRemoved, deleted, companyId, roboticPrepCompleted, roboticPrepCompletedDate, p1Completed);
                new WorkFullLengthLiningM1Gateway(null).Insert(workId, measurementTakenBy, trafficControl, siteDetails, pipeSizeChange, standardByPass, standardByPassComments, trafficControlDetails, measurementType, measurementFromMH, videoDoneFromMH, videoDoneToMH, deleted, companyId, accessType);
                new WorkFullLengthLiningM2Gateway(null).Insert(workId, videoLength, measurementTakenBy2, dropPipe, dropPipeInvertDepth, cappedLaterals, lineWithID, hydrantAddress, hydroWireWithin10FtOfInversionMH, distanceToInversionMH, surfaceGrade, hydroPulley, fridgeCart, twoPump, sixBypass, scaffolding, winchExtention, extraGenerator, greyCableExtension, easementMats, rampRequired,  deleted, companyId, cameraSkid);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
            }

            return workId;
        }
        private void WorkUpdate()
        {
            // Get general variables
            int projectId = Int32.Parse(hdfCurrentProject.Value.Trim());
            int companyId = Convert.ToInt32(Session["companyID"]);
            FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
            DataView dataViewFlatSectionJl = new DataView(flatSectionJlTDS.FlatSectionJl);
            dataViewFlatSectionJl.RowFilter = "(Selected = 1) AND (Deleted = 0)";

            foreach (DataRowView row in dataViewFlatSectionJl)
            {
                int workId = Int32.Parse(row["WorkID"].ToString());
                int assetId = Int32.Parse(row["AssetID"].ToString());
                string workType = "Junction Lining Lateral";

                // Get original variables
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(workId, companyId);

                string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
                int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
                string originalComment = workGateway.GetCommentsOriginal(workId);
                string originalHistory = workGateway.GetHistoryOriginal(workId);

                // Get new comment
                WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                workCommentsGateway.LoadByWorkIdWorkType(workId, companyId, "Junction Lining Lateral");
                WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                string newComments = workComments.GetAllComments(workId, companyId, workCommentsGateway.Table.Rows.Count, "\n");

                // Get new history
                WorkHistoryGateway workHistoryGateway = new WorkHistoryGateway();
                workHistoryGateway.LoadByWorkIdWorkType(workId, companyId, "Junction Lining Lateral");
                WorkHistory workHistory = new WorkHistory(workHistoryGateway.Data);
                string newHistory = workHistory.GetAllHistory(workId, companyId, workHistoryGateway.Table.Rows.Count, "\n");

                Work work = new Work(null);
                work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComments, newHistory);

                flatSectionJl.UpdateCommentsHistoryForSummaryEdit(workId, workType, companyId);
            }
        }
        private void workUpdate(int workId, int projectId, int assetId, int companyId, string workType)
        {
            // Get original variables
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);

            string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
            int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
            string originalComment = workGateway.GetCommentsOriginal(workId);
            string originalHistory = workGateway.GetHistoryOriginal(workId);

            //Get new comment
            WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
            workCommentsGateway.LoadByAssetIdWorkTypeProjectId(assetId, companyId, workType, projectId);

            WorkComments workComments = new WorkComments(workCommentsGateway.Data);
            string newComment = workComments.GetCommentsSummary(companyId, workCommentsGateway.Table.Rows.Count, "\n");

            Work work = new Work(null);
            work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComment, originalHistory);
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Insert Direct
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="libraryCategoriesId">libraryCategoriesId</param>
        /// <param name="clientId">clientId</param>
        /// <param name="measurementTakenBy">measurementTakenBy</param>
        /// <param name="repairconfirmationDate">repairconfirmationDate</param>
        /// <param name="bypassRequired">bypassRequired</param>
        /// <param name="roboticDistances">roboticDistances</param>
        /// <param name="proposedLiningDate">proposedLiningDate</param>
        /// <param name="deadlineLiningDate">deadlineLiningDate</param>
        /// <param name="finalVideoDate">finalVideoDate</param>
        /// <param name="estimatedJoints">estimatedJoints</param>
        /// <param name="jointsTestSealed">jointsTestSealed</param>
        /// <param name="issueIdentified">issueIdentified</param>
        /// <param name="issueLfs">issueLfs</param>
        /// <param name="issueClient">issueClient</param>
        /// <param name="issueSales">issueSales</param>        
        /// <param name="issueGivenToClient">issueGivenToClient</param>
        /// <param name="issueResolved">issueResolved</param>
        /// <param name="issueInvestigation">issueInvestigation</param>
        /// <param name="repairId">repairId</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="comments">comments</param>
        /// <param name="history">history</param>
        /// <returns>rowsAffected</returns>
        public int InsertDirect(int projectId, int assetId, int? libraryCategoriesId, string clientId, string measurementTakenBy, DateTime? repairconfirmationDate, bool bypassRequired, string roboticDistances, DateTime? proposedLiningDate, DateTime? deadlineLiningDate, DateTime? finalVideoDate, int? estimatedJoints, int? jointsTestSealed, bool issueIdentified, bool issueLfs, bool issueClient, bool issueSales, bool issueGivenToClient, bool issueResolved, bool issueInvestigation, string repairId, bool deleted, int companyId, string comments, string history)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Point Repairs", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Point Repairs", libraryCategoriesId, deleted, companyId, comments, history);
                new WorkPointRepairsGateway(null).Insert(workId, clientId, measurementTakenBy, repairconfirmationDate, bypassRequired, roboticDistances, proposedLiningDate, deadlineLiningDate, finalVideoDate, estimatedJoints, jointsTestSealed, issueIdentified, issueLfs, issueClient, issueSales, issueGivenToClient, issueResolved, issueInvestigation, repairId, deleted, companyId);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Point Repairs", projectId);
            }

            return workId;
        }
        /// <summary>
        /// UpdateComments
        /// </summary>
        /// <param name="jlWorkId">workIdjlWorkIdparam>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        public void UpdateComments(int jlWorkId, string workType, int companyId)
        {
            foreach (JlNavigatorTDS.JlNavigatorRow row in (JlNavigatorTDS.JlNavigatorDataTable)Table)
            {
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(jlWorkId, companyId);
                int assetId = workGateway.GetAssetId(jlWorkId);
                int projectId = workGateway.GetProjectId(jlWorkId);

                if (row.AssetID_ == assetId)
                {
                    // Update Comments
                    // ... Get raWorkId
                    int raWorkId = 0;

                    // ... Get raWorkId
                    int flWorkId = 0;

                    // ... Load All Comments
                    FlatSectionJLAllComments flatSectionJLAllComments = new FlatSectionJLAllComments();
                    flatSectionJLAllComments.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.Comments = flatSectionJLAllComments.GetJLOrFLOrRAComments(companyId, flatSectionJLAllComments.Table.Rows.Count, "\n");

                    if (!row.IsHistoryNull())
                    {
                        row.Comments = row.Comments.Replace("<br>", "\n");
                    }

                    // Update History
                    FlatSectionJLAllHistory flatSectionJLAllHistory = new FlatSectionJLAllHistory();
                    flatSectionJLAllHistory.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.History = flatSectionJLAllHistory.GetJLOrFLOrRAHistory(companyId, flatSectionJLAllHistory.Table.Rows.Count, "\n");

                    if (!row.IsHistoryNull())
                    {
                        row.History = row.History.Replace("<br>", "\n");
                    }

                    // Save work
                    // ... Get original variables
                    workGateway.LoadByWorkId(jlWorkId, companyId);

                    string originalWorkType = workGateway.GetWorkTypeOriginal(jlWorkId);
                    int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(jlWorkId);
                    string originalComment = workGateway.GetCommentsOriginal(jlWorkId);
                    string originalHistory = workGateway.GetHistoryOriginal(jlWorkId);

                    Work work = new Work(null);
                    work.UpdateDirect(jlWorkId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, jlWorkId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, row.Comments, row.History);
                }
            }
        }
        /// <summary>
        /// UpdateCommentsHistory
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="newComments">newComments</param>
        /// <param name="newHistory">newHistory</param>
        /// <param name="companyId">companyId</param>
        public void UpdateCommentsHistory(int workId, int assetId, int projectId, string newComments, string newHistory, int companyId)
        {
            JlNavigatorTDS.JlNavigatorRow jlNavigatorRow = GetRow(assetId);
            jlNavigatorRow.Comments = newComments;
            jlNavigatorRow.History = newHistory;

            // Save work
            // ... Get original variables
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);

            string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
            int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
            string originalComment = workGateway.GetCommentsOriginal(workId);
            string originalHistory = workGateway.GetHistoryOriginal(workId);

            Work work = new Work(null);
            work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComments, newHistory);
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="inProject">inProject</param>
        /// <returns>WorkID</returns>
        public int Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int assetId, int companyId, bool inProject)
        {
            ManholeRehabilitationTDS manholeRehabilitationChanges = (ManholeRehabilitationTDS)Data.GetChanges();
            int workId = 0;

            if (manholeRehabilitationChanges.WorkDetails.Rows.Count > 0)
            {
                ManholeRehabilitationWorkDetailsGateway manholeRehabilitationWorkDetailsGateway = new ManholeRehabilitationWorkDetailsGateway(manholeRehabilitationChanges);

                // Update manhole rehabilitation
                foreach (ManholeRehabilitationTDS.WorkDetailsRow row in (ManholeRehabilitationTDS.WorkDetailsDataTable)manholeRehabilitationChanges.WorkDetails)
                {
                    // Unchanged values
                    workId = row.WorkID;

                    WorkManholeRehabilitationGateway workManholeRehabilitationGateway = new WorkManholeRehabilitationGateway();
                    workManholeRehabilitationGateway.LoadByWorkId(workId, companyId);

                    if (workManholeRehabilitationGateway.Table.Rows.Count > 0)
                    {
                        // Update Information
                        // Original values
                        // ... work values
                        DateTime? originalPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDateOriginal(workId);
                        DateTime? originalSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDateOriginal(workId);

                        // ... Comments
                        string originalComments = manholeRehabilitationWorkDetailsGateway.GetCommentsOriginal(workId);

                        // New variables
                        DateTime? newPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                        DateTime? newSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);

                        // comments
                        string newComments = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                        // Update work
                        UpdateWork(countryId, provinceId, countyId, cityId, projectId, assetId, originalPreppedDate, originalSprayedDate, row.BatchID, originalComments, false, companyId, newPreppedDate, newSprayedDate, row.BatchID, newComments, false);
                    }
                    else
                    {
                        // Loading workId
                        WorkGateway workGateway = new WorkGateway();
                        workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Manhole Rehabilitation", companyId);

                        if (workGateway.Table.Rows.Count == 0)
                        {
                            // New variables
                            DateTime? newPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                            DateTime? newSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);
                            int? newBatchId = manholeRehabilitationWorkDetailsGateway.GetBatchID(workId);
                            string newComments = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                            // InsertWork
                            Work work = new Work();

                            int? libraryCategories = null;
                            string history = "";

                            int newWorkId = work.InsertDirect(projectId, assetId, "Manhole Rehabilitation", libraryCategories, false, companyId, newComments, history);

                            // ... Insert manhole rehabilitation work
                            WorkManholeRehabilitation workManholeRehabilitation = new WorkManholeRehabilitation();
                            workManholeRehabilitation.InsertDirect(newWorkId, newPreppedDate, newSprayedDate, newBatchId, false, companyId);

                            workId = newWorkId;
                        }
                    }
                }
            }

            return workId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="projectId">projectId</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="builRebuild">builRebuild</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="comments">comments</param>
        /// <param name="history">history</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>
        /// <returns>int</returns>
        public int InsertDirect(int projectId, 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? builRebuild, 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 comments, string history, 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)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Junction Lining Lateral", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Junction Lining Lateral", null, false, companyId, comments, history);
                new WorkJunctionLiningLateralGateway(null).Insert(workId, sectionWorkId, pipeLocated, servicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, delivered, builRebuild, preVideo, linerInstalled, finalVideo, cost, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, deleted, companyId, videoLengthToPropertyLine, liningThruCo, noticeDelivered, hamiltonInspectionNumber, flange, gasket, depthOfLocated, digRequiredPriorToLining, digRequiredPriorToLiningCompleted, digRequiredAfterLining, digRequiredAfterLiningCompleted, outOfScope, holdClientIssue, holdClientIssueResolved, holdLFSIssue, holdLFSIssueResolved, requiresRoboticPrep,  requiresRoboticPrepCompleted, linerType, prepType, dyeTestReq, dyeTestComplete, contractYear);

                // Update WorkJunctionLiningSection
                UpdateSection(sectionWorkId, workId, companyId);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Junction Lining Lateral", projectId);
            }

            return workId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="libraryCategoriesId">libraryCategoriesId</param>
        /// <param name="numLats">numLats</param>
        /// <param name="notLinedYet">notLinedYet</param>
        /// <param name="allMeasured">allMeasured</param>
        /// <param name="issueWithLaterals">issueWithLaterals</param>
        /// <param name="notMeasuredYet">notMeasuredYet</param>
        /// <param name="notDeliveredYet">notDeliveredYet</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="history">history</param>
        /// <param name="trafficControl">trafficControl</param>
        /// <param name="trafficControlDetails">trafficControlDetails</param>
        /// <param name="standardBypass">standardBypass</param>
        /// <param name="standardBypassComments">standardBypassComments</param>
        /// <param name="availableToLine">availableToLine</param>
        /// <returns></returns>
        public int InsertDirect(int projectId, int assetId, int? libraryCategoriesId, int numLats, int notLinedYet, bool allMeasured, string issueWithLaterals, int notMeasuredYet, int notDeliveredYet, bool deleted, int companyId, string comments, string history, string trafficControl, string trafficControlDetails, bool standardBypass, string standardBypassComments, int availableToLine)
        {
            int workId = 0;

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Junction Lining Section", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Junction Lining Section", libraryCategoriesId, deleted, companyId, comments, history);
                new WorkJunctionLiningSectionGateway(null).Insert(workId, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, deleted, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Junction Lining Section", projectId);
            }

            return workId;
        }
        private void workUpdate()
        {
            // Get general variables
            int workId = Int32.Parse(hdfWorkId.Value.Trim());
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            int assetId = Int32.Parse(hdfAssetId.Value.Trim());
            int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
            string workType = hdfWorkType.Value.Trim();

            // Update comments for rehab assessment
            // Get original variables
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);

            string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
            int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
            string originalComment = workGateway.GetCommentsOriginal(workId);
            string originalHistory = workGateway.GetHistoryOriginal(workId);

            //Get all new rehab assessment comments
            RehabAssessmentCommentDetailsGateway rehabAssessmentCommentDetailsGateway = new RehabAssessmentCommentDetailsGateway(rehabAssessmentTDS);
            rehabAssessmentCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, workType);
            RehabAssessmentCommentDetails rehabAssessmentCommentDetails = new RehabAssessmentCommentDetails(rehabAssessmentCommentDetailsGateway.Data);
            string newComment = rehabAssessmentCommentDetails.GetAllRehabAssessmentComments(workId, companyId, rehabAssessmentCommentDetailsGateway.Table.Rows.Count, "\n");

            Work work = new Work(null);
            work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComment, originalHistory);

            // Update comments for full length lining
            int workIdFll = Int32.Parse(hdfWorkIdFll.Value.Trim());

            if (workIdFll != 0)
            {
                WorkGateway workGatewayForFll = new WorkGateway();
                workGatewayForFll.LoadByWorkId(workIdFll, companyId);

                string originalWorkTypeForFll = workGatewayForFll.GetWorkTypeOriginal(workIdFll);
                int? originalLibraryCategoriesIdForFll = workGatewayForFll.GetLibraryCategoriesIdOriginal(workIdFll);
                string originalCommentForFll = workGatewayForFll.GetCommentsOriginal(workIdFll);
                string originalHistoryForFll = workGatewayForFll.GetHistoryOriginal(workIdFll);

                //Get all new fulllengthlining comments
                FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway();
                fullLengthLiningCommentDetailsGateway.LoadAllByWorkIdWorkType(workIdFll, companyId, "Full Length Lining");
                FullLengthLiningCommentDetails fullLengthLiningCommentDetails = new FullLengthLiningCommentDetails(fullLengthLiningCommentDetailsGateway.Data);
                string newCommentForFll = fullLengthLiningCommentDetails.GetAllFullLengthLiningComments(workIdFll, companyId, fullLengthLiningCommentDetailsGateway.Table.Rows.Count, "\n");

                // Save comments
                Work workForFll = new Work(null);
                workForFll.UpdateDirect(workIdFll, projectId, assetId, originalWorkTypeForFll, originalLibraryCategoriesIdForFll, false, companyId, originalCommentForFll, originalHistoryForFll, workIdFll, projectId, assetId, originalWorkTypeForFll, originalLibraryCategoriesIdForFll, false, companyId, newCommentForFll, originalHistoryForFll);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Insert a new Full Length Lining Work (direct to DB), empty works
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="libraryCategoriesId">libraryCategoriesId</param>
        /// <param name="clientId">clientId</param>
        /// <param name="proposedLiningDate">proposedLiningDate</param>
        /// <param name="deadlineLiningDate">deadlineLiningDate</param>
        /// <param name="p1Date">p1Date</param>
        /// <param name="m1Date">m1Date</param>
        /// <param name="m2Date">m2Date</param>
        /// <param name="installDate">installDate</param>
        /// <param name="finalVideoDate">finalVideoDate</param>
        /// <param name="issueIdentified">issueIdentified</param>
        /// <param name="issueLfs">issueLfs</param>
        /// <param name="issueClient">issueClient</param>
        /// <param name="issueSales">issueSales</param>
        /// <param name="issueGivenToClient">issueGivenToClient</param>
        /// <param name="issueResolved">issueResolved</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="issueInvestigation">issueInvestigation</param>
        /// <param name="comments">comments</param>
        /// <param name="history">history</param>
        /// <returns>int</returns>
        public int InsertDirectEmptyWorks(int projectId, int assetId, int? libraryCategoriesId, string clientId, DateTime? proposedLiningDate, DateTime? deadlineLiningDate, DateTime? p1Date, DateTime? m1Date, DateTime? m2Date, DateTime? installDate, DateTime? finalVideoDate, bool issueIdentified, bool issueLfs, bool issueClient, bool issueSales, bool issueGivenToClient, bool issueResolved, bool deleted, int companyId, bool issueInvestigation, string comments, string history)
        {
            int workId = 0;

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);

            if (workGateway.Table.Rows.Count == 0)
            {
                workId = new Work(null).InsertDirect(projectId, assetId, "Full Length Lining", libraryCategoriesId, deleted, companyId, comments, history);
                new WorkFullLengthLiningGateway(null).Insert(workId, clientId, proposedLiningDate, deadlineLiningDate, p1Date, m1Date, m2Date, installDate, finalVideoDate, issueIdentified, issueLfs, issueClient, issueSales, issueGivenToClient, issueResolved, deleted, companyId, issueInvestigation);
                new WorkFullLengthLiningP1Gateway(null).Insert(workId, null, deleted, companyId, false, null, false);
                new WorkFullLengthLiningM1Gateway(null).Insert(workId, "", "", "", false, false, "", "", "", "", "", "", deleted, companyId, "");
                new WorkFullLengthLiningM2Gateway(null).Insert(workId,"", "", false, "", null, "", "", "No", "", "", false, false, false, false, false, false, false, false, false, false, deleted, companyId, false);
            }
            else
            {
                workId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
            }

            return workId;
        }