From 6e2eb207a322a298a667453a64f21519ebb8bd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 29 Sep 2022 12:51:57 +0200 Subject: [PATCH] New Utility Window. scraping of StockGroups, and coupled Stocks, Show in listview on UtilityWindow --- BrowserHelper/Settings/TestSettings.cs | 1 + StockDAL/StockScrapePage.cs | 18 ++++ StockDal.Interface/IStockScrapePage.cs | 1 + StockInfoCore/StockInfoDISetup.cs | 1 + StockInfoCore/appsettings.json | 14 +++- StockInfoCore/frmInitial.Designer.cs | 13 +++ StockInfoCore/frmInitial.cs | 10 ++- StockInfoCore/frmUtilities.Designer.cs | 111 +++++++++++++++++++++++++ StockInfoCore/frmUtilities.cs | 56 +++++++++++++ StockInfoCore/frmUtilities.resx | 60 +++++++++++++ 10 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 StockInfoCore/frmUtilities.Designer.cs create mode 100644 StockInfoCore/frmUtilities.cs create mode 100644 StockInfoCore/frmUtilities.resx diff --git a/BrowserHelper/Settings/TestSettings.cs b/BrowserHelper/Settings/TestSettings.cs index 978b76d..88731fb 100644 --- a/BrowserHelper/Settings/TestSettings.cs +++ b/BrowserHelper/Settings/TestSettings.cs @@ -11,5 +11,6 @@ namespace BrowserHelper.Settings public int TimeoutInterval { get; set; } public string[] StockWishes { get; set; } public string[] StocWishCols { get; set; } + public string[] StockGroups { get; set; } } } diff --git a/StockDAL/StockScrapePage.cs b/StockDAL/StockScrapePage.cs index 68b9c94..220487a 100644 --- a/StockDAL/StockScrapePage.cs +++ b/StockDAL/StockScrapePage.cs @@ -88,6 +88,24 @@ namespace StockDAL File.WriteAllText($"Aktier_{listText}.txt", result); } + public List GetGroupStocksList(string listText,int startNo=0) + { + var resList = new List(); + var nr = startNo; + Thread.Sleep(500); + chooseList.SelectDropDownByText(listText); + Thread.Sleep(3000); + var stocklist = tblList.ReadHandledStock(); + foreach (var stock in stocklist) + { + resList.Add(new StockGroupModel { Id = ++nr, StockGroup = listText, StockName = stock.ColumnValue }); + //result += $"{listText}: {stock.ColumnValue} {System.Environment.NewLine}"; + } + //File.WriteAllText($"Aktier_{listText}.txt", result); + return resList; + } + + //public void CreateProduct() //{ // lnkProduct.Click(); diff --git a/StockDal.Interface/IStockScrapePage.cs b/StockDal.Interface/IStockScrapePage.cs index 4e3276f..b8da215 100644 --- a/StockDal.Interface/IStockScrapePage.cs +++ b/StockDal.Interface/IStockScrapePage.cs @@ -8,6 +8,7 @@ namespace StockDAL.Interface List SearchStockAndCollect(string stockName); void GetStocksPerList(string listText); void PerformClickOnSpecialValue(string name, string operation); + List GetGroupStocksList(string listText, int startNo = 0); } } diff --git a/StockInfoCore/StockInfoDISetup.cs b/StockInfoCore/StockInfoDISetup.cs index d2add6e..5e8d8a7 100644 --- a/StockInfoCore/StockInfoDISetup.cs +++ b/StockInfoCore/StockInfoDISetup.cs @@ -42,6 +42,7 @@ namespace StockInfoCore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); return services; diff --git a/StockInfoCore/appsettings.json b/StockInfoCore/appsettings.json index 431ee8e..8b99d94 100644 --- a/StockInfoCore/appsettings.json +++ b/StockInfoCore/appsettings.json @@ -4,5 +4,17 @@ "ApplicationUrl": "https://finansportalen.millistream.com/shares.php", "TimeoutInterval": 30, "StockWishes": [ "Arion Bank SDB", "Boliden", "Ericsson A", "Getinge B", "Investor A", "SAS", "Securitas B", "SSAB A", "Handelsbanken A", "Swedbank A" ], - "StocWishCols": ["Aktie","Senast","Tid"] + "StocWishCols": [ "Aktie", "Senast", "Tid" ], + "StockGroups": [ + "OMX Stockholm Large Cap", + "OMX Stockholm Mid Cap", + "OMX Stockholm Small Cap", + "Börshandlade fonder (ETF)", + "Spotlight Next", + "Spotlight", + "OMX Stockholm First North", + "NGM Equity", + "beQuoted", + "Nordic SME" + ] } \ No newline at end of file diff --git a/StockInfoCore/frmInitial.Designer.cs b/StockInfoCore/frmInitial.Designer.cs index 11ea324..1665df5 100644 --- a/StockInfoCore/frmInitial.Designer.cs +++ b/StockInfoCore/frmInitial.Designer.cs @@ -51,6 +51,7 @@ namespace StockInfoCore this.cmbOwners = new System.Windows.Forms.ComboBox(); this.pbInitial = new System.Windows.Forms.ProgressBar(); this.tmrProgBar = new System.Windows.Forms.Timer(this.components); + this.btnUtils = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.gB1.SuspendLayout(); this.gbStockMgmnt.SuspendLayout(); @@ -264,11 +265,22 @@ namespace StockInfoCore this.tmrProgBar.Interval = 250; this.tmrProgBar.Tick += new System.EventHandler(this.tmrProgBar_Tick); // + // btnUtils + // + this.btnUtils.Location = new System.Drawing.Point(18, 421); + this.btnUtils.Name = "btnUtils"; + this.btnUtils.Size = new System.Drawing.Size(75, 23); + this.btnUtils.TabIndex = 12; + this.btnUtils.Text = "Utilities"; + this.btnUtils.UseVisualStyleBackColor = true; + this.btnUtils.Click += new System.EventHandler(this.btnUtils_Click); + // // frmInitial // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(895, 538); + this.Controls.Add(this.btnUtils); this.Controls.Add(this.pbInitial); this.Controls.Add(this.gpOwners); this.Controls.Add(this.lblStockRows); @@ -316,6 +328,7 @@ namespace StockInfoCore private System.Windows.Forms.Button btnBackupAll; private ProgressBar pbInitial; private System.Windows.Forms.Timer tmrProgBar; + private Button btnUtils; } } diff --git a/StockInfoCore/frmInitial.cs b/StockInfoCore/frmInitial.cs index d7d861a..f32e9ef 100644 --- a/StockInfoCore/frmInitial.cs +++ b/StockInfoCore/frmInitial.cs @@ -35,6 +35,7 @@ namespace StockInfoCore private readonly frmPersonShareConnect _personShareConnect; private readonly frmBackup _backupWindow; private readonly frmEditStock _editStock; + private readonly frmUtilities _utilities; bool loading = false; int progressValue = 0; @@ -55,7 +56,8 @@ namespace StockInfoCore frmPerson personWindow, frmPersonShareConnect personShareConnect, frmBackup backupWindow, - frmEditStock editStock + frmEditStock editStock, + frmUtilities utilities ) { InitializeComponent(); @@ -74,6 +76,7 @@ namespace StockInfoCore _personShareConnect = personShareConnect; _backupWindow = backupWindow; _editStock = editStock; + _utilities = utilities; } private void Form1_Load(object sender, EventArgs e) @@ -326,5 +329,10 @@ namespace StockInfoCore pbInitial.Visible = false; progressValue = 0; } + + private void btnUtils_Click(object sender, EventArgs e) + { + _utilities.ShowDialog(); + } } } diff --git a/StockInfoCore/frmUtilities.Designer.cs b/StockInfoCore/frmUtilities.Designer.cs new file mode 100644 index 0000000..6465a26 --- /dev/null +++ b/StockInfoCore/frmUtilities.Designer.cs @@ -0,0 +1,111 @@ +namespace StockInfoCore +{ + partial class frmUtilities + { + /// + /// 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.lblUtilityHeader = new System.Windows.Forms.Label(); + this.btnReadStockLists = new System.Windows.Forms.Button(); + this.lvStockGroups = new System.Windows.Forms.ListView(); + this.ch1 = new System.Windows.Forms.ColumnHeader(); + this.ch2 = new System.Windows.Forms.ColumnHeader(); + this.ch3 = new System.Windows.Forms.ColumnHeader(); + this.SuspendLayout(); + // + // lblUtilityHeader + // + this.lblUtilityHeader.AutoSize = true; + this.lblUtilityHeader.Font = new System.Drawing.Font("Segoe UI", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.lblUtilityHeader.Location = new System.Drawing.Point(19, 12); + this.lblUtilityHeader.Name = "lblUtilityHeader"; + this.lblUtilityHeader.Size = new System.Drawing.Size(86, 28); + this.lblUtilityHeader.TabIndex = 0; + this.lblUtilityHeader.Text = "Utilities"; + this.lblUtilityHeader.TextAlign = System.Drawing.ContentAlignment.BottomCenter; + // + // btnReadStockLists + // + this.btnReadStockLists.Location = new System.Drawing.Point(28, 64); + this.btnReadStockLists.Name = "btnReadStockLists"; + this.btnReadStockLists.Size = new System.Drawing.Size(134, 23); + this.btnReadStockLists.TabIndex = 1; + this.btnReadStockLists.Text = "List Stocks By Group"; + this.btnReadStockLists.UseVisualStyleBackColor = true; + this.btnReadStockLists.Click += new System.EventHandler(this.btnReadStockLists_Click); + // + // lvStockGroups + // + this.lvStockGroups.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.ch1, + this.ch2, + this.ch3}); + this.lvStockGroups.Location = new System.Drawing.Point(174, 69); + this.lvStockGroups.Name = "lvStockGroups"; + this.lvStockGroups.Size = new System.Drawing.Size(397, 214); + this.lvStockGroups.TabIndex = 2; + this.lvStockGroups.UseCompatibleStateImageBehavior = false; + this.lvStockGroups.View = System.Windows.Forms.View.Details; + // + // ch1 + // + this.ch1.Text = "Id"; + // + // ch2 + // + this.ch2.Text = "StockGroup"; + this.ch2.Width = 150; + // + // ch3 + // + this.ch3.Text = "StockName"; + this.ch3.Width = 200; + // + // frmUtilities + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(583, 503); + this.Controls.Add(this.lvStockGroups); + this.Controls.Add(this.btnReadStockLists); + this.Controls.Add(this.lblUtilityHeader); + this.Name = "frmUtilities"; + this.Text = "Utilities"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label lblUtilityHeader; + private Button btnReadStockLists; + private ListView lvStockGroups; + private ColumnHeader ch1; + private ColumnHeader ch2; + private ColumnHeader ch3; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmUtilities.cs b/StockInfoCore/frmUtilities.cs new file mode 100644 index 0000000..2bbbd0c --- /dev/null +++ b/StockInfoCore/frmUtilities.cs @@ -0,0 +1,56 @@ +using BrowserHelper.Settings; +using DataDomain; +using StockDal.Interface; +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 StockInfoCore +{ + public partial class frmUtilities : Form + { + private readonly TestSettings _testSettings; + private readonly IStockScrapePage _stockScrapePage; + + public frmUtilities(TestSettings testSettings,IStockScrapePage stockScrapePage) + { + InitializeComponent(); + _testSettings = testSettings; + _stockScrapePage = stockScrapePage; + } + + private void btnReadStockLists_Click(object sender, EventArgs e) + { + var groupNames = _testSettings.StockGroups; + var groupStockList = new List(); + var rowNr = 0; + foreach (var group in groupNames) + { + var biggest = groupStockList.Count>0? + groupStockList.Aggregate((g1, g2) => g1.Id > g2.Id ? g1 : g2) + :null; + if(biggest != null) + groupStockList.AddRange(_stockScrapePage.GetGroupStocksList(group,biggest.Id)); + else + groupStockList.AddRange(_stockScrapePage.GetGroupStocksList(group)); + } + + foreach(var group in groupStockList) + { + var x = lvStockGroups.Items.Add(group.Id.ToString()); + x.SubItems.Add(group.StockGroup.ToString()); + x.SubItems.Add(group.StockName.ToString()); + } + + lvStockGroups.Refresh(); + //_stockScrapePage.GetStocksPerList("OMX Stockholm Large Cap"); + } + } +} diff --git a/StockInfoCore/frmUtilities.resx b/StockInfoCore/frmUtilities.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmUtilities.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