Handles even selling
This commit is contained in:
@ -3,6 +3,7 @@ using Helpers;
|
||||
using StockDAL.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@ -21,6 +22,11 @@ namespace StockInfo
|
||||
}
|
||||
|
||||
private void frmSelling_Load(object sender, EventArgs e)
|
||||
{
|
||||
ReloadRemainingStocks();
|
||||
}
|
||||
|
||||
private void ReloadRemainingStocks()
|
||||
{
|
||||
remainingStocks = _stockRepository.GetAllRemainingStocks().ToList();
|
||||
foreach (var stock in remainingStocks)
|
||||
@ -56,11 +62,11 @@ namespace StockInfo
|
||||
txtStockId.Text = stkMemSelected.StockId;
|
||||
txtBuyDate.Text = stkMemSelected.BuyDate.ToShortDateString();
|
||||
txtBuyNumber.Text = stkMemSelected.PostAmount.ToString();
|
||||
txtBuyPrice.Text = stkMemSelected.BuyValue.ToString();
|
||||
txtBuyValue.Text = (stkMemSelected.BuyValue * stkMemSelected.PostAmount).ToString();
|
||||
txtBuyPrice.Text = stkMemSelected.BuyValue.ToString("N2");
|
||||
txtBuyValue.Text = (stkMemSelected.BuyValue * stkMemSelected.PostAmount).ToString("N2");
|
||||
|
||||
txtSoldDate.Text = DateTime.Today.ToShortDateString();
|
||||
txtSoldPrice.Text = stkMemSelected.ActValue.ToString();
|
||||
txtSoldPrice.Text = stkMemSelected.ActValue.ToString("N2");
|
||||
txtSoldAmount.Text = stkMemSelected.ActAmount.ToString();
|
||||
}
|
||||
|
||||
@ -87,7 +93,44 @@ namespace StockInfo
|
||||
{
|
||||
txtSellValue.Text = (decimal.Parse(txtSoldPrice.Text) * long.Parse(txtSoldAmount.Text)).ToString();
|
||||
txtRemainingNo.Text = stkMemSelected.ActAmount > 0 ? (stkMemSelected.PostAmount - long.Parse(txtSoldAmount.Text)).ToString() : 0.ToString();
|
||||
var gainLoose = (decimal.Parse(txtSellValue.Text) - decimal.Parse(txtBuyPrice.Text)*long.Parse(txtSoldAmount.Text));
|
||||
txtGainLoose.Text = gainLoose.ToString();
|
||||
if (gainLoose > 0)
|
||||
{
|
||||
txtGainLoose.BackColor = Color.LightGreen;
|
||||
}
|
||||
else if (gainLoose == 0)
|
||||
{
|
||||
txtGainLoose.BackColor = default;
|
||||
}
|
||||
else
|
||||
{
|
||||
txtGainLoose.BackColor = Color.LightPink;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnConfirm_Click(object sender, EventArgs e)
|
||||
{
|
||||
SellCurrentStock();
|
||||
}
|
||||
|
||||
private void SellCurrentStock()
|
||||
{
|
||||
if (txtSoldAmount.Text.IsNumeric() && txtSoldPrice.Text.IsNumeric())
|
||||
{
|
||||
_stockRepository.UpdateActualForSell(stkMemSelected.Id, int.Parse(txtSoldAmount.Text), decimal.Parse(txtSoldPrice.Text), DateTime.Parse(txtSoldDate.Text));
|
||||
var answer = MessageBox.Show($"Ok att sälja {stkMemSelected.StockId} ?","Selling" , MessageBoxButtons.OKCancel);
|
||||
if (DialogResult.OK == answer)
|
||||
{
|
||||
ReloadRemainingStocks();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Something wrong with amounts");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user