/// <summary> /// Save all udfs to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ActualCostsAddTDS subcontractorsChanges = (ActualCostsAddTDS)Data.GetChanges(); if (subcontractorsChanges != null) { if (subcontractorsChanges.SubcontractorCosts.Rows.Count > 0) { ActualCostsAddSubcontractorCostsGateway actualCostsAddSubcontractorCostsGateway = new ActualCostsAddSubcontractorCostsGateway(subcontractorsChanges); foreach (ActualCostsAddTDS.SubcontractorCostsRow row in (ActualCostsAddTDS.SubcontractorCostsDataTable)subcontractorsChanges.SubcontractorCosts) { // Insert new subcontractor hours if ((!row.Deleted) && (!row.InDatabase)) { int projectId = row.ProjectID; int refId = row.RefID; int subcontractorId = row.SubcontractorID; decimal rateUsd = 0; if (!row.IsRateUsdNull()) rateUsd = row.RateUsd; decimal totalUsd = 0; if (!row.IsTotalUsdNull()) totalUsd = row.TotalUsd; string comment = ""; if (!row.IsCommentNull()) comment = row.Comment; ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null); actualCostsSubcontractorCosts.InsertDirect(projectId, refId, subcontractorId, row.Date, row.Quantity, row.RateCad, row.TotalCad, rateUsd, totalUsd, comment, row.Deleted, row.COMPANY_ID); } } } } }
/// <summary> /// Save /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ActualCostsInformationTDS subcontractorHoursInformationChanges = (ActualCostsInformationTDS)Data.GetChanges(); if (subcontractorHoursInformationChanges.SubcontractorBasicInformation.Rows.Count > 0) { ActualCostsInformationSubcontractorBasicInformationGateway actualCostsInformationSubcontractorBasicInformationGateway = new ActualCostsInformationSubcontractorBasicInformationGateway(subcontractorHoursInformationChanges); // Update employee foreach (ActualCostsInformationTDS.SubcontractorBasicInformationRow row in (ActualCostsInformationTDS.SubcontractorBasicInformationDataTable)subcontractorHoursInformationChanges.SubcontractorBasicInformation) { // Insert new hours if ((!row.Deleted) && (!row.InDatabase)) { string comment = ""; if (!row.IsCommentNull()) comment = row.Comment; ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null); actualCostsSubcontractorCosts.InsertDirect(row.ProjectID, row.RefID, row.SubcontractorID, row.Date, row.Quantity, row.RateCad, row.TotalCad, row.RateUsd, row.TotalUsd, comment, row.Deleted, row.COMPANY_ID); } // Update hours if ((!row.Deleted) && (row.InDatabase)) { int projectId = row.ProjectID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // Original values int originalSubcontractorId = actualCostsInformationSubcontractorBasicInformationGateway.GetSubcontractorIDOriginal(projectId, refId); DateTime originalDate = actualCostsInformationSubcontractorBasicInformationGateway.GetDateOriginal(projectId, refId); double originalQuantity = actualCostsInformationSubcontractorBasicInformationGateway.GetQuantityOriginal(projectId, refId); decimal originalRateCad = actualCostsInformationSubcontractorBasicInformationGateway.GetRateCadOriginal(projectId, refId); decimal originalTotalCad = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalCadOriginal(projectId, refId); decimal originalRateUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetRateUsdOriginal(projectId, refId); decimal originalTotalUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalUsdOriginal(projectId, refId); string originalComment = actualCostsInformationSubcontractorBasicInformationGateway.GetCommentOriginal(projectId, refId); // New values int newSubcontractorId = actualCostsInformationSubcontractorBasicInformationGateway.GetSubcontractorID(projectId, refId); DateTime newDate = actualCostsInformationSubcontractorBasicInformationGateway.GetDate(projectId, refId); double newQuantity = actualCostsInformationSubcontractorBasicInformationGateway.GetQuantity(projectId, refId); decimal newRateCad = actualCostsInformationSubcontractorBasicInformationGateway.GetRateCad(projectId, refId); decimal newTotalCad = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalCad(projectId, refId); decimal newRateUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetRateUsd(projectId, refId); decimal newTotalUsd = actualCostsInformationSubcontractorBasicInformationGateway.GetTotalUsd(projectId, refId); string newComment = actualCostsInformationSubcontractorBasicInformationGateway.GetComment(projectId, refId); ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null); actualCostsSubcontractorCosts.UpdateDirect(projectId, refId, originalSubcontractorId, originalDate, originalQuantity, originalRateCad, originalTotalCad, originalRateUsd, originalTotalUsd, originalComment, originalDeleted, originalCompanyId, projectId, refId, newSubcontractorId, newDate, newQuantity, newRateCad, newTotalCad, newRateUsd, newTotalUsd, newComment, originalDeleted, originalCompanyId); } // Delete hours if ((row.Deleted) && (row.InDatabase)) { ActualCostsSubcontractorCosts actualCostsSubcontractorCosts = new ActualCostsSubcontractorCosts(null); actualCostsSubcontractorCosts.DeleteDirect(row.ProjectID, row.RefID, row.COMPANY_ID); } } } }