Edit stocklist. add stocks,

This commit is contained in:
2022-02-07 23:58:10 +01:00
parent b3d1a46c6c
commit d56e69b448
12 changed files with 87 additions and 43 deletions

View File

@ -54,6 +54,7 @@ namespace StockInfoCore
private void LoadStockData()
{
var stockChosen = _stockRepository.GetStockMember(CurrentStockMember);
txtStockName.Text = stockChosen.StockId;
txtStockExtId.Text = stockChosen.StockExtId;
txtActValue.Text = stockChosen.ActValue.ToString();
//txtActDate.Text = (DateTime.Today + stockChosen.ActDate.Value.TimeOfDay).ToString();
@ -83,14 +84,14 @@ namespace StockInfoCore
txtBuyDate.Text = stockChosen.BuyDate.ToString(); // = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
txtActValue.Text = stockChosen.ActValue.ToString(); // = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
txtActAmount.Text = stockChosen.ActAmount.ToString(); // = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
txtSoldDate.Text = stockChosen.SoldDate.ToString(); // = null; //DateTime.MaxValue;
txtSoldDate.Text = stockChosen.SoldDate == DateTime.MinValue ? String.Empty : stockChosen.SoldDate.ToString(); // = null; //DateTime.MaxValue;
txtSoldPrice.Text = stockChosen.SoldValue.ToString(); // = decimal.Parse("0");
txtComment.Text = stockChosen.Comment;
}
private void AddValidateData()
private void AddValidateData(bool New)
{
var currentStock = new StockMember();
currentStock.StockId = txtStockName.Text.Trim();
@ -101,10 +102,15 @@ namespace StockInfoCore
currentStock.BuyDate = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
currentStock.ActAmount = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text);
currentStock.SoldDate = DateTime.Parse(txtSoldDate.Text);
currentStock.SoldDate = txtSoldDate.Text.Trim() == "" ? DateTime.MinValue : DateTime.Parse(txtSoldDate.Text);
currentStock.SoldValue = decimal.Parse(txtSoldPrice.Text);
currentStock.Comment = txtComment.Text;
currentStock.Comment = txtComment.Text.Length<1?String.Empty: txtComment.Text;
//RegisteredStocks.Add(currentStock);
if (!New)
{
currentStock.Id = CurrentStockMember;
}
try
{
_stockRepository.SaveStockMember(currentStock);
@ -119,6 +125,7 @@ namespace StockInfoCore
private void initiateRegWin()
{
txtStockName.Text = "";
txtStockExtId.Text = "";
txtBuyPrice.Text = "";
txtBuyDate.Text = "";
@ -133,7 +140,7 @@ namespace StockInfoCore
private void btnSaveToDB_Click(object sender, EventArgs e)
{
AddValidateData();
AddValidateData(false);
}
private void txtBoughtAmount_TextChanged(object sender, EventArgs e)
@ -149,5 +156,10 @@ namespace StockInfoCore
e.DrawText();
}
}
private void btnSaveNew_Click(object sender, EventArgs e)
{
AddValidateData(true);
}
}
}