diff --git a/RepositoryPattern/frmInitial.Designer.cs b/RepositoryPattern/frmInitial.Designer.cs
index 81f4d82..193fd18 100644
--- a/RepositoryPattern/frmInitial.Designer.cs
+++ b/RepositoryPattern/frmInitial.Designer.cs
@@ -41,6 +41,7 @@ namespace RepositoryPattern
this.chbShowBrowser = new System.Windows.Forms.CheckBox();
this.gbStockMgmnt = new System.Windows.Forms.GroupBox();
this.btnStockReg = new System.Windows.Forms.Button();
+ this.btnValueView = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.gB1.SuspendLayout();
this.gbStockMgmnt.SuspendLayout();
@@ -151,6 +152,7 @@ namespace RepositoryPattern
//
// gbStockMgmnt
//
+ this.gbStockMgmnt.Controls.Add(this.btnValueView);
this.gbStockMgmnt.Controls.Add(this.btnStockReg);
this.gbStockMgmnt.Location = new System.Drawing.Point(411, 411);
this.gbStockMgmnt.Name = "gbStockMgmnt";
@@ -168,6 +170,16 @@ namespace RepositoryPattern
this.btnStockReg.UseVisualStyleBackColor = true;
this.btnStockReg.Click += new System.EventHandler(this.btnStockReg_Click);
//
+ // btnValueView
+ //
+ this.btnValueView.Location = new System.Drawing.Point(7, 39);
+ this.btnValueView.Name = "btnValueView";
+ this.btnValueView.Size = new System.Drawing.Size(95, 23);
+ this.btnValueView.TabIndex = 1;
+ this.btnValueView.Text = "See values";
+ this.btnValueView.UseVisualStyleBackColor = true;
+ this.btnValueView.Click += new System.EventHandler(this.btnValueView_Click);
+ //
// frmInitial
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -210,6 +222,7 @@ namespace RepositoryPattern
private System.Windows.Forms.CheckBox chbShowBrowser;
private System.Windows.Forms.GroupBox gbStockMgmnt;
private System.Windows.Forms.Button btnStockReg;
+ private System.Windows.Forms.Button btnValueView;
}
}
diff --git a/RepositoryPattern/frmInitial.cs b/RepositoryPattern/frmInitial.cs
index ffc3ff5..b3ec877 100644
--- a/RepositoryPattern/frmInitial.cs
+++ b/RepositoryPattern/frmInitial.cs
@@ -13,11 +13,12 @@ namespace RepositoryPattern
{
public partial class frmInitial : Form
{
- IProductRepository _productRepository;
+ private readonly IProductRepository _productRepository;
private readonly IStockMemberRepository _stockMemberRepository;
private readonly IStockMarketRepository _stockMarketRepository;
- private frmRegisterStock regWindow;
+ private frmRegisterStock regWindow;
+ private frmMyStocks stockWindow;
public frmInitial(IProductRepository productRepository, IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository)
{
@@ -80,13 +81,28 @@ namespace RepositoryPattern
{
if (rdbStock.Checked)
{
+ Cursor.Current = Cursors.WaitCursor;
_stockMarketRepository.LoadStockMarketList();
regWindow = new frmRegisterStock();
regWindow.Stocks = _stockMarketRepository.StockMarketList;
+ Cursor.Current = DefaultCursor;
regWindow.ShowDialog();
_stockMemberRepository.InsertMany(regWindow.RegisteredStocks);
}
}
+
+ private void btnValueView_Click(object sender, EventArgs e)
+ {
+ if (rdbStock.Checked)
+ {
+ Cursor.Current = Cursors.WaitCursor;
+ _stockMarketRepository.LoadStockMarketList();
+ stockWindow = new frmMyStocks(_productRepository,_stockMemberRepository,_stockMarketRepository);
+ stockWindow.Stocks = _stockMarketRepository.StockMarketList;
+ Cursor.Current = DefaultCursor;
+ stockWindow.ShowDialog();
+ }
+ }
}
}
diff --git a/RepositoryPattern/frmMyStocks.Designer.cs b/RepositoryPattern/frmMyStocks.Designer.cs
new file mode 100644
index 0000000..818bc33
--- /dev/null
+++ b/RepositoryPattern/frmMyStocks.Designer.cs
@@ -0,0 +1,230 @@
+
+namespace RepositoryPattern
+{
+ partial class frmMyStocks
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.lvMyStocks = new System.Windows.Forms.ListView();
+ this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader9 = new System.Windows.Forms.ColumnHeader();
+ this.columnHeader10 = new System.Windows.Forms.ColumnHeader();
+ this.txtBuyTotal = new System.Windows.Forms.TextBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.txtTotDiff = new System.Windows.Forms.TextBox();
+ this.label3 = new System.Windows.Forms.Label();
+ this.txtCurrValue = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // lvMyStocks
+ //
+ this.lvMyStocks.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.lvMyStocks.BackColor = System.Drawing.SystemColors.InactiveCaption;
+ this.lvMyStocks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.columnHeader1,
+ this.columnHeader2,
+ this.columnHeader3,
+ this.columnHeader4,
+ this.columnHeader5,
+ this.columnHeader6,
+ this.columnHeader7,
+ this.columnHeader8,
+ this.columnHeader9,
+ this.columnHeader10});
+ this.lvMyStocks.GridLines = true;
+ this.lvMyStocks.HideSelection = false;
+ this.lvMyStocks.Location = new System.Drawing.Point(12, 32);
+ this.lvMyStocks.Name = "lvMyStocks";
+ this.lvMyStocks.Size = new System.Drawing.Size(911, 278);
+ this.lvMyStocks.TabIndex = 0;
+ this.lvMyStocks.UseCompatibleStateImageBehavior = false;
+ this.lvMyStocks.View = System.Windows.Forms.View.Details;
+ this.lvMyStocks.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.lvMyStocks_DrawColumnHeader);
+ //
+ // columnHeader1
+ //
+ this.columnHeader1.Name = "columnHeader1";
+ this.columnHeader1.Text = "Stock Name";
+ this.columnHeader1.Width = 80;
+ //
+ // columnHeader2
+ //
+ this.columnHeader2.Name = "columnHeader2";
+ this.columnHeader2.Text = "Buy Price";
+ this.columnHeader2.Width = 80;
+ //
+ // columnHeader3
+ //
+ this.columnHeader3.Name = "columnHeader3";
+ this.columnHeader3.Text = "Amount Stk";
+ this.columnHeader3.Width = 80;
+ //
+ // columnHeader4
+ //
+ this.columnHeader4.Name = "columnHeader4";
+ this.columnHeader4.Text = "Buy Date";
+ this.columnHeader4.Width = 80;
+ //
+ // columnHeader5
+ //
+ this.columnHeader5.Name = "columnHeader5";
+ this.columnHeader5.Text = "Value diff";
+ //
+ // columnHeader6
+ //
+ this.columnHeader6.Name = "columnHeader6";
+ this.columnHeader6.Text = "Value diff %";
+ this.columnHeader6.Width = 80;
+ //
+ // columnHeader7
+ //
+ this.columnHeader7.Name = "columnHeader7";
+ this.columnHeader7.Text = "Market price";
+ this.columnHeader7.Width = 80;
+ //
+ // columnHeader8
+ //
+ this.columnHeader8.Name = "columnHeader8";
+ this.columnHeader8.Text = "Market Date";
+ this.columnHeader8.Width = 80;
+ //
+ // columnHeader9
+ //
+ this.columnHeader9.Name = "columnHeader9";
+ this.columnHeader9.Text = "Current value";
+ this.columnHeader9.Width = 80;
+ //
+ // columnHeader10
+ //
+ this.columnHeader10.Name = "columnHeader10";
+ this.columnHeader10.Text = "Owned days";
+ //
+ // txtBuyTotal
+ //
+ this.txtBuyTotal.Location = new System.Drawing.Point(163, 321);
+ this.txtBuyTotal.Name = "txtBuyTotal";
+ this.txtBuyTotal.ReadOnly = true;
+ this.txtBuyTotal.Size = new System.Drawing.Size(100, 23);
+ this.txtBuyTotal.TabIndex = 1;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.label1.Location = new System.Drawing.Point(56, 319);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(101, 21);
+ this.label1.TabIndex = 2;
+ this.label1.Text = "Bought Totalt";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.label2.Location = new System.Drawing.Point(269, 319);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(55, 21);
+ this.label2.TabIndex = 4;
+ this.label2.Text = "TotDiff";
+ //
+ // txtTotDiff
+ //
+ this.txtTotDiff.Location = new System.Drawing.Point(330, 321);
+ this.txtTotDiff.Name = "txtTotDiff";
+ this.txtTotDiff.ReadOnly = true;
+ this.txtTotDiff.Size = new System.Drawing.Size(100, 23);
+ this.txtTotDiff.TabIndex = 3;
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.label3.Location = new System.Drawing.Point(509, 319);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(105, 21);
+ this.label3.TabIndex = 6;
+ this.label3.Text = "Current Value";
+ //
+ // txtCurrValue
+ //
+ this.txtCurrValue.Location = new System.Drawing.Point(620, 321);
+ this.txtCurrValue.Name = "txtCurrValue";
+ this.txtCurrValue.ReadOnly = true;
+ this.txtCurrValue.Size = new System.Drawing.Size(100, 23);
+ this.txtCurrValue.TabIndex = 5;
+ //
+ // frmMyStocks
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(935, 481);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.txtCurrValue);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.txtTotDiff);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.txtBuyTotal);
+ this.Controls.Add(this.lvMyStocks);
+ this.Name = "frmMyStocks";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "frmMyStocks";
+ this.Shown += new System.EventHandler(this.frmMyStocks_Shown);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.ListView lvMyStocks;
+ private System.Windows.Forms.ColumnHeader columnHeader1;
+ private System.Windows.Forms.ColumnHeader columnHeader2;
+ private System.Windows.Forms.ColumnHeader columnHeader3;
+ private System.Windows.Forms.ColumnHeader columnHeader4;
+ private System.Windows.Forms.ColumnHeader columnHeader5;
+ private System.Windows.Forms.ColumnHeader columnHeader6;
+ private System.Windows.Forms.ColumnHeader columnHeader7;
+ private System.Windows.Forms.ColumnHeader columnHeader8;
+ private System.Windows.Forms.ColumnHeader columnHeader9;
+ private System.Windows.Forms.ColumnHeader columnHeader10;
+ private System.Windows.Forms.TextBox txtBuyTotal;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.TextBox txtTotDiff;
+ private System.Windows.Forms.Label label3;
+ private System.Windows.Forms.TextBox txtCurrValue;
+ }
+}
\ No newline at end of file
diff --git a/RepositoryPattern/frmMyStocks.cs b/RepositoryPattern/frmMyStocks.cs
new file mode 100644
index 0000000..e60edf4
--- /dev/null
+++ b/RepositoryPattern/frmMyStocks.cs
@@ -0,0 +1,101 @@
+using StockDal.Interface;
+using StockDomain;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace RepositoryPattern
+{
+ public partial class frmMyStocks : Form
+ {
+ Color hdrColor;
+ private readonly IProductRepository _productRepository;
+ private readonly IStockMemberRepository _stockMemberRepository;
+ private readonly IStockMarketRepository _stockMarketRepository;
+ public decimal BoughtSum { get; set; }
+ public decimal TotalDiff { get; set; }
+ public decimal CurrentSum { get; set; }
+
+ public Dictionary Stocks { get; set; }
+ public IEnumerable CurrentStocks { get; set; }
+
+ public frmMyStocks(IProductRepository productRepository, IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository)
+ {
+ hdrColor = Color.CadetBlue;
+ InitializeComponent();
+ _productRepository = productRepository;
+ _stockMemberRepository = stockMemberRepository;
+ _stockMarketRepository = stockMarketRepository;
+ }
+
+
+ private void ReloadData()
+ {
+ CurrentStocks = _stockMemberRepository.GetStocks();
+ foreach(var stock in CurrentStocks)
+ {
+ stock.ActValue = Stocks[stock.StockId.Trim()].LatestPrice;
+ stock.ActDate = DateTime.Today;
+ _stockMemberRepository.UpdateActPrice(stock.Id, stock.ActValue);
+ AddItemToListView(stock);
+ }
+
+ txtBuyTotal.Text = BoughtSum.ToString();
+ txtBuyTotal.Refresh();
+ txtCurrValue.Text = CurrentSum.ToString();
+ txtCurrValue.Refresh();
+ txtTotDiff.Text = TotalDiff.ToString();
+ txtTotDiff.Refresh();
+ }
+
+ private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
+ {
+ using (Brush hBr = new SolidBrush(hdrColor))
+ {
+ e.Graphics.FillRectangle(hBr, e.Bounds);
+ e.DrawText();
+ }
+ }
+
+ private void AddItemToListView(StockMember currStock)
+ {
+ var lv = lvMyStocks.Items.Add(currStock.StockId);
+ lv.SubItems.Add(currStock.BuyValue.ToString());
+ lv.SubItems.Add(currStock.PostAmount.ToString());
+ lv.SubItems.Add(currStock.BuyDate.ToString());
+ var buyValue = currStock.PostAmount * currStock.BuyValue;
+ var actValue = currStock.PostAmount * currStock.ActValue;
+ var diffValue = actValue - buyValue;
+ var diffproc = diffValue / buyValue * 100;
+ BoughtSum += buyValue;
+ TotalDiff += diffValue;
+ CurrentSum += actValue;
+ var lvs = lv.SubItems.Add(diffValue.ToString());
+ lv.SubItems.Add(Math.Round(diffproc,2).ToString());
+ lv.SubItems.Add(currStock.ActValue.ToString());
+ lv.SubItems.Add(currStock.ActDate.ToString());
+ lv.SubItems.Add(actValue.ToString());
+ var owned = (DateTime.Today - currStock.BuyDate).TotalDays;
+ lv.SubItems.Add(owned.ToString());
+ if (diffValue < 0)
+ {
+ lv.BackColor = Color.Red;
+ }
+ else
+ {
+ lv.BackColor = Color.Green;
+ }
+ }
+
+ private void frmMyStocks_Shown(object sender, EventArgs e)
+ {
+ ReloadData();
+ }
+ }
+}
diff --git a/RepositoryPattern/frmMyStocks.resx b/RepositoryPattern/frmMyStocks.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/RepositoryPattern/frmMyStocks.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/RepositoryPattern/frmRegisterStock.Designer.cs b/RepositoryPattern/frmRegisterStock.Designer.cs
index 2a55d37..6ffad6e 100644
--- a/RepositoryPattern/frmRegisterStock.Designer.cs
+++ b/RepositoryPattern/frmRegisterStock.Designer.cs
@@ -259,6 +259,7 @@ namespace RepositoryPattern
this.Number,
this.Comment});
this.lwRegBuffer.GridLines = true;
+ this.lwRegBuffer.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lwRegBuffer.HideSelection = false;
this.lwRegBuffer.Location = new System.Drawing.Point(39, 427);
this.lwRegBuffer.Name = "lwRegBuffer";
@@ -266,6 +267,7 @@ namespace RepositoryPattern
this.lwRegBuffer.TabIndex = 24;
this.lwRegBuffer.UseCompatibleStateImageBehavior = false;
this.lwRegBuffer.View = System.Windows.Forms.View.Details;
+ this.lwRegBuffer.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.lwRegBuffer_DrawColumnHeader);
//
// Stock
//
diff --git a/RepositoryPattern/frmRegisterStock.cs b/RepositoryPattern/frmRegisterStock.cs
index 193137b..d38c448 100644
--- a/RepositoryPattern/frmRegisterStock.cs
+++ b/RepositoryPattern/frmRegisterStock.cs
@@ -13,7 +13,7 @@ namespace RepositoryPattern
{
public partial class frmRegisterStock : Form
{
-
+ Color hdr = Color.Red;
public Dictionary Stocks { get; set; }
public List RegisteredStocks { get; set; } = new List();
@@ -73,6 +73,7 @@ namespace RepositoryPattern
lv.SubItems.Add(currStock.BuyValue.ToString());
lv.SubItems.Add(currStock.PostAmount.ToString());
lv.SubItems.Add(currStock.Comment);
+ //lv.BackColor = Color.Aquamarine;
}
private void AddValidateData()
@@ -83,7 +84,7 @@ namespace RepositoryPattern
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.BuyDate = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text);
currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text);
currentStock.SoldDate = null; //DateTime.MaxValue;
currentStock.SoldValue = decimal.Parse("0");
@@ -115,5 +116,14 @@ namespace RepositoryPattern
{
txtActAmount.Text = txtBoughtAmount.Text;
}
+
+ private void lwRegBuffer_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
+ {
+ using (Brush hBr = new SolidBrush(hdr))
+ {
+ e.Graphics.FillRectangle(hBr, e.Bounds);
+ e.DrawText();
+ }
+ }
}
}
diff --git a/StockDal.Interface/IStockMemberRepository.cs b/StockDal.Interface/IStockMemberRepository.cs
index b8271c3..f9bb483 100644
--- a/StockDal.Interface/IStockMemberRepository.cs
+++ b/StockDal.Interface/IStockMemberRepository.cs
@@ -8,7 +8,7 @@ namespace StockDal.Interface
{
IEnumerable GetStocks();
//bool Insert(StockMember stockMember);
- bool Update(StockMember stockMember);
+ void UpdateActPrice(int Id, decimal price);
bool Delete(string stockMemberId);
void InsertMany(List stockMembers);
}
diff --git a/StockDal/StockMemberRepository.cs b/StockDal/StockMemberRepository.cs
index a21bf86..efe28a2 100644
--- a/StockDal/StockMemberRepository.cs
+++ b/StockDal/StockMemberRepository.cs
@@ -47,9 +47,18 @@ namespace StockDal
", stockMembers);
}
- public bool Update(StockMember stockMember)
+ public void UpdateActPrice(int Id, decimal price)
{
- throw new NotImplementedException();
+ using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
+ if (db.State == ConnectionState.Closed)
+ db.Open();
+
+ db.Execute(
+ @"UPDATE [dbo].[StockMember]
+ SET ActValue = @val,
+ ActDate = @date
+ WHERE Id = @id
+ ", new { val = price, date = DateTime.Today, id = Id });
}
IEnumerable IStockMemberRepository.GetStocks()