Latest sold info implemented
This commit is contained in:
14
DataDomain/LatestSoldStock.cs
Normal file
14
DataDomain/LatestSoldStock.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DataDomain
|
||||||
|
{
|
||||||
|
public class LatestSoldStock
|
||||||
|
{
|
||||||
|
public decimal SoldStockPrice { get; set; }
|
||||||
|
public DateTime? LatestSoldDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -43,10 +43,27 @@ namespace StockDAL
|
|||||||
entity.ActAmount = rest < 0 ? 0 : rest;
|
entity.ActAmount = rest < 0 ? 0 : rest;
|
||||||
entity.SoldDate = DateTime.Today;
|
entity.SoldDate = DateTime.Today;
|
||||||
entity.SoldValue = sellAmount * sellPrice;
|
entity.SoldValue = sellAmount * sellPrice;
|
||||||
|
entity.SoldStockPrice = sellPrice;
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LatestSoldStock LatestSell(string StockName)
|
||||||
|
{
|
||||||
|
using var context = new StockContext();
|
||||||
|
var result = (from stk in context.Stocks
|
||||||
|
where stk.StockId == StockName
|
||||||
|
&& stk.SoldDate == (from stk2 in context.Stocks
|
||||||
|
where stk2.StockId == stk.StockId
|
||||||
|
select stk2.SoldDate).Max()
|
||||||
|
select new LatestSoldStock
|
||||||
|
{
|
||||||
|
SoldStockPrice = stk.SoldStockPrice,
|
||||||
|
LatestSoldDate = stk.SoldDate
|
||||||
|
}).FirstOrDefault();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<StockMember> GetAllStocks()
|
public IEnumerable<StockMember> GetAllStocks()
|
||||||
{
|
{
|
||||||
@ -100,7 +117,8 @@ namespace StockDAL
|
|||||||
SoldValue = o.SoldValue,
|
SoldValue = o.SoldValue,
|
||||||
SoldDate = o.SoldDate,
|
SoldDate = o.SoldDate,
|
||||||
Comment = o.Comment,
|
Comment = o.Comment,
|
||||||
PostAmount = o.PostAmount
|
PostAmount = o.PostAmount,
|
||||||
|
SoldStockPrice = o.SoldStockPrice
|
||||||
}).ToList();
|
}).ToList();
|
||||||
context.Stocks.AddRange(insertStocks);
|
context.Stocks.AddRange(insertStocks);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|||||||
@ -12,6 +12,7 @@ namespace StockDAL.Interface
|
|||||||
IEnumerable<StockMember> GetAllRemainingStocks();
|
IEnumerable<StockMember> GetAllRemainingStocks();
|
||||||
IEnumerable<StockMember> GetAllStocks();
|
IEnumerable<StockMember> GetAllStocks();
|
||||||
void InsertMany(List<StockMember> stockMembers);
|
void InsertMany(List<StockMember> stockMembers);
|
||||||
|
LatestSoldStock LatestSell(string StockName);
|
||||||
void RemoveAllStocks();
|
void RemoveAllStocks();
|
||||||
void RestoreStockMembers(List<StockMember> stockMembers);
|
void RestoreStockMembers(List<StockMember> stockMembers);
|
||||||
void SaveStockMember(StockMember stockMember);
|
void SaveStockMember(StockMember stockMember);
|
||||||
|
|||||||
69
StockInfoCore/frmRegisterStock.Designer.cs
generated
69
StockInfoCore/frmRegisterStock.Designer.cs
generated
@ -58,12 +58,18 @@ namespace StockInfoCore
|
|||||||
this.Number = new System.Windows.Forms.ColumnHeader();
|
this.Number = new System.Windows.Forms.ColumnHeader();
|
||||||
this.Comment = new System.Windows.Forms.ColumnHeader();
|
this.Comment = new System.Windows.Forms.ColumnHeader();
|
||||||
this.btnSaveToDB = new System.Windows.Forms.Button();
|
this.btnSaveToDB = new System.Windows.Forms.Button();
|
||||||
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.txtLatestSoldPrice = new System.Windows.Forms.TextBox();
|
||||||
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
|
this.txtLatestSoldDate = new System.Windows.Forms.TextBox();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.groupBox1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// cmbStockChoser
|
// cmbStockChoser
|
||||||
//
|
//
|
||||||
this.cmbStockChoser.FormattingEnabled = true;
|
this.cmbStockChoser.FormattingEnabled = true;
|
||||||
this.cmbStockChoser.Location = new System.Drawing.Point(38, 39);
|
this.cmbStockChoser.Location = new System.Drawing.Point(38, 12);
|
||||||
this.cmbStockChoser.Name = "cmbStockChoser";
|
this.cmbStockChoser.Name = "cmbStockChoser";
|
||||||
this.cmbStockChoser.Size = new System.Drawing.Size(179, 23);
|
this.cmbStockChoser.Size = new System.Drawing.Size(179, 23);
|
||||||
this.cmbStockChoser.TabIndex = 0;
|
this.cmbStockChoser.TabIndex = 0;
|
||||||
@ -82,7 +88,7 @@ namespace StockInfoCore
|
|||||||
// lblStockExtId
|
// lblStockExtId
|
||||||
//
|
//
|
||||||
this.lblStockExtId.AutoSize = true;
|
this.lblStockExtId.AutoSize = true;
|
||||||
this.lblStockExtId.Location = new System.Drawing.Point(38, 78);
|
this.lblStockExtId.Location = new System.Drawing.Point(38, 44);
|
||||||
this.lblStockExtId.Name = "lblStockExtId";
|
this.lblStockExtId.Name = "lblStockExtId";
|
||||||
this.lblStockExtId.Size = new System.Drawing.Size(62, 15);
|
this.lblStockExtId.Size = new System.Drawing.Size(62, 15);
|
||||||
this.lblStockExtId.TabIndex = 2;
|
this.lblStockExtId.TabIndex = 2;
|
||||||
@ -90,7 +96,7 @@ namespace StockInfoCore
|
|||||||
//
|
//
|
||||||
// txtStockExtId
|
// txtStockExtId
|
||||||
//
|
//
|
||||||
this.txtStockExtId.Location = new System.Drawing.Point(153, 75);
|
this.txtStockExtId.Location = new System.Drawing.Point(153, 41);
|
||||||
this.txtStockExtId.Name = "txtStockExtId";
|
this.txtStockExtId.Name = "txtStockExtId";
|
||||||
this.txtStockExtId.Size = new System.Drawing.Size(269, 23);
|
this.txtStockExtId.Size = new System.Drawing.Size(269, 23);
|
||||||
this.txtStockExtId.TabIndex = 3;
|
this.txtStockExtId.TabIndex = 3;
|
||||||
@ -303,11 +309,59 @@ namespace StockInfoCore
|
|||||||
this.btnSaveToDB.UseVisualStyleBackColor = true;
|
this.btnSaveToDB.UseVisualStyleBackColor = true;
|
||||||
this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click);
|
this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click);
|
||||||
//
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.txtLatestSoldDate);
|
||||||
|
this.groupBox1.Controls.Add(this.label2);
|
||||||
|
this.groupBox1.Controls.Add(this.txtLatestSoldPrice);
|
||||||
|
this.groupBox1.Controls.Add(this.label1);
|
||||||
|
this.groupBox1.Location = new System.Drawing.Point(301, 81);
|
||||||
|
this.groupBox1.Name = "groupBox1";
|
||||||
|
this.groupBox1.Size = new System.Drawing.Size(255, 83);
|
||||||
|
this.groupBox1.TabIndex = 26;
|
||||||
|
this.groupBox1.TabStop = false;
|
||||||
|
this.groupBox1.Text = "Latest Sold";
|
||||||
|
//
|
||||||
|
// txtLatestSoldPrice
|
||||||
|
//
|
||||||
|
this.txtLatestSoldPrice.Location = new System.Drawing.Point(127, 23);
|
||||||
|
this.txtLatestSoldPrice.Name = "txtLatestSoldPrice";
|
||||||
|
this.txtLatestSoldPrice.ReadOnly = true;
|
||||||
|
this.txtLatestSoldPrice.Size = new System.Drawing.Size(111, 23);
|
||||||
|
this.txtLatestSoldPrice.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// label1
|
||||||
|
//
|
||||||
|
this.label1.AutoSize = true;
|
||||||
|
this.label1.Location = new System.Drawing.Point(12, 26);
|
||||||
|
this.label1.Name = "label1";
|
||||||
|
this.label1.Size = new System.Drawing.Size(59, 15);
|
||||||
|
this.label1.TabIndex = 6;
|
||||||
|
this.label1.Text = "Sold price";
|
||||||
|
//
|
||||||
|
// txtLatestSoldDate
|
||||||
|
//
|
||||||
|
this.txtLatestSoldDate.Location = new System.Drawing.Point(127, 52);
|
||||||
|
this.txtLatestSoldDate.Name = "txtLatestSoldDate";
|
||||||
|
this.txtLatestSoldDate.ReadOnly = true;
|
||||||
|
this.txtLatestSoldDate.Size = new System.Drawing.Size(111, 23);
|
||||||
|
this.txtLatestSoldDate.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(12, 55);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(56, 15);
|
||||||
|
this.label2.TabIndex = 8;
|
||||||
|
this.label2.Text = "Sold date";
|
||||||
|
//
|
||||||
// frmRegisterStock
|
// frmRegisterStock
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(441, 602);
|
this.ClientSize = new System.Drawing.Size(570, 602);
|
||||||
|
this.Controls.Add(this.groupBox1);
|
||||||
this.Controls.Add(this.btnSaveToDB);
|
this.Controls.Add(this.btnSaveToDB);
|
||||||
this.Controls.Add(this.lwRegBuffer);
|
this.Controls.Add(this.lwRegBuffer);
|
||||||
this.Controls.Add(this.btnSaveStock);
|
this.Controls.Add(this.btnSaveStock);
|
||||||
@ -337,6 +391,8 @@ namespace StockInfoCore
|
|||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "frmRegisterStock";
|
this.Text = "frmRegisterStock";
|
||||||
this.Shown += new System.EventHandler(this.frmRegisterStock_Shown);
|
this.Shown += new System.EventHandler(this.frmRegisterStock_Shown);
|
||||||
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
this.groupBox1.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -373,5 +429,10 @@ namespace StockInfoCore
|
|||||||
private System.Windows.Forms.ColumnHeader Number;
|
private System.Windows.Forms.ColumnHeader Number;
|
||||||
private System.Windows.Forms.ColumnHeader Comment;
|
private System.Windows.Forms.ColumnHeader Comment;
|
||||||
private System.Windows.Forms.Button btnSaveToDB;
|
private System.Windows.Forms.Button btnSaveToDB;
|
||||||
|
private System.Windows.Forms.GroupBox groupBox1;
|
||||||
|
private System.Windows.Forms.TextBox txtLatestSoldDate;
|
||||||
|
private System.Windows.Forms.Label label2;
|
||||||
|
private System.Windows.Forms.TextBox txtLatestSoldPrice;
|
||||||
|
private System.Windows.Forms.Label label1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using DataDomain;
|
using DataDomain;
|
||||||
|
using StockDAL.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
@ -14,12 +15,15 @@ namespace StockInfoCore
|
|||||||
public partial class frmRegisterStock : Form
|
public partial class frmRegisterStock : Form
|
||||||
{
|
{
|
||||||
Color hdr = Color.Red;
|
Color hdr = Color.Red;
|
||||||
|
private readonly IStockRepository _stockRepository;
|
||||||
|
|
||||||
public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
|
public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
|
||||||
public List<StockMember> RegisteredStocks { get; set; } = new List<StockMember>();
|
public List<StockMember> RegisteredStocks { get; set; } = new List<StockMember>();
|
||||||
|
|
||||||
public frmRegisterStock()
|
public frmRegisterStock(IStockRepository stockRepository)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_stockRepository = stockRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadStockCombo()
|
private void LoadStockCombo()
|
||||||
@ -50,6 +54,12 @@ namespace StockInfoCore
|
|||||||
txtStockExtId.Text = stockChosen.StockName;
|
txtStockExtId.Text = stockChosen.StockName;
|
||||||
txtActValue.Text = stockChosen.LatestPrice.ToString();
|
txtActValue.Text = stockChosen.LatestPrice.ToString();
|
||||||
txtActDate.Text = (DateTime.Today + stockChosen.TimeOfDay).ToString();
|
txtActDate.Text = (DateTime.Today + stockChosen.TimeOfDay).ToString();
|
||||||
|
var stockSold = _stockRepository.LatestSell(stockChosen.StockName.Trim());
|
||||||
|
if (stockSold != null)
|
||||||
|
{
|
||||||
|
txtLatestSoldDate.Text = stockSold.LatestSoldDate.Value.ToString();
|
||||||
|
txtLatestSoldPrice.Text = stockSold.SoldStockPrice.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnSaveStock_Click(object sender, EventArgs e)
|
private void btnSaveStock_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user