/// <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);
            }
        }
        /// <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="companyId">companyId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        public void Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int companyId, int sectionAssetId)
        {
            RehabAssessmentTDS rehabAssessmentChanges = (RehabAssessmentTDS)Data.GetChanges();

            if (rehabAssessmentChanges.WorkDetails.Rows.Count > 0)
            {
                RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway(rehabAssessmentChanges);

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

                    // Original values
                    // ... General
                    string originalClientId = rehabAssessmentWorkDetailsGateway.GetClientIdOriginal(workId);
                    DateTime? originalPreFlushDate = rehabAssessmentWorkDetailsGateway.GetPreFlushDateOriginal(workId);
                    DateTime? originalPreVideoDate = rehabAssessmentWorkDetailsGateway.GetPreVideoDateOriginal(workId);

                    // ... P1
                    DateTime? originalP1Date = rehabAssessmentWorkDetailsGateway.GetP1DateOriginal(workId);
                    int? originalCxisRemoved = rehabAssessmentWorkDetailsGateway.GetCxisRemovedOriginal(workId);
                    bool originalRoboticPrepCompleted = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedOriginal(workId);
                    DateTime? originalRoboticPrepCompletedDate = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDateOriginal(workId);
                    bool originalP1Completed = rehabAssessmentWorkDetailsGateway.GetP1CompletedOriginal(workId);

                    // ... M1
                    DateTime? originalM1Date = rehabAssessmentWorkDetailsGateway.GetM1DateOriginal(workId);
                    string originalMeasurementTakenBy = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenByOriginal(workId);
                    string originalTrafficControl = rehabAssessmentWorkDetailsGateway.GetTrafficControlOriginal(workId);
                    string originalSiteDetails = rehabAssessmentWorkDetailsGateway.GetSiteDetailsOriginal(workId);
                    bool originalPipeSizeChange = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                    bool originalStandardBypass = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                    string originalStandardBypassComments = rehabAssessmentWorkDetailsGateway.GetStandardBypassCommentsOriginal(workId);
                    string originalTrafficControlDetails = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetailsOriginal(workId);
                    string originalMeasurementType = rehabAssessmentWorkDetailsGateway.GetMeasurementTypeOriginal(workId);
                    string originalMeasurementFromMh = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMhOriginal(workId);
                    string originalVideoDoneFromMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMhOriginal(workId);
                    string originalVideoDoneToMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMhOriginal(workId);
                    string originalMaterial = rehabAssessmentWorkDetailsGateway.GetMaterialOriginal(workId);
                    string originalAccessType = rehabAssessmentWorkDetailsGateway.GetAccessTypeOriginal(workId);

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

                    // ... M2
                    string originalVideoDistance = rehabAssessmentWorkDetailsGateway.GetVideoDistanceOriginal(workId);

                    // New variables
                    // ... General
                    string newClientId = rehabAssessmentWorkDetailsGateway.GetClientId(workId);

                    // ... P1
                    DateTime? newP1Date = rehabAssessmentWorkDetailsGateway.GetP1Date(workId);
                    int? newCxisRemoved = rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId);
                    bool newRoboticPrepCompleted = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                    DateTime? newRoboticPrepCompletedDate = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                    bool newP1Completed = rehabAssessmentWorkDetailsGateway.GetP1Completed(workId);

                    // ... M1
                    DateTime? newM1Date = rehabAssessmentWorkDetailsGateway.GetM1Date(workId);
                    string newMeasurementTakenBy = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenBy(workId);
                    string newTrafficControl = rehabAssessmentWorkDetailsGateway.GetTrafficControl(workId);
                    string newSiteDetails = rehabAssessmentWorkDetailsGateway.GetSiteDetails(workId);
                    bool newPipeSizeChange = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                    bool newStandardBypass = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                    string newStandardBypassComments = rehabAssessmentWorkDetailsGateway.GetStandardBypassComments(workId);
                    string newTrafficControlDetails = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetails(workId);
                    string newMeasurementType = rehabAssessmentWorkDetailsGateway.GetMeasurementType(workId);
                    string newMeasurementFromMh = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                    string newVideoDoneFromMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMh(workId);
                    string newVideoDoneToMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMh(workId);
                    string newMaterial = rehabAssessmentWorkDetailsGateway.GetMaterial(workId);
                    string newAccessType = rehabAssessmentWorkDetailsGateway.GetAccessType(workId);

                    // ... M2
                    string newVideoDistance = rehabAssessmentWorkDetailsGateway.GetVideoDistance(workId);

                    // ... Comments
                    string newComments = rehabAssessmentWorkDetailsGateway.GetComments(workId);

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

                    // ... FLL WorkID
                    int workIdFll = 0; if (!workDetailsRow.IsWorkIDFllNull()) workIdFll = workDetailsRow.WorkIDFll;

                    if (workIdFll != 0) // ... Has Fll work
                    {
                        WorkFullLengthLiningGateway workFullLengthLiningGateway = new WorkFullLengthLiningGateway();
                        workFullLengthLiningGateway.LoadByWorkId(workIdFll, companyId);

                        DateTime? originalProposedLiningDate = workFullLengthLiningGateway.GetProposedLiningDate(workIdFll);
                        DateTime? originalDeadlineLiningDate = workFullLengthLiningGateway.GetDeadlineLiningDate(workIdFll);
                        DateTime? originalM2Date = workFullLengthLiningGateway.GetM2Date(workIdFll);
                        DateTime? originalInstallDate = workFullLengthLiningGateway.GetInstallDate(workIdFll);
                        DateTime? originalFinalVideoDate = workFullLengthLiningGateway.GetFinalVideoDate(workIdFll);
                        bool originalIssueIdentified = workFullLengthLiningGateway.GetIssueIdentified(workIdFll);
                        bool originalIssueLFS = workFullLengthLiningGateway.GetIssueLFS(workIdFll);
                        bool originalIssueClient = workFullLengthLiningGateway.GetIssueClient(workIdFll);
                        bool originalIssueSales = workFullLengthLiningGateway.GetIssueSales(workIdFll);
                        bool originalIssueGivenToClient = workFullLengthLiningGateway.GetIssueGivenToClient(workIdFll);
                        bool originalIssueResolved = workFullLengthLiningGateway.GetIssueResolved(workIdFll);
                        bool originalIssueInvestigation = workFullLengthLiningGateway.GetIssueInvestigation(workIdFll);

                        // ... Update work
                        UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientId, originalProposedLiningDate, originalDeadlineLiningDate, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenBy, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoDistance, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientId, originalProposedLiningDate, originalDeadlineLiningDate, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoDistance, newComments, false, companyId, newAccessType, newP1Completed);
                        UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                    }
                    else
                    {
                        if (newClientId != "" || newP1Date.HasValue || newCxisRemoved.HasValue || newM1Date.HasValue || newMeasurementTakenBy != "" || newMaterial != "" || newTrafficControl != "" || newMeasurementType != "" || newMeasurementFromMh != "" || newVideoDoneFromMh != "" || newVideoDoneToMh != "" || newStandardBypassComments != "" || newTrafficControlDetails != ""  || newVideoDistance != "") // 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, "", "");

                            WorkFullLengthLiningGateway workFullLengthLiningGateway = new WorkFullLengthLiningGateway();
                            workFullLengthLiningGateway.LoadByWorkId(workIdFll, companyId);

                            DateTime? originalProposedLiningDate = workFullLengthLiningGateway.GetProposedLiningDate(workIdFll);
                            DateTime? originalDeadlineLiningDate = workFullLengthLiningGateway.GetDeadlineLiningDate(workIdFll);
                            DateTime? originalM2Date = workFullLengthLiningGateway.GetM2Date(workIdFll);
                            DateTime? originalInstallDate = workFullLengthLiningGateway.GetInstallDate(workIdFll);
                            DateTime? originalFinalVideoDate = workFullLengthLiningGateway.GetFinalVideoDate(workIdFll);
                            bool originalIssueIdentified = workFullLengthLiningGateway.GetIssueIdentified(workIdFll);
                            bool originalIssueLFS = workFullLengthLiningGateway.GetIssueLFS(workIdFll);
                            bool originalIssueClient = workFullLengthLiningGateway.GetIssueClient(workIdFll);
                            bool originalIssueSales = workFullLengthLiningGateway.GetIssueSales(workIdFll);
                            bool originalIssueGivenToClient = workFullLengthLiningGateway.GetIssueGivenToClient(workIdFll);
                            bool originalIssueResolved = workFullLengthLiningGateway.GetIssueResolved(workIdFll);
                            bool originalIssueInvestigation = workFullLengthLiningGateway.GetIssueInvestigation(workIdFll);

                            // ... Update work
                            UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientId, originalProposedLiningDate, originalDeadlineLiningDate, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenBy, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoDistance, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientId, originalProposedLiningDate, originalDeadlineLiningDate, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoDistance, newComments, false, companyId, newAccessType, newP1Completed);
                            UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                        }
                        else // ... Do not have Fll work
                        {
                            UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                        }
                    }

                    // JL Section WorkID
                    int sectionWorkId = 0;
                    WorkGateway workGatewayForJL = new WorkGateway();
                    workGatewayForJL.LoadByProjectIdAssetIdWorkType(projectId, sectionAssetId, "Junction Lining Section", companyId);

                    if (workGatewayForJL.Table.Rows.Count > 0)
                    {
                        sectionWorkId = workGatewayForJL.GetWorkId(sectionAssetId, "Junction Lining Section", projectId);
                        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);

                        WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                        workJunctionLiningSection.UpdateDirect(sectionWorkId, numLats, notLinedYet, allMeasured, deleted, issueWithLaterals, notMeasuredYet, notDeliveredYet, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, newTrafficControl, newTrafficControlDetails, newStandardBypass, newStandardBypassComments, availableToLine);
                    }
                }
            }
        }