public static void DeserializeWares(string directory) { List <Ware> TempWares = new List <Ware>(); string waresFileName = directory + @"\Wares.json"; try { using (StreamReader r = new StreamReader(waresFileName)) { string json = r.ReadToEnd(); TempWares = JsonConvert.DeserializeObject <List <Ware> >(json); Console.WriteLine(TempWares.Count()); } foreach (Ware ware in TempWares) { Ware globalWare = GlobalWares.Where(x => x.Name.Equals(ware.Name)).FirstOrDefault(); if (globalWare == null) { GlobalWares.Add(ware); } } //GlobalWares = TempWares; } catch (Exception err) { //Error opening the history file, ideally I should check if the file exists insted of handling this exception Console.WriteLine("Exception on MetroWindow_Loaded"); Console.WriteLine(err.Message); } }
public TradeOperation(double time, string shipId, string fullLogEntry, string shipName, int quantity, string product, string soldToId, string soldToName, string faction, int money) { if ("Please load the XML".Equals(shipId)) { return; } this.Time = time; Ship ourShip = Ship.GetShip(shipId); //this is to ensure the last name of the ship sticks OurShip.ShipName = shipName; this.OurShip = ourShip; this.FullLogEntry = fullLogEntry; this.Quantity = quantity; Ware itemSold = Ware.GetWare(product); this.ItemSold = itemSold; this.SoldTo = Ship.GetSoldTo(soldToId); this.SoldTo.ShipName = soldToName; this.Faction = faction; this.Money = money; ourShip.AddTradeOperation(this); PartialSumByShip = OurShip.GetListOfTradeOperations().Sum(x => x.Money); PartialSumByWare = 0; itemSold.AddTradeOperation(this); }
public void ParseTextEntry(XmlReader logEntry) { this.FullLogEntry = logEntry.Value; this.OurShip = Ship.GetShip(getShipID(logEntry.Value)); this.OurShip.ShipName = getShipName(logEntry.Value, this.OurShip.ShipID); this.Quantity = getQtdSold(logEntry.Value); this.ItemSold = Ware.GetWare(getProduct(logEntry.Value, this.Quantity)); this.SoldTo = Ship.GetSoldTo(getDestinationID(logEntry.Value)); this.SoldTo.ShipName = getSoldToName(logEntry.Value, this.SoldTo.ShipID); }
public static void AddTradeOperationToWareList(TradeOperation tradeOp) { Ware ware = GlobalWares.Where(x => x.Name.Equals(tradeOp.ItemSold.Name)).FirstOrDefault(); //if (ware == null) //{ // ware = tradeOp.ItemSold; // ShipsWithTradeOperations.Add(ship); //} ware.AddTradeOperation(tradeOp); }
public static Ware GetWare(string wareName) { Ware ware = MainWindow.GlobalWares.Where(x => x.Name.Equals(wareName)).FirstOrDefault(); //if (ware == null) //{ // ware = new Ware(wareName); //} return(ware); }
private void Histogram_DataClick(object sender, ChartPoint chartPoint) { //ShowEstimatedProfitRadio.IsChecked = false; //ShowFullMoneyEarnedRadio.IsChecked = false; //ShowTotalItemsRadio.IsChecked = false; Ware ware = null; try { ware = WaresSummaries.Where(x => x.Ware.Name.Equals(((LiveCharts.Wpf.Series)chartPoint.SeriesView).Title)).FirstOrDefault().Ware; SeriesCollection.Clear(); } catch (Exception) { //TODO: Bad programming, improve this and probably show items sold by ship return; //throw; } List <ShipsSummary> shipsSummaries = new List <ShipsSummary>(); foreach (Ship ship in MainWindow.ShipsWithTradeOperations) { List <TradeOperation> tradeOperations = ship.GetListOfTradeOperations().Where(x => x.ItemSold.Name.Equals(ware.Name)).ToList(); ShipsSummary shipSummary = new ShipsSummary(); shipSummary.Ship = ship; shipSummary.Ware = ware; shipSummary.TotalProfit = tradeOperations.Sum(x => x.EstimatedProfit); shipSummary.TotalValueSold = tradeOperations.Sum(x => x.Money); shipSummary.QuantitySold = tradeOperations.Sum(x => x.Quantity); shipsSummaries.Add(shipSummary); } foreach (ShipsSummary shipsummary in shipsSummaries.OrderByDescending(x => x.QuantitySold)) { if (shipsummary.QuantitySold > 0) { ColumnSeries column = null; if (ShowEstimatedProfitRadio.IsChecked.Value) { column = new ColumnSeries { Title = shipsummary.Ship.FullShipname, Values = new ChartValues <double> { shipsummary.TotalProfit } }; } if (ShowFullMoneyEarnedRadio.IsChecked.Value) { column = new ColumnSeries { Title = shipsummary.Ship.FullShipname, Values = new ChartValues <double> { shipsummary.TotalValueSold } }; } if (ShowTotalItemsRadio.IsChecked.Value) { column = new ColumnSeries { Title = shipsummary.Ship.FullShipname, Values = new ChartValues <double> { shipsummary.QuantitySold } }; } SeriesCollection.Add(column); } } //Console.WriteLine("Double Click"); }