Compare commits
10 Commits
2dd9eae9c3
...
c406e94eda
| Author | SHA1 | Date | |
|---|---|---|---|
| c406e94eda | |||
| 390bc6eeeb | |||
| 2017f004d3 | |||
| d3b28ae51a | |||
| e4fee01015 | |||
| f51d6e9689 | |||
| 8839d7dff3 | |||
| 3f737a8010 | |||
| ec71d60a2a | |||
| a87f91b921 |
@ -1,4 +1,5 @@
|
||||
using Autofac;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using StockDal;
|
||||
using StockDal.Interface;
|
||||
using System;
|
||||
|
||||
@ -10,6 +10,11 @@
|
||||
<PackageReference Include="Autofac" Version="6.1.0" />
|
||||
<PackageReference Include="Dapper" Version="2.0.78" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.29" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="87.0.4280.8800" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
|
||||
</ItemGroup>
|
||||
@ -20,4 +25,10 @@
|
||||
<ProjectReference Include="..\StockDomain\StockDomain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="App.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
41
RepositoryPattern/frmInitial.Designer.cs
generated
41
RepositoryPattern/frmInitial.Designer.cs
generated
@ -39,8 +39,12 @@ namespace RepositoryPattern
|
||||
this.lblStockRows = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
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();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
@ -146,11 +150,42 @@ namespace RepositoryPattern
|
||||
this.chbShowBrowser.UseCompatibleTextRendering = true;
|
||||
this.chbShowBrowser.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// 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";
|
||||
this.gbStockMgmnt.Size = new System.Drawing.Size(257, 123);
|
||||
this.gbStockMgmnt.TabIndex = 8;
|
||||
this.gbStockMgmnt.TabStop = false;
|
||||
//
|
||||
// btnStockReg
|
||||
//
|
||||
this.btnStockReg.Location = new System.Drawing.Point(6, 9);
|
||||
this.btnStockReg.Name = "btnStockReg";
|
||||
this.btnStockReg.Size = new System.Drawing.Size(96, 23);
|
||||
this.btnStockReg.TabIndex = 0;
|
||||
this.btnStockReg.Text = "Stock Purchase";
|
||||
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);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 509);
|
||||
this.ClientSize = new System.Drawing.Size(800, 546);
|
||||
this.Controls.Add(this.gbStockMgmnt);
|
||||
this.Controls.Add(this.chbShowBrowser);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Controls.Add(this.lblStockRows);
|
||||
@ -167,6 +202,7 @@ namespace RepositoryPattern
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.gB1.ResumeLayout(false);
|
||||
this.gB1.PerformLayout();
|
||||
this.gbStockMgmnt.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -184,6 +220,9 @@ namespace RepositoryPattern
|
||||
private System.Windows.Forms.Label lblStockRows;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.CheckBox chbShowBrowser;
|
||||
private System.Windows.Forms.GroupBox gbStockMgmnt;
|
||||
private System.Windows.Forms.Button btnStockReg;
|
||||
private System.Windows.Forms.Button btnValueView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,10 +13,13 @@ 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 frmMyStocks stockWindow;
|
||||
|
||||
public frmInitial(IProductRepository productRepository, IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -34,10 +37,11 @@ namespace RepositoryPattern
|
||||
{
|
||||
if (rdbNorth.Checked)
|
||||
{
|
||||
dataGridView.DataSource = _productRepository.GetProducts(); }
|
||||
dataGridView.DataSource = _productRepository.GetProducts();
|
||||
}
|
||||
else if (rdbStock.Checked)
|
||||
{
|
||||
dataGridView.DataSource = _stockMemberRepository.GetStocks();
|
||||
dataGridView.DataSource = _stockMemberRepository.GetAllStocks();
|
||||
}
|
||||
lblTotalRecords.Text = $"Total records: {dataGridView.RowCount}";
|
||||
}
|
||||
@ -72,5 +76,33 @@ namespace RepositoryPattern
|
||||
lblStockRows.Text = stocklist.Count().ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnStockReg_Click(object sender, EventArgs e)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
384
RepositoryPattern/frmMyStocks.Designer.cs
generated
Normal file
384
RepositoryPattern/frmMyStocks.Designer.cs
generated
Normal file
@ -0,0 +1,384 @@
|
||||
|
||||
namespace RepositoryPattern
|
||||
{
|
||||
partial class frmMyStocks
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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();
|
||||
this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
|
||||
this.columnHeader11 = 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.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.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
this.chkAutoReload = new System.Windows.Forms.CheckBox();
|
||||
this.lbUpdateTimes = new System.Windows.Forms.ListBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.txtTotalMinus = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.txtTotalPlus = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// lvMyStocks
|
||||
//
|
||||
this.lvMyStocks.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| 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.columnHeader7,
|
||||
this.columnHeader11,
|
||||
this.columnHeader3,
|
||||
this.columnHeader4,
|
||||
this.columnHeader5,
|
||||
this.columnHeader6,
|
||||
this.columnHeader8,
|
||||
this.columnHeader9,
|
||||
this.columnHeader10});
|
||||
this.lvMyStocks.GridLines = true;
|
||||
this.lvMyStocks.HideSelection = false;
|
||||
this.lvMyStocks.Location = new System.Drawing.Point(14, 43);
|
||||
this.lvMyStocks.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.lvMyStocks.Name = "lvMyStocks";
|
||||
this.lvMyStocks.Size = new System.Drawing.Size(1191, 369);
|
||||
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 = 120;
|
||||
//
|
||||
// columnHeader2
|
||||
//
|
||||
this.columnHeader2.Name = "columnHeader2";
|
||||
this.columnHeader2.Text = "Buy Price";
|
||||
this.columnHeader2.Width = 80;
|
||||
//
|
||||
// columnHeader7
|
||||
//
|
||||
this.columnHeader7.Name = "columnHeader7";
|
||||
this.columnHeader7.Text = "Market price";
|
||||
this.columnHeader7.Width = 100;
|
||||
//
|
||||
// columnHeader11
|
||||
//
|
||||
this.columnHeader11.Name = "columnHeader11";
|
||||
this.columnHeader11.Text = "Price Diff";
|
||||
this.columnHeader11.Width = 100;
|
||||
//
|
||||
// columnHeader3
|
||||
//
|
||||
this.columnHeader3.Name = "columnHeader3";
|
||||
this.columnHeader3.Text = "Amount Stk";
|
||||
this.columnHeader3.Width = 100;
|
||||
//
|
||||
// columnHeader4
|
||||
//
|
||||
this.columnHeader4.Name = "columnHeader4";
|
||||
this.columnHeader4.Text = "Buy Date";
|
||||
this.columnHeader4.Width = 100;
|
||||
//
|
||||
// columnHeader5
|
||||
//
|
||||
this.columnHeader5.Name = "columnHeader5";
|
||||
this.columnHeader5.Text = "Value diff";
|
||||
this.columnHeader5.Width = 100;
|
||||
//
|
||||
// columnHeader6
|
||||
//
|
||||
this.columnHeader6.Name = "columnHeader6";
|
||||
this.columnHeader6.Text = "Value diff %";
|
||||
this.columnHeader6.Width = 80;
|
||||
//
|
||||
// columnHeader8
|
||||
//
|
||||
this.columnHeader8.Name = "columnHeader8";
|
||||
this.columnHeader8.Text = "Market Date";
|
||||
this.columnHeader8.Width = 100;
|
||||
//
|
||||
// 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.txtBuyTotal.Location = new System.Drawing.Point(186, 428);
|
||||
this.txtBuyTotal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.txtBuyTotal.Name = "txtBuyTotal";
|
||||
this.txtBuyTotal.ReadOnly = true;
|
||||
this.txtBuyTotal.Size = new System.Drawing.Size(114, 27);
|
||||
this.txtBuyTotal.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
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(64, 425);
|
||||
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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
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(307, 425);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(55, 21);
|
||||
this.label2.TabIndex = 4;
|
||||
this.label2.Text = "TotDiff";
|
||||
//
|
||||
// txtTotDiff
|
||||
//
|
||||
this.txtTotDiff.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.txtTotDiff.Location = new System.Drawing.Point(377, 428);
|
||||
this.txtTotDiff.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.txtTotDiff.Name = "txtTotDiff";
|
||||
this.txtTotDiff.ReadOnly = true;
|
||||
this.txtTotDiff.Size = new System.Drawing.Size(114, 27);
|
||||
this.txtTotDiff.TabIndex = 3;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
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(582, 425);
|
||||
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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.txtCurrValue.Location = new System.Drawing.Point(709, 428);
|
||||
this.txtCurrValue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.txtCurrValue.Name = "txtCurrValue";
|
||||
this.txtCurrValue.ReadOnly = true;
|
||||
this.txtCurrValue.Size = new System.Drawing.Size(114, 27);
|
||||
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(15, 9);
|
||||
this.chkAutoReload.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.chkAutoReload.Name = "chkAutoReload";
|
||||
this.chkAutoReload.Size = new System.Drawing.Size(148, 24);
|
||||
this.chkAutoReload.TabIndex = 7;
|
||||
this.chkAutoReload.Text = "Automatic Reload";
|
||||
this.chkAutoReload.UseVisualStyleBackColor = true;
|
||||
this.chkAutoReload.CheckedChanged += new System.EventHandler(this.chkAutoReload_CheckedChanged);
|
||||
//
|
||||
// lbUpdateTimes
|
||||
//
|
||||
this.lbUpdateTimes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.lbUpdateTimes.FormattingEnabled = true;
|
||||
this.lbUpdateTimes.ItemHeight = 20;
|
||||
this.lbUpdateTimes.Location = new System.Drawing.Point(16, 500);
|
||||
this.lbUpdateTimes.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.lbUpdateTimes.Name = "lbUpdateTimes";
|
||||
this.lbUpdateTimes.Size = new System.Drawing.Size(137, 124);
|
||||
this.lbUpdateTimes.TabIndex = 8;
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(14, 472);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(97, 20);
|
||||
this.label4.TabIndex = 9;
|
||||
this.label4.Text = "LatestUpdate";
|
||||
//
|
||||
// numericUpDown1
|
||||
//
|
||||
this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.numericUpDown1.Location = new System.Drawing.Point(161, 593);
|
||||
this.numericUpDown1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.numericUpDown1.Name = "numericUpDown1";
|
||||
this.numericUpDown1.Size = new System.Drawing.Size(119, 27);
|
||||
this.numericUpDown1.TabIndex = 10;
|
||||
this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.label5.AutoSize = true;
|
||||
this.label5.Location = new System.Drawing.Point(160, 569);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(132, 20);
|
||||
this.label5.TabIndex = 11;
|
||||
this.label5.Text = "Uppdatering (min)";
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label6.Location = new System.Drawing.Point(200, 476);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(89, 21);
|
||||
this.label6.TabIndex = 13;
|
||||
this.label6.Text = "Total Minus";
|
||||
//
|
||||
// txtTotalMinus
|
||||
//
|
||||
this.txtTotalMinus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.txtTotalMinus.Location = new System.Drawing.Point(295, 474);
|
||||
this.txtTotalMinus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.txtTotalMinus.Name = "txtTotalMinus";
|
||||
this.txtTotalMinus.ReadOnly = true;
|
||||
this.txtTotalMinus.Size = new System.Drawing.Size(114, 27);
|
||||
this.txtTotalMinus.TabIndex = 12;
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.label7.Location = new System.Drawing.Point(438, 476);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(75, 21);
|
||||
this.label7.TabIndex = 15;
|
||||
this.label7.Text = "Total Plus";
|
||||
//
|
||||
// txtTotalPlus
|
||||
//
|
||||
this.txtTotalPlus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.txtTotalPlus.Location = new System.Drawing.Point(533, 474);
|
||||
this.txtTotalPlus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.txtTotalPlus.Name = "txtTotalPlus";
|
||||
this.txtTotalPlus.ReadOnly = true;
|
||||
this.txtTotalPlus.Size = new System.Drawing.Size(114, 27);
|
||||
this.txtTotalPlus.TabIndex = 14;
|
||||
//
|
||||
// frmMyStocks
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1217, 651);
|
||||
this.Controls.Add(this.label7);
|
||||
this.Controls.Add(this.txtTotalPlus);
|
||||
this.Controls.Add(this.label6);
|
||||
this.Controls.Add(this.txtTotalMinus);
|
||||
this.Controls.Add(this.label5);
|
||||
this.Controls.Add(this.numericUpDown1);
|
||||
this.Controls.Add(this.label4);
|
||||
this.Controls.Add(this.lbUpdateTimes);
|
||||
this.Controls.Add(this.chkAutoReload);
|
||||
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.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.Name = "frmMyStocks";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "frmMyStocks";
|
||||
this.Shown += new System.EventHandler(this.frmMyStocks_Shown);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
|
||||
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;
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
private System.Windows.Forms.CheckBox chkAutoReload;
|
||||
private System.Windows.Forms.ListBox lbUpdateTimes;
|
||||
private System.Windows.Forms.Label label4;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader11;
|
||||
private System.Windows.Forms.NumericUpDown numericUpDown1;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.TextBox txtTotalMinus;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.TextBox txtTotalPlus;
|
||||
}
|
||||
}
|
||||
154
RepositoryPattern/frmMyStocks.cs
Normal file
154
RepositoryPattern/frmMyStocks.cs
Normal file
@ -0,0 +1,154 @@
|
||||
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 decimal TotalPlus { get; set; }
|
||||
public decimal TotalMinus { get; set; }
|
||||
|
||||
public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
|
||||
public IEnumerable<StockMember> CurrentStocks { get; set; }
|
||||
|
||||
public frmMyStocks(IProductRepository productRepository, IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository)
|
||||
{
|
||||
hdrColor = Color.CadetBlue;
|
||||
InitializeComponent();
|
||||
_productRepository = productRepository;
|
||||
_stockMemberRepository = stockMemberRepository;
|
||||
_stockMarketRepository = stockMarketRepository;
|
||||
numericUpDown1.Value = timer1.Interval / 60000;
|
||||
numericUpDown1.Enabled = false;
|
||||
}
|
||||
|
||||
|
||||
private void ReloadData()
|
||||
{
|
||||
CurrentStocks = _stockMemberRepository.GetStocks();
|
||||
lvMyStocks.Items.Clear();
|
||||
BoughtSum = 0m;
|
||||
TotalDiff = 0m;
|
||||
CurrentSum = 0m;
|
||||
TotalMinus = 0m;
|
||||
TotalPlus = 0m;
|
||||
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();
|
||||
txtTotalMinus.Text = TotalMinus.ToString();
|
||||
txtTotalMinus.Refresh();
|
||||
txtTotalPlus.Text = TotalPlus.ToString();
|
||||
txtTotalPlus.Refresh();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void TotalReload()
|
||||
{
|
||||
_stockMarketRepository.LoadStockMarketList();
|
||||
Stocks = _stockMarketRepository.StockMarketList;
|
||||
ReloadData();
|
||||
lbUpdateTimes.Items.Add(DateTime.Now.ToLongTimeString());
|
||||
}
|
||||
|
||||
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());
|
||||
var currValue = lv.SubItems.Add(currStock.ActValue.ToString());
|
||||
//var saveBcolor = currValue.BackColor;
|
||||
//var valueLevel = currStock.ActValue - currStock.BuyValue;
|
||||
//currValue.ForeColor = valueLevel > 5 ? Color.Red : saveBcolor;
|
||||
var priceDiff = currStock.ActValue - currStock.BuyValue;
|
||||
lv.SubItems.Add(priceDiff.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;
|
||||
if (diffValue < 0)
|
||||
{
|
||||
TotalMinus += diffValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalPlus += diffValue;
|
||||
}
|
||||
var lvs = lv.SubItems.Add(diffValue.ToString());
|
||||
lv.SubItems.Add(Math.Round(diffproc, 2).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.Pink;
|
||||
}
|
||||
else
|
||||
{
|
||||
lv.BackColor = Color.LightGreen;
|
||||
}
|
||||
}
|
||||
|
||||
private void frmMyStocks_Shown(object sender, EventArgs e)
|
||||
{
|
||||
ReloadData();
|
||||
}
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
TotalReload();
|
||||
}
|
||||
|
||||
private void chkAutoReload_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
timer1.Enabled = chkAutoReload.Checked;
|
||||
numericUpDown1.Enabled = chkAutoReload.Checked;
|
||||
}
|
||||
|
||||
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
timer1.Interval = Convert.ToInt32(numericUpDown1.Value * 60000);
|
||||
}
|
||||
}
|
||||
}
|
||||
60
RepositoryPattern/frmMyStocks.resx
Normal file
60
RepositoryPattern/frmMyStocks.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
377
RepositoryPattern/frmRegisterStock.Designer.cs
generated
Normal file
377
RepositoryPattern/frmRegisterStock.Designer.cs
generated
Normal file
@ -0,0 +1,377 @@
|
||||
|
||||
namespace RepositoryPattern
|
||||
{
|
||||
partial class frmRegisterStock
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.cmbStockChoser = new System.Windows.Forms.ComboBox();
|
||||
this.btnClose = new System.Windows.Forms.Button();
|
||||
this.lblStockExtId = new System.Windows.Forms.Label();
|
||||
this.txtStockExtId = new System.Windows.Forms.TextBox();
|
||||
this.txtBuyPrice = new System.Windows.Forms.TextBox();
|
||||
this.lblBuyPrice = new System.Windows.Forms.Label();
|
||||
this.txtBuyDate = new System.Windows.Forms.TextBox();
|
||||
this.lblBuyDate = new System.Windows.Forms.Label();
|
||||
this.txtBoughtAmount = new System.Windows.Forms.TextBox();
|
||||
this.lblBoughtAmount = new System.Windows.Forms.Label();
|
||||
this.txtActValue = new System.Windows.Forms.TextBox();
|
||||
this.lblActValue = new System.Windows.Forms.Label();
|
||||
this.txtActDate = new System.Windows.Forms.TextBox();
|
||||
this.lblActDate = new System.Windows.Forms.Label();
|
||||
this.txtActAmount = new System.Windows.Forms.TextBox();
|
||||
this.lblRemaining = new System.Windows.Forms.Label();
|
||||
this.txtSoldPrice = new System.Windows.Forms.TextBox();
|
||||
this.lblSoldValue = new System.Windows.Forms.Label();
|
||||
this.txtSoldDate = new System.Windows.Forms.TextBox();
|
||||
this.lblSoldDate = new System.Windows.Forms.Label();
|
||||
this.txtComment = new System.Windows.Forms.TextBox();
|
||||
this.lblComment = new System.Windows.Forms.Label();
|
||||
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
|
||||
//
|
||||
this.cmbStockChoser.FormattingEnabled = true;
|
||||
this.cmbStockChoser.Location = new System.Drawing.Point(38, 39);
|
||||
this.cmbStockChoser.Name = "cmbStockChoser";
|
||||
this.cmbStockChoser.Size = new System.Drawing.Size(179, 23);
|
||||
this.cmbStockChoser.TabIndex = 0;
|
||||
this.cmbStockChoser.SelectedIndexChanged += new System.EventHandler(this.cmbStockChoser_SelectedIndexChanged);
|
||||
//
|
||||
// btnClose
|
||||
//
|
||||
this.btnClose.Location = new System.Drawing.Point(347, 567);
|
||||
this.btnClose.Name = "btnClose";
|
||||
this.btnClose.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnClose.TabIndex = 1;
|
||||
this.btnClose.Text = "Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
//
|
||||
// lblStockExtId
|
||||
//
|
||||
this.lblStockExtId.AutoSize = true;
|
||||
this.lblStockExtId.Location = new System.Drawing.Point(38, 78);
|
||||
this.lblStockExtId.Name = "lblStockExtId";
|
||||
this.lblStockExtId.Size = new System.Drawing.Size(62, 15);
|
||||
this.lblStockExtId.TabIndex = 2;
|
||||
this.lblStockExtId.Text = "StockExtId";
|
||||
//
|
||||
// txtStockExtId
|
||||
//
|
||||
this.txtStockExtId.Location = new System.Drawing.Point(153, 75);
|
||||
this.txtStockExtId.Name = "txtStockExtId";
|
||||
this.txtStockExtId.Size = new System.Drawing.Size(269, 23);
|
||||
this.txtStockExtId.TabIndex = 3;
|
||||
//
|
||||
// txtBuyPrice
|
||||
//
|
||||
this.txtBuyPrice.Location = new System.Drawing.Point(153, 104);
|
||||
this.txtBuyPrice.Name = "txtBuyPrice";
|
||||
this.txtBuyPrice.Size = new System.Drawing.Size(111, 23);
|
||||
this.txtBuyPrice.TabIndex = 5;
|
||||
//
|
||||
// lblBuyPrice
|
||||
//
|
||||
this.lblBuyPrice.AutoSize = true;
|
||||
this.lblBuyPrice.Location = new System.Drawing.Point(38, 107);
|
||||
this.lblBuyPrice.Name = "lblBuyPrice";
|
||||
this.lblBuyPrice.Size = new System.Drawing.Size(56, 15);
|
||||
this.lblBuyPrice.TabIndex = 4;
|
||||
this.lblBuyPrice.Text = "Buy price";
|
||||
//
|
||||
// txtBuyDate
|
||||
//
|
||||
this.txtBuyDate.Location = new System.Drawing.Point(153, 133);
|
||||
this.txtBuyDate.Name = "txtBuyDate";
|
||||
this.txtBuyDate.Size = new System.Drawing.Size(142, 23);
|
||||
this.txtBuyDate.TabIndex = 7;
|
||||
//
|
||||
// lblBuyDate
|
||||
//
|
||||
this.lblBuyDate.AutoSize = true;
|
||||
this.lblBuyDate.Location = new System.Drawing.Point(38, 136);
|
||||
this.lblBuyDate.Name = "lblBuyDate";
|
||||
this.lblBuyDate.Size = new System.Drawing.Size(73, 15);
|
||||
this.lblBuyDate.TabIndex = 6;
|
||||
this.lblBuyDate.Text = "Bought Date";
|
||||
//
|
||||
// txtBoughtAmount
|
||||
//
|
||||
this.txtBoughtAmount.Location = new System.Drawing.Point(153, 162);
|
||||
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
|
||||
//
|
||||
this.lblBoughtAmount.AutoSize = true;
|
||||
this.lblBoughtAmount.Location = new System.Drawing.Point(38, 165);
|
||||
this.lblBoughtAmount.Name = "lblBoughtAmount";
|
||||
this.lblBoughtAmount.Size = new System.Drawing.Size(93, 15);
|
||||
this.lblBoughtAmount.TabIndex = 8;
|
||||
this.lblBoughtAmount.Text = "Bought Number";
|
||||
//
|
||||
// txtActValue
|
||||
//
|
||||
this.txtActValue.Location = new System.Drawing.Point(153, 191);
|
||||
this.txtActValue.Name = "txtActValue";
|
||||
this.txtActValue.Size = new System.Drawing.Size(111, 23);
|
||||
this.txtActValue.TabIndex = 11;
|
||||
//
|
||||
// lblActValue
|
||||
//
|
||||
this.lblActValue.AutoSize = true;
|
||||
this.lblActValue.Location = new System.Drawing.Point(38, 194);
|
||||
this.lblActValue.Name = "lblActValue";
|
||||
this.lblActValue.Size = new System.Drawing.Size(76, 15);
|
||||
this.lblActValue.TabIndex = 10;
|
||||
this.lblActValue.Text = "Current price";
|
||||
//
|
||||
// txtActDate
|
||||
//
|
||||
this.txtActDate.Location = new System.Drawing.Point(153, 220);
|
||||
this.txtActDate.Name = "txtActDate";
|
||||
this.txtActDate.Size = new System.Drawing.Size(142, 23);
|
||||
this.txtActDate.TabIndex = 13;
|
||||
//
|
||||
// lblActDate
|
||||
//
|
||||
this.lblActDate.AutoSize = true;
|
||||
this.lblActDate.Location = new System.Drawing.Point(38, 223);
|
||||
this.lblActDate.Name = "lblActDate";
|
||||
this.lblActDate.Size = new System.Drawing.Size(61, 15);
|
||||
this.lblActDate.TabIndex = 12;
|
||||
this.lblActDate.Text = "Value date";
|
||||
//
|
||||
// txtActAmount
|
||||
//
|
||||
this.txtActAmount.Location = new System.Drawing.Point(153, 249);
|
||||
this.txtActAmount.Name = "txtActAmount";
|
||||
this.txtActAmount.Size = new System.Drawing.Size(111, 23);
|
||||
this.txtActAmount.TabIndex = 15;
|
||||
//
|
||||
// lblRemaining
|
||||
//
|
||||
this.lblRemaining.AutoSize = true;
|
||||
this.lblRemaining.Location = new System.Drawing.Point(38, 252);
|
||||
this.lblRemaining.Name = "lblRemaining";
|
||||
this.lblRemaining.Size = new System.Drawing.Size(109, 15);
|
||||
this.lblRemaining.TabIndex = 14;
|
||||
this.lblRemaining.Text = "Remaining number";
|
||||
//
|
||||
// txtSoldPrice
|
||||
//
|
||||
this.txtSoldPrice.Location = new System.Drawing.Point(153, 278);
|
||||
this.txtSoldPrice.Name = "txtSoldPrice";
|
||||
this.txtSoldPrice.Size = new System.Drawing.Size(111, 23);
|
||||
this.txtSoldPrice.TabIndex = 17;
|
||||
//
|
||||
// lblSoldValue
|
||||
//
|
||||
this.lblSoldValue.AutoSize = true;
|
||||
this.lblSoldValue.Location = new System.Drawing.Point(38, 281);
|
||||
this.lblSoldValue.Name = "lblSoldValue";
|
||||
this.lblSoldValue.Size = new System.Drawing.Size(59, 15);
|
||||
this.lblSoldValue.TabIndex = 16;
|
||||
this.lblSoldValue.Text = "Sold price";
|
||||
//
|
||||
// txtSoldDate
|
||||
//
|
||||
this.txtSoldDate.Location = new System.Drawing.Point(153, 307);
|
||||
this.txtSoldDate.Name = "txtSoldDate";
|
||||
this.txtSoldDate.Size = new System.Drawing.Size(142, 23);
|
||||
this.txtSoldDate.TabIndex = 19;
|
||||
//
|
||||
// lblSoldDate
|
||||
//
|
||||
this.lblSoldDate.AutoSize = true;
|
||||
this.lblSoldDate.Location = new System.Drawing.Point(38, 310);
|
||||
this.lblSoldDate.Name = "lblSoldDate";
|
||||
this.lblSoldDate.Size = new System.Drawing.Size(57, 15);
|
||||
this.lblSoldDate.TabIndex = 18;
|
||||
this.lblSoldDate.Text = "Sold Date";
|
||||
//
|
||||
// txtComment
|
||||
//
|
||||
this.txtComment.Location = new System.Drawing.Point(153, 336);
|
||||
this.txtComment.Multiline = true;
|
||||
this.txtComment.Name = "txtComment";
|
||||
this.txtComment.Size = new System.Drawing.Size(269, 72);
|
||||
this.txtComment.TabIndex = 21;
|
||||
//
|
||||
// lblComment
|
||||
//
|
||||
this.lblComment.AutoSize = true;
|
||||
this.lblComment.Location = new System.Drawing.Point(39, 339);
|
||||
this.lblComment.Name = "lblComment";
|
||||
this.lblComment.Size = new System.Drawing.Size(61, 15);
|
||||
this.lblComment.TabIndex = 20;
|
||||
this.lblComment.Text = "Comment";
|
||||
//
|
||||
// btnSaveStock
|
||||
//
|
||||
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.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
|
||||
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;
|
||||
this.lwRegBuffer.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.lwRegBuffer_DrawColumnHeader);
|
||||
//
|
||||
// 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.txtComment);
|
||||
this.Controls.Add(this.lblComment);
|
||||
this.Controls.Add(this.txtSoldDate);
|
||||
this.Controls.Add(this.lblSoldDate);
|
||||
this.Controls.Add(this.txtSoldPrice);
|
||||
this.Controls.Add(this.lblSoldValue);
|
||||
this.Controls.Add(this.txtActAmount);
|
||||
this.Controls.Add(this.lblRemaining);
|
||||
this.Controls.Add(this.txtActDate);
|
||||
this.Controls.Add(this.lblActDate);
|
||||
this.Controls.Add(this.txtActValue);
|
||||
this.Controls.Add(this.lblActValue);
|
||||
this.Controls.Add(this.txtBoughtAmount);
|
||||
this.Controls.Add(this.lblBoughtAmount);
|
||||
this.Controls.Add(this.txtBuyDate);
|
||||
this.Controls.Add(this.lblBuyDate);
|
||||
this.Controls.Add(this.txtBuyPrice);
|
||||
this.Controls.Add(this.lblBuyPrice);
|
||||
this.Controls.Add(this.txtStockExtId);
|
||||
this.Controls.Add(this.lblStockExtId);
|
||||
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);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ComboBox cmbStockChoser;
|
||||
private System.Windows.Forms.Button btnClose;
|
||||
private System.Windows.Forms.Label lblStockExtId;
|
||||
private System.Windows.Forms.TextBox txtStockExtId;
|
||||
private System.Windows.Forms.TextBox txtBuyPrice;
|
||||
private System.Windows.Forms.Label lblBuyPrice;
|
||||
private System.Windows.Forms.TextBox txtBuyDate;
|
||||
private System.Windows.Forms.Label lblBuyDate;
|
||||
private System.Windows.Forms.TextBox txtBoughtAmount;
|
||||
private System.Windows.Forms.Label lblBoughtAmount;
|
||||
private System.Windows.Forms.TextBox txtActValue;
|
||||
private System.Windows.Forms.Label lblActValue;
|
||||
private System.Windows.Forms.TextBox txtActDate;
|
||||
private System.Windows.Forms.Label lblActDate;
|
||||
private System.Windows.Forms.TextBox txtActAmount;
|
||||
private System.Windows.Forms.Label lblRemaining;
|
||||
private System.Windows.Forms.TextBox txtSoldPrice;
|
||||
private System.Windows.Forms.Label lblSoldValue;
|
||||
private System.Windows.Forms.TextBox txtSoldDate;
|
||||
private System.Windows.Forms.Label lblSoldDate;
|
||||
private System.Windows.Forms.TextBox txtComment;
|
||||
private System.Windows.Forms.Label lblComment;
|
||||
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;
|
||||
}
|
||||
}
|
||||
129
RepositoryPattern/frmRegisterStock.cs
Normal file
129
RepositoryPattern/frmRegisterStock.cs
Normal file
@ -0,0 +1,129 @@
|
||||
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 frmRegisterStock : Form
|
||||
{
|
||||
Color hdr = Color.Red;
|
||||
public Dictionary<string, DiTraderStockRow> Stocks { get; set; }
|
||||
public List<StockMember> RegisteredStocks { get; set; } = new List<StockMember>();
|
||||
|
||||
public frmRegisterStock()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LoadStockCombo()
|
||||
{
|
||||
if (Stocks.Count() > 0)
|
||||
{
|
||||
foreach (var key in Stocks.Keys)
|
||||
{
|
||||
cmbStockChoser.Items.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void frmRegisterStock_Shown(object sender, EventArgs e)
|
||||
{
|
||||
LoadStockCombo();
|
||||
}
|
||||
|
||||
private void cmbStockChoser_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
var stockChosen = Stocks[cmbStockChoser.SelectedItem.ToString()];
|
||||
txtStockExtId.Text = stockChosen.StockName;
|
||||
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);
|
||||
//lv.BackColor = Color.Aquamarine;
|
||||
}
|
||||
|
||||
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 = 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");
|
||||
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;
|
||||
}
|
||||
|
||||
private void lwRegBuffer_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
|
||||
{
|
||||
using (Brush hBr = new SolidBrush(hdr))
|
||||
{
|
||||
e.Graphics.FillRectangle(hBr, e.Bounds);
|
||||
e.DrawText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
RepositoryPattern/frmRegisterStock.resx
Normal file
60
RepositoryPattern/frmRegisterStock.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@ -7,8 +7,10 @@ namespace StockDal.Interface
|
||||
public interface IStockMemberRepository
|
||||
{
|
||||
IEnumerable<StockMember> GetStocks();
|
||||
bool Insert(StockMember stockMember);
|
||||
bool Update(StockMember stockMember);
|
||||
//bool Insert(StockMember stockMember);
|
||||
void UpdateActPrice(int Id, decimal price);
|
||||
bool Delete(string stockMemberId);
|
||||
void InsertMany(List<StockMember> stockMembers);
|
||||
IEnumerable<StockMember> GetAllStocks();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
using OpenQA.Selenium;
|
||||
using Newtonsoft.Json;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Chrome;
|
||||
using StockDal.Interface;
|
||||
using StockDomain;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -13,6 +15,8 @@ namespace StockDal
|
||||
public class StockMarketRepository : IStockMarketRepository
|
||||
{
|
||||
public Dictionary<string, DiTraderStockRow> StockMarketList { get; set; }
|
||||
|
||||
public List<DiTraderStockRow> DumpObjects { get; set; } = new List<DiTraderStockRow>();
|
||||
public DiTraderStockRow SaveRow { get; set; }
|
||||
public StringBuilder TextResults { get; set; }
|
||||
public bool ViewBrowser { get; set; }
|
||||
@ -27,7 +31,6 @@ namespace StockDal
|
||||
private void Find_Data()
|
||||
{
|
||||
TextResults = new StringBuilder();
|
||||
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||
IList<IWebElement> searchElements = driver.FindElements(By.TagName("tbody"));
|
||||
foreach (IWebElement i in searchElements)
|
||||
{
|
||||
@ -56,12 +59,22 @@ namespace StockDal
|
||||
{
|
||||
TextResults.Append(appendText + "\r\n");
|
||||
}
|
||||
htmlDocument1 = null;
|
||||
}
|
||||
htmlDocument = null;
|
||||
|
||||
TextResults.Append("\r\n");
|
||||
}
|
||||
var oxe = StockMarketList;
|
||||
|
||||
// var oxe = StockMarketList;
|
||||
}
|
||||
|
||||
private void SaveLogging()
|
||||
{
|
||||
var output = JsonConvert.SerializeObject(DumpObjects, Formatting.Indented);
|
||||
File.WriteAllText($"D:\\TimCoDemos\\DemoLogs\\Log{DateTime.Now.ToShortDateString()}.txt",output);
|
||||
}
|
||||
|
||||
private void AddValueToListRow(int pos, string value)
|
||||
{
|
||||
switch (pos)
|
||||
@ -115,16 +128,24 @@ namespace StockDal
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
SaveRow.TimeOfDay = TimeSpan.Parse(value);
|
||||
SaveRow.TimeOfDay = value==""?TimeSpan.Parse("00:01"): TimeSpan.Parse(value);
|
||||
//StockMarketList.Add(SaveRow.StockName, SaveRow);
|
||||
try
|
||||
{
|
||||
StockMarketList.Add(SaveRow.StockName, SaveRow);
|
||||
}
|
||||
catch (ArgumentException ae)
|
||||
{
|
||||
try
|
||||
{
|
||||
StockMarketList.Add(SaveRow.StockName + "-2", SaveRow);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DumpObjects.Add(SaveRow);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -132,29 +153,36 @@ namespace StockDal
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenBrowser()
|
||||
private void OpenBrowser(bool burl2 = false)
|
||||
{
|
||||
var driverService = ChromeDriverService.CreateDefaultService();
|
||||
driverService.HideCommandPromptWindow = true;
|
||||
|
||||
if (ViewBrowser)
|
||||
{
|
||||
if (driver == null)
|
||||
{
|
||||
driver = new ChromeDriver(driverService);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (driver == null)
|
||||
{
|
||||
var options = new ChromeOptions();
|
||||
options.AddArgument("headless");
|
||||
driver = new ChromeDriver(driverService, options);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//var url0 = "https://money.cnn.com/data/hotstocks/index.html";
|
||||
var url = "https://trader.di.se/index.php/stocklist/index/2055?list=7126";
|
||||
var url2 = "https://trader.di.se/index.php/stocklist/index/2055?list=7116";
|
||||
//var url1 = "https://www.finansportalen.se/aktiekurser/";
|
||||
driver.Navigate().GoToUrl(burl2 ? url2 : url);
|
||||
|
||||
driver.Navigate().GoToUrl(url);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -165,13 +193,22 @@ namespace StockDal
|
||||
|
||||
public void LoadStockMarketList()
|
||||
{
|
||||
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||
DumpObjects = new List<DiTraderStockRow>();
|
||||
OpenBrowser();
|
||||
Find_Data();
|
||||
OpenBrowser(true);
|
||||
Find_Data();
|
||||
if (DumpObjects.Any())
|
||||
{
|
||||
SaveLogging();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LoadStockMarketList(bool viewBrowser)
|
||||
{
|
||||
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||
ViewBrowser = viewBrowser;
|
||||
OpenBrowser();
|
||||
Find_Data();
|
||||
@ -179,13 +216,14 @@ namespace StockDal
|
||||
|
||||
public void RefreshMarketList()
|
||||
{
|
||||
StockMarketList = new Dictionary<string, DiTraderStockRow>();
|
||||
driver.Navigate().Refresh();
|
||||
Find_Data();
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
driver.Quit();
|
||||
driver?.Quit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,19 +16,54 @@ 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)
|
||||
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<StockMember> IStockMemberRepository.GetStocks()
|
||||
public IEnumerable<StockMember> 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
|
||||
@ -42,7 +77,28 @@ namespace StockDal
|
||||
,SoldDate
|
||||
,Comment
|
||||
,PostAmount
|
||||
FROM dbo.StockMember", commandType: CommandType.Text);
|
||||
FROM dbo.StockMember
|
||||
Where SoldDate is null
|
||||
ORDER BY PostAmount * (actvalue - BuyValue) desc", commandType: CommandType.Text);
|
||||
}
|
||||
public IEnumerable<StockMember> GetAllStocks()
|
||||
{
|
||||
using IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString);
|
||||
if (db.State == ConnectionState.Closed)
|
||||
db.Open();
|
||||
return db.Query<StockMember>(@"SELECT Id
|
||||
,StockId
|
||||
,StockExtId
|
||||
,BuyValue
|
||||
,BuyDate
|
||||
,ActValue
|
||||
,ActDate
|
||||
,SoldValue
|
||||
,SoldDate
|
||||
,Comment
|
||||
,PostAmount
|
||||
FROM dbo.StockMember
|
||||
ORDER BY PostAmount * (actvalue - BuyValue) desc", commandType: CommandType.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user