private void AddCoin_Click(object sender, EventArgs e) { using (var form = new FrmManageCoins(true, _coinConfigs)) { if (form.ShowDialog() != DialogResult.OK) { return; } if (!_coinNames.Any(c => c.ExtEquals(form.SelectedCoin))) { MessageBox.Show("Coin does not exist.", "Error"); return; } _coinConfigs.Add(new CoinConfig { Name = form.SelectedCoin, Bought = 0, Paid = 0, StartupPrice = 0, Index = _coinConfigs.Count(c => c.Name.ExtEquals(form.SelectedCoin)) }); _loadLines = true; SelectPortfolio(string.Empty); } }
private void RemoveCoin_Click(object sender, EventArgs e) { using (var form = new FrmManageCoins(false, _coinConfigs)) { if (form.ShowDialog() != DialogResult.OK) { return; } _coinConfigs.RemoveAll(a => a.Name.ExtEquals(form.SelectedCoin) && a.Index == form.SelectedCoinIndex); _coinConfigs.ForEach(x => x.Index = 0); //Reset coin indexes foreach (var coinName in _coinConfigs.Select(x => x.Name).Distinct().ToList()) { var index = 0; foreach (var config in _coinConfigs.Where(x => x.Name == coinName).ToList()) { config.Index = index++; } } } _loadLines = true; SelectPortfolio(string.Empty); }