// ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void Delete(int workId, int companyId)
        {
            WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
            workFullLengthLiningM1LateralGateway.LoadByWorkId(workId, companyId);

            foreach (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALRow row in (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALDataTable)workFullLengthLiningM1LateralGateway.Table)
            {
                // delete lfs lateral client
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(workId, companyId);
                int currentProjectId = workGateway.GetProjectId(workId);

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

                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(row.Lateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(row.Lateral, clientId, companyId);
                }

                // Delete work lateral
                workFullLengthLiningM1LateralGateway.Delete(workId, row.Lateral, companyId);

                // Delete section
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
                lfsAssetSewerLateral.DeleteDirect(row.Lateral, companyId);
            }
        }
Пример #2
0
        /// <summary>
        /// Save a JL Work
        /// </summary>
        /// <param name="originalId">originalId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</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="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        private void SaveJLWork(Guid originalId, int section_assetId, int numLats, int notLinedYet, bool allMeasured, string issueWithLaterals, int notMeasuredYet, int notDeliveredYet, int projectId, Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId)
        {
            // Insert Junction Lining Section
            WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
            int sectionWorkId = workJunctionLiningSection.InsertDirect(projectId, section_assetId, null, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, false, companyId, "", "", "", "", false, "", 0);

            // Insert Junction Lining Laterals
            SectionTDS sectionTDS = new SectionTDS();

            SectionGateway sectionGateway = new SectionGateway(sectionTDS);
            sectionGateway.LoadById(originalId, companyId);

            JlinerGateway jlinerGateway = new JlinerGateway(sectionTDS);
            jlinerGateway.LoadByIdCompanyId(originalId, companyId);

            foreach (SectionTDS.LFS_JUNCTION_LINER2Row row in (SectionTDS.LFS_JUNCTION_LINER2DataTable)jlinerGateway.Table)
            {
                string lateralID = ""; if (!row.IsDetailIDNull()) lateralID = row.DetailID;
                string address = ""; if (!row.IsAddressNull()) address = row.Address;
                string distanceFromUSMH = ""; if (!row.IsDistanceFromUSMHNull()) distanceFromUSMH = row.DistanceFromUSMH.ToString();
                string distanceFromDSMH = ""; if (!row.IsDistanceFromDSMHNull()) distanceFromDSMH = row.DistanceFromDSMH.ToString();
                DateTime? pipeLocated = null; if (!row.IsPipeLocatedNull()) pipeLocated = row.PipeLocated;
                DateTime? servicesLocated = null; if (!row.IsServicesLocatedNull()) servicesLocated = row.ServicesLocated;
                DateTime? coInstalled = null; if (!row.IsCoInstalledNull()) coInstalled = row.CoInstalled;
                DateTime? backfilledConcrete = null; if (!row.IsBackfilledConcreteNull()) backfilledConcrete = row.BackfilledConcrete;
                DateTime? backfilledSoil = null; if (!row.IsBackfilledSoilNull()) backfilledSoil = row.BackfilledSoil;
                DateTime? grouted = null; if (!row.IsGroutedNull()) grouted = row.Grouted;
                DateTime? cored = null; if (!row.IsCoredNull()) cored = row.Cored;
                DateTime? prepped = null; if (!row.IsPreppedNull()) prepped = row.Prepped;
                DateTime? measured = null; if (!row.IsMeasuredNull()) measured = row.Measured;
                string linerSize = ""; if (!row.IsLinerSizeNull()) linerSize = row.LinerSize;
                DateTime? inProcess = null; if (!row.IsInProcessNull()) inProcess = row.InProcess;
                DateTime? inStock = null; if (!row.IsInStockNull()) inStock = row.InStock;
                DateTime? delivered = null; if (!row.IsDeliveredNull()) delivered = row.Delivered;
                int? buildRebuid = null; if (!row.IsBuildRebuildNull()) buildRebuid = row.BuildRebuild;
                DateTime? preVideo = null; if (!row.IsPreVideoNull()) preVideo = row.PreVideo;
                DateTime? linerInstalled = null; if (!row.IsLinerInstalledNull()) linerInstalled = row.LinerInstalled;
                DateTime? finalVideo = null; if (!row.IsFinalVideoNull()) finalVideo = row.FinalVideo;
                string map = ""; if (!row.IsMapNull()) map = row.Map;
                decimal? cost = null; if (!row.IsCostNull()) cost = row.Cost;
                DateTime? videoInspection = null; if (!row.IsVideoInspectionNull()) videoInspection = row.VideoInspection;
                bool coRequired = row.CoRequired;
                bool pitRequired = row.PitRequired;
                string coPitLocation = ""; if (!row.IsCoPitLocationNull()) coPitLocation = row.CoPitLocation;
                bool postContractDigRequired = row.PostContractDigRequired;
                string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;
                string history = ""; if (!row.IsHistoryNull()) history = row.History;
                DateTime? coCutDown = null; if (!row.IsCoCutDownNull()) coCutDown = row.CoCutDown;
                DateTime? finalRestoration = null; if (!row.IsFinalRestorationNull()) finalRestoration = row.FinalRestoration;
                string clientLateralId = ""; if (!row.IsClientLateralIDNull()) clientLateralId = row.ClientLateralID;
                string videoLengthToPropertyLine = ""; if (!row.IsVideoLengthToPropertyLineNull()) videoLengthToPropertyLine = row.VideoLengthToPropertyLine;
                bool liningThruCo = row.LiningThruCo;
                DateTime? noticeDelivered = null; if (!row.IsNoticeDeliveredNull()) noticeDelivered = row.NoticeDelivered;
                string hamiltonInspectionNumber = ""; if (!row.IsHamiltonInspectionNumberNull()) hamiltonInspectionNumber = row.HamiltonInspectionNumber;
                bool dyeTestReq = row.DyeTestReq;
                DateTime? dyeTestComplete = null; if (!row.IsDyeTestCompleteNull()) dyeTestComplete = row.DyeTestComplete;

                // Fields only presents in new Junction lining
                string flange = "";
                string gasket = "";
                string connectionType = "";
                string depthOfLocated = "";
                bool digRequiredPriorToLining = false;
                DateTime? digRequiredPriorToLiningCompleted = null;
                bool digRequiredAfterLining = false;
                DateTime? digRequiredAfterLiningCompleted = null;
                bool outOfScope = false;
                bool holdClientIssue = false;
                DateTime? holdClientIssueResolved  = null;
                bool holdLFSIssue = false;
                DateTime? holdLFSIssueResolved = null;
                bool requiresRoboticPrep = false;
                DateTime? requiresRoboticPrepCompleted = null;

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

                // Insert into LFS Asset Lateral
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
                int lateralAssetId = lfsAssetSewerLateral.InsertDirect(countryId, provinceId, countyId, cityId, section_assetId, address, lateralID, "", "", "", "", "Live", "", distanceFromUSMH, distanceFromDSMH, "", false, companyId, connectionType);

                // Insert into LFS Asset Lateral Client
                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.InsertDirect(lateralAssetId, clientId, clientLateralId, false, companyId);

                // Insert into Work Junction Lining Lateral
                WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
                int workLateral = workJunctionLiningLateral.InsertDirect(projectId, lateralAssetId, sectionWorkId, pipeLocated, servicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, delivered, buildRebuid, preVideo, linerInstalled, finalVideo, cost, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, false, companyId, comments, history, videoLengthToPropertyLine, liningThruCo, noticeDelivered, hamiltonInspectionNumber, flange, gasket, depthOfLocated, digRequiredPriorToLining, digRequiredPriorToLiningCompleted, digRequiredAfterLining, digRequiredAfterLiningCompleted, outOfScope, holdClientIssue, holdClientIssueResolved, holdLFSIssue, holdLFSIssueResolved, requiresRoboticPrep, requiresRoboticPrepCompleted, "", "", dyeTestReq, dyeTestComplete, "");

                // Insert into Work Comments
                JlinerCommentGateway jlinerCommentGateway = new JlinerCommentGateway(sectionTDS);
                jlinerCommentGateway.LoadByIdRefId(originalId, row.RefID, companyId);

                foreach (SectionTDS.LFS_JUNCTION_LINER2_COMMENTRow rowComment in (SectionTDS.LFS_JUNCTION_LINER2_COMMENTDataTable)jlinerCommentGateway.Table)
                {
                    int loginId = rowComment.LoginID;
                    DateTime dateTime_ = rowComment.DateTime_;
                    string comment = rowComment.Comment;

                    WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                    workCommentsGateway.LoadByWorkIdWorkType(workLateral, companyId, "Junction Lining Lateral");
                    WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                    workComments.Insert(workLateral, 0, "Junction Lining Lateral", "Bulk Upload Comments", loginId, dateTime_, comment, null, false, companyId, false, "Junction Lining");

                    // Update Comments
                    workCommentsGateway.Update();
                }

                // Insert into Work History
                JlinerHistoryGateway jlinerHistoryGateway = new JlinerHistoryGateway(sectionTDS);
                jlinerHistoryGateway.LoadByIdRefId(originalId, row.RefID, companyId);

                foreach (SectionTDS.LFS_JUNCTION_LINER2_HISTORYRow rowHistory in (SectionTDS.LFS_JUNCTION_LINER2_HISTORYDataTable)jlinerHistoryGateway.Table)
                {
                    int loginId = rowHistory.LoginID;
                    DateTime dateTime_H = rowHistory.DateTime_;
                    string history_ = rowHistory.History;

                    WorkHistoryGateway workHistoryGateway = new WorkHistoryGateway();
                    workHistoryGateway.LoadByWorkIdWorkType(workLateral, companyId, "Junction Lining Lateral");
                    WorkHistory workHistory = new WorkHistory(workHistoryGateway.Data);
                    workHistory.Insert(workLateral, 0, "Junction Lining Lateral", "Bulk Upload History", loginId, dateTime_H, history_, null, false, companyId, false, "Junction Lining");

                    // Update History
                    workHistoryGateway.Update();
                }
            }
        }
        /// <summary>
        /// Delete lateral work
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="lateral">lateral</param>
        /// <param name="companyId">companyId</param>
        /// <param name="projectId">projectId</param>
        private void DeleteFLLLateral(int workId, int lateral, int companyId, int projectId)
        {
            // Delete work lateral
            WorkFullLengthLiningM1Lateral workFullLengthLiningM1Lateral = new WorkFullLengthLiningM1Lateral(null);
            workFullLengthLiningM1Lateral.DeleteDirect(workId, lateral, companyId);

            // Delete section
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(lateral, companyId);

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

                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.DeleteDirect(lateral, clientId, companyId);
            }
        }
        /// <summary>
        /// Save all sections & works to database (direct)
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="videoLength">videoLength</param>
        /// <param name="companyId">companyId</param>
        /// <param name="isNewMeasuredFromDsmh">isNewMeasuredFromDsmh</param>
        public void Save(int workId, int projectId, int sectionAssetId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string videoLength, int companyId, bool isNewMeasuredFromDsmh, bool prepDataRoboticPrep, DateTime? prepDataRoboticPrepCompleted)
        {
            FullLengthLiningTDS fullLengthLiningChanges = (FullLengthLiningTDS)Data.GetChanges();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            // Change row process state
                            NotProcess(row.Lateral);
                        }
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// LateralUpdate
        /// </summary>
        /// <param name="currentProjectId">currentProjectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="distanceFromDsmh">distanceFromDsmh</param>
        /// <param name="distanceFromUsmh">distanceFromUsmh</param>
        /// <param name="mapSize">mapSize</param>
        /// <param name="companyId">companyId</param>
        /// <param name="clientLateralId">clientLateralId</param>
        /// <param name="address">address</param>
        /// <param name="connectionType">connectionType</param>
        private void LateralUpdate(int currentProjectId, int assetId, string distanceFromDsmh, string distanceFromUsmh, string mapSize, int companyId, string clientLateralId, string address, string connectionType)
        {
            AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway();
            assetSewerLateralGateway.LoadByAssetId(assetId, companyId);

            // original values
            int originalSection_ = assetSewerLateralGateway.GetSection(assetId);
            string originalAddress = assetSewerLateralGateway.GetAddress(assetId);
            string originalLateralId = assetSewerLateralGateway.GetLateralId(assetId);
            string originalLatitudeAtSection = assetSewerLateralGateway.GetLatitudeAtSection(assetId);
            string originalLongitudeAtSection = assetSewerLateralGateway.GetLongitudeAtSection(assetId);
            string originalLatitudeAtPropertyLine = assetSewerLateralGateway.GetLatitudeAtPropertyLine(assetId);
            string originalLongitudeAtPropertyLine = assetSewerLateralGateway.GetLongitudeAtPropertyLine(assetId);
            string originalState = assetSewerLateralGateway.GetState(assetId);
            string originalSize_ = assetSewerLateralGateway.GetSize(assetId);
            string originalDistanceFromUsmh = assetSewerLateralGateway.GetDistanceFromUSMH(assetId);
            string originalDistanceFromDsmh = assetSewerLateralGateway.GetDistanceFromDSMH(assetId);
            string originalMapSize = assetSewerLateralGateway.GetMapSize(assetId);
            bool originalDelete = assetSewerLateralGateway.GetDeleted(assetId);
            int originalCompanyId = assetSewerLateralGateway.GetCompanyId(assetId);
            string originalConnectionType = assetSewerLateralGateway.GetConnectionType(assetId);

            // new values
            string newAddress = address;
            string newDistanceFromUsmh = originalDistanceFromUsmh;
            string newDistanceFromDsmh = originalDistanceFromDsmh;
            string newMapSize = mapSize;
            string newConnectionType = connectionType;

            // Update Sewer lateral
            AssetSewerLateral assetSewerLateral = new AssetSewerLateral(null);
            assetSewerLateral.UpdateDirect(assetId, originalSection_, originalAddress, originalLateralId, originalLatitudeAtSection, originalLongitudeAtSection, originalLatitudeAtPropertyLine, originalLongitudeAtPropertyLine, originalState, originalSize_, originalDistanceFromUsmh, originalDistanceFromDsmh, originalMapSize, originalDelete, originalCompanyId, originalConnectionType, assetId, originalSection_, newAddress, originalLateralId, originalLatitudeAtSection, originalLongitudeAtSection, originalLatitudeAtPropertyLine, originalLongitudeAtPropertyLine, originalState, originalSize_, newDistanceFromUsmh, newDistanceFromDsmh, newMapSize, originalDelete, originalCompanyId, newConnectionType);

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

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

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

                lfsAssetSewerLateralClient.UpdateDirect(assetId, clientId, originalClientLateralId, false, companyId, assetId, clientId, newClientLateralId, false, companyId);
            }
        }
Пример #6
0
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="assetIdLateral">assetIdLateral</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="companyId">companyId</param>
        private void Delete(int workId, int assetIdLateral, int sectionWorkId, int companyId)
        {
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);
            int currentProjectId = workGateway.GetProjectId(workId);

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

            // delete lateral work
            WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
            workJunctionLiningLateral.DeleteDirect(workId, sectionWorkId, companyId);

            // delete lfs lateral
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(assetIdLateral, companyId);

            if (isDeleted)
            {
                // delete lfs lateral client
                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(assetIdLateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(assetIdLateral, clientId, companyId);
                }
            }
        }
        /// <summary>
        /// Delete lateral work
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="lateral">lateral</param>
        /// <param name="companyId">companyId</param>
        /// <param name="clientId">clientId</param>
        private void DeleteFLLLateral(int workId, int lateral, int companyId, int clientId)
        {
            // Delete work lateral
            WorkFullLengthLiningM1Lateral workFullLengthLiningM1Lateral = new WorkFullLengthLiningM1Lateral(null);
            workFullLengthLiningM1Lateral.DeleteDirect(workId, lateral, companyId);

            // Delete section
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(lateral, companyId);

            if (isDeleted)
            {
                LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                lfsAssetSewerLateralClient.DeleteDirect(lateral, clientId, companyId);
            }
        }
        /// <summary>
        /// Save all sections & works to database (direct)
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="length">length</param>
        /// <param name="companyId">companyId</param>
        /// <param name="isNewMeasuredFromDsmh">isNewMeasuredFromDsmh</param>
        /// <param name="prepDataRoboticPrep">prepDataRoboticPrep</param>
        /// <param name="prepDataRoboticPrepCompleted">prepDataRoboticPrepCompleted</param>
        public void Save(int workId, int projectId, int sectionAssetId, Int64 countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string length, int companyId, bool isNewMeasuredFromDsmh, bool prepDataRoboticPrep, DateTime? prepDataRoboticPrepCompleted)
        {
            // Update Laterals
            RehabAssessmentLateralDetailsGateway rehabAssessmentLateralDetailsGateway = new RehabAssessmentLateralDetailsGateway(Data);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    // ... Delete laterals
                    if ((row.InDatabase) && (row.Deleted))
                    {
                        DeleteFLLLateral(workId, row.Lateral, companyId, clientId);
                    }
                }
            }
        }