diff --git a/MyStocks/App.config b/MyStocks/App.config new file mode 100644 index 0000000..9399453 --- /dev/null +++ b/MyStocks/App.config @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyStocks/MyStocks.csproj b/MyStocks/MyStocks.csproj new file mode 100644 index 0000000..83ae2bb --- /dev/null +++ b/MyStocks/MyStocks.csproj @@ -0,0 +1,150 @@ + + + + + Debug + AnyCPU + {B72206DB-4BA5-4C74-B61D-8CCAB6DA9634} + WinExe + MyStocks + MyStocks + v4.7.2 + 512 + true + true + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Autofac.6.1.0\lib\netstandard2.0\Autofac.dll + + + ..\packages\Dapper.2.0.78\lib\net461\Dapper.dll + + + ..\packages\HtmlAgilityPack.1.11.30\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Data.SqlClient.4.8.2\lib\net461\System.Data.SqlClient.dll + + + ..\packages\System.Diagnostics.DiagnosticSource.5.0.1\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + + + + + + + + + + + + Form + + + + Form + + + + Form + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {3e23c2d6-3257-42b1-a6df-f6f7b7e71b17} + StockDal.Interface + + + {4a000259-9a8e-4a83-bdcf-40d06a2ee6cf} + StockDal + + + {a4b17e50-0ff3-4b94-81f8-e7aab3d333df} + StockDomain + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/MyStocks/Program.cs b/MyStocks/Program.cs new file mode 100644 index 0000000..98242be --- /dev/null +++ b/MyStocks/Program.cs @@ -0,0 +1,41 @@ +using Autofac; +using RepositoryPattern; +using StockDal; +using StockDal.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MyStocks +{ + static class Program + { + public static IContainer Container; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Container = Configure(); + Application.Run(new frmInitial( Container.Resolve(), Container.Resolve())); + } + /// + /// Setting dependency injection + /// + /// + static IContainer Configure() + { + var builder = new ContainerBuilder(); + builder.RegisterType().As(); + builder.RegisterType().As(); + builder.RegisterType(); + return builder.Build(); + } + } +} diff --git a/MyStocks/Properties/AssemblyInfo.cs b/MyStocks/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..47e0682 --- /dev/null +++ b/MyStocks/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MyStocks")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MyStocks")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b72206db-4ba5-4c74-b61d-8ccab6da9634")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MyStocks/Properties/Resources.Designer.cs b/MyStocks/Properties/Resources.Designer.cs new file mode 100644 index 0000000..10564bc --- /dev/null +++ b/MyStocks/Properties/Resources.Designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace MyStocks.Properties +{ + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MyStocks.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MyStocks/Properties/Resources.resx b/MyStocks/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MyStocks/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MyStocks/Properties/Settings.Designer.cs b/MyStocks/Properties/Settings.Designer.cs new file mode 100644 index 0000000..1534def --- /dev/null +++ b/MyStocks/Properties/Settings.Designer.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace MyStocks.Properties +{ + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MyStocks/Properties/Settings.settings b/MyStocks/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MyStocks/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/MyStocks/frmInitial.Designer.cs b/MyStocks/frmInitial.Designer.cs new file mode 100644 index 0000000..193fd18 --- /dev/null +++ b/MyStocks/frmInitial.Designer.cs @@ -0,0 +1,228 @@ + +namespace RepositoryPattern +{ + partial class frmInitial + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.lblTotalRecords = new System.Windows.Forms.Label(); + this.gB1 = new System.Windows.Forms.GroupBox(); + this.btnReload = new System.Windows.Forms.Button(); + this.rdbStock = new System.Windows.Forms.RadioButton(); + this.rdbNorth = new System.Windows.Forms.RadioButton(); + this.btnTestScrapFunction = new System.Windows.Forms.Button(); + 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 + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 16); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(776, 389); + this.dataGridView.TabIndex = 0; + // + // lblTotalRecords + // + this.lblTotalRecords.AutoSize = true; + this.lblTotalRecords.Location = new System.Drawing.Point(12, 408); + this.lblTotalRecords.Name = "lblTotalRecords"; + this.lblTotalRecords.Size = new System.Drawing.Size(98, 15); + this.lblTotalRecords.TabIndex = 2; + this.lblTotalRecords.Text = "Total Records: ???"; + // + // gB1 + // + this.gB1.Controls.Add(this.btnReload); + this.gB1.Controls.Add(this.rdbStock); + this.gB1.Controls.Add(this.rdbNorth); + this.gB1.Location = new System.Drawing.Point(157, 411); + this.gB1.Name = "gB1"; + this.gB1.Size = new System.Drawing.Size(248, 35); + this.gB1.TabIndex = 3; + this.gB1.TabStop = false; + // + // btnReload + // + this.btnReload.Location = new System.Drawing.Point(158, 9); + this.btnReload.Name = "btnReload"; + this.btnReload.Size = new System.Drawing.Size(75, 23); + this.btnReload.TabIndex = 2; + this.btnReload.Text = "Reload"; + this.btnReload.UseVisualStyleBackColor = true; + this.btnReload.Click += new System.EventHandler(this.btnReload_Click); + // + // rdbStock + // + this.rdbStock.AutoSize = true; + this.rdbStock.Checked = true; + this.rdbStock.Location = new System.Drawing.Point(98, 9); + this.rdbStock.Name = "rdbStock"; + this.rdbStock.Size = new System.Drawing.Size(54, 19); + this.rdbStock.TabIndex = 1; + this.rdbStock.TabStop = true; + this.rdbStock.Text = "Stock"; + this.rdbStock.UseVisualStyleBackColor = true; + // + // rdbNorth + // + this.rdbNorth.AutoSize = true; + this.rdbNorth.Location = new System.Drawing.Point(7, 9); + this.rdbNorth.Name = "rdbNorth"; + this.rdbNorth.Size = new System.Drawing.Size(84, 19); + this.rdbNorth.TabIndex = 0; + this.rdbNorth.Text = "NorthWind"; + this.rdbNorth.UseVisualStyleBackColor = true; + // + // btnTestScrapFunction + // + this.btnTestScrapFunction.Location = new System.Drawing.Point(12, 452); + this.btnTestScrapFunction.Name = "btnTestScrapFunction"; + this.btnTestScrapFunction.Size = new System.Drawing.Size(75, 23); + this.btnTestScrapFunction.TabIndex = 4; + this.btnTestScrapFunction.Text = "LoadScrap"; + this.btnTestScrapFunction.UseVisualStyleBackColor = true; + this.btnTestScrapFunction.Click += new System.EventHandler(this.btnTestScrapFunction_Click); + // + // lblStockRows + // + this.lblStockRows.AutoSize = true; + this.lblStockRows.Location = new System.Drawing.Point(93, 456); + this.lblStockRows.Name = "lblStockRows"; + this.lblStockRows.Size = new System.Drawing.Size(14, 15); + this.lblStockRows.TabIndex = 5; + this.lblStockRows.Text = "#"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(157, 452); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 6; + this.button1.Text = "ReLoad"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // chbShowBrowser + // + this.chbShowBrowser.AutoSize = true; + this.chbShowBrowser.Location = new System.Drawing.Point(12, 478); + this.chbShowBrowser.Name = "chbShowBrowser"; + this.chbShowBrowser.Size = new System.Drawing.Size(100, 22); + this.chbShowBrowser.TabIndex = 7; + this.chbShowBrowser.Text = "Show Browser"; + 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, 546); + this.Controls.Add(this.gbStockMgmnt); + this.Controls.Add(this.chbShowBrowser); + this.Controls.Add(this.button1); + this.Controls.Add(this.lblStockRows); + this.Controls.Add(this.btnTestScrapFunction); + this.Controls.Add(this.gB1); + this.Controls.Add(this.lblTotalRecords); + this.Controls.Add(this.dataGridView); + this.MinimizeBox = false; + this.Name = "frmInitial"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Repository Pattern"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmInitial_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.gB1.ResumeLayout(false); + this.gB1.PerformLayout(); + this.gbStockMgmnt.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Label lblTotalRecords; + private System.Windows.Forms.GroupBox gB1; + private System.Windows.Forms.RadioButton rdbStock; + private System.Windows.Forms.RadioButton rdbNorth; + private System.Windows.Forms.Button btnReload; + private System.Windows.Forms.Button btnTestScrapFunction; + 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; + } +} + diff --git a/MyStocks/frmInitial.cs b/MyStocks/frmInitial.cs new file mode 100644 index 0000000..6cd8f66 --- /dev/null +++ b/MyStocks/frmInitial.cs @@ -0,0 +1,99 @@ +using StockDal.Interface; +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 frmInitial : Form + { + private readonly IStockMemberRepository _stockMemberRepository; + private readonly IStockMarketRepository _stockMarketRepository; + + private frmRegisterStock regWindow; + private frmMyStocks stockWindow; + + public frmInitial( IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository) + { + InitializeComponent(); + _stockMemberRepository = stockMemberRepository; + _stockMarketRepository = stockMarketRepository; + } + + private void Form1_Load(object sender, EventArgs e) + { + ReloadData(); + } + + private void ReloadData() + { + dataGridView.DataSource = _stockMemberRepository.GetStocks(); + lblTotalRecords.Text = $"Total records: {dataGridView.RowCount}"; + } + + private void btnReload_Click(object sender, EventArgs e) + { + ReloadData(); + } + + private void btnTestScrapFunction_Click(object sender, EventArgs e) + { + if (rdbStock.Checked) + { + _stockMarketRepository.LoadStockMarketList(chbShowBrowser.Checked); + var stocklist = _stockMarketRepository.StockMarketList; + lblStockRows.Text = stocklist.Count().ToString(); + } + } + + private void frmInitial_FormClosing(object sender, FormClosingEventArgs e) + { + _stockMarketRepository.Clean(); + } + + private void button1_Click(object sender, EventArgs e) + { + if (rdbStock.Checked) + { + lblStockRows.Text = ""; + _stockMarketRepository.RefreshMarketList(); + var stocklist = _stockMarketRepository.StockMarketList; + 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(_stockMemberRepository,_stockMarketRepository); + stockWindow.Stocks = _stockMarketRepository.StockMarketList; + Cursor.Current = DefaultCursor; + stockWindow.ShowDialog(); + } + } + } +} diff --git a/MyStocks/frmInitial.resx b/MyStocks/frmInitial.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/MyStocks/frmInitial.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/MyStocks/frmMyStocks.Designer.cs b/MyStocks/frmMyStocks.Designer.cs new file mode 100644 index 0000000..e049892 --- /dev/null +++ b/MyStocks/frmMyStocks.Designer.cs @@ -0,0 +1,330 @@ + +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.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(); + ((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)"; + // + // 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.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; + } +} \ No newline at end of file diff --git a/MyStocks/frmMyStocks.cs b/MyStocks/frmMyStocks.cs new file mode 100644 index 0000000..33c0719 --- /dev/null +++ b/MyStocks/frmMyStocks.cs @@ -0,0 +1,134 @@ +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 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(IStockMemberRepository stockMemberRepository, IStockMarketRepository stockMarketRepository) + { + hdrColor = Color.CadetBlue; + InitializeComponent(); + _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; + 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 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; + 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); + } + } +} diff --git a/MyStocks/frmMyStocks.resx b/MyStocks/frmMyStocks.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/MyStocks/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/MyStocks/frmRegisterStock.Designer.cs b/MyStocks/frmRegisterStock.Designer.cs new file mode 100644 index 0000000..6ffad6e --- /dev/null +++ b/MyStocks/frmRegisterStock.Designer.cs @@ -0,0 +1,377 @@ + +namespace RepositoryPattern +{ + partial class frmRegisterStock + { + /// + /// 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.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; + } +} \ No newline at end of file diff --git a/MyStocks/frmRegisterStock.cs b/MyStocks/frmRegisterStock.cs new file mode 100644 index 0000000..d38c448 --- /dev/null +++ b/MyStocks/frmRegisterStock.cs @@ -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 Stocks { get; set; } + public List RegisteredStocks { get; set; } = new List(); + + 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(); + } + } + } +} diff --git a/MyStocks/frmRegisterStock.resx b/MyStocks/frmRegisterStock.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/MyStocks/frmRegisterStock.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/MyStocks/packages.config b/MyStocks/packages.config new file mode 100644 index 0000000..c2d9df0 --- /dev/null +++ b/MyStocks/packages.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MyStocksApp.sln b/MyStocksApp.sln new file mode 100644 index 0000000..2914929 --- /dev/null +++ b/MyStocksApp.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31005.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyStocks", "MyStocks\MyStocks.csproj", "{B72206DB-4BA5-4C74-B61D-8CCAB6DA9634}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDal", "StockDal\StockDal.csproj", "{4A000259-9A8E-4A83-BDCF-40D06A2EE6CF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDal.Interface", "StockDal.Interface\StockDal.Interface.csproj", "{3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDomain", "StockDomain\StockDomain.csproj", "{A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B72206DB-4BA5-4C74-B61D-8CCAB6DA9634}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B72206DB-4BA5-4C74-B61D-8CCAB6DA9634}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B72206DB-4BA5-4C74-B61D-8CCAB6DA9634}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B72206DB-4BA5-4C74-B61D-8CCAB6DA9634}.Release|Any CPU.Build.0 = Release|Any CPU + {4A000259-9A8E-4A83-BDCF-40D06A2EE6CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A000259-9A8E-4A83-BDCF-40D06A2EE6CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A000259-9A8E-4A83-BDCF-40D06A2EE6CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A000259-9A8E-4A83-BDCF-40D06A2EE6CF}.Release|Any CPU.Build.0 = Release|Any CPU + {3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17}.Release|Any CPU.Build.0 = Release|Any CPU + {A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {782C8C8E-4779-4501-8551-F139EECBE385} + EndGlobalSection +EndGlobal diff --git a/StockDal.Interface/IStockMarketRepository.cs b/StockDal.Interface/IStockMarketRepository.cs new file mode 100644 index 0000000..48254f7 --- /dev/null +++ b/StockDal.Interface/IStockMarketRepository.cs @@ -0,0 +1,20 @@ +using StockDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDal.Interface +{ + public interface IStockMarketRepository + { + Dictionary StockMarketList { get; set; } + bool ViewBrowser { get; set; } + + void Clean(); + void LoadStockMarketList(); + void LoadStockMarketList(bool viewBrowser); + void RefreshMarketList(); + } +} diff --git a/StockDal.Interface/IStockMemberRepository.cs b/StockDal.Interface/IStockMemberRepository.cs new file mode 100644 index 0000000..f9bb483 --- /dev/null +++ b/StockDal.Interface/IStockMemberRepository.cs @@ -0,0 +1,15 @@ +using StockDomain; +using System; +using System.Collections.Generic; + +namespace StockDal.Interface +{ + public interface IStockMemberRepository + { + IEnumerable GetStocks(); + //bool Insert(StockMember stockMember); + void UpdateActPrice(int Id, decimal price); + bool Delete(string stockMemberId); + void InsertMany(List stockMembers); + } +} diff --git a/StockDal.Interface/Properties/AssemblyInfo.cs b/StockDal.Interface/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e000ebc --- /dev/null +++ b/StockDal.Interface/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StockDal.Interface")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StockDal.Interface")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("3e23c2d6-3257-42b1-a6df-f6f7b7e71b17")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/StockDal.Interface/StockDal.Interface.csproj b/StockDal.Interface/StockDal.Interface.csproj new file mode 100644 index 0000000..34459a0 --- /dev/null +++ b/StockDal.Interface/StockDal.Interface.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {3E23C2D6-3257-42B1-A6DF-F6F7B7E71B17} + Library + Properties + StockDal.Interface + StockDal.Interface + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + {a4b17e50-0ff3-4b94-81f8-e7aab3d333df} + StockDomain + + + + \ No newline at end of file diff --git a/StockDal/AppConnection.cs b/StockDal/AppConnection.cs new file mode 100644 index 0000000..853d7dc --- /dev/null +++ b/StockDal/AppConnection.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RepositoryPattern +{ + public class AppConnection + { + public static string ConnectionString => ConfigurationManager.ConnectionStrings["cn"].ConnectionString; + } + public class StockDBConnection + { + public static string ConnectionString => ConfigurationManager.ConnectionStrings["StockDB"].ConnectionString; + } +} diff --git a/StockDal/Properties/AssemblyInfo.cs b/StockDal/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b1e1807 --- /dev/null +++ b/StockDal/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StockDal")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StockDal")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4a000259-9a8e-4a83-bdcf-40d06a2ee6cf")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/StockDal/StockDal.csproj b/StockDal/StockDal.csproj new file mode 100644 index 0000000..df4650e --- /dev/null +++ b/StockDal/StockDal.csproj @@ -0,0 +1,104 @@ + + + + + Debug + AnyCPU + {4A000259-9A8E-4A83-BDCF-40D06A2EE6CF} + Library + Properties + StockDal + StockDal + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Dapper.2.0.78\lib\net461\Dapper.dll + + + ..\packages\HtmlAgilityPack.1.11.30\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Selenium.WebDriverBackedSelenium.3.141.0\lib\net45\Selenium.WebDriverBackedSelenium.dll + + + + + ..\packages\System.Configuration.ConfigurationManager.5.0.0\lib\net461\System.Configuration.ConfigurationManager.dll + + + + + ..\packages\System.Data.SqlClient.4.8.2\lib\net461\System.Data.SqlClient.dll + + + + + + ..\packages\System.Security.AccessControl.5.0.0\lib\net461\System.Security.AccessControl.dll + + + ..\packages\System.Security.Permissions.5.0.0\lib\net461\System.Security.Permissions.dll + + + ..\packages\System.Security.Principal.Windows.5.0.0\lib\net461\System.Security.Principal.Windows.dll + + + + + + + + + + + ..\packages\Selenium.WebDriver.3.141.0\lib\net45\WebDriver.dll + + + + + + + + + + + + + + + {3e23c2d6-3257-42b1-a6df-f6f7b7e71b17} + StockDal.Interface + + + {a4b17e50-0ff3-4b94-81f8-e7aab3d333df} + StockDomain + + + + + + + \ No newline at end of file diff --git a/StockDal/StockMarketRepository.cs b/StockDal/StockMarketRepository.cs new file mode 100644 index 0000000..693759d --- /dev/null +++ b/StockDal/StockMarketRepository.cs @@ -0,0 +1,230 @@ +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; + +namespace StockDal +{ + public class StockMarketRepository : IStockMarketRepository + { + public Dictionary StockMarketList { get; set; } + + public List DumpObjects { get; set; } = new List(); + public DiTraderStockRow SaveRow { get; set; } + public StringBuilder TextResults { get; set; } + public bool ViewBrowser { get; set; } + + public IWebDriver driver; + + public StockMarketRepository() + { + ViewBrowser = false; + } + + private void Find_Data() + { + TextResults = new StringBuilder(); + IList searchElements = driver.FindElements(By.TagName("tbody")); + foreach (IWebElement i in searchElements) + { + + HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); + var text = i.GetAttribute("innerHTML"); + htmlDocument.LoadHtml(text); + var inputs = htmlDocument.DocumentNode.Descendants("tr").ToList(); + foreach (var items in inputs) + { + HtmlAgilityPack.HtmlDocument htmlDocument1 = new HtmlAgilityPack.HtmlDocument(); + htmlDocument1.LoadHtml(items.InnerHtml); + var tds = htmlDocument1.DocumentNode.Descendants("td").ToList(); + var appendText = ""; + var fNr = 0; + foreach (var item in tds) + { + var intext = item.InnerText.Replace("\r\n", ""); + appendText += appendText.Length == 0 ? intext : " " + intext; + if (tds.Count == 10) + { + AddValueToListRow(fNr++, intext); + } + } + if (!string.IsNullOrEmpty(appendText)) + { + TextResults.Append(appendText + "\r\n"); + } + htmlDocument1 = null; + } + htmlDocument = null; + + TextResults.Append("\r\n"); + } + + // 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) + { + case 0: + { + SaveRow = new DiTraderStockRow(); + SaveRow.StockName = value; + break; + } + case 1: + { + SaveRow.ProcChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 2: + { + SaveRow.RealChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 3: + { + SaveRow.BuyPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 4: + { + SaveRow.SellPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 5: + { + SaveRow.LatestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 6: + { + SaveRow.HighestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 7: + { + SaveRow.LowestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 8: + { + + SaveRow.Volume = string.IsNullOrWhiteSpace(value) ? 0 : long.Parse(value.Replace(" ", "")); + break; + } + case 9: + { + 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: + break; + } + } + + 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); + + } + catch + { + throw; + } + + } + + public void LoadStockMarketList() + { + StockMarketList = new Dictionary(); + DumpObjects = new List(); + OpenBrowser(); + Find_Data(); + OpenBrowser(true); + Find_Data(); + if (DumpObjects.Any()) + { + SaveLogging(); + } + } + + + public void LoadStockMarketList(bool viewBrowser) + { + StockMarketList = new Dictionary(); + ViewBrowser = viewBrowser; + OpenBrowser(); + Find_Data(); + } + + public void RefreshMarketList() + { + StockMarketList = new Dictionary(); + driver.Navigate().Refresh(); + Find_Data(); + } + + public void Clean() + { + driver?.Quit(); + } + + } +} diff --git a/StockDal/StockMemberRepository.cs b/StockDal/StockMemberRepository.cs new file mode 100644 index 0000000..8ef29c1 --- /dev/null +++ b/StockDal/StockMemberRepository.cs @@ -0,0 +1,89 @@ +using Dapper; +using RepositoryPattern; +using StockDal.Interface; +using StockDomain; +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; + +namespace StockDal +{ + public class StockMemberRepository : IStockMemberRepository + { + public bool Delete(string stockMemberId) + { + throw new NotImplementedException(); + } + + public void InsertMany(List stockMembers) + { + 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 void UpdateActPrice(int Id, decimal price) + { + 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() + { + using (IDbConnection db = new SqlConnection(StockDBConnection.ConnectionString)) + { + if (db.State == ConnectionState.Closed) + db.Open(); + return db.Query(@"SELECT Id + ,StockId + ,StockExtId + ,BuyValue + ,BuyDate + ,ActValue + ,ActDate + ,SoldValue + ,SoldDate + ,Comment + ,PostAmount + FROM dbo.StockMember", commandType: CommandType.Text); + } + } + } +} diff --git a/StockDal/packages.config b/StockDal/packages.config new file mode 100644 index 0000000..7220df1 --- /dev/null +++ b/StockDal/packages.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/StockDomain/DiTraderStockRow.cs b/StockDomain/DiTraderStockRow.cs new file mode 100644 index 0000000..47fda61 --- /dev/null +++ b/StockDomain/DiTraderStockRow.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDomain +{ + public class DiTraderStockRow + { + public string StockName { get; set; } + public decimal ProcChange { get; set; } + public decimal RealChange { get; set; } + public decimal BuyPrice { get; set; } + public decimal SellPrice { get; set; } + public decimal LatestPrice { get; set; } + public decimal HighestPrice { get; set; } + public decimal LowestPrice { get; set; } + public long Volume { get; set; } + public TimeSpan TimeOfDay { get; set; } + } +} diff --git a/StockDomain/Properties/AssemblyInfo.cs b/StockDomain/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..07cc490 --- /dev/null +++ b/StockDomain/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StockDomain")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StockDomain")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a4b17e50-0ff3-4b94-81f8-e7aab3d333df")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/StockDomain/StockDomain.csproj b/StockDomain/StockDomain.csproj new file mode 100644 index 0000000..315d304 --- /dev/null +++ b/StockDomain/StockDomain.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + {A4B17E50-0FF3-4B94-81F8-E7AAB3D333DF} + Library + Properties + StockDomain + StockDomain + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StockDomain/StockMember.cs b/StockDomain/StockMember.cs new file mode 100644 index 0000000..6c45d9d --- /dev/null +++ b/StockDomain/StockMember.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + + +namespace StockDomain +{ + public class StockMember + { + public int Id { get; set; } + public string StockId { get; set; } + public string StockExtId { get; set; } + public decimal BuyValue { get; set; } + public DateTime BuyDate { 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 string PostId { get; set; } + public string Comment { get; set; } + public long PostAmount { get; set; } + + } +}