Infered timercontrol and continous update
This commit is contained in:
22
RepositoryPattern/frmMyStocks.Designer.cs
generated
22
RepositoryPattern/frmMyStocks.Designer.cs
generated
@ -29,6 +29,7 @@ namespace RepositoryPattern
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
this.components = new System.ComponentModel.Container();
|
||||||
this.lvMyStocks = new System.Windows.Forms.ListView();
|
this.lvMyStocks = new System.Windows.Forms.ListView();
|
||||||
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
|
||||||
this.columnHeader2 = 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.txtTotDiff = new System.Windows.Forms.TextBox();
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
this.txtCurrValue = new System.Windows.Forms.TextBox();
|
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();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// lvMyStocks
|
// lvMyStocks
|
||||||
@ -186,11 +189,28 @@ namespace RepositoryPattern
|
|||||||
this.txtCurrValue.Size = new System.Drawing.Size(100, 23);
|
this.txtCurrValue.Size = new System.Drawing.Size(100, 23);
|
||||||
this.txtCurrValue.TabIndex = 5;
|
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
|
// frmMyStocks
|
||||||
//
|
//
|
||||||
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(935, 481);
|
this.ClientSize = new System.Drawing.Size(935, 481);
|
||||||
|
this.Controls.Add(this.chkAutoReload);
|
||||||
this.Controls.Add(this.label3);
|
this.Controls.Add(this.label3);
|
||||||
this.Controls.Add(this.txtCurrValue);
|
this.Controls.Add(this.txtCurrValue);
|
||||||
this.Controls.Add(this.label2);
|
this.Controls.Add(this.label2);
|
||||||
@ -226,5 +246,7 @@ namespace RepositoryPattern
|
|||||||
private System.Windows.Forms.TextBox txtTotDiff;
|
private System.Windows.Forms.TextBox txtTotDiff;
|
||||||
private System.Windows.Forms.Label label3;
|
private System.Windows.Forms.Label label3;
|
||||||
private System.Windows.Forms.TextBox txtCurrValue;
|
private System.Windows.Forms.TextBox txtCurrValue;
|
||||||
|
private System.Windows.Forms.Timer timer1;
|
||||||
|
private System.Windows.Forms.CheckBox chkAutoReload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
//
|
||||||
namespace RepositoryPattern
|
namespace RepositoryPattern
|
||||||
{
|
{
|
||||||
public partial class frmMyStocks : Form
|
public partial class frmMyStocks : Form
|
||||||
@ -38,6 +38,10 @@ namespace RepositoryPattern
|
|||||||
private void ReloadData()
|
private void ReloadData()
|
||||||
{
|
{
|
||||||
CurrentStocks = _stockMemberRepository.GetStocks();
|
CurrentStocks = _stockMemberRepository.GetStocks();
|
||||||
|
lvMyStocks.Items.Clear();
|
||||||
|
BoughtSum = 0m;
|
||||||
|
TotalDiff = 0m;
|
||||||
|
CurrentSum = 0m;
|
||||||
foreach(var stock in CurrentStocks)
|
foreach(var stock in CurrentStocks)
|
||||||
{
|
{
|
||||||
stock.ActValue = Stocks[stock.StockId.Trim()].LatestPrice;
|
stock.ActValue = Stocks[stock.StockId.Trim()].LatestPrice;
|
||||||
@ -54,6 +58,12 @@ namespace RepositoryPattern
|
|||||||
txtTotDiff.Refresh();
|
txtTotDiff.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TotalReload()
|
||||||
|
{
|
||||||
|
Stocks = _stockMarketRepository.StockMarketList;
|
||||||
|
ReloadData();
|
||||||
|
}
|
||||||
|
|
||||||
private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
|
private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
|
||||||
{
|
{
|
||||||
using (Brush hBr = new SolidBrush(hdrColor))
|
using (Brush hBr = new SolidBrush(hdrColor))
|
||||||
@ -85,11 +95,11 @@ namespace RepositoryPattern
|
|||||||
lv.SubItems.Add(owned.ToString());
|
lv.SubItems.Add(owned.ToString());
|
||||||
if (diffValue < 0)
|
if (diffValue < 0)
|
||||||
{
|
{
|
||||||
lv.BackColor = Color.Red;
|
lv.BackColor = Color.Pink;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lv.BackColor = Color.Green;
|
lv.BackColor = Color.LightGreen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,5 +107,15 @@ namespace RepositoryPattern
|
|||||||
{
|
{
|
||||||
ReloadData();
|
ReloadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void timer1_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
TotalReload();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chkAutoReload_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
timer1.Enabled = chkAutoReload.Checked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user