コード例 #1
0
        /// <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);
                        }
                    }
                }
            }
        }