/// <summary> /// Save all to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ActualCostsAddTDS insuranceCompaniesChanges = (ActualCostsAddTDS)Data.GetChanges(); if (insuranceCompaniesChanges != null) { if (insuranceCompaniesChanges.InsuranceCompaniesCosts.Rows.Count > 0) { ActualCostsAddInsuranceCompaniesCostsGateway actualCostsAddInsuranceCompaniesCostsGateway = new ActualCostsAddInsuranceCompaniesCostsGateway(insuranceCompaniesChanges); foreach (ActualCostsAddTDS.InsuranceCompaniesCostsRow row in (ActualCostsAddTDS.InsuranceCompaniesCostsDataTable)insuranceCompaniesChanges.InsuranceCompaniesCosts) { // Insert new insurance cost if ((!row.Deleted) && (!row.InDatabase)) { int projectId = row.ProjectID; int refId = row.RefID; int insuranceCompanyId = row.InsuranceCompanyID; decimal rateUsd = 0; if (!row.IsRateUsdNull()) rateUsd = row.RateUsd; string comment = ""; if (!row.IsCommentNull()) comment = row.Comment; ActualCostsInsuranceCompaniesCosts actualCostsInsuranceCompaniesCosts = new ActualCostsInsuranceCompaniesCosts(null); actualCostsInsuranceCompaniesCosts.InsertDirect(projectId, refId, insuranceCompanyId, row.Date, row.RateCad, rateUsd, comment, row.Deleted, row.COMPANY_ID); } } } } }
// //////////////////////////////////////////////////////////////////////// // PRIVATE METHODS // /// <summary> /// GetNewRefId /// </summary> /// <param name="projectId">projectId</param> /// <param name="companyId">companyId</param> /// <returns>New ID</returns> public int GetNewRefId(int projectId, int companyId) { int newRefId = 0; if (Table.Rows.Count == 0) { ActualCostsAddInsuranceCompaniesCostsGateway rr = new ActualCostsAddInsuranceCompaniesCostsGateway(); rr.LoadAllByProjectId(projectId, companyId); foreach (ActualCostsAddTDS.InsuranceCompaniesCostsRow row1 in (ActualCostsAddTDS.InsuranceCompaniesCostsDataTable)rr.Table) { if (newRefId < row1.RefID) { newRefId = row1.RefID; } } } else { // ... If there are rows at the grid // ... ... Verify if there are rows for the same project at the grid bool existProject = false; foreach (ActualCostsAddTDS.InsuranceCompaniesCostsRow row2 in (ActualCostsAddTDS.InsuranceCompaniesCostsDataTable)Table) { if (projectId == row2.ProjectID) { existProject = true; } } // ... ... If there are rows at the grid get new Id if (existProject) { foreach (ActualCostsAddTDS.InsuranceCompaniesCostsRow row3 in (ActualCostsAddTDS.InsuranceCompaniesCostsDataTable)Table) { if (projectId == row3.ProjectID) { if (newRefId < row3.RefID) { newRefId = row3.RefID; } } } } else { // ... ... There are no rows for the project at the grid, verify on de db. ActualCostsAddInsuranceCompaniesCostsGateway rrsc = new ActualCostsAddInsuranceCompaniesCostsGateway(); rrsc.LoadAllByProjectId(projectId, companyId); foreach (ActualCostsAddTDS.InsuranceCompaniesCostsRow row3 in (ActualCostsAddTDS.InsuranceCompaniesCostsDataTable)rrsc.Table) { if (newRefId < row3.RefID) { newRefId = row3.RefID; } } } } newRefId++; return newRefId; }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS - DATASET // /// <summary> /// LoadAllByProjectId /// </summary> /// <param name="projectId">projectId</param> /// <param name="companyId">companyId</param> public void LoadAllByProjectId(int projectId, int companyId) { ActualCostsAddInsuranceCompaniesCostsGateway actualCostsAddInsuranceCompaniesCostsGateway = new ActualCostsAddInsuranceCompaniesCostsGateway(Data); actualCostsAddInsuranceCompaniesCostsGateway.LoadAllByProjectId(projectId, companyId); }