private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int i = 0; foreach (company company in concreteSub.getCompanies()) { if (comboBox1.SelectedIndex == i) { newCompany = company; break; } else { i++; } } }
public void update() { dataGridView1.Rows.Clear(); dataGridView1.Refresh(); foreach (company company in StockMarket.getCompanies()) { if (company.Name == companyName) { newCompany = company; break; } } int[] number = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Double[] price = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] volume = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int index = 0; var firstBuyPrice = newCompany.getBuyOrders().FirstOrDefault(); if (firstBuyPrice != null) { price[index] = firstBuyPrice.Price; } foreach (Order B in newCompany.getBuyOrders()) { if (price[index] == B.Price) { number[index]++; volume[index] += B.Size; } else { index++; number[index] = 1; price[index] = B.Price; volume[index] = B.Size; } } for (int j = 0; j < 10; j++) { string[] row1 = { (price[j] == 0 ? "" : number[j].ToString()), (volume[j] == 0 ? "" :volume[j].ToString()), (price[j] == 0 ? "" : price[j].ToString()) }; dataGridView1.Rows.Add(row1); } int[] number2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Double[] price2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] volume2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int index2 = 0; var firstSellPrice = newCompany.getSellOrders().FirstOrDefault(); if (firstSellPrice != null) { price[index2] = firstSellPrice.Price; } foreach (Order S in newCompany.getSellOrders()) { if (price2[index2] == S.Price) { number2[index2]++; volume2[index2] += S.Size; } else { index2++; number2[index2] = 1; price2[index2] = S.Price; volume2[index2] = S.Size; } } for (int k = 0; k < 10; k++) { dataGridView1[3, k].Value = (price2[k] == 0 ? "" : price2[k].ToString()); dataGridView1[4, k].Value = (volume2[k] == 0 ? "" : volume2[k].ToString()); dataGridView1[5, k].Value = (price2[k] == 0 ? "" : number2[k].ToString()); } }
public void addCompany(String symbol, String name, double price) { company newCompany = new company(symbol, name, price, this); companies.Add(newCompany); }