/// <summary> /// Save all catalysts to database (direct) /// </summary> /// <param name="companyId">companyId</param> /// <param name="runDetails">runDetails</param> /// <param name="projectId">projectId</param> public void Save(int companyId, string runDetails, int projectId) { string[] runDetailsList = runDetails.Split('>'); FullLengthLiningTDS fullLengthLiningWetOutCatalystsDetailsChanges = (FullLengthLiningTDS)Data.GetChanges(); if (fullLengthLiningWetOutCatalystsDetailsChanges.WetOutCatalystsDetails.Rows.Count > 0) { FullLengthLiningWetOutCatalystsDetailsGateway fullLengthLiningWetOutCatalystsDetailsGateway = new FullLengthLiningWetOutCatalystsDetailsGateway(fullLengthLiningWetOutCatalystsDetailsChanges); foreach (FullLengthLiningTDS.WetOutCatalystsDetailsRow row in (FullLengthLiningTDS.WetOutCatalystsDetailsDataTable)fullLengthLiningWetOutCatalystsDetailsChanges.WetOutCatalystsDetails) { // Insert new catalysts if ((!row.Deleted) && (!row.InDatabase)) { for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } if (newWorkId > 0) { WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null); workFullLengthLiningWetOutCatalysts.InsertDirect(newWorkId, row.RefID, row.CatalystID, row.PercentageByWeight, row.LbsForMixQuantity, row.LbsForDrum, row.Deleted, row.COMPANY_ID); } } } // Update catalysts if ((!row.Deleted) && (row.InDatabase)) { int workId = row.WorkID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; int originalCatalystId = row.CatalystID; // original values decimal originalPercentageByWeight = fullLengthLiningWetOutCatalystsDetailsGateway.GetPercentageByWeightOriginal(workId, refId); decimal originalLbsForMixQuantity = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForMixQuantityOriginal(workId, refId); string originalLbsForDrum = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForDrumOriginal(workId, refId); // new values decimal newPercentageByWeight = fullLengthLiningWetOutCatalystsDetailsGateway.GetPercentageByWeight(workId, refId); decimal newLbsForMixQuantity = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForMixQuantity(workId, refId); string newLbsForDrum = fullLengthLiningWetOutCatalystsDetailsGateway.GetLbsForDrum(workId, refId); for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } if (newWorkId > 0) { FullLengthLiningWetOutCatalystsDetailsGateway fullLengthLiningWetOutCatalystsDetailsGatewayForReview = new FullLengthLiningWetOutCatalystsDetailsGateway(); fullLengthLiningWetOutCatalystsDetailsGatewayForReview.LoadByWorkId(newWorkId, companyId); if (fullLengthLiningWetOutCatalystsDetailsGatewayForReview.Table.Rows.Count > 0) { WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null); workFullLengthLiningWetOutCatalysts.UpdateDirect(newWorkId, refId, originalCatalystId, originalPercentageByWeight, originalLbsForMixQuantity, originalLbsForDrum, originalDeleted, originalCompanyId, workId, refId, originalCatalystId, newPercentageByWeight, newLbsForMixQuantity, newLbsForDrum, originalDeleted, originalCompanyId); } else { WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null); workFullLengthLiningWetOutCatalysts.InsertDirect(newWorkId, row.RefID, row.CatalystID, row.PercentageByWeight, row.LbsForMixQuantity, row.LbsForDrum, row.Deleted, row.COMPANY_ID); } } } } // Deleted catalysts if ((row.Deleted) && (row.InDatabase)) { for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } if (newWorkId > 0) { WorkFullLengthLiningWetOutCatalysts workFullLengthLiningWetOutCatalysts = new WorkFullLengthLiningWetOutCatalysts(null); workFullLengthLiningWetOutCatalysts.DeleteDirect(newWorkId, row.RefID, row.COMPANY_ID); } } } } } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// LoadAll /// </summary> /// <param name="workId">workId</param> /// <param name="companyId">companyId</param> public void LoadAll(int workId, int companyId) { FullLengthLiningWetOutCatalystsDetailsGateway fullLengthLiningWetOutCatalystsDetailsGateway = new FullLengthLiningWetOutCatalystsDetailsGateway(Data); fullLengthLiningWetOutCatalystsDetailsGateway.LoadAllByWorkId(workId, companyId); }