private string StatMostValuableTrophy(string statData) { string[] aircraftsData = statData.Split(','); string trophy = "не было"; double trophyPrice = 0; foreach (string aircraftData in aircraftsData) { Aircraft aircraft = Aircrafts.FindEnemyAircraft(aircraftData.Split('=')[0]); if (aircraft == null) { continue; } if (trophyPrice < aircraft.price) { trophy = aircraft.aircraftName; trophyPrice = aircraft.price; } } return(trophy); }
private void StatBoxValues(DataGrid StatBox, string statData, int percentBaseCount, double percentBasePrice, bool inaccurate = false) { StatBox.Items.Clear(); StatBox.Columns.Clear(); if (String.IsNullOrWhiteSpace(statData)) { return; } StatBox.AutoGenerateColumns = false; StatBox.Columns.Add(new DataGridTextColumn { Header = "тип", Binding = new Binding("aircraft") }); StatBox.Columns.Add(new DataGridTextColumn { Header = "количество", Binding = new Binding("count"), Width = new DataGridLength(100) }); StatBox.Columns.Add(new DataGridTextColumn { Header = "от общего кол-ва", Binding = new Binding("percent"), Width = new DataGridLength(120) }); StatBox.Columns.Add(new DataGridTextColumn { Header = String.Format("от ущерба {0}", (inaccurate ? " (примерно)" : String.Empty)), Binding = new Binding("pricePercent"), Width = new DataGridLength(120) }); string[] aircraftsData = statData.Split(','); string inacc = (inaccurate ? "до " : String.Empty); foreach (string aircraftData in aircraftsData) { dynamic newRow = new ExpandoObject(); string[] data = aircraftData.Split('='); int count = Int32.Parse(data[1]); int percentCount = (count * 100) / percentBaseCount; Aircraft aircraft = Aircrafts.FindEnemyAircraft(data[0]); double price = aircraft.price * count; int percentPrice = (int)((price * 100) / percentBasePrice); ((IDictionary <string, object>)newRow)["aircraft"] = data[0]; ((IDictionary <string, object>)newRow)["count"] = data[1]; ((IDictionary <string, object>)newRow)["percent"] = String.Format("{0}%", percentCount); ((IDictionary <string, object>)newRow)["pricePercent"] = String.Format("{0}{1}%", inacc, percentPrice); StatBox.Items.Add(newRow); } }