private void CalculateOutcome() { List <HistoryView> avaiableInvestments = SqlConnector.GetHistoryView_All(); double sum = 0; double sumInvested = 0; double percent; foreach (HistoryView iv in avaiableInvestments) { sum += iv.Difference; sumInvested += iv.ValuePurchased; } percent = (100 * (sumInvested + sum) / sumInvested) - 100; this.HistoryValueLabel.Text = ($"{sum.ToString("0.00")} ({percent.ToString("0.00")}%)"); if (sum > 0) { this.HistoryValueLabel.ForeColor = Color.Green; } else { this.HistoryValueLabel.ForeColor = Color.Red; } }
public HistoryInvestments() { InitializeComponent(); this.HistoryDataGridView.DataSource = SqlConnector.GetHistoryView_All(); CalculateOutcome(); }