/// <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); } } } }