diff --git a/RepositoryPattern/frmMyStocks.Designer.cs b/RepositoryPattern/frmMyStocks.Designer.cs index 818bc33..c9f12e4 100644 --- a/RepositoryPattern/frmMyStocks.Designer.cs +++ b/RepositoryPattern/frmMyStocks.Designer.cs @@ -29,6 +29,7 @@ namespace RepositoryPattern /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.lvMyStocks = new System.Windows.Forms.ListView(); this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); this.columnHeader2 = new System.Windows.Forms.ColumnHeader(); @@ -46,6 +47,8 @@ namespace RepositoryPattern this.txtTotDiff = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.txtCurrValue = new System.Windows.Forms.TextBox(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.chkAutoReload = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // lvMyStocks @@ -186,11 +189,28 @@ namespace RepositoryPattern this.txtCurrValue.Size = new System.Drawing.Size(100, 23); this.txtCurrValue.TabIndex = 5; // + // timer1 + // + this.timer1.Interval = 150000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // chkAutoReload + // + this.chkAutoReload.AutoSize = true; + this.chkAutoReload.Location = new System.Drawing.Point(13, 7); + this.chkAutoReload.Name = "chkAutoReload"; + this.chkAutoReload.Size = new System.Drawing.Size(121, 19); + this.chkAutoReload.TabIndex = 7; + this.chkAutoReload.Text = "Automatic Reload"; + this.chkAutoReload.UseVisualStyleBackColor = true; + this.chkAutoReload.CheckedChanged += new System.EventHandler(this.chkAutoReload_CheckedChanged); + // // 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.chkAutoReload); this.Controls.Add(this.label3); this.Controls.Add(this.txtCurrValue); this.Controls.Add(this.label2); @@ -226,5 +246,7 @@ namespace RepositoryPattern private System.Windows.Forms.TextBox txtTotDiff; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox txtCurrValue; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.CheckBox chkAutoReload; } } \ No newline at end of file diff --git a/RepositoryPattern/frmMyStocks.cs b/RepositoryPattern/frmMyStocks.cs index e60edf4..6fc5e96 100644 --- a/RepositoryPattern/frmMyStocks.cs +++ b/RepositoryPattern/frmMyStocks.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; - +// namespace RepositoryPattern { public partial class frmMyStocks : Form @@ -38,6 +38,10 @@ namespace RepositoryPattern private void ReloadData() { CurrentStocks = _stockMemberRepository.GetStocks(); + lvMyStocks.Items.Clear(); + BoughtSum = 0m; + TotalDiff = 0m; + CurrentSum = 0m; foreach(var stock in CurrentStocks) { stock.ActValue = Stocks[stock.StockId.Trim()].LatestPrice; @@ -54,6 +58,12 @@ namespace RepositoryPattern txtTotDiff.Refresh(); } + private void TotalReload() + { + Stocks = _stockMarketRepository.StockMarketList; + ReloadData(); + } + private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { using (Brush hBr = new SolidBrush(hdrColor)) @@ -85,11 +95,11 @@ namespace RepositoryPattern lv.SubItems.Add(owned.ToString()); if (diffValue < 0) { - lv.BackColor = Color.Red; + lv.BackColor = Color.Pink; } else { - lv.BackColor = Color.Green; + lv.BackColor = Color.LightGreen; } } @@ -97,5 +107,15 @@ namespace RepositoryPattern { ReloadData(); } + + private void timer1_Tick(object sender, EventArgs e) + { + TotalReload(); + } + + private void chkAutoReload_CheckedChanged(object sender, EventArgs e) + { + timer1.Enabled = chkAutoReload.Checked; + } } }