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

@ -84,6 +84,8 @@ namespace RepositoryPattern
regWindow = new frmRegisterStock();
regWindow.Stocks = _stockMarketRepository.StockMarketList;
regWindow.ShowDialog();
_stockMemberRepository.InsertMany(regWindow.RegisteredStocks);
}
}
}

View File

@ -51,8 +51,13 @@ namespace RepositoryPattern
this.lblSoldDate = new System.Windows.Forms.Label();
this.txtComment = new System.Windows.Forms.TextBox();
this.lblComment = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.btnSaveStock = new System.Windows.Forms.Button();
this.lwRegBuffer = new System.Windows.Forms.ListView();
this.Stock = new System.Windows.Forms.ColumnHeader();
this.Price = new System.Windows.Forms.ColumnHeader();
this.Number = new System.Windows.Forms.ColumnHeader();
this.Comment = new System.Windows.Forms.ColumnHeader();
this.btnSaveToDB = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// cmbStockChoser
@ -128,6 +133,7 @@ namespace RepositoryPattern
this.txtBoughtAmount.Name = "txtBoughtAmount";
this.txtBoughtAmount.Size = new System.Drawing.Size(111, 23);
this.txtBoughtAmount.TabIndex = 9;
this.txtBoughtAmount.TextChanged += new System.EventHandler(this.txtBoughtAmount_TextChanged);
//
// lblBoughtAmount
//
@ -235,31 +241,74 @@ namespace RepositoryPattern
this.lblComment.TabIndex = 20;
this.lblComment.Text = "Comment";
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 15;
this.listBox1.Location = new System.Drawing.Point(39, 467);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(383, 94);
this.listBox1.TabIndex = 22;
//
// btnSaveStock
//
this.btnSaveStock.Location = new System.Drawing.Point(39, 424);
this.btnSaveStock.Location = new System.Drawing.Point(39, 385);
this.btnSaveStock.Name = "btnSaveStock";
this.btnSaveStock.Size = new System.Drawing.Size(75, 23);
this.btnSaveStock.TabIndex = 23;
this.btnSaveStock.Text = "Register";
this.btnSaveStock.UseVisualStyleBackColor = true;
this.btnSaveStock.Click += new System.EventHandler(this.btnSaveStock_Click);
//
// lwRegBuffer
//
this.lwRegBuffer.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Stock,
this.Price,
this.Number,
this.Comment});
this.lwRegBuffer.GridLines = true;
this.lwRegBuffer.HideSelection = false;
this.lwRegBuffer.Location = new System.Drawing.Point(39, 427);
this.lwRegBuffer.Name = "lwRegBuffer";
this.lwRegBuffer.Size = new System.Drawing.Size(383, 119);
this.lwRegBuffer.TabIndex = 24;
this.lwRegBuffer.UseCompatibleStateImageBehavior = false;
this.lwRegBuffer.View = System.Windows.Forms.View.Details;
//
// Stock
//
this.Stock.Name = "Stock";
this.Stock.Text = "Stock";
this.Stock.Width = 120;
//
// Price
//
this.Price.Name = "Price";
this.Price.Text = "Price";
this.Price.Width = 80;
//
// Number
//
this.Number.Name = "Number";
this.Number.Text = "Number";
this.Number.Width = 80;
//
// Comment
//
this.Comment.Name = "Comment";
this.Comment.Text = "Comment";
this.Comment.Width = 120;
//
// btnSaveToDB
//
this.btnSaveToDB.Location = new System.Drawing.Point(266, 567);
this.btnSaveToDB.Name = "btnSaveToDB";
this.btnSaveToDB.Size = new System.Drawing.Size(75, 23);
this.btnSaveToDB.TabIndex = 25;
this.btnSaveToDB.Text = "Save";
this.btnSaveToDB.UseVisualStyleBackColor = true;
this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click);
//
// frmRegisterStock
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(441, 602);
this.Controls.Add(this.btnSaveToDB);
this.Controls.Add(this.lwRegBuffer);
this.Controls.Add(this.btnSaveStock);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.txtComment);
this.Controls.Add(this.lblComment);
this.Controls.Add(this.txtSoldDate);
@ -283,6 +332,7 @@ namespace RepositoryPattern
this.Controls.Add(this.btnClose);
this.Controls.Add(this.cmbStockChoser);
this.Name = "frmRegisterStock";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "frmRegisterStock";
this.Shown += new System.EventHandler(this.frmRegisterStock_Shown);
this.ResumeLayout(false);
@ -314,7 +364,12 @@ namespace RepositoryPattern
private System.Windows.Forms.Label lblSoldDate;
private System.Windows.Forms.TextBox txtComment;
private System.Windows.Forms.Label lblComment;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button btnSaveStock;
private System.Windows.Forms.ListView lwRegBuffer;
private System.Windows.Forms.ColumnHeader Stock;
private System.Windows.Forms.ColumnHeader Price;
private System.Windows.Forms.ColumnHeader Number;
private System.Windows.Forms.ColumnHeader Comment;
private System.Windows.Forms.Button btnSaveToDB;
}
}

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()
{
@ -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;
}
}
}

View File

@ -7,8 +7,9 @@ namespace StockDal.Interface
public interface IStockMemberRepository
{
IEnumerable<StockMember> GetStocks();
bool Insert(StockMember stockMember);
//bool Insert(StockMember stockMember);
bool Update(StockMember stockMember);
bool Delete(string stockMemberId);
void InsertMany(List<StockMember> stockMembers);
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>

View File

@ -185,7 +185,7 @@ namespace StockDal
public void Clean()
{
driver.Quit();
driver?.Quit();
}
}

View File

@ -16,9 +16,35 @@ namespace StockDal
throw new NotImplementedException();
}
public bool Insert(StockMember stockMember)
public void InsertMany(List<StockMember> stockMembers)
{
throw new NotImplementedException();
using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
if (db.State == ConnectionState.Closed)
db.Open();
db.Execute(
@"INSERT INTO [dbo].[StockMember]
(StockId
,StockExtId
,BuyValue
,BuyDate
,ActValue
,ActDate
,SoldValue
,SoldDate
,Comment
,PostAmount)
VALUES
(@StockId
,@StockExtId
,@BuyValue
,@BuyDate
,@ActValue
,@ActDate
,@SoldValue
,@SoldDate
,@Comment
,@PostAmount)
", stockMembers);
}
public bool Update(StockMember stockMember)
@ -28,7 +54,7 @@ namespace StockDal
IEnumerable<StockMember> IStockMemberRepository.GetStocks()
{
using System.Data.IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
if (db.State == ConnectionState.Closed)
db.Open();
return db.Query<StockMember>(@"SELECT Id

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

View File

@ -12,13 +12,14 @@ namespace StockDomain
public string StockExtId { get; set; }
public decimal BuyValue { get; set; }
public DateTime BuyDate { get; set; }
public long BuyAmount { get; set; }
public decimal ActValue { get; set; }
public DateTime ActDate { get; set; }
public long ActAmount { get; set; }
public decimal SoldValue { get; set; }
public DateTime SoldDate { get; set; }
public DateTime? SoldDate { get; set; }
// public string PostId { get; set; }
public string Comment { get; set; }
public long PostAmount { get; set; }
}
}