private void CopyEDStationEconomiesToDataRows(EDStation StationObject, System.Data.DataTable EconomyTable)
{
try
{
// get all existing economies from the database (memory list)
List<DataRow> Existing = EconomyTable.Select("station_id = " + StationObject.Id).ToList();
foreach (String Economy in StationObject.Economies)
{
// get the current new economy id
Int32 EconomyID = (Int32)DBConvert.From(BaseTableNameToID("economy", Economy));
// and check, if it is already existing
var Found = from DataRow relevantEconomy in Existing
where relevantEconomy.Field<Int32>("economy_id") == EconomyID
select relevantEconomy;
// if it's not existing, insert it
if(Found.Count() == 0)
{
DataRow newRow = EconomyTable.NewRow();
newRow["station_id"] = StationObject.Id;
newRow["economy_id"] = EconomyID;
EconomyTable.Rows.Add(newRow);
}
else
{
Existing.Remove(Found.First());
}
}
// remove all old, not more existing data
foreach (DataRow RemovedRow in Existing)
EconomyTable.Rows.Remove(RemovedRow);
}
catch (Exception ex)
{
throw new Exception("Error while copying station economy data", ex);
}
}