It is now possible to register owned stocks for keeping track on them

This commit is contained in:
2021-01-28 20:20:33 +01:00
parent ec71d60a2a
commit 3f737a8010
10 changed files with 174 additions and 24 deletions

View File

@ -15,6 +15,7 @@ namespace RepositoryPattern
{
public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
public List<StockMember> RegisteredStocks { get; set; } = new List<StockMember>();
public frmRegisterStock()
{
@ -25,7 +26,7 @@ namespace RepositoryPattern
{
if (Stocks.Count() > 0)
{
foreach(var key in Stocks.Keys)
foreach (var key in Stocks.Keys)
{
cmbStockChoser.Items.Add(key);
}
@ -50,5 +51,69 @@ namespace RepositoryPattern
txtActValue.Text = stockChosen.LatestPrice.ToString();
txtActDate.Text = (DateTime.Today + stockChosen.TimeOfDay).ToString();
}
private void btnSaveStock_Click(object sender, EventArgs e)
{
AddValidateData();
RefreshListViewFromRegList();
}
private void RefreshListViewFromRegList()
{
lwRegBuffer.Items.Clear();
foreach (var currStock in RegisteredStocks)
{
AddItemToListView(currStock);
}
}
private void AddItemToListView(StockMember currStock)
{
var lv = lwRegBuffer.Items.Add(currStock.StockId);
lv.SubItems.Add(currStock.BuyValue.ToString());
lv.SubItems.Add(currStock.PostAmount.ToString());
lv.SubItems.Add(currStock.Comment);
}
private void AddValidateData()
{
var currentStock = new StockMember();
currentStock.StockId = cmbStockChoser.SelectedItem.ToString();
currentStock.StockExtId = txtStockExtId.Text;
currentStock.BuyValue = decimal.Parse(string.IsNullOrEmpty(txtBuyPrice.Text) ? "0" : txtBuyPrice.Text);
currentStock.PostAmount = long.Parse(string.IsNullOrEmpty(txtBoughtAmount.Text) ? "0" : txtBoughtAmount.Text);
currentStock.ActDate = DateTime.Parse(txtActDate.Text);
currentStock.BuyDate = DateTime.Today;
currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
currentStock.SoldDate = null; //DateTime.MaxValue;
currentStock.SoldValue = decimal.Parse("0");
currentStock.Comment = txtComment.Text;
RegisteredStocks.Add(currentStock);
initiateRegWin();
}
private void initiateRegWin()
{
txtStockExtId.Text = "";
txtBuyPrice.Text = "";
txtBuyDate.Text = "";
txtBoughtAmount.Text = "";
txtActValue.Text = "";
txtActDate.Text = "";
txtActAmount.Text = "";
txtSoldPrice.Text = "";
txtSoldDate.Text = "";
txtComment.Text = "";
}
private void btnSaveToDB_Click(object sender, EventArgs e)
{
}
private void txtBoughtAmount_TextChanged(object sender, EventArgs e)
{
txtActAmount.Text = txtBoughtAmount.Text;
}
}
}