private void CreateMarketEntryLine(Entity.CommodityType commodityType, TableLayoutPanel layout, int row) { var commodityTypeLabel = new Label() { Text = commodityType.Name, TextAlign = ContentAlignment.MiddleLeft, Dock = DockStyle.Fill, AutoSize = true, MinimumSize = new Size(50, 25) }; var marketEntryLine = new MarketEntryLine(commodityType) { Dock = DockStyle.Fill }; layout.Controls.Add(commodityTypeLabel, 0, row); layout.Controls.Add(marketEntryLine, 1, row); _marketEntryLines.Add(commodityType, marketEntryLine); }
private void CreateUpdateOrDeleteMarketEntry( Core.AbstractEntityManager <Entity.MarketEntry> marketEntryManager, Entity.CommodityType commodityType, MarketEntryLine marketEntryLine, ref int createdEntries, ref int updatedEntries, ref int removedEntries, ref int skippedEntries ) { var potentialMatches = marketEntryManager.GetAll().Where(x => x.CommodityType == commodityType && x.SpaceStation == _spaceStationComboBox.SelectedItem); if (marketEntryLine.IsEmpty()) { // If there are no market entires for the current commodity type and space stations, skip this line if (potentialMatches.Count() == 0) { skippedEntries++; return; } // Otherwise: Delete the potential match (should only be one) marketEntryManager.RemoveObject(potentialMatches.First()); removedEntries++; return; } // Else: If there is a matching entry, update that one, otherwise create a new one if (potentialMatches.Count() == 0) { _entityHandler.AddObject( marketEntryLine.CreateMarketEntry(), commodityType, ((Entity.SpaceStation)_spaceStationComboBox.SelectedItem) ); createdEntries++; } else { var tempEntry = marketEntryLine.CreateMarketEntry(); var marketEntry = potentialMatches.First(); // skip if nothing must be updated if (tempEntry.Equals(marketEntry)) { return; } marketEntry.SellToStationPrice = tempEntry.SellToStationPrice; marketEntry.BuyFromStationPrice = tempEntry.BuyFromStationPrice; marketEntry.Demand = tempEntry.Demand; marketEntry.Supply = tempEntry.Supply; _entityHandler.UpdateObject(marketEntry); updatedEntries++; } }