/// <summary> /// Save all to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ActualCostsAddTDS bondingChanges = (ActualCostsAddTDS)Data.GetChanges(); if (bondingChanges != null) { if (bondingChanges.BondingCompaniesCosts.Rows.Count > 0) { ActualCostsAddBondingCompaniesCostsGateway actualCostsAddBondingCompaniesCostsGateway = new ActualCostsAddBondingCompaniesCostsGateway(bondingChanges); foreach (ActualCostsAddTDS.BondingCompaniesCostsRow row in (ActualCostsAddTDS.BondingCompaniesCostsDataTable)bondingChanges.BondingCompaniesCosts) { // Insert new bonding costs if ((!row.Deleted) && (!row.InDatabase)) { int projectId = row.ProjectID; int refId = row.RefID; int bondingCompanyId = row.BondingCompanyID; decimal rateUsd = 0; if (!row.IsRateUsdNull()) rateUsd = row.RateUsd; string comment = ""; if (!row.IsCommentNull()) comment = row.Comment; ActualCostsBondingCompaniesCosts actualCostsBondingCompaniesCosts = new ActualCostsBondingCompaniesCosts(null); actualCostsBondingCompaniesCosts.InsertDirect(projectId, refId, bondingCompanyId, 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) { ActualCostsAddBondingCompaniesCostsGateway rr = new ActualCostsAddBondingCompaniesCostsGateway(); rr.LoadAllByProjectId(projectId, companyId); foreach (ActualCostsAddTDS.BondingCompaniesCostsRow row1 in (ActualCostsAddTDS.BondingCompaniesCostsDataTable)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.BondingCompaniesCostsRow row2 in (ActualCostsAddTDS.BondingCompaniesCostsDataTable)Table) { if (projectId == row2.ProjectID) { existProject = true; } } // ... ... If there are rows at the grid get new Id if (existProject) { foreach (ActualCostsAddTDS.BondingCompaniesCostsRow row3 in (ActualCostsAddTDS.BondingCompaniesCostsDataTable)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. ActualCostsAddBondingCompaniesCostsGateway rrsc = new ActualCostsAddBondingCompaniesCostsGateway(); rrsc.LoadAllByProjectId(projectId, companyId); foreach (ActualCostsAddTDS.BondingCompaniesCostsRow row3 in (ActualCostsAddTDS.BondingCompaniesCostsDataTable)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) { ActualCostsAddBondingCompaniesCostsGateway actualCostsAddBondingCompaniesCostsGateway = new ActualCostsAddBondingCompaniesCostsGateway(Data); actualCostsAddBondingCompaniesCostsGateway.LoadAllByProjectId(projectId, companyId); }