/// <summary>Lets the user record an operation.</summary> private void OpRecord(Operation op) { using (var dlg = new FormOp(op, stocks.ToDictionary(stk => stk.Key, stk => stk.Value.Shares))) { var ans = dlg.ShowDialog(this); if (ans != DialogResult.OK) { return; } bool already = stocks.ContainsKey(dlg.StockName); if (already) { var stk = stocks[dlg.StockName]; stk.Shares += dlg.Shares; // Update GUI: var irow = GetRow(dlg.StockName); GetCell(irow, colShares).Value = stk.Shares; db.OpRecord(false, dlg.StockName, dlg.Date, dlg.Shares, dlg.Total, dlg.Comment); ProcessInput((string)GetCell(irow, colPrice).Value, irow); // only after the database is updated! } else // new stock in portfolio { AddStock(dlg.StockName, dlg.Shares); db.OpRecord(true, dlg.StockName, dlg.Date, dlg.Shares, dlg.Total, dlg.Comment); } } }
private void OpRecord(Operation op) { using (var dlg = new FormOp(op, GetPortfolio())) { var ans = dlg.ShowDialog(this); if (ans != DialogResult.OK) { return; } Model.Portfolio.AddShares(this, dlg.StockName, dlg.Shares, dlg.Total, dlg.Date, dlg.Comment); } }