Ejemplo n.º 1
0
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int workId, int companyId)
        {
            WorkPointRepairsGateway workPointRepairsGateway = new WorkPointRepairsGateway();
            workPointRepairsGateway.LoadByWorkId(workId, companyId);

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

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

                // Delete work
                Work work = new Work(null);
                work.DeleteDirect(workId, companyId);
            }
        }
        /// <summary>
        /// Save a Previous PR work
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="companyId">companyId</param>
        private void SavePreviousPRWork(int projectId, int section_assetId, int companyId)
        {
            // Load Previous work - Point Repairs data (last sections work)
            string workType = "Point Repairs";
            WorkPointRepairsGateway workPointRepairsGateway = new WorkPointRepairsGateway();
            workPointRepairsGateway.LoadTop1ByProjectIdAssetIdWorkType(projectId, section_assetId, workType, companyId);

            int workId = workPointRepairsGateway.GetWorkIdTop1();
            string clientId = ""; if (workPointRepairsGateway.GetClientId(workId) != "") clientId = workPointRepairsGateway.GetClientId(workId);
            string measurementTakenBy = ""; if (workPointRepairsGateway.GetMeasurementTakenBy(workId) != "") measurementTakenBy = workPointRepairsGateway.GetMeasurementTakenBy(workId);
            DateTime? repairConfirmationDate = null; if (workPointRepairsGateway.GetRepairConfirmationDate(workId).HasValue) repairConfirmationDate = workPointRepairsGateway.GetRepairConfirmationDate(workId);
            bool bypassRequired = workPointRepairsGateway.GetBypassRequired(workId);
            string roboticDistances = ""; if (workPointRepairsGateway.GetRoboticDistances(workId) != "") roboticDistances = workPointRepairsGateway.GetRoboticDistances(workId);
            DateTime? proposedLiningDate = null; if (workPointRepairsGateway.GetProposedLiningDate(workId).HasValue) proposedLiningDate = workPointRepairsGateway.GetProposedLiningDate(workId);
            DateTime? deadlineLiningDate = null; if (workPointRepairsGateway.GetDeadlineLiningDate(workId).HasValue) deadlineLiningDate = workPointRepairsGateway.GetDeadlineLiningDate(workId);
            DateTime? finalVideoDate = null; if (workPointRepairsGateway.GetFinalVideoDate(workId).HasValue) finalVideoDate = workPointRepairsGateway.GetFinalVideoDate(workId);
            int? estimatedJoints = null; if (workPointRepairsGateway.GetEstimatedJoints(workId).HasValue) estimatedJoints = workPointRepairsGateway.GetEstimatedJoints(workId);
            int? jointsTestSealed = null; if (workPointRepairsGateway.GetJointsTestSealed(workId).HasValue) jointsTestSealed = workPointRepairsGateway.GetJointsTestSealed(workId);
            bool issueIdentified = workPointRepairsGateway.GetIssueIdentified(workId);
            bool issueLfs = workPointRepairsGateway.GetIssueLFS(workId);
            bool issueClient = workPointRepairsGateway.GetIssueClient(workId);
            bool issueSales = workPointRepairsGateway.GetIssueSales(workId);
            bool issueGivenToClient = workPointRepairsGateway.GetIssueGivenToClient(workId);
            bool issueResolved = workPointRepairsGateway.GetIssueResolved(workId);
            bool issueInvestigation = workPointRepairsGateway.GetIssueInvestigation(workId);
            string repairId = ""; if (workPointRepairsGateway.GetRepairID(workId) != "") repairId = workPointRepairsGateway.GetRepairID(workId);

            // Load Previous work - General work data
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);

            int? libraryCategoriesId = null; if (workGateway.GetLibraryCategoriesId(workId).HasValue) libraryCategoriesId = workGateway.GetLibraryCategoriesId(workId);
            string comments = workGateway.GetComments(workId);
            string history = workGateway.GetHistory(workId);

            // Save new work
            WorkPointRepairs workPointRepairs = new WorkPointRepairs(null);
            int newSectionWorkId = workPointRepairs.InsertDirect(projectId, section_assetId, libraryCategoriesId, clientId, measurementTakenBy, repairConfirmationDate, bypassRequired, roboticDistances, proposedLiningDate, deadlineLiningDate, finalVideoDate, estimatedJoints, jointsTestSealed, issueIdentified, issueLfs, issueClient, issueSales, issueGivenToClient, issueResolved, issueInvestigation, repairId, false, companyId, comments, history);

            // Load Previous work  -  Save pr repair
            WorkPointRepairsRepairGateway workPointRepairsRepairGateway = new WorkPointRepairsRepairGateway();
            workPointRepairsRepairGateway.LoadByWorkId(workId, companyId);

            foreach (WorkTDS.LFS_WORK_POINT_REPAIRS_REPAIRRow row in (WorkTDS.LFS_WORK_POINT_REPAIRS_REPAIRDataTable)workPointRepairsRepairGateway.Table)
            {
                string repairPointId = row.RepairPointID;
                string type = ""; if (!row.IsTypeNull()) type = row.Type;
                string reamDistance = ""; if (!row.IsReamDistanceNull()) reamDistance = row.ReamDistance;
                DateTime? reamDate = null; if (!row.IsReamDateNull()) reamDate = row.ReamDate;
                string linerDistance = ""; if (!row.IsLinerDistanceNull()) linerDistance = row.LinerDistance;
                string direction = ""; if (!row.IsDirectionNull()) direction = row.Direction;
                int? reinstates = null; if (!row.IsReinstatesNull()) reinstates = row.Reinstates;
                string ltmh = ""; if (!row.IsLTMHNull()) ltmh = row.LTMH;
                string vtmh = ""; if (!row.IsVTMHNull()) vtmh = row.VTMH;
                string distance = ""; if (!row.IsDistanceNull()) distance = row.Distance;
                string size_ = ""; if (!row.IsSize_Null()) size_ = row.Size_;
                DateTime? installDate = null; if (!row.IsInstallDateNull()) installDate = row.InstallDate;
                string mhShot = ""; if (!row.IsMHShotNull()) mhShot = row.MHShot;
                string groutDistance = ""; if (!row.IsGroutDistanceNull()) groutDistance = row.GroutDistance;
                DateTime? groutDate = null; if (!row.IsGroutDateNull()) groutDate = row.GroutDate;
                string approval = ""; if (!row.IsApprovalNull()) approval = row.Approval;
                bool extraRepair = row.ExtraRepair;
                bool cancelled = row.Cancelled;
                string commentsRepair = ""; if (!row.IsCommentsNull()) commentsRepair = row.Comments;
                string defectQualifier = ""; if (!row.IsDefectQualifierNull()) defectQualifier = row.DefectQualifier;
                string defecDetails = ""; if (!row.IsDefectDetailsNull()) defecDetails = row.DefectDetails;
                string length = ""; if (!row.IsLengthNull()) length = row.Length;
                DateTime? reinstateDate = null; if (!row.IsReinstateDateNull()) reinstateDate = row.ReinstateDate;

                WorkPointRepairsRepair workPointRepairsRepair = new WorkPointRepairsRepair();
                workPointRepairsRepair.InsertDirect(newSectionWorkId, repairPointId, type, reamDistance, reamDate, linerDistance, direction, reinstates, ltmh, vtmh, distance, size_, installDate, mhShot, groutDistance, groutDate, approval, extraRepair, cancelled, commentsRepair, false, companyId, defectQualifier, defectQualifier, length, reinstateDate);
            }

            // Load Previous work  - Comments and History
            SavePreviousComments(workId, workType, companyId, newSectionWorkId);
            SavePreviousHistory(workId, workType, companyId, newSectionWorkId);
        }
        /// <summary>
        /// Save all repairs to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            PointRepairsTDS pointRepairsChanges = (PointRepairsTDS)Data.GetChanges();

            if (pointRepairsChanges.RepairDetails.Rows.Count > 0)
            {
                PointRepairsRepairDetailsGateway pointRepairsRepairDetailsGateway = new PointRepairsRepairDetailsGateway(pointRepairsChanges);

                foreach (PointRepairsTDS.RepairDetailsRow row in (PointRepairsTDS.RepairDetailsDataTable)pointRepairsChanges.RepairDetails)
                {
                    // Insert new repair
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        int workId = row.WorkID;
                        string repairPointId = row.RepairPointID;
                        string reamDistance = ""; if (!row.IsReamDistanceNull()) reamDistance = row.ReamDistance;
                        DateTime? reamDate = null; if (!row.IsReamDateNull()) reamDate = row.ReamDate;
                        string linerDistance = ""; if (!row.IsLinerDistanceNull()) linerDistance = row.LinerDistance;
                        string direction = ""; if (!row.IsDirectionNull()) direction = row.Direction;
                        int? reinstates = null; if (!row.IsReinstatesNull()) reinstates = row.Reinstates;
                        string ltmh = ""; if (!row.IsLTMHNull()) ltmh = row.LTMH;
                        string vtmh = ""; if (!row.IsVTMHNull()) vtmh = row.VTMH;
                        string distance = ""; if (!row.IsDistanceNull()) distance = row.Distance;
                        string size_ = ""; if (!row.IsSize_Null()) size_ = row.Size_;
                        DateTime? installDate = null; if (!row.IsInstallDateNull()) installDate = row.InstallDate;
                        string mhshot = ""; if (!row.IsMHShotNull()) mhshot = row.MHShot;
                        string groutDistance = ""; if (!row.IsGroutDistanceNull()) groutDistance = row.GroutDistance;
                        DateTime? groutDate = null; if (!row.IsGroutDateNull()) groutDate = row.GroutDate;
                        string approval = ""; if (!row.IsApprovalNull()) approval = row.Approval;
                        bool extraRepair = row.ExtraRepair;
                        bool cancelled = row.Cancelled;
                        string comments = ""; if (!row.IsCommentsNull()) comments = row.Comments;
                        string defectQualifier = ""; if (!row.IsDefectQualifierNull()) defectQualifier = row.DefectQualifier;
                        string defectDetails = ""; if (!row.IsDefectDetailsNull()) defectDetails = row.DefectDetails;
                        string length = ""; if (!row.IsLengthNull()) length = row.Length;
                        DateTime? reinstateDate = null; if (!row.IsReinstateDateNull()) reinstateDate = row.ReinstateDate;

                        WorkPointRepairsRepair workPointRepairsRepair = new WorkPointRepairsRepair(null);
                        workPointRepairsRepair.InsertDirect(workId, repairPointId, row.Type, reamDistance, reamDate, linerDistance, direction, reinstates, ltmh, vtmh, distance, size_, installDate, mhshot, groutDistance, groutDate, approval, extraRepair, cancelled, comments, row.Deleted, row.COMPANY_ID, defectQualifier, defectDetails, length, reinstateDate);
                    }

                    // Update repair
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        string repairPointId = row.RepairPointID;
                        string type = row.Type;

                        // Original values
                        string originalReamDistance = pointRepairsRepairDetailsGateway.GetReamDistanceOriginal(workId, repairPointId);
                        DateTime? originalReamDate = null; if (pointRepairsRepairDetailsGateway.GetReamDateOriginal(workId, repairPointId).HasValue) originalReamDate = pointRepairsRepairDetailsGateway.GetReamDateOriginal(workId, repairPointId);
                        string originalLinerDistance = pointRepairsRepairDetailsGateway.GetLinerDistanceOriginal(workId, repairPointId);
                        string originalDirection = pointRepairsRepairDetailsGateway.GetDirectionOriginal(workId, repairPointId);
                        int? originalReinstates = null; if (pointRepairsRepairDetailsGateway.GetReinstatesOriginal(workId, repairPointId).HasValue) originalReinstates = pointRepairsRepairDetailsGateway.GetReinstatesOriginal(workId, repairPointId);
                        string originalLtmh = pointRepairsRepairDetailsGateway.GetLTMHOriginal(workId, repairPointId);
                        string originalVtmh = pointRepairsRepairDetailsGateway.GetVTMHOriginal(workId, repairPointId);
                        string originalDistance = pointRepairsRepairDetailsGateway.GetDistanceOriginal(workId, repairPointId);
                        string originalSize_ = pointRepairsRepairDetailsGateway.GetSize_Original(workId, repairPointId);
                        DateTime? originalInstallDate = null; if (pointRepairsRepairDetailsGateway.GetInstallDateOriginal(workId, repairPointId).HasValue) originalInstallDate = pointRepairsRepairDetailsGateway.GetInstallDateOriginal(workId, repairPointId);
                        string originalMhShot = pointRepairsRepairDetailsGateway.GetMHShotOriginal(workId, repairPointId);
                        string originalGroutDistance = pointRepairsRepairDetailsGateway.GetGroutDistanceOriginal(workId, repairPointId);
                        DateTime? originalGroutDate = null; if (pointRepairsRepairDetailsGateway.GetGroutDateOriginal(workId, repairPointId).HasValue) originalGroutDate = pointRepairsRepairDetailsGateway.GetGroutDateOriginal(workId, repairPointId);
                        string originalApproval = pointRepairsRepairDetailsGateway.GetApprovalOriginal(workId, repairPointId);
                        bool originalExtraRepair = pointRepairsRepairDetailsGateway.GetExtraRepairOriginal(workId, repairPointId);
                        bool originalCancelled = pointRepairsRepairDetailsGateway.GetCancelledOriginal(workId, repairPointId);
                        string originalComments = pointRepairsRepairDetailsGateway.GetCommentsOriginal(workId, repairPointId);
                        string originalDefectQualifier = pointRepairsRepairDetailsGateway.GetDefectQualifierOriginal(workId, repairPointId);
                        string originalDefectDetails = pointRepairsRepairDetailsGateway.GetDefectDetailsOriginal(workId, repairPointId);
                        string originalLength = pointRepairsRepairDetailsGateway.GetLengthOriginal(workId, repairPointId);
                        DateTime? originalReinstateDate = null; if (pointRepairsRepairDetailsGateway.GetReinstateDateOriginal(workId, repairPointId).HasValue) originalReinstateDate = pointRepairsRepairDetailsGateway.GetReinstateDateOriginal(workId, repairPointId);

                        // New values
                        string newReamDistance = pointRepairsRepairDetailsGateway.GetReamDistance(workId, repairPointId);
                        DateTime? newReamDate = null; if (pointRepairsRepairDetailsGateway.GetReamDate(workId, repairPointId).HasValue) newReamDate = pointRepairsRepairDetailsGateway.GetReamDate(workId, repairPointId);
                        string newLinerDistance = pointRepairsRepairDetailsGateway.GetLinerDistance(workId, repairPointId);
                        string newDirection = pointRepairsRepairDetailsGateway.GetDirection(workId, repairPointId);
                        int? newReinstates = null; if (pointRepairsRepairDetailsGateway.GetReinstates(workId, repairPointId).HasValue) newReinstates = pointRepairsRepairDetailsGateway.GetReinstates(workId, repairPointId);
                        string newLtmh = pointRepairsRepairDetailsGateway.GetLTMH(workId, repairPointId);
                        string newVtmh = pointRepairsRepairDetailsGateway.GetVTMH(workId, repairPointId);
                        string newDistance = pointRepairsRepairDetailsGateway.GetDistance(workId, repairPointId);
                        string newSize_ = pointRepairsRepairDetailsGateway.GetSize_(workId, repairPointId);
                        DateTime? newInstallDate = null; if (pointRepairsRepairDetailsGateway.GetInstallDate(workId, repairPointId).HasValue) newInstallDate = pointRepairsRepairDetailsGateway.GetInstallDate(workId, repairPointId);
                        string newMhShot = pointRepairsRepairDetailsGateway.GetMHShot(workId, repairPointId);
                        string newGroutDistance = pointRepairsRepairDetailsGateway.GetGroutDistance(workId, repairPointId);
                        DateTime? newGroutDate = null; if (pointRepairsRepairDetailsGateway.GetGroutDate(workId, repairPointId).HasValue) newGroutDate = pointRepairsRepairDetailsGateway.GetGroutDate(workId, repairPointId);
                        string newApproval = pointRepairsRepairDetailsGateway.GetApproval(workId, repairPointId);
                        bool newExtraRepair = pointRepairsRepairDetailsGateway.GetExtraRepair(workId, repairPointId);
                        bool newCancelled = pointRepairsRepairDetailsGateway.GetCancelled(workId, repairPointId);
                        string newComments = pointRepairsRepairDetailsGateway.GetComments(workId, repairPointId);
                        string newDefectQualifier = pointRepairsRepairDetailsGateway.GetDefectQualifier(workId, repairPointId);
                        string newDefectDetails = pointRepairsRepairDetailsGateway.GetDefectDetails(workId, repairPointId);
                        string newLength = pointRepairsRepairDetailsGateway.GetLength(workId, repairPointId);
                        DateTime? newReinstateDate = null; if (pointRepairsRepairDetailsGateway.GetReinstateDate(workId, repairPointId).HasValue) newReinstateDate = pointRepairsRepairDetailsGateway.GetReinstateDate(workId, repairPointId);

                        WorkPointRepairsRepair workPointRepairsRepair = new WorkPointRepairsRepair(null);
                        workPointRepairsRepair.Updatedirect(workId, repairPointId, type, originalReamDistance, originalReamDate, originalLinerDistance, originalDirection, originalReinstates, originalLtmh, originalVtmh, originalDistance, originalSize_, originalInstallDate, originalMhShot, originalGroutDistance, originalGroutDate, originalApproval, originalExtraRepair, originalCancelled, originalComments, false, companyId, originalDefectQualifier, originalDefectDetails, originalLength, workId, repairPointId, type, newReamDistance, newReamDate, newLinerDistance, newDirection, newReinstates, newLtmh, newVtmh, newDistance, newSize_, newInstallDate, newMhShot, newGroutDistance, newGroutDate, newApproval, newExtraRepair, newCancelled, newComments, false, companyId, newDefectQualifier, newDefectDetails, newLength, originalReinstateDate, newReinstateDate);

                    }

                    // Delete repair
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        string repairPointId = row.RepairPointID;

                        WorkPointRepairsRepair workPointRepairsRepair = new WorkPointRepairsRepair(null);
                        workPointRepairsRepair.DeleteDirect(workId, repairPointId, row.COMPANY_ID);
                    }
                }
            }
        }