Handles even selling
This commit is contained in:
30
StockInfo/frmSelling.Designer.cs
generated
30
StockInfo/frmSelling.Designer.cs
generated
@ -50,6 +50,8 @@ namespace StockInfo
|
||||
this.txtId = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.gbSell = new System.Windows.Forms.GroupBox();
|
||||
this.txtGainLoose = new System.Windows.Forms.TextBox();
|
||||
this.label12 = new System.Windows.Forms.Label();
|
||||
this.btnConfirm = new System.Windows.Forms.Button();
|
||||
this.txtRemainingNo = new System.Windows.Forms.TextBox();
|
||||
this.label11 = new System.Windows.Forms.Label();
|
||||
@ -137,7 +139,7 @@ namespace StockInfo
|
||||
this.gbInfo.Controls.Add(this.label1);
|
||||
this.gbInfo.Location = new System.Drawing.Point(13, 170);
|
||||
this.gbInfo.Name = "gbInfo";
|
||||
this.gbInfo.Size = new System.Drawing.Size(276, 216);
|
||||
this.gbInfo.Size = new System.Drawing.Size(276, 250);
|
||||
this.gbInfo.TabIndex = 1;
|
||||
this.gbInfo.TabStop = false;
|
||||
this.gbInfo.Text = "Actual Stock";
|
||||
@ -246,6 +248,8 @@ namespace StockInfo
|
||||
//
|
||||
// gbSell
|
||||
//
|
||||
this.gbSell.Controls.Add(this.txtGainLoose);
|
||||
this.gbSell.Controls.Add(this.label12);
|
||||
this.gbSell.Controls.Add(this.btnConfirm);
|
||||
this.gbSell.Controls.Add(this.txtRemainingNo);
|
||||
this.gbSell.Controls.Add(this.label11);
|
||||
@ -259,19 +263,37 @@ namespace StockInfo
|
||||
this.gbSell.Controls.Add(this.label7);
|
||||
this.gbSell.Location = new System.Drawing.Point(296, 170);
|
||||
this.gbSell.Name = "gbSell";
|
||||
this.gbSell.Size = new System.Drawing.Size(236, 216);
|
||||
this.gbSell.Size = new System.Drawing.Size(236, 250);
|
||||
this.gbSell.TabIndex = 2;
|
||||
this.gbSell.TabStop = false;
|
||||
this.gbSell.Text = "Sell decision";
|
||||
//
|
||||
// txtGainLoose
|
||||
//
|
||||
this.txtGainLoose.Location = new System.Drawing.Point(121, 165);
|
||||
this.txtGainLoose.Name = "txtGainLoose";
|
||||
this.txtGainLoose.ReadOnly = true;
|
||||
this.txtGainLoose.Size = new System.Drawing.Size(73, 23);
|
||||
this.txtGainLoose.TabIndex = 14;
|
||||
//
|
||||
// label12
|
||||
//
|
||||
this.label12.AutoSize = true;
|
||||
this.label12.Location = new System.Drawing.Point(12, 168);
|
||||
this.label12.Name = "label12";
|
||||
this.label12.Size = new System.Drawing.Size(73, 15);
|
||||
this.label12.TabIndex = 13;
|
||||
this.label12.Text = "Gain / Loose";
|
||||
//
|
||||
// btnConfirm
|
||||
//
|
||||
this.btnConfirm.Location = new System.Drawing.Point(121, 165);
|
||||
this.btnConfirm.Location = new System.Drawing.Point(121, 221);
|
||||
this.btnConfirm.Name = "btnConfirm";
|
||||
this.btnConfirm.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnConfirm.TabIndex = 12;
|
||||
this.btnConfirm.Text = "Confirm";
|
||||
this.btnConfirm.UseVisualStyleBackColor = true;
|
||||
this.btnConfirm.Click += new System.EventHandler(this.btnConfirm_Click);
|
||||
//
|
||||
// txtRemainingNo
|
||||
//
|
||||
@ -411,5 +433,7 @@ namespace StockInfo
|
||||
private System.Windows.Forms.Label label8;
|
||||
private System.Windows.Forms.TextBox txtSoldDate;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.TextBox txtGainLoose;
|
||||
private System.Windows.Forms.Label label12;
|
||||
}
|
||||
}
|
||||
@ -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