/// <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>
        /// UpdateCommentsHistoryForSummaryEdit
        /// </summary>
        /// <param name="jlWorkId">jlWorkId</param>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        /// <returns>comments</returns>
        public void UpdateCommentsHistoryForSummaryEdit(int jlWorkId, string workType, int companyId)
        {
            foreach (FlatSectionJlTDS.FlatSectionJlRow row in (FlatSectionJlTDS.FlatSectionJlDataTable)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;
                    WorkGateway raWorkGateway = new WorkGateway();
                    raWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Rehab Assessment", companyId);
                    if (raWorkGateway.Table.Rows.Count > 0)
                    {
                        raWorkId = raWorkGateway.GetWorkId(row.Section_, "Rehab Assessment", projectId);
                    }

                    // ... Get flWorkId
                    int flWorkId = 0;
                    WorkGateway flWorkGateway = new WorkGateway();
                    flWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Full Length Lining", companyId);
                    if (flWorkGateway.Table.Rows.Count > 0)
                    {
                        flWorkId = flWorkGateway.GetWorkId(row.Section_, "Full Length Lining", projectId);
                    }

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

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

                    // Add M1 comments
                    WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
                    workFullLengthLiningM1LateralGateway.LoadByWorkIdLateral(flWorkId, row.AssetID, companyId);
                    if (workFullLengthLiningM1LateralGateway.Table.Rows.Count > 0)
                    {
                        string m1LateralComments = workFullLengthLiningM1LateralGateway.GetComments(flWorkId, row.AssetID);
                        if (m1LateralComments != "")
                        {
                            row.Comments = row.Comments + "\n\nType: M1 Lateral Comments\nComment: " + m1LateralComments;
                        }
                    }

                    WorkFullLengthLiningM1Gateway workFullLengthLiningM1Gateway = new WorkFullLengthLiningM1Gateway();
                    workFullLengthLiningM1Gateway.LoadByWorkId(flWorkId, companyId);
                    if (workFullLengthLiningM1Gateway.Table.Rows.Count > 0)
                    {
                        string trafficControlDetails = workFullLengthLiningM1Gateway.GetTrafficControlDetails(flWorkId);
                        if (trafficControlDetails != "")
                        {
                            row.Comments = row.Comments + "\n\nType: Traffic Control Details\nComment: " + trafficControlDetails ;
                        }

                        string standardByPassComments = workFullLengthLiningM1Gateway.GetStandardBypassComments(flWorkId);
                        if (standardByPassComments != "")
                        {
                            row.Comments = row.Comments + "\n\nType: Standard Bypass Comments\nComment: " + standardByPassComments ;
                        }
                    }

                    if (!row.IsCommentsNull())
                    {
                        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");
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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;
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = "Full Length Lining";
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfErrorFieldList.Value = "";

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

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

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);
            hdfWorkId.Value = workGateway.GetWorkId(assetId, workType, projectId).ToString();
            hdfWorkIdJl.Value = GetWorkId(projectId, assetId, "Junction Lining Section", companyId).ToString();
        }
        private bool LateralsCouldBeDeletedInJl(int lateral)
        {
            bool delete = false;

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

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

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

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

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

            return delete;
        }
        /// <summary>
        /// Save all comments to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>   
        /// <param name="runDetails">runDetails</param>
        /// <param name="projectId">projectId</param>
        public void Save(int companyId, string runDetails, int projectId)
        {
            string[] runDetailsList = runDetails.Split('>');

            FullLengthLiningTDS fullLengthLiningWetOutCommentsDetailsChanges = (FullLengthLiningTDS)Data.GetChanges();

            if (fullLengthLiningWetOutCommentsDetailsChanges.WetOutCommentsDetails.Rows.Count > 0)
            {
                FullLengthLiningWetOutCommentsDetailsGateway fullLengthLiningWetOutCommentsDetailsGateway = new FullLengthLiningWetOutCommentsDetailsGateway(fullLengthLiningWetOutCommentsDetailsChanges);

                foreach (FullLengthLiningTDS.WetOutCommentsDetailsRow row in (FullLengthLiningTDS.WetOutCommentsDetailsDataTable)fullLengthLiningWetOutCommentsDetailsChanges.WetOutCommentsDetails)
                {
                    // Insert new comments
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null);
                            int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;

                            workFullLengthLiningWetOutComments.InsertDirect(newWorkId, row.RefID, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType);
                        }
                    }

                    // Update comments
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        bool originalDeleted = false;
                        int originalCompanyId = companyId;

                        // original values
                        string originalType = fullLengthLiningWetOutCommentsDetailsGateway.GetTypeOriginal(workId, refId);
                        string originalSubject = fullLengthLiningWetOutCommentsDetailsGateway.GetSubjectOriginal(workId, refId);
                        int originalUserId = fullLengthLiningWetOutCommentsDetailsGateway.GetUserIdOriginal(workId, refId);
                        DateTime? originalDateTime = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetDateTime_Original(workId, refId) != null) originalDateTime = fullLengthLiningWetOutCommentsDetailsGateway.GetDateTime_Original(workId, refId);
                        string originalComment = fullLengthLiningWetOutCommentsDetailsGateway.GetCommentOriginal(workId, refId);
                        int? originalLibraryFilesId = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId);
                        string originalWorkType = fullLengthLiningWetOutCommentsDetailsGateway.GetWorkTypeOriginal(workId, refId);

                        // new values
                        string newType = fullLengthLiningWetOutCommentsDetailsGateway.GetType(workId, refId);
                        string newSubject = fullLengthLiningWetOutCommentsDetailsGateway.GetSubject(workId, refId);
                        string newComment = fullLengthLiningWetOutCommentsDetailsGateway.GetComment(workId, refId);
                        int? newLibraryFilesId = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_ID(workId, refId);

                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            string workType = "Full Length Lining Wet Out";
                            FullLengthLiningWetOutCommentsDetailsGateway fullLengthLiningWetOutCommentsDetailsGatewayForReview = new FullLengthLiningWetOutCommentsDetailsGateway();
                            fullLengthLiningWetOutCommentsDetailsGatewayForReview.LoadAllByWorkIdWorkType(newWorkId, companyId, workType);
                            if (fullLengthLiningWetOutCommentsDetailsGatewayForReview.Table.Rows.Count > 0)
                            {
                                WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null);
                                workFullLengthLiningWetOutComments.UpdateDirect(newWorkId, refId, originalType, originalSubject, originalUserId, originalDateTime, originalComment, originalLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType, workId, refId, newType, newSubject, originalUserId, originalDateTime, newComment, newLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType);
                            }
                            else
                            {
                                WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null);
                                int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;

                                workFullLengthLiningWetOutComments.InsertDirect(newWorkId, row.RefID, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType);
                            }
                        }
                    }

                    // Deleted comments
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }
                            WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null);
                            workFullLengthLiningWetOutComments.DeleteDirect(newWorkId, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }
        /// <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;
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = "Rehab Assessment";
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();

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

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);
            hdfWorkId.Value = workGateway.GetWorkId(assetId, workType, projectId).ToString();
        }
        /// <summary>
        /// Save all catalysts to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>   
        /// <param name="runDetails">runDetails</param>
        /// <param name="projectId">projectId</param>
        public void Save(int companyId, string runDetails, int projectId)
        {
            string[] runDetailsList = runDetails.Split('>');

            FullLengthLiningTDS fullLengthLiningWetOutCatalystsDetailsChanges = (FullLengthLiningTDS)Data.GetChanges();

            if (fullLengthLiningWetOutCatalystsDetailsChanges.WetOutCatalystsDetails.Rows.Count > 0)
            {
                FullLengthLiningWetOutCatalystsDetailsGateway fullLengthLiningWetOutCatalystsDetailsGateway = new FullLengthLiningWetOutCatalystsDetailsGateway(fullLengthLiningWetOutCatalystsDetailsChanges);

                foreach (FullLengthLiningTDS.WetOutCatalystsDetailsRow row in (FullLengthLiningTDS.WetOutCatalystsDetailsDataTable)fullLengthLiningWetOutCatalystsDetailsChanges.WetOutCatalystsDetails)
                {
                    // Insert new catalysts
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;

                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            if (newWorkId > 0)
                            {
                                WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null);
                                workFullLengthLiningWetOutCatalysts.InsertDirect(newWorkId, row.RefID, row.CatalystID, row.PercentageByWeight, row.LbsForMixQuantity, row.LbsForDrum, row.Deleted, row.COMPANY_ID);
                            }
                        }
                    }

                    // Update catalysts
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        bool originalDeleted = false;
                        int originalCompanyId = companyId;
                        int originalCatalystId = row.CatalystID;

                        // original values
                        decimal originalPercentageByWeight = fullLengthLiningWetOutCatalystsDetailsGateway.GetPercentageByWeightOriginal(workId, refId);
                        decimal originalLbsForMixQuantity = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForMixQuantityOriginal(workId, refId);
                        string originalLbsForDrum = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForDrumOriginal(workId, refId);

                        // new values
                        decimal newPercentageByWeight = fullLengthLiningWetOutCatalystsDetailsGateway.GetPercentageByWeight(workId, refId);
                        decimal newLbsForMixQuantity = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForMixQuantity(workId, refId);
                        string newLbsForDrum = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForDrum(workId, refId);

                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;

                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            if (newWorkId > 0)
                            {
                                FullLengthLiningWetOutCatalystsDetailsGateway fullLengthLiningWetOutCatalystsDetailsGatewayForReview = new FullLengthLiningWetOutCatalystsDetailsGateway();
                                fullLengthLiningWetOutCatalystsDetailsGatewayForReview.LoadByWorkId(newWorkId, companyId);

                                if (fullLengthLiningWetOutCatalystsDetailsGatewayForReview.Table.Rows.Count > 0)
                                {
                                    WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null);
                                    workFullLengthLiningWetOutCatalysts.UpdateDirect(newWorkId, refId, originalCatalystId, originalPercentageByWeight, originalLbsForMixQuantity, originalLbsForDrum, originalDeleted, originalCompanyId, workId, refId, originalCatalystId, newPercentageByWeight, newLbsForMixQuantity, newLbsForDrum, originalDeleted, originalCompanyId);
                                }
                                else
                                {
                                    WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null);
                                    workFullLengthLiningWetOutCatalysts.InsertDirect(newWorkId, row.RefID, row.CatalystID, row.PercentageByWeight, row.LbsForMixQuantity, row.LbsForDrum, row.Deleted, row.COMPANY_ID);
                                }
                            }
                        }
                    }

                    // Deleted catalysts
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;

                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            if (newWorkId > 0)
                            {
                                WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null);
                                workFullLengthLiningWetOutCatalysts.DeleteDirect(newWorkId, row.RefID, row.COMPANY_ID);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// UpdateForReport
        /// </summary>
        public void UpdateForReport()
        {
            foreach (JltoBuildReportTDS.JLToBuildRow jlToBuildRow in ((JltoBuildReportTDS.JLToBuildDataTable)Table))
            {
                // Load work
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByProjectIdAssetIdWorkType(jlToBuildRow.ProjectID, jlToBuildRow.AssetID, "Junction Lining Lateral", jlToBuildRow.COMPANY_ID);
                int workId = workGateway.GetWorkId(jlToBuildRow.AssetID, "Junction Lining Lateral", jlToBuildRow.ProjectID);

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

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

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

                // Update Lateral
                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                workJunctionLiningLateral.UpdateDirect(workId, sectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, false, jlToBuildRow.COMPANY_ID, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, newPipeLocated, newServicesLocated, newCoInstalled, newBackfilledConcrete, newBackfilledSoil, newGrouted, newCored, newPrepped, newMeasured, newLinerSize, newInProcess, newInStock, newDelivered, newBuildRebuild, newPreVideo, newLinerInstalled, newFinalVideo, newCost, newVideoInspection, newCoRequired, newPitRequired, newCoPitLocation, newPostContractDigRequired, newCoCutDown, newFinalRestoration, jlToBuildRow.COMPANY_ID, newVideoLengthToPropertyLine, newLiningThruCo, newNoticeDelivered, newHamiltonInspectionNumber, newFlange, newGasket, newDepthOfLocated, newDigRequiredPriorToLining, newDigRequiredPriorToLiningCompleted, newDigRequiredAfterLining, newDigRequiredAfterLiningCompleted, newOutOfScope, newHoldClientIssue, newHoldClientIssueResolved, newHoldLFSIssue, newHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, newLinerType, newPrepType, newDyeTestReq, newDyeTestComplete, originalContractYear, newContractYear);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateFieldsForSections
        /// </summary>
        private void UpdateFieldsForSections()
        {
            // Distance Validation
            foreach (JltoBuildReportTDS.JLToBuildRow row in ((JltoBuildReportTDS.JLToBuildDataTable)Table))
            {
                if (!row.IsMainSizeNull())
                {
                    if (Distance.IsValidDistance(row.MainSize))
                    {
                        Distance distance = new Distance(row.MainSize);

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

            foreach (JltoBuildReportTDS.JLToBuildRow row in ((JltoBuildReportTDS.JLToBuildDataTable)Table))
            {
                // Validate RoboticPrepCompleted
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByProjectIdAssetIdWorkType(row.ProjectID, row.Section_, "Full Length Lining", row.COMPANY_ID);
                if (workGateway.Table.Rows.Count > 0)
                {
                    // ... Get WorkId for Full Length Lining
                    int workIdFll = workGateway.GetWorkId(row.Section_, "Full Length Lining", row.ProjectID);

                    // ... Load if there is robotic prep completed
                    FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway();
                    fullLengthLiningWorkDetailsGateway.LoadByWorkIdAssetId(workIdFll, row.AssetID, row.COMPANY_ID);

                    bool roboticPrepCompleted = false;
                    DateTime? roboticPrepCompletedDate = null;

                    roboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompleted(workIdFll);
                    roboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workIdFll);

                    if ((roboticPrepCompleted) && (!roboticPrepCompletedDate.HasValue))
                    {
                        row.Delete();
                    }
                }
            }
        }
        /// <summary>
        /// DeleteJLLaterals
        /// </summary>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="lateral_assetId">lateral_assetId</param>
        /// <param name="companyId">companyId</param>       
        /// <param name="sectionWorkId">sectionWorkId</param>
        private void DeleteJLLaterals(int currentProjectId, int lateral_assetId, int companyId, int sectionWorkId)
        {
            // Load work id
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, lateral_assetId, "Junction Lining Lateral", companyId);

            if (workGateway.Table.Rows.Count > 0)
            {
                int workId = workGateway.GetWorkId(lateral_assetId, "Junction Lining Lateral", currentProjectId);

                if (workId > 0)
                {
                    // Delete work
                    WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                    workJunctionLiningLateral.DeleteDirect(workId, sectionWorkId, companyId);
                }
            }
        }
        /// <summary>
        /// UpdateJLLaterals
        /// </summary>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="lateral_assetId">lateral_assetId</param>
        /// <param name="companyId">companyId</param>        
        /// <param name="clientInspectionNo">clientInspectionNo</param>
        /// <param name="requiresRoboticPrep">requiresRoboticPrep</param>
        /// <param name="requiresRoboticPrepDate">requiresRoboticPrepDate</param>
        /// <param name="holdClientIssue">holdClientIssue</param>
        /// <param name="holdLFSIssue">holdLFSIssue</param>
        /// <param name="flange">flange</param>
        /// <param name="dyeTestReq">dyeTestReq</param>
        /// <param name="dyeTestComplete">dyeTestComplete</param>
        private void UpdateJLLaterals(int currentProjectId, int lateral_assetId, int companyId, string clientInspectionNo, bool requiresRoboticPrep, DateTime? requiresRoboticPrepDate, bool holdClientIssue, bool holdLFSIssue, string flange, bool dyeTestReq, DateTime? dyeTestComplete, string contractYear)
        {
            // Load work id
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, lateral_assetId, "Junction Lining Lateral", companyId);
            if (workGateway.Table.Rows.Count > 0)
            {
                int workId = workGateway.GetWorkId(lateral_assetId, "Junction Lining Lateral", currentProjectId);

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

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

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

                    // Update work
                    WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                    workJunctionLiningLateral.UpdateDirect(workId, originalSectionWorkId, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, false, companyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, originalHamiltonInspectionNumber, originalFlange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, originalHoldClientIssue, originalHoldClientIssueResolved, originalHoldLFSIssue, originalHoldLFSIssueResolved, originalRequiresRoboticPrep, originalRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, originalDyeTestReq, originalDyeTestComplete, originalPipeLocated, originalServicesLocated, originalCoInstalled, originalBackfilledConcrete, originalBackfilledSoil, originalGrouted, originalCored, originalPrepped, originalMeasured, originalLinerSize, originalInProcess, originalInStock, originalDelivered, originalBuildRebuild, originalPreVideo, originalLinerInstalled, originalFinalVideo, originalCost, originalVideoInspection, originalCoRequired, originalPitRequired, originalCoPitLocation, originalPostContractDigRequired, originalCoCutDown, originalFinalRestoration, companyId, originalVideoLengthToPropertyLine, originalLiningThruCo, originalNoticeDelivered, newClientInspectionNo, flange, originalGasket, originalDepthOfLocated, originalDigRequiredPriorToLining, originalDigRequiredPriorToLiningCompleted, originalDigRequiredAfterLining, originalDigRequiredAfterLiningCompleted, originalOutOfScope, newHoldClientIssue, originalHoldClientIssueResolved,  newHoldLFSIssue, originalHoldLFSIssueResolved, newRequiresRoboticPrep, newRequiresRoboticPrepCompleted, originalLinerType, originalPrepType, newDyeTetRepair, newDyeTestComplete, originalContractYear, newContractYear);
                }
            }
        }
        /// <summary>
        /// Save a Previous RA work
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="companyId">companyId</param>
        private void SavePreviousWork(int parentProjectId, int childProjectId, int assetId, string workType, int companyId)
        {
            int parentWorkId = 0;
            int childWorkId = 0;
            int childJLLWorkId = 0;
            int parentJLLWorkID = 0;

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

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

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

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

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

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

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

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

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

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

                            workUpdate(childJLLWorkId, childProjectId, lateral_assetId, companyId, "Junction Lining Lateral");
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    workUpdate(childWorkId, childProjectId, assetId, companyId, workType);
                }
            }
        }
        /// <summary>
        /// UpdateFieldsForSections
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="companyId">companyId</param>
        private void UpdateFieldsForSections(int projectId, int companyId)
        {
            foreach (FlatSectionJlTDS.FlatSectionJlRow row in (FlatSectionJlTDS.FlatSectionJlDataTable)Table)
            {
                int jlWorkId = row.WorkID;

                // ... Get raWorkId
                int raWorkId = 0;
                WorkGateway raWorkGateway = new WorkGateway();
                raWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Rehab Assessment", companyId);
                if (raWorkGateway.Table.Rows.Count > 0)
                {
                    raWorkId = raWorkGateway.GetWorkId(row.Section_, "Rehab Assessment", projectId);
                }

                // ... Get flWorkId
                int flWorkId = 0;
                WorkGateway flWorkGateway = new WorkGateway();
                flWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Full Length Lining", companyId);
                if (flWorkGateway.Table.Rows.Count > 0)
                {
                    flWorkId = flWorkGateway.GetWorkId(row.Section_, "Full Length Lining", projectId);
                }

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

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

                // Add M1 comments
                WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
                workFullLengthLiningM1LateralGateway.LoadByWorkIdLateral(flWorkId, row.AssetID, companyId);
                if (workFullLengthLiningM1LateralGateway.Table.Rows.Count > 0)
                {
                    string m1LateralComments = workFullLengthLiningM1LateralGateway.GetComments(flWorkId, row.AssetID);
                    if (m1LateralComments != "")
                    {
                        row.Comments = row.Comments + "\n\nType: M1 Lateral Comments\nComment: " + m1LateralComments ;
                    }
                }

                WorkFullLengthLiningM1Gateway workFullLengthLiningM1Gateway = new WorkFullLengthLiningM1Gateway();
                workFullLengthLiningM1Gateway.LoadByWorkId(flWorkId, companyId);
                if (workFullLengthLiningM1Gateway.Table.Rows.Count > 0)
                {
                    string trafficControlDetails = workFullLengthLiningM1Gateway.GetTrafficControlDetails(flWorkId);
                    if (trafficControlDetails != "")
                    {
                        row.Comments = row.Comments + "\n\nType: Traffic Control Details\nComment: " + trafficControlDetails;
                    }

                    string standardByPassComments = workFullLengthLiningM1Gateway.GetStandardBypassComments(flWorkId);
                    if (standardByPassComments != "")
                    {
                        row.Comments = row.Comments + "\n\nType: Standard Bypass Comments\nComment: " + standardByPassComments ;
                    }

                    string measurementFromMH = "USMH"; if (workFullLengthLiningM1Gateway.GetMeasurementFromMh(flWorkId) != "") measurementFromMH = workFullLengthLiningM1Gateway.GetMeasurementFromMh(flWorkId);

                    if (measurementFromMH == "DSMH")
                    {
                        string auxDistanceFromUSMH = row.DistanceFromUSMH;
                        row.DistanceFromUSMH = row.DistanceFromDSMH;
                        row.DistanceFromDSMH = auxDistanceFromUSMH;
                    }
                }

                if (!row.IsCommentsNull())
                {
                    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");
                }

                // Update FlowOrderID
                if (!row.IsFlowOrderIDNull())
                {
                    row.LateralID = row.FlowOrderID + "-JL-" + row.LateralID;
                }
                else
                {
                    row.LateralID = "JL-" + row.LateralID;
                }

                // Update MainSize
                if (!row.IsMainSizeNull())
                {
                    try
                    {
                        if (Distance.IsValidDistance(row.MainSize))
                        {
                            Distance distance = new Distance(row.MainSize);

                            switch (distance.DistanceType)
                            {
                                case 2:
                                    row.MainSize = distance.ToStringInEng1();
                                    break;
                                case 3:
                                    if (Convert.ToDouble(row.MainSize) > 99)
                                    {
                                        double newMainSize = 0;
                                        newMainSize = Convert.ToDouble(row.MainSize) * 0.03937;
                                        row.MainSize = Convert.ToString(Math.Ceiling(newMainSize)) + "\"";
                                    }
                                    else
                                    {
                                        row.MainSize = row.MainSize + "\"";
                                    }
                                    break;
                                case 4:
                                    row.MainSize = distance.ToStringInEng1();
                                    break;
                                case 5:
                                    row.MainSize = distance.ToStringInEng1();
                                    break;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Example #17
0
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = "Manhole Rehabilitation";
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();
            hdfInProject.Value = Request.QueryString["in_project"].ToString();
            hdfExistBatchId.Value = "False";

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            if (projectGateway.Table.Rows.Count > 0)
            {
                // ... Get ids
                Int64 currentCountry = projectGateway.GetCountryID(projectId);
                Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
                Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
                Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

                hdfCountryId.Value = currentCountry.ToString();
                hdfProvinceId.Value = currentProvince.ToString();
                hdfCountyId.Value = currentCounty.ToString();
                hdfCityId.Value = currentCity.ToString();
            }
            else
            {
                hdfCountryId.Value = "";
                hdfProvinceId.Value = "";
                hdfCountyId.Value = "";
                hdfCityId.Value = "";
            }

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

            WorkGateway workGateway = new WorkGateway();
            hdfWorkId.Value = "0";

            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);

            if (workGateway.Table.Rows.Count > 0)
            {
                hdfWorkId.Value = workGateway.GetWorkId(assetId, workType, projectId).ToString();
            }
        }
        /// <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);
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_EDIT"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["client_id"] == null) || ((string)Request.QueryString["project_id"] == null) || ((string)Request.QueryString["row_asset_id"] == null) || ((string)Request.QueryString["row_focus"] == null) || ((string)Request.QueryString["work_type"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in jl_comments.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
                hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfAssetId.Value = Convert.ToString(Request.QueryString["row_asset_id"]);
                hdfAdminPermission.Value = Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_ADMIN"]).ToString();
                hdfWorkType.Value = Request.QueryString["work_type"].ToString();
                hdfSection_.Value = Request.QueryString["section_"].ToString();
                hdfUpdate.Value = "yes";

                // ... Names for UserList
                string workType = hdfWorkType.Value.Trim();
                int companyId = Int32.Parse(hdfCompanyId.Value);

                LoginGateway loginGateway = new LoginGateway();
                loginGateway.LoadByLoginId(Convert.ToInt32(hdfLoginId.Value), companyId);
                hdfCreatedBy.Value = loginGateway.GetLastName(Convert.ToInt32(hdfLoginId.Value), companyId) + " " + loginGateway.GetFirstName(Convert.ToInt32(hdfLoginId.Value), companyId);
                hdfCreationDateTime.Value = DateTime.Now.ToString();

                // Prepare initial data
                Session.Remove("flatSectionJlCommentDetailsDummy");

                // If coming from
                // ... flat_section_jl_summary.aspx or flat_section_jl_edit.aspx
                if (Request.QueryString["source_page"] == "flat_section_jl_summary.aspx" || Request.QueryString["source_page"] == "flat_section_jl_edit.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                    Session["rowFocus"] = Convert.ToInt32(Request.QueryString["row_focus"].ToString());

                    // ... Load comments to edit
                    flatSectionJlTDS = (FlatSectionJlTDS)Session["flatSectionJlTDS"];
                    jlNavigatorTDS = (JlNavigatorTDS)Session["jlNavigatorTDS"];

                    // Get workId
                    int assetId = Int32.Parse(hdfAssetId.Value.Trim());
                    int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
                    int jlWorkId = 0;
                    int raWorkId = 0;
                    int flWorkId = 0;

                    WorkGateway searchWorkGateway = new WorkGateway();
                    searchWorkGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, assetId, "Junction Lining Lateral", companyId);

                    // ... If the project has jl works
                    if (searchWorkGateway.Table.Rows.Count > 0)
                    {
                        jlWorkId = searchWorkGateway.GetWorkId(assetId, "Junction Lining Lateral", currentProjectId);

                        // ... ...Tag Page
                        hdfWorkId.Value = jlWorkId.ToString().Trim();

                        // ... ...Get ra work id for comments
                        int section_ = Int32.Parse(hdfSection_.Value) ;
                        WorkGateway workGatewayRAFL = new WorkGateway();

                        // ... ...Get fl work id for comments
                        workGatewayRAFL.LoadByProjectIdAssetIdWorkType(currentProjectId, section_, "Full Length Lining", companyId);
                        if (workGatewayRAFL.Table.Rows.Count > 0)
                        {
                            flWorkId = workGatewayRAFL.GetWorkId(section_, "Full Length Lining", currentProjectId);
                        }

                        workGatewayRAFL.LoadByProjectIdAssetIdWorkType(currentProjectId, section_, "Rehab Assessment", companyId);
                        if (workGatewayRAFL.Table.Rows.Count > 0)
                        {
                            raWorkId = workGatewayRAFL.GetWorkId(section_, "Rehab Assessment", currentProjectId);
                        }

                        // ... ...Get comments
                        FlatSectionJlCommentDetailsGateway flatSectionJlCommentDetailsGateway = new FlatSectionJlCommentDetailsGateway(flatSectionJlTDS);
                        flatSectionJlCommentDetailsGateway.LoadAllByJlWorkIdRaWorkIdFlWorkId(jlWorkId, raWorkId, flWorkId, companyId);

                        FlatSectionJlCommentDetails flatSectionJlCommentDetails = new FlatSectionJlCommentDetails(flatSectionJlCommentDetailsGateway.Data);
                        flatSectionJlCommentDetails.UpdateForProcess();

                        // ... ...Get history
                        FlatSectionJlHistoryDetailsGateway flatSectionJlHistoryDetailsGateway = new FlatSectionJlHistoryDetailsGateway(flatSectionJlTDS);
                        flatSectionJlHistoryDetailsGateway.LoadAllByJlWorkIdRaWorkIdFlWorkId(jlWorkId, raWorkId, flWorkId, companyId);
                    }

                    // ... Store datasets
                    Session["flatSectionJlTDS"] = flatSectionJlTDS;
                    Session["jlNavigatorTDS"] = jlNavigatorTDS;
                    Session["flatSectionJlCommentDetails"] = flatSectionJlTDS.FlatSectionJlCommentDetails;
                }
            }
            else
            {
                // Restore datasets
                flatSectionJlTDS = (FlatSectionJlTDS)Session["flatSectionJlTDS"];
                jlNavigatorTDS = (JlNavigatorTDS)Session["jlNavigatorTDS"];
                flatSectionJlCommentDetails = flatSectionJlTDS.FlatSectionJlCommentDetails;

                // Store
                Session["flatSectionJlCommentDetails"] = flatSectionJlTDS.FlatSectionJlCommentDetails;
            }
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);

            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

            // Get workId
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Point Repairs", companyId);
            hdfWorkId.Value = workGateway.GetWorkId(assetId, "Point Repairs", projectId).ToString();
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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;
        }
Example #23
0
        protected void grdLaterals_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
            {
                int lateral = int.Parse(((Label)e.Row.FindControl("lblLateral")).Text);

                if (lateral > 0)
                {
                    FullLengthLiningLateralDetailsGateway gateway = new FullLengthLiningLateralDetailsGateway(fullLengthLiningTDS);
                    ((TextBox)e.Row.FindControl("tbxMaterial")).Text = gateway.GetMaterialType(lateral);
                }
            }

            // Control value for footer material
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                // For Material
                ((DropDownList)e.Row.FindControl("ddlNewMaterial")).SelectedIndex = 0;
            }

            // Control of edit controls
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                int lateral = int.Parse(((Label)e.Row.FindControl("lblLateral")).Text);

                if (lateral > 0)
                {
                    FullLengthLiningLateralDetailsGateway gateway = new FullLengthLiningLateralDetailsGateway(fullLengthLiningTDS);

                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    // ... Control material and connection type dropdownlists
                    ((DropDownList)e.Row.FindControl("ddlMaterialEdit")).SelectedValue = gateway.GetMaterialType(lateral);
                    ((DropDownList)e.Row.FindControl("ddlConnectionTypeEdit")).SelectedValue = gateway.GetConnectionType(lateral);

                    // .... If lateral us used in junction lining
                    if (gateway.GetInJlDatabase(lateral))
                    {
                        if (!LateralsCouldBeDeletedInJl(lateral))
                        {
                            ((CheckBox)e.Row.FindControl("cbxJlEdit")).Enabled = false;
                        }
                    }

                    // ... Control live value
                    int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value);
                    WorkGateway workGateway = new WorkGateway();
                    workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, lateral, "Junction Lining Lateral", companyId);

                    // ... If lateral is not used in junction lining
                    if (!workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(lateral, currentProjectId, "Junction Lining Lateral", companyId))
                    {
                        ((DropDownList)e.Row.FindControl("ddlLiveEdit")).Visible = true;
                        ((DropDownList)e.Row.FindControl("ddlLiveEdit")).SelectedValue = gateway.GetLive(lateral);
                        ((TextBox)e.Row.FindControl("tbxJlLive")).Visible = false;
                    }
                    else
                    {
                        ((DropDownList)e.Row.FindControl("ddlLiveEdit")).Visible = false;
                        ((TextBox)e.Row.FindControl("tbxJlLive")).Visible = true;
                    }
                }
            }
        }
        protected void btnPrintLateralLocationSheet_Click(object sender, EventArgs e)
        {
            mForm7 master = (mForm7)this.Master;
            ScriptManager scriptManager = (ScriptManager)master.FindControl("ScriptManagerMaster7");

            if (!scriptManager.IsInAsyncPostBack)
            {
                string url = "";
                string client = "";
                string name = "";
                string project = "";
                string title = "Full Length Lining Search Results";

                // ... for client
                int currentClientId = Int32.Parse(hdfCurrentClientId.Value.ToString());
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadByCompaniesId(currentClientId, companyId);
                client += "Client: " + companiesGateway.GetName(currentClientId);

                // ... for project
                int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());
                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(currentProjectId);
                project = projectGateway.GetName(currentProjectId);
                name = client + " > Project: " + project + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")";

                // ... for title view
                if (hdfBtnOrigin.Value == "Go")
                {
                    int viewId = Int32.Parse(ddlView.SelectedValue.Trim());

                    // ... Load name view
                    WorkViewGateway workViewGateway = new WorkViewGateway();
                    workViewGateway.LoadByViewId(viewId, companyId);

                    title = workViewGateway.GetName(viewId);
                }

                // Report call
                Page.Validate();
                if (Page.IsValid)
                {
                    PostPageChanges();

                    int assetId = GetAssetId();
                    if (assetId > 0)
                    {
                        WorkGateway workGateway = new WorkGateway();
                        workGateway.LoadByProjectIdAssetIdWorkType(Int32.Parse(hdfCurrentProjectId.Value), assetId, "Full Length Lining", Int32.Parse(hdfCompanyId.Value));
                        int workId = workGateway.GetWorkId(assetId, "Full Length Lining", Int32.Parse(hdfCurrentProjectId.Value));

                        FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway();
                        fullLengthLiningWorkDetailsGateway.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));
                        string measuredFrom = fullLengthLiningWorkDetailsGateway.GetMeasurementFromMh(workId);

                        Response.Write("<script language='javascript'> {window.open('./../../CWP/Common/lateral_location_sheet_report.aspx?source_page=lm&project_id=" + hdfCurrentProjectId.Value + "&client_id=" + hdfCurrentClientId.Value + "&work_id=" + workId.ToString() + "&measured_from=" + measuredFrom + "&asset_id=" + assetId.ToString() + "', '_blank', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=800, height=680');}</script>");
                    }
                    else
                    {
                        cvSelection.IsValid = false;
                    }
                }

                if (url != "") Response.Redirect(url);
            }
        }
Example #25
0
        private void LoadWorkData(int workId, int assetId)
        {
            FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway(fullLengthLiningTDS);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    tbxInversionDataNotesAndInstallationResults.Text = fullLengthLiningWorkDetailsGateway.GetInstallationResults(workId);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                // ... ... Show comments
                tbxCommentsDataComments.Text = fullLengthLiningAllComments.GetFLOrRAComments(companyId, fullLengthLiningAllComments.Table.Rows.Count, "\n");
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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;
        }
        /// <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="sectionAssetId">sectionAssetId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="includeWetOutInformation">includeWetOutInformation</param>
        /// <param name="includeInversionInformation">includeInversionInformation</param>
        public void Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int sectionAssetId, int companyId, bool includeWetOutInformation, bool includeInversionInformation)
        {
            FullLengthLiningTDS fullLengthLiningChanges = (FullLengthLiningTDS)Data.GetChanges();

            if (fullLengthLiningChanges.WorkDetails.Rows.Count > 0)
            {
                FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway(fullLengthLiningChanges);

                // Update sections
                foreach (FullLengthLiningTDS.WorkDetailsRow row in (FullLengthLiningTDS.WorkDetailsDataTable)fullLengthLiningChanges.WorkDetails)
                {
                    // Unchanged values
                    int workId = row.WorkID;

                    // Original values
                    string originalClientId = fullLengthLiningWorkDetailsGateway.GetClientIdOriginal(workId);
                    DateTime? originalProposedLiningDate = fullLengthLiningWorkDetailsGateway.GetProposedLiningDateOriginal(workId);
                    DateTime? originalDeadlineLiningDate = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDateOriginal(workId);
                    DateTime? originalP1Date = fullLengthLiningWorkDetailsGateway.GetP1DateOriginal(workId);
                    DateTime? originalM1Date = fullLengthLiningWorkDetailsGateway.GetM1DateOriginal(workId);
                    DateTime? originalM2Date = fullLengthLiningWorkDetailsGateway.GetM2DateOriginal(workId);
                    DateTime? originalInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDateOriginal(workId);
                    DateTime? originalFinalVideoDate = fullLengthLiningWorkDetailsGateway.GetFinalVideoDateOriginal(workId);
                    bool originalIssueIdentified = fullLengthLiningWorkDetailsGateway.GetIssueIdentifiedOriginal(workId);
                    bool originalIssueLFS = fullLengthLiningWorkDetailsGateway.GetIssueLFSOriginal(workId);
                    bool originalIssueClient = fullLengthLiningWorkDetailsGateway.GetIssueClientOriginal(workId);
                    bool originalIssueSales = fullLengthLiningWorkDetailsGateway.GetIssueSalesOriginal(workId);
                    bool originalIssueGivenToClient = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClientOriginal(workId);
                    bool originalIssueResolved = fullLengthLiningWorkDetailsGateway.GetIssueResolvedOriginal(workId);
                    bool originalIssueInvestigation = fullLengthLiningWorkDetailsGateway.GetIssueInvestigationOriginal(workId);
                    int? originalCxisRemoved = fullLengthLiningWorkDetailsGateway.GetCxisRemovedOriginal(workId);
                    bool originalRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedOriginal(workId);
                    DateTime? originalRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDateOriginal(workId);
                    DateTime? originalPreFlushDate = fullLengthLiningWorkDetailsGateway.GetPreFlushDateOriginal(workId);
                    DateTime? originalPreVideoDate = fullLengthLiningWorkDetailsGateway.GetPreVideoDateOriginal(workId);
                    int originalRaWorkId = fullLengthLiningWorkDetailsGateway.GetRaWorkIdOriginal(workId);
                    bool originalP1Completed = fullLengthLiningWorkDetailsGateway.GetP1CompletedOriginal(workId);

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

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

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

                    // New variables
                    string newClientId = fullLengthLiningWorkDetailsGateway.GetClientId(workId);
                    DateTime? newProposedLiningDate = fullLengthLiningWorkDetailsGateway.GetProposedLiningDate(workId);
                    DateTime? newDeadlineLiningDate = fullLengthLiningWorkDetailsGateway.GetDeadlineLiningDate(workId);
                    DateTime? newP1Date = fullLengthLiningWorkDetailsGateway.GetP1Date(workId);
                    DateTime? newM1Date = fullLengthLiningWorkDetailsGateway.GetM1Date(workId);
                    DateTime? newM2Date = fullLengthLiningWorkDetailsGateway.GetM2Date(workId);
                    DateTime? newInstallDate = fullLengthLiningWorkDetailsGateway.GetInstallDate(workId);
                    DateTime? newFinalVideoDate = fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId);
                    bool newIssueIdentified = fullLengthLiningWorkDetailsGateway.GetIssueIdentified(workId);
                    bool newIssueLFS = fullLengthLiningWorkDetailsGateway.GetIssueLFS(workId);
                    bool newIssueClient = fullLengthLiningWorkDetailsGateway.GetIssueClient(workId);
                    bool newIssueSales = fullLengthLiningWorkDetailsGateway.GetIssueSales(workId);
                    bool newIssueGivenToClient = fullLengthLiningWorkDetailsGateway.GetIssueGivenToClient(workId);
                    bool newIssueResolved = fullLengthLiningWorkDetailsGateway.GetIssueResolved(workId);
                    bool newIssueInvestigation = fullLengthLiningWorkDetailsGateway.GetIssueInvestigation(workId);
                    int? newCxisRemoved = fullLengthLiningWorkDetailsGateway.GetCxisRemoved(workId);
                    bool newRoboticPrepCompleted = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                    DateTime? newRoboticPrepCompletedDate = fullLengthLiningWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                    DateTime? newPreFlushDate = fullLengthLiningWorkDetailsGateway.GetPreFlushDate(workId);
                    DateTime? newPreVideoDate = fullLengthLiningWorkDetailsGateway.GetPreVideoDate(workId);
                    int newRaWorkId = fullLengthLiningWorkDetailsGateway.GetRaWorkId(workId);
                    bool newP1Completed = fullLengthLiningWorkDetailsGateway.GetP1Completed(workId);

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

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

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

                    // Update work
                    UpdateWork(countryId, provinceId, countyId, cityId, workId, 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, originalMeasurementTakenByM2, originalDropPipe, originalDropPipeInvertDepth, originalCappedLaterals, originalLineWithId, originalHydrantAddress, originalHydroWireWithin10FtOfInversionMH, originalDistanceToInversionMh, originalSurfaceGrade, originalHydroPulley, originalFridgeCart, originalTwoPump, originalSixBypass, originalScaffolding, originalWinchExtension, originalExtraGenerator, originalGreyCableExtension, originalEasementMats, originalRampRequired, originalVideoLength, originalComments, originalPreFlushDate, originalPreVideoDate, originalRaWorkId, false, companyId, originalMaterial, originalCameraSkid, originalAccessType, originalP1Completed, newClientId, newProposedLiningDate, newDeadlineLiningDate, newP1Date, newM1Date, newM2Date, newInstallDate, newFinalVideoDate, newIssueIdentified, newIssueLFS, newIssueClient, newIssueSales, newIssueGivenToClient, newIssueResolved, newIssueInvestigation, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newMeasurementTakenByM2, newDropPipe, newDropPipeInvertDepth, newCappedLaterals, newLineWithId, newHydrantAddress, newHydroWireWithin10FtOfInversionMH, newDistanceToInversionMh, newSurfaceGrade, newHydroPulley, newFridgeCart, newTwoPump, newSixBypass, newScaffolding, newWinchExtension, newExtraGenerator, newGreyCableExtension, newEasementMats, newRampRequired, newVideoLength, newComments, newPreFlushDate, newPreVideoDate, newRaWorkId, sectionAssetId, false, companyId, newCameraSkid, newAccessType, newP1Completed);

                    // For wet out information
                    if (includeWetOutInformation)
                    {
                        // Update data
                        WorkFullLengthLiningWetOutGateway workFullLengthLiningWetOutGateway = new WorkFullLengthLiningWetOutGateway();
                        workFullLengthLiningWetOutGateway.LoadByWorkId(workId, companyId);

                        // ... Verify if work has wet out data information
                        if (workFullLengthLiningWetOutGateway.Table.Rows.Count > 0)
                        {
                            // Wet Out data original values
                            string originalLinerTube = fullLengthLiningWorkDetailsGateway.GetLinerTubeOriginal(workId);
                            int originalResinID = fullLengthLiningWorkDetailsGateway.GetResinIdOriginal(workId);
                            decimal originalExcessResin = fullLengthLiningWorkDetailsGateway.GetExcessResinOriginal(workId);
                            string originalPoundsDrums = fullLengthLiningWorkDetailsGateway.GetPoundsDrumsOriginal(workId);
                            decimal originalDrumDiameter = fullLengthLiningWorkDetailsGateway.GetDrumDiameterOriginal(workId);
                            decimal originalHoistMaximumHeight = fullLengthLiningWorkDetailsGateway.GetHoistMaximumHeightOriginal(workId);
                            decimal originalHoistMinimumHeight = fullLengthLiningWorkDetailsGateway.GetHoistMinimumHeightOriginal(workId);
                            decimal originalDownDropTubeLenght = fullLengthLiningWorkDetailsGateway.GetDownDropTubeLenghtOriginal(workId);
                            decimal originalPumpHeightAboveGround = fullLengthLiningWorkDetailsGateway.GetPumpHeightAboveGroundOriginal(workId);
                            int originalTubeResinToFeltFactor = fullLengthLiningWorkDetailsGateway.GetTubeResinToFeltFactorOriginal(workId);
                            DateTime originalDateOfSheet = fullLengthLiningWorkDetailsGateway.GetDateOfSheetOriginal(workId);
                            int originalEmployeeID = fullLengthLiningWorkDetailsGateway.GetEmployeeIdOriginal(workId);
                            string originalRunDetails = fullLengthLiningWorkDetailsGateway.GetRunDetailsOriginal(workId);
                            string originalRunDetails2 = fullLengthLiningWorkDetailsGateway.GetRunDetails2Original(workId);
                            DateTime originalWetOutDate = fullLengthLiningWorkDetailsGateway.GetWetOutDateOriginal(workId);
                            DateTime? originalWetOutInstallDate = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDateOriginal(workId);
                            string originalThickness = fullLengthLiningWorkDetailsGateway.GetInversionThicknessOriginal(workId);
                            decimal originalLengthToLine = fullLengthLiningWorkDetailsGateway.GetLengthToLineOriginal(workId);
                            decimal originalPlusExtra = fullLengthLiningWorkDetailsGateway.GetPlusExtraOriginal(workId);
                            decimal originalForTurnOffset = fullLengthLiningWorkDetailsGateway.GetForTurnOffsetOriginal(workId);
                            decimal originalLengthToWetOut = fullLengthLiningWorkDetailsGateway.GetLengthToWetOutOriginal(workId);
                            decimal originalTubeMaxColdHead = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHeadOriginal(workId);
                            decimal originalTubeMaxColdHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHeadPsiOriginal(workId);
                            decimal originalTubeMaxHotHead = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHeadOriginal(workId);
                            decimal originalTubeMaxHotHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHeadPsiOriginal(workId);
                            decimal originalTubeIdealHead = fullLengthLiningWorkDetailsGateway.GetTubeIdealHeadOriginal(workId);
                            decimal originalTubeIdealHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeIdealHeadPsiOriginal(workId);
                            decimal originalNetResinForTube = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeOriginal(workId);
                            decimal originalNetResinForTubeUsgals = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgalsOriginal(workId);
                            string originalNetResinForTubeDrumsIns = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeDrumsInsOriginal(workId);
                            decimal originalNetResinForTubeLbsFt = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeLbsFtOriginal(workId);
                            decimal originalNetResinForTubeUsgFt = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgFtOriginal(workId);
                            int originalExtraResinForMix = fullLengthLiningWorkDetailsGateway.GetExtraResinForMixOriginal(workId);
                            decimal originalExtraLbsForMix = fullLengthLiningWorkDetailsGateway.GetExtraLbsForMixOriginal(workId);
                            decimal originalTotalMixQuantity = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityOriginal(workId);
                            decimal originalTotalMixQuantityUsgals = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityUsgalsOriginal(workId);
                            string originalTotalMixQuantityDrumsIns = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityDrumsInsOriginal(workId);
                            string originalInversionType = fullLengthLiningWorkDetailsGateway.GetInversionTypeOriginal(workId);
                            decimal originalDepthOfInversionMH = fullLengthLiningWorkDetailsGateway.GetDepthOfInversionMHOriginal(workId);
                            decimal originalTubeForColumn = fullLengthLiningWorkDetailsGateway.GetTubeForColumnOriginal(workId);
                            decimal originalTubeForStartDry = fullLengthLiningWorkDetailsGateway.GetTubeForStartDryOriginal(workId);
                            decimal originalTotalTube = fullLengthLiningWorkDetailsGateway.GetTotalTubeOriginal(workId);
                            string originalDropTubeConnects = fullLengthLiningWorkDetailsGateway.GetDropTubeConnectsOriginal(workId);
                            decimal originalAllowsHeadTo = fullLengthLiningWorkDetailsGateway.GetAllowsHeadToOriginal(workId);
                            decimal originalRollerGap = fullLengthLiningWorkDetailsGateway.GetRollerGapOriginal(workId);
                            decimal originalHeightNeeded = fullLengthLiningWorkDetailsGateway.GetHeightNeededOriginal(workId);
                            string originalAvailable = fullLengthLiningWorkDetailsGateway.GetAvailableOriginal(workId);
                            string originalHoistHeight = fullLengthLiningWorkDetailsGateway.GetHoistHeightOriginal(workId);
                            string originalCommentsCipp = fullLengthLiningWorkDetailsGateway.GetCommentsCippOriginal(workId);
                            string originalResinLabel = fullLengthLiningWorkDetailsGateway.GetResinsLabelOriginal(workId);
                            string originalDrumContainsLabel = fullLengthLiningWorkDetailsGateway.GetDrumContainsLabelOriginal(workId);
                            string originalLinerTubeLabel = fullLengthLiningWorkDetailsGateway.GetLinerTubeLabelOriginal(workId);
                            string originalForLbDrumsLabel = fullLengthLiningWorkDetailsGateway.GetForLbDrumsLabelOriginal(workId);
                            string originalNetResinLabel = fullLengthLiningWorkDetailsGateway.GetNetResinLabelOriginal(workId);
                            string originalCatalystLabel = fullLengthLiningWorkDetailsGateway.GetCatalystLabelOriginal(workId);

                            // Wet Out new data
                            string newLinerTube = fullLengthLiningWorkDetailsGateway.GetLinerTube(workId);
                            int newResinID = fullLengthLiningWorkDetailsGateway.GetResinId(workId);
                            decimal newExcessResin = fullLengthLiningWorkDetailsGateway.GetExcessResin(workId);
                            string newPoundsDrums = fullLengthLiningWorkDetailsGateway.GetPoundsDrums(workId);
                            decimal newDrumDiameter = fullLengthLiningWorkDetailsGateway.GetDrumDiameter(workId);
                            decimal newHoistMaximumHeight = fullLengthLiningWorkDetailsGateway.GetHoistMaximumHeight(workId);
                            decimal newHoistMinimumHeight = fullLengthLiningWorkDetailsGateway.GetHoistMinimumHeight(workId);
                            decimal newDownDropTubeLenght = fullLengthLiningWorkDetailsGateway.GetDownDropTubeLenght(workId);
                            decimal newPumpHeightAboveGround = fullLengthLiningWorkDetailsGateway.GetPumpHeightAboveGround(workId);
                            int newTubeResinToFeltFactor = fullLengthLiningWorkDetailsGateway.GetTubeResinToFeltFactor(workId);
                            DateTime newDateOfSheet = fullLengthLiningWorkDetailsGateway.GetDateOfSheet(workId);
                            int newEmployeeID = fullLengthLiningWorkDetailsGateway.GetEmployeeId(workId);
                            string newRunDetails = fullLengthLiningWorkDetailsGateway.GetRunDetails(workId);
                            string newRunDetails2 = fullLengthLiningWorkDetailsGateway.GetRunDetails2(workId);
                            DateTime newWetOutDate = fullLengthLiningWorkDetailsGateway.GetWetOutDate(workId);
                            DateTime? newWetOutInstallDate = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId);
                            string newThickness = fullLengthLiningWorkDetailsGateway.GetInversionThickness(workId);
                            decimal newLengthToLine = fullLengthLiningWorkDetailsGateway.GetLengthToLine(workId);
                            decimal newPlusExtra = fullLengthLiningWorkDetailsGateway.GetPlusExtra(workId);
                            decimal newForTurnOffset = fullLengthLiningWorkDetailsGateway.GetForTurnOffset(workId);
                            decimal newLengthToWetOut = fullLengthLiningWorkDetailsGateway.GetLengthToWetOut(workId);
                            decimal newTubeMaxColdHead = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHead(workId);
                            decimal newTubeMaxColdHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeMaxColdHeadPsi(workId);
                            decimal newTubeMaxHotHead = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHead(workId);
                            decimal newTubeMaxHotHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeMaxHotHeadPsi(workId);
                            decimal newTubeIdealHead = fullLengthLiningWorkDetailsGateway.GetTubeIdealHead(workId);
                            decimal newTubeIdealHeadPsi = fullLengthLiningWorkDetailsGateway.GetTubeIdealHeadPsi(workId);
                            decimal newNetResinForTube = fullLengthLiningWorkDetailsGateway.GetNetResinForTube(workId);
                            decimal newNetResinForTubeUsgals = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgals(workId);
                            string newNetResinForTubeDrumsIns = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeDrumsIns(workId);
                            decimal newNetResinForTubeLbsFt = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeLbsFt(workId);
                            decimal newNetResinForTubeUsgFt = fullLengthLiningWorkDetailsGateway.GetNetResinForTubeUsgFt(workId);
                            int newExtraResinForMix = fullLengthLiningWorkDetailsGateway.GetExtraResinForMix(workId);
                            decimal newExtraLbsForMix = fullLengthLiningWorkDetailsGateway.GetExtraLbsForMix(workId);
                            decimal newTotalMixQuantity = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantity(workId);
                            decimal newTotalMixQuantityUsgals = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityUsgals(workId);
                            string newTotalMixQuantityDrumsIns = fullLengthLiningWorkDetailsGateway.GetTotalMixQuantityDrumsIns(workId);
                            string newInversionType = fullLengthLiningWorkDetailsGateway.GetInversionType(workId);
                            decimal newDepthOfInversionMH = fullLengthLiningWorkDetailsGateway.GetDepthOfInversionMH(workId);
                            decimal newTubeForColumn = fullLengthLiningWorkDetailsGateway.GetTubeForColumn(workId);
                            decimal newTubeForStartDry = fullLengthLiningWorkDetailsGateway.GetTubeForStartDry(workId);
                            decimal newTotalTube = fullLengthLiningWorkDetailsGateway.GetTotalTube(workId);
                            string newDropTubeConnects = fullLengthLiningWorkDetailsGateway.GetDropTubeConnects(workId);
                            decimal newAllowsHeadTo = fullLengthLiningWorkDetailsGateway.GetAllowsHeadTo(workId);
                            decimal newRollerGap = fullLengthLiningWorkDetailsGateway.GetRollerGap(workId);
                            decimal newHeightNeeded = fullLengthLiningWorkDetailsGateway.GetHeightNeeded(workId);
                            string newAvailable = fullLengthLiningWorkDetailsGateway.GetAvailable(workId);
                            string newHoistHeight = fullLengthLiningWorkDetailsGateway.GetHoistHeight(workId);
                            string newCommentsCipp = fullLengthLiningWorkDetailsGateway.GetCommentsCipp(workId);
                            string newResinLabel = fullLengthLiningWorkDetailsGateway.GetResinsLabel(workId);
                            string newDrumContainsLabel = fullLengthLiningWorkDetailsGateway.GetDrumContainsLabel(workId);
                            string newLinerTubeLabel = fullLengthLiningWorkDetailsGateway.GetLinerTubeLabel(workId);
                            string newForLbDrumsLabel = fullLengthLiningWorkDetailsGateway.GetForLbDrumsLabel(workId);
                            string newNetResinLabel = fullLengthLiningWorkDetailsGateway.GetNetResinLabel(workId);
                            string newCatalystLabel = fullLengthLiningWorkDetailsGateway.GetCatalystLabel(workId);

                            string originalInversionComment = "";
                            string originalPipeType = "";
                            string originalPipeCondition = "";
                            string originalGroundMoisture = "";
                            decimal originalBoilerSize = 0m;
                            decimal originalPumpTotalCapacity = 0m;
                            decimal originalLayFlatSize = 0m;
                            decimal originalLayFlatQuantityTotal = 0m;
                            decimal originalWaterStartTemp = 0m;
                            decimal originalTemp1 =  0m;
                            decimal originalHoldAtT1 = 0m;
                            decimal originalTempT2 = 0m;
                            decimal originalCookAtT2 = 0m;
                            decimal originalCoolDownFor = 0m;
                            decimal originalCoolToTemp = 0m;
                            decimal originalDropInPipeRun = 0m;
                            decimal originalPipeSlopOf = 0m;
                            decimal originalF45F120 = 0m;
                            decimal originalHold = 0m;
                            decimal originalF120F185 = 0m;
                            decimal originalCookTime = 0m;
                            decimal originalCoolTime = 0m;
                            decimal originalAproxTotal = 0m;
                            decimal originalWaterChangesPerHour = 0m;
                            decimal originalReturnWaterVelocity = 0m;
                            decimal originalLayflatBackPressure = 0m;
                            decimal originalPumpLiftAtIdealHead = 0m;
                            decimal originalWaterToFillLinerColumn = 0m;
                            decimal originalWaterPerFit = 0m;
                            string originalInstallationResults = "";
                            string originalInversionLinerTubeLabel = "";
                            string originalHeadsIdealLabel = "";
                            string originalPumpingAndCirculationLabel = "";

                            // Inversion new Data
                            string newInversionComment = "";
                            string newPipeType = "";
                            string newPipeCondition = "";
                            string newGroundMoisture = "";
                            decimal newBoilerSize = 0m;
                            decimal newPumpTotalCapacity = 0m;
                            decimal newLayFlatSize = 0m;
                            decimal newLayFlatQuantityTotal = 0m;
                            decimal newWaterStartTemp = 0m;
                            decimal newTemp1 = 0m;
                            decimal newHoldAtT1 = 0m;
                            decimal newTempT2 = 0m;
                            decimal newCookAtT2 = 0m;
                            decimal newCoolDownFor = 0m;
                            decimal newCoolToTemp = 0m;
                            decimal newDropInPipeRun = 0m;
                            decimal newPipeSlopOf = 0m;
                            decimal newF45F120 = 0m;
                            decimal newHold = 0m;
                            decimal newF120F185 = 0m;
                            decimal newCookTime = 0m;
                            decimal newCoolTime = 0m;
                            decimal newAproxTotal = 0m;
                            decimal newWaterChangesPerHour = 0m;
                            decimal newReturnWaterVelocity = 0m;
                            decimal newLayflatBackPressure = 0m;
                            decimal newPumpLiftAtIdealHead = 0m;
                            decimal newWaterToFillLinerColumn = 0m;
                            decimal newWaterPerFit = 0m;
                            string newInstallationResults = "";
                            string newInversionLinerTubeLabel = "";
                            string newHeadsIdealLabel = "";
                            string newPumpingAndCirculationLabel = "";

                            if (includeInversionInformation)
                            {
                                // InversionData original values
                                originalInversionComment = fullLengthLiningWorkDetailsGateway.GetInversionCommentOriginal(workId);
                                originalPipeType = fullLengthLiningWorkDetailsGateway.GetPipeTypeOriginal(workId);
                                originalPipeCondition = fullLengthLiningWorkDetailsGateway.GetPipeConditionOriginal(workId);
                                originalGroundMoisture = fullLengthLiningWorkDetailsGateway.GetGroundMoistureOriginal(workId);
                                originalBoilerSize = fullLengthLiningWorkDetailsGateway.GetBoilerSizeOriginal(workId);
                                originalPumpTotalCapacity = fullLengthLiningWorkDetailsGateway.GetPumpTotalCapacityOriginal(workId);
                                originalLayFlatSize = fullLengthLiningWorkDetailsGateway.GetLayFlatSizeOriginal(workId);
                                originalLayFlatQuantityTotal = fullLengthLiningWorkDetailsGateway.GetLayFlatQuantityTotalOriginal(workId);
                                originalWaterStartTemp = fullLengthLiningWorkDetailsGateway.GetWaterStartTempOriginal(workId);
                                originalTemp1 = fullLengthLiningWorkDetailsGateway.GetTemp1Original(workId);
                                originalHoldAtT1 = fullLengthLiningWorkDetailsGateway.GetHoldAtT1Original(workId);
                                originalTempT2 = fullLengthLiningWorkDetailsGateway.GetTempT2Original(workId);
                                originalCookAtT2 = fullLengthLiningWorkDetailsGateway.GetCookAtT2Original(workId);
                                originalCoolDownFor = fullLengthLiningWorkDetailsGateway.GetCoolDownForOriginal(workId);
                                originalCoolToTemp = fullLengthLiningWorkDetailsGateway.GetCoolToTempOriginal(workId);
                                originalDropInPipeRun = fullLengthLiningWorkDetailsGateway.GetDropInPipeRunOriginal(workId);
                                originalPipeSlopOf = fullLengthLiningWorkDetailsGateway.GetPipeSlopOfOriginal(workId);
                                originalF45F120 = fullLengthLiningWorkDetailsGateway.GetF45F120Original(workId);
                                originalHold = fullLengthLiningWorkDetailsGateway.GetHoldOriginal(workId);
                                originalF120F185 = fullLengthLiningWorkDetailsGateway.GetF120F185Original(workId);
                                originalCookTime = fullLengthLiningWorkDetailsGateway.GetCookTimeOriginal(workId);
                                originalCoolTime = fullLengthLiningWorkDetailsGateway.GetCoolTimeOriginal(workId);
                                originalAproxTotal = fullLengthLiningWorkDetailsGateway.GetAproxTotalOriginal(workId);
                                originalWaterChangesPerHour = fullLengthLiningWorkDetailsGateway.GetWaterChangesPerHourOriginal(workId);
                                originalReturnWaterVelocity = fullLengthLiningWorkDetailsGateway.GetReturnWaterVelocityOriginal(workId);
                                originalLayflatBackPressure = fullLengthLiningWorkDetailsGateway.GetLayflatBackPressureOriginal(workId);
                                originalPumpLiftAtIdealHead = fullLengthLiningWorkDetailsGateway.GetPumpLiftAtIdealHeadOriginal(workId);
                                originalWaterToFillLinerColumn = fullLengthLiningWorkDetailsGateway.GetWaterToFillLinerColumnOriginal(workId);
                                originalWaterPerFit = fullLengthLiningWorkDetailsGateway.GetWaterPerFitOriginal(workId);
                                originalInstallationResults = fullLengthLiningWorkDetailsGateway.GetInstallationResultsOriginal(workId);
                                originalInversionLinerTubeLabel = fullLengthLiningWorkDetailsGateway.GetInversionLinerTubeLabelOriginal(workId);
                                originalHeadsIdealLabel = fullLengthLiningWorkDetailsGateway.GetHeadsIdealLabelOriginal(workId);
                                originalPumpingAndCirculationLabel = fullLengthLiningWorkDetailsGateway.GetPumpingAndCirculationLabelOriginal(workId);

                                // Inversion new Data
                                newInversionComment = fullLengthLiningWorkDetailsGateway.GetInversionComment(workId);
                                newPipeType = fullLengthLiningWorkDetailsGateway.GetPipeType(workId);
                                newPipeCondition = fullLengthLiningWorkDetailsGateway.GetPipeCondition(workId);
                                newGroundMoisture = fullLengthLiningWorkDetailsGateway.GetGroundMoisture(workId);
                                newBoilerSize = fullLengthLiningWorkDetailsGateway.GetBoilerSize(workId);
                                newPumpTotalCapacity = fullLengthLiningWorkDetailsGateway.GetPumpTotalCapacity(workId);
                                newLayFlatSize = fullLengthLiningWorkDetailsGateway.GetLayFlatSize(workId);
                                newLayFlatQuantityTotal = fullLengthLiningWorkDetailsGateway.GetLayFlatQuantityTotal(workId);
                                newWaterStartTemp = fullLengthLiningWorkDetailsGateway.GetWaterStartTemp(workId);
                                newTemp1 = fullLengthLiningWorkDetailsGateway.GetTemp1(workId);
                                newHoldAtT1 = fullLengthLiningWorkDetailsGateway.GetHoldAtT1(workId);
                                newTempT2 = fullLengthLiningWorkDetailsGateway.GetTempT2(workId);
                                newCookAtT2 = fullLengthLiningWorkDetailsGateway.GetCookAtT2(workId);
                                newCoolDownFor = fullLengthLiningWorkDetailsGateway.GetCoolDownFor(workId);
                                newCoolToTemp = fullLengthLiningWorkDetailsGateway.GetCoolToTemp(workId);
                                newDropInPipeRun = fullLengthLiningWorkDetailsGateway.GetDropInPipeRun(workId);
                                newPipeSlopOf = fullLengthLiningWorkDetailsGateway.GetPipeSlopOf(workId);
                                newF45F120 = fullLengthLiningWorkDetailsGateway.GetF45F120(workId);
                                newHold = fullLengthLiningWorkDetailsGateway.GetHold(workId);
                                newF120F185 = fullLengthLiningWorkDetailsGateway.GetF120F185(workId);
                                newCookTime = fullLengthLiningWorkDetailsGateway.GetCookTime(workId);
                                newCoolTime = fullLengthLiningWorkDetailsGateway.GetCoolTime(workId);
                                newAproxTotal = fullLengthLiningWorkDetailsGateway.GetAproxTotal(workId);
                                newWaterChangesPerHour = fullLengthLiningWorkDetailsGateway.GetWaterChangesPerHour(workId);
                                newReturnWaterVelocity = fullLengthLiningWorkDetailsGateway.GetReturnWaterVelocity(workId);
                                newLayflatBackPressure = fullLengthLiningWorkDetailsGateway.GetLayflatBackPressure(workId);
                                newPumpLiftAtIdealHead = fullLengthLiningWorkDetailsGateway.GetPumpLiftAtIdealHead(workId);
                                newWaterToFillLinerColumn = fullLengthLiningWorkDetailsGateway.GetWaterToFillLinerColumn(workId);
                                newWaterPerFit = fullLengthLiningWorkDetailsGateway.GetWaterPerFit(workId);
                                newInstallationResults = fullLengthLiningWorkDetailsGateway.GetInstallationResults(workId);
                                newInversionLinerTubeLabel = fullLengthLiningWorkDetailsGateway.GetInversionLinerTubeLabel(workId);
                                newHeadsIdealLabel = fullLengthLiningWorkDetailsGateway.GetHeadsIdealLabel(workId);
                                newPumpingAndCirculationLabel = fullLengthLiningWorkDetailsGateway.GetPumpingAndCirculationLabel(workId);
                            }

                            // Get All sectionIds for insert
                            string runDetails = row.RunDetails;
                            string[] runDetailsList = runDetails.Split('>');

                            for (int i = 0; i < runDetailsList.Length; i++)
                            {
                                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                                string sectionId = runDetailsList[i].ToString();
                                assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                                int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                                WorkGateway workGateway = new WorkGateway();
                                int newWorkId = 0;
                                workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                                if (workGateway.Table.Rows.Count > 0)
                                {
                                    newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                                }

                                WorkFullLengthLiningWetOutGateway workFullLengthLiningWetOutGatewayForReview = new WorkFullLengthLiningWetOutGateway();
                                workFullLengthLiningWetOutGatewayForReview.LoadByWorkId(newWorkId, companyId);
                                if (workFullLengthLiningWetOutGatewayForReview.Table.Rows.Count > 0)
                                {
                                    // Update work with cipp information
                                    UpdateWorkWetOutInformation(newWorkId, originalLinerTube, originalResinID, originalExcessResin, originalPoundsDrums, originalDrumDiameter, originalHoistMaximumHeight, originalHoistMinimumHeight, originalDownDropTubeLenght, originalPumpHeightAboveGround, originalTubeResinToFeltFactor, originalDateOfSheet, originalEmployeeID, originalRunDetails, originalRunDetails2, originalWetOutDate, originalWetOutInstallDate, originalThickness, originalLengthToLine, originalPlusExtra, originalForTurnOffset, originalLengthToWetOut, originalTubeMaxColdHead, originalTubeMaxColdHeadPsi, originalTubeMaxHotHead, originalTubeMaxHotHeadPsi, originalTubeIdealHead, originalTubeIdealHeadPsi, originalNetResinForTube, originalNetResinForTubeUsgals, originalNetResinForTubeDrumsIns, originalNetResinForTubeLbsFt, originalNetResinForTubeUsgFt, originalExtraResinForMix, originalExtraLbsForMix, originalTotalMixQuantity, originalTotalMixQuantityUsgals, originalTotalMixQuantityDrumsIns, originalInversionType, originalDepthOfInversionMH, originalTubeForColumn, originalTubeForStartDry, originalTotalTube, originalDropTubeConnects, originalAllowsHeadTo, originalRollerGap, originalHeightNeeded, originalAvailable, originalHoistHeight, originalCommentsCipp, originalResinLabel, originalDrumContainsLabel, originalLinerTubeLabel, originalForLbDrumsLabel, originalNetResinLabel, originalCatalystLabel, originalInversionComment, originalPipeType, originalPipeCondition, originalGroundMoisture, originalBoilerSize, originalPumpTotalCapacity, originalLayFlatSize, originalLayFlatQuantityTotal, originalWaterStartTemp, originalTemp1, originalHoldAtT1, originalTempT2, originalCookAtT2, originalCoolDownFor, originalCoolToTemp, originalDropInPipeRun, originalPipeSlopOf, originalF45F120, originalHold, originalF120F185, originalCookTime, originalCoolTime, originalAproxTotal, originalWaterChangesPerHour, originalReturnWaterVelocity, originalLayflatBackPressure, originalPumpLiftAtIdealHead, originalWaterToFillLinerColumn, originalWaterPerFit, originalInstallationResults, originalInversionLinerTubeLabel, originalHeadsIdealLabel, originalPumpingAndCirculationLabel, false, companyId, newLinerTube, newResinID, newExcessResin, newPoundsDrums, newDrumDiameter, newHoistMaximumHeight, newHoistMinimumHeight, newDownDropTubeLenght, newPumpHeightAboveGround, newTubeResinToFeltFactor, newDateOfSheet, newEmployeeID, newRunDetails, newRunDetails2, newWetOutDate, newWetOutInstallDate, newThickness, newLengthToLine, newPlusExtra, newForTurnOffset, newLengthToWetOut, newTubeMaxColdHead, newTubeMaxColdHeadPsi, newTubeMaxHotHead, newTubeMaxHotHeadPsi, newTubeIdealHead, newTubeIdealHeadPsi, newNetResinForTube, newNetResinForTubeUsgals, newNetResinForTubeDrumsIns, newNetResinForTubeLbsFt, newNetResinForTubeUsgFt, newExtraResinForMix, newExtraLbsForMix, newTotalMixQuantity, newTotalMixQuantityUsgals, newTotalMixQuantityDrumsIns, newInversionType, newDepthOfInversionMH, newTubeForColumn, newTubeForStartDry, newTotalTube, newDropTubeConnects, newAllowsHeadTo, newRollerGap, newHeightNeeded, newAvailable, newHoistHeight, newCommentsCipp, newResinLabel, newDrumContainsLabel, newLinerTubeLabel, newForLbDrumsLabel, newNetResinLabel, newCatalystLabel, newInversionComment, newPipeType, newPipeCondition, newGroundMoisture, newBoilerSize, newPumpTotalCapacity, newLayFlatSize, newLayFlatQuantityTotal, newWaterStartTemp, newTemp1, newHoldAtT1, newTempT2, newCookAtT2, newCoolDownFor, newCoolToTemp, newDropInPipeRun, newPipeSlopOf, newF45F120, newHold, newF120F185, newCookTime, newCoolTime, newAproxTotal, newWaterChangesPerHour, newReturnWaterVelocity, newLayflatBackPressure, newPumpLiftAtIdealHead, newWaterToFillLinerColumn, newWaterPerFit, newInstallationResults, newInversionLinerTubeLabel, newHeadsIdealLabel, newPumpingAndCirculationLabel, false, companyId, includeWetOutInformation, includeInversionInformation);
                                }
                                else
                                {
                                    // ... Insert wet out data
                                    string inversionComment = fullLengthLiningWorkDetailsGateway.GetInversionComment(workId);
                                    string installationResults = fullLengthLiningWorkDetailsGateway.GetInstallationResults(workId);
                                    DateTime? wetOutInstallDate = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId);

                                    InsertWorkWetOutInformation(newWorkId, row.LinerTube, row.ResinID, row.ExcessResin, row.PoundsDrums, row.DrumDiameter, row.HoistMaximumHeight, row.HoistMinimumHeight, row.DownDropTubeLenght, row.PumpHeightAboveGround, row.TubeResinToFeltFactor, row.DateOfSheet, row.EmployeeID, row.RunDetails, row.RunDetails2, row.WetOutDate, wetOutInstallDate, row.Thickness, row.LengthToLine, row.PlusExtra, row.ForTurnOffset, row.LengthToWetOut, row.TubeMaxColdHead, row.TubeMaxColdHeadPsi, row.TubeMaxHotHead, row.TubeMaxHotHeadPsi, row.TubeIdealHead, row.TubeIdealHeadPsi, row.NetResinForTube, row.NetResinForTubeUsgals, row.NetResinForTubeDrumsIns, row.NetResinForTubeLbsFt, row.NetResinForTubeUsgFt, row.ExtraResinForMix, row.ExtraLbsForMix, row.TotalMixQuantity, row.TotalMixQuantityUsgals, row.TotalMixQuantityDrumsIns, row.InversionType, row.DepthOfInversionMH, row.TubeForColumn, row.TubeForStartDry, row.TotalTube, row.DropTubeConnects, row.AllowsHeadTo, row.RollerGap, row.HeightNeeded, row.Available, row.HoistHeight, row.CommentsCipp, row.ResinsLabel, row.DrumContainsLabel, row.LinerTubeLabel, row.ForLbDrumsLabel, row.NetResinLabel, row.CatalystLabel, inversionComment, row.PipeType, row.PipeCondition, row.GroundMoisture, row.BoilerSize, row.PumpTotalCapacity, row.LayFlatSize, row.LayFlatQuantityTotal, row.WaterStartTemp, row.Temp1, row.HoldAtT1, row.TempT2, row.CookAtT2, row.CoolDownFor, row.CoolToTemp, row.DropInPipeRun, row.PipeSlopOf, row.F45F120, row.Hold, row.F120F185, row.CookTime, row.CoolTime, row.AproxTotal, row.WaterChangesPerHour, row.ReturnWaterVelocity, row.LayflatBackPressure, row.PumpLiftAtIdealHead, row.WaterToFillLinerColumn, row.WaterPerFit, installationResults, row.InversionLinerTubeLabel, row.HeadsIdealLabel, row.PumpingAndCirculationLabel, row.Deleted, row.COMPANY_ID, includeWetOutInformation, includeInversionInformation);
                                }
                            }
                        }
                        else
                        {
                            // Get All sectionIds for insert
                            string runDetails = row.RunDetails;
                            string[] runDetailsList = runDetails.Split('>');

                            for (int i = 0; i < runDetailsList.Length; i++)
                            {
                                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                                string sectionId = runDetailsList[i].ToString();
                                assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                                int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                                WorkGateway workGateway = new WorkGateway();
                                workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                                if (workGateway.Table.Rows.Count > 0)
                                {
                                    int newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);

                                    // ... Insert wet out data
                                    string inversionComment = fullLengthLiningWorkDetailsGateway.GetInversionComment(workId);
                                    string installationResults = fullLengthLiningWorkDetailsGateway.GetInstallationResults(workId);
                                    DateTime? wetOutInstallDate = fullLengthLiningWorkDetailsGateway.GetWetOutInstallDate(workId);

                                    InsertWorkWetOutInformation(newWorkId, row.LinerTube, row.ResinID, row.ExcessResin, row.PoundsDrums, row.DrumDiameter, row.HoistMaximumHeight, row.HoistMinimumHeight, row.DownDropTubeLenght, row.PumpHeightAboveGround, row.TubeResinToFeltFactor, row.DateOfSheet, row.EmployeeID, row.RunDetails, row.RunDetails2, row.WetOutDate, wetOutInstallDate, row.Thickness, row.LengthToLine, row.PlusExtra, row.ForTurnOffset, row.LengthToWetOut, row.TubeMaxColdHead, row.TubeMaxColdHeadPsi, row.TubeMaxHotHead, row.TubeMaxHotHeadPsi, row.TubeIdealHead, row.TubeIdealHeadPsi, row.NetResinForTube, row.NetResinForTubeUsgals, row.NetResinForTubeDrumsIns, row.NetResinForTubeLbsFt, row.NetResinForTubeUsgFt, row.ExtraResinForMix, row.ExtraLbsForMix, row.TotalMixQuantity, row.TotalMixQuantityUsgals, row.TotalMixQuantityDrumsIns, row.InversionType, row.DepthOfInversionMH, row.TubeForColumn, row.TubeForStartDry, row.TotalTube, row.DropTubeConnects, row.AllowsHeadTo, row.RollerGap, row.HeightNeeded, row.Available, row.HoistHeight, row.CommentsCipp, row.ResinsLabel, row.DrumContainsLabel, row.LinerTubeLabel, row.ForLbDrumsLabel, row.NetResinLabel, row.CatalystLabel, inversionComment, row.PipeType, row.PipeCondition, row.GroundMoisture, row.BoilerSize, row.PumpTotalCapacity, row.LayFlatSize, row.LayFlatQuantityTotal, row.WaterStartTemp, row.Temp1, row.HoldAtT1, row.TempT2, row.CookAtT2, row.CoolDownFor, row.CoolToTemp, row.DropInPipeRun, row.PipeSlopOf, row.F45F120, row.Hold, row.F120F185, row.CookTime, row.CoolTime, row.AproxTotal, row.WaterChangesPerHour, row.ReturnWaterVelocity, row.LayflatBackPressure, row.PumpLiftAtIdealHead, row.WaterToFillLinerColumn, row.WaterPerFit, installationResults, row.InversionLinerTubeLabel, row.HeadsIdealLabel, row.PumpingAndCirculationLabel, row.Deleted, row.COMPANY_ID, includeWetOutInformation, includeInversionInformation);
                                }
                            }
                        }
                    }

                    // Update 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);
                    }
                }
            }
        }
        /// <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 int GetWorkId(int projectId, int assetId, string workType, int companyId)
        {
            int workId = 0;
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);
            if (workGateway.Table.Rows.Count > 0)
            {
                // Get WorkId
                workId = workGateway.GetWorkId(assetId, workType, projectId);
            }

            return workId;
        }
        /// <summary>
        /// Save all field cure record to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>        
        /// <param name="runDetails">runDetails</param>
        /// <param name="projectId">projectId</param>
        public void Save(int companyId, string runDetails, int projectId)
        {
            string[] runDetailsList = runDetails.Split('>');

            FlInversionFieldCureRecordTDS flInversionFieldCureRecordChanges = (FlInversionFieldCureRecordTDS)Data.GetChanges();

            if (flInversionFieldCureRecordChanges.InversionFieldCureRecord.Rows.Count > 0)
            {
                FlInversionFieldCureRecordGateway flInversionFieldCureRecordGateway = new FlInversionFieldCureRecordGateway(flInversionFieldCureRecordChanges);

                foreach (FlInversionFieldCureRecordTDS.InversionFieldCureRecordRow row in (FlInversionFieldCureRecordTDS.InversionFieldCureRecordDataTable)flInversionFieldCureRecordChanges.InversionFieldCureRecord)
                {
                    // Insert new field cure records
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        DateTime readingTime = row.ReadingTime;
                        decimal? headFt = null; if (!row.IsHeadFtNull()) headFt = row.HeadFt;
                        decimal? boilerInF = null; if (!row.IsBoilerInFNull()) boilerInF = row.BoilerInF;
                        decimal? boilerOutF = null; if (!row.IsBoilerOutFNull()) boilerOutF = row.BoilerOutF;
                        decimal? pumpFlow = null; if (!row.IsPumpFlowNull()) pumpFlow = row.PumpFlow;
                        decimal? pumpPsi = null; if (!row.IsPumpPsiNull()) pumpPsi = row.PumpPsi;
                        decimal? mh1Top = null; if (!row.IsMH1TopNull()) mh1Top = row.MH1Top;
                        decimal? mh1Bot = null; if (!row.IsMH1BotNull()) mh1Bot = row.MH1Bot;
                        decimal? mh2Top = null; if (!row.IsMH2TopNull()) mh2Top = row.MH2Top;
                        decimal? mh2Bot = null; if (!row.IsMH2BotNull()) mh2Bot = row.MH2Bot;
                        decimal? mh3Top = null; if (!row.IsMH3TopNull()) mh3Top = row.MH3Top;
                        decimal? mh3Bot = null; if (!row.IsMH3BotNull()) mh3Bot = row.MH3Bot;
                        decimal? mh4Top = null; if (!row.IsMH4TopNull()) mh4Top = row.MH4Top;
                        decimal? mh4Bot = null; if (!row.IsMH4BotNull()) mh4Bot = row.MH4Bot;
                        string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;

                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            WorkFullLengthLiningInversionFieldCureRecord workFullLengthLiningInversionFieldCureRecord = new WorkFullLengthLiningInversionFieldCureRecord(null);
                            workFullLengthLiningInversionFieldCureRecord.InsertDirect(newWorkId, row.RefID, readingTime, headFt, boilerInF, boilerOutF, pumpFlow, pumpPsi, mh1Top, mh1Bot, mh2Top, mh2Bot, mh3Top, mh3Bot, mh4Top, mh4Bot, comments, row.Deleted, row.COMPANY_ID);
                        }
                    }

                    // Update field cure records
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        bool originalDeleted = false;
                        int originalCompanyId = companyId;

                        // original values
                        DateTime originalReadingTime= flInversionFieldCureRecordGateway.GetReadingTimeOriginal(workId, refId);
                        decimal? originalHeadFt = flInversionFieldCureRecordGateway.GetHeadFtOriginal(workId, refId);
                        decimal? originalBoilerInF = flInversionFieldCureRecordGateway.GetBoilerInFOriginal(workId, refId);
                        decimal? originalBoilerOutF = flInversionFieldCureRecordGateway.GetBoilerOutFOriginal(workId, refId);
                        decimal? originalPumpFlow = flInversionFieldCureRecordGateway.GetPumpFlowOriginal(workId, refId);
                        decimal? originalPumpPsi = flInversionFieldCureRecordGateway.GetPumpPsiOriginal(workId, refId);
                        decimal? originalMH1Top = flInversionFieldCureRecordGateway.GetMH1TopOriginal(workId, refId);
                        decimal? originalMH1Bot = flInversionFieldCureRecordGateway.GetMH1BotOriginal(workId, refId);
                        decimal? originalMH2Top = flInversionFieldCureRecordGateway.GetMH2TopOriginal(workId, refId);
                        decimal? originalMH2Bot = flInversionFieldCureRecordGateway.GetMH2BotOriginal(workId, refId);
                        decimal? originalMH3Top = flInversionFieldCureRecordGateway.GetMH3TopOriginal(workId, refId);
                        decimal? originalMH3Bot = flInversionFieldCureRecordGateway.GetMH3BotOriginal(workId, refId);
                        decimal? originalMH4Top = flInversionFieldCureRecordGateway.GetMH4TopOriginal(workId, refId);
                        decimal? originalMH4Bot = flInversionFieldCureRecordGateway.GetMH4BotOriginal(workId, refId);
                        string originalComments = flInversionFieldCureRecordGateway .GetCommentsOriginal(workId, refId);

                        // new values
                        DateTime newReadingTime = flInversionFieldCureRecordGateway.GetReadingTime(workId, refId);
                        decimal? newHeadFt = flInversionFieldCureRecordGateway.GetHeadFt(workId, refId);
                        decimal? newBoilerInF = flInversionFieldCureRecordGateway.GetBoilerInF(workId, refId);
                        decimal? newBoilerOutF = flInversionFieldCureRecordGateway.GetBoilerOutF(workId, refId);
                        decimal? newPumpFlow = flInversionFieldCureRecordGateway.GetPumpFlow(workId, refId);
                        decimal? newPumpPsi = flInversionFieldCureRecordGateway.GetPumpPsi(workId, refId);
                        decimal? newMH1Top = flInversionFieldCureRecordGateway.GetMH1Top(workId, refId);
                        decimal? newMH1Bot = flInversionFieldCureRecordGateway.GetMH1Bot(workId, refId);
                        decimal? newMH2Top = flInversionFieldCureRecordGateway.GetMH2Top(workId, refId);
                        decimal? newMH2Bot = flInversionFieldCureRecordGateway.GetMH2Bot(workId, refId);
                        decimal? newMH3Top = flInversionFieldCureRecordGateway.GetMH3Top(workId, refId);
                        decimal? newMH3Bot = flInversionFieldCureRecordGateway.GetMH3Bot(workId, refId);
                        decimal? newMH4Top = flInversionFieldCureRecordGateway.GetMH4Top(workId, refId);
                        decimal? newMH4Bot = flInversionFieldCureRecordGateway.GetMH4Bot(workId, refId);
                        string newComments = flInversionFieldCureRecordGateway .GetComments(workId, refId);

                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            FlInversionFieldCureRecordGateway flInversionFieldCureRecordGatewayForReview = new FlInversionFieldCureRecordGateway();
                            flInversionFieldCureRecordGatewayForReview.LoadByWorkId(newWorkId, companyId);
                            if (flInversionFieldCureRecordGatewayForReview.Table.Rows.Count > 0)
                            {
                                WorkFullLengthLiningInversionFieldCureRecord workFullLengthLiningInversionFieldCureRecord = new WorkFullLengthLiningInversionFieldCureRecord(null);
                                workFullLengthLiningInversionFieldCureRecord.UpdateDirect(newWorkId, refId, originalReadingTime, originalHeadFt, originalBoilerInF, originalBoilerOutF, originalPumpFlow, originalPumpPsi, originalMH1Top, originalMH1Bot, originalMH2Top, originalMH2Bot, originalMH3Top, originalMH3Bot, originalMH4Top, originalMH4Bot, originalComments, originalDeleted, originalCompanyId, workId, refId, newReadingTime, newHeadFt, newBoilerInF, newBoilerOutF, newPumpFlow, newPumpPsi, newMH1Top, newMH1Bot, newMH2Top, newMH2Bot, newMH3Top, newMH3Bot, newMH4Top, newMH4Bot, originalComments, originalDeleted, originalCompanyId);
                            }
                            else
                            {
                                DateTime readingTime = row.ReadingTime;
                                decimal? headFt = null; if (!row.IsHeadFtNull()) headFt = row.HeadFt;
                                decimal? boilerInF = null; if (!row.IsBoilerInFNull()) boilerInF = row.BoilerInF;
                                decimal? boilerOutF = null; if (!row.IsBoilerOutFNull()) boilerOutF = row.BoilerOutF;
                                decimal? pumpFlow = null; if (!row.IsPumpFlowNull()) pumpFlow = row.PumpFlow;
                                decimal? pumpPsi = null; if (!row.IsPumpPsiNull()) pumpPsi = row.PumpPsi;
                                decimal? mh1Top = null; if (!row.IsMH1TopNull()) mh1Top = row.MH1Top;
                                decimal? mh1Bot = null; if (!row.IsMH1BotNull()) mh1Bot = row.MH1Bot;
                                decimal? mh2Top = null; if (!row.IsMH2TopNull()) mh2Top = row.MH2Top;
                                decimal? mh2Bot = null; if (!row.IsMH2BotNull()) mh2Bot = row.MH2Bot;
                                decimal? mh3Top = null; if (!row.IsMH3TopNull()) mh3Top = row.MH3Top;
                                decimal? mh3Bot = null; if (!row.IsMH3BotNull()) mh3Bot = row.MH3Bot;
                                decimal? mh4Top = null; if (!row.IsMH4TopNull()) mh4Top = row.MH4Top;
                                decimal? mh4Bot = null; if (!row.IsMH4BotNull()) mh4Bot = row.MH4Bot;
                                string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;

                                WorkFullLengthLiningInversionFieldCureRecord workFullLengthLiningInversionFieldCureRecord = new WorkFullLengthLiningInversionFieldCureRecord(null);
                                workFullLengthLiningInversionFieldCureRecord.InsertDirect(newWorkId, row.RefID, readingTime, headFt, boilerInF, boilerOutF, pumpFlow, pumpPsi, mh1Top, mh1Bot, mh2Top, mh2Bot, mh3Top, mh3Bot, mh4Top, mh4Bot, comments, row.Deleted, row.COMPANY_ID);
                            }
                        }
                    }

                    // Deleted field cure records
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        for (int i = 0; i < runDetailsList.Length; i++)
                        {
                            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                            string sectionId = runDetailsList[i].ToString();
                            assetSewerSectionGateway.LoadBySectionId(sectionId, companyId);
                            int assetId = assetSewerSectionGateway.GetAssetID(sectionId);

                            WorkGateway workGateway = new WorkGateway();
                            int newWorkId = 0;
                            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId);
                            if (workGateway.Table.Rows.Count > 0)
                            {
                                newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId);
                            }

                            WorkFullLengthLiningInversionFieldCureRecord workFullLengthLiningInversionFieldCureRecord = new WorkFullLengthLiningInversionFieldCureRecord(null);
                            workFullLengthLiningInversionFieldCureRecord.DeleteDirect(newWorkId, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }