diff --git a/DataDomain/PersonStock.cs b/DataDomain/PersonStock.cs index dc646ba..7747698 100644 --- a/DataDomain/PersonStock.cs +++ b/DataDomain/PersonStock.cs @@ -12,5 +12,6 @@ namespace DataDomain public int PersonId { get; set; } public int StockId { get; set; } public string Comment { get; set; } + } } diff --git a/DataDomain/StockGrpPers.cs b/DataDomain/StockGrpPers.cs new file mode 100644 index 0000000..31eef6b --- /dev/null +++ b/DataDomain/StockGrpPers.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class StockGrpPers + { + public string StockId { get; set; } + public string StockGroup { get; set;} + public int PersId { get; set;} + } +} diff --git a/StockDAL/StockMarketRepository.cs b/StockDAL/StockMarketRepository.cs index c7015e5..4d55163 100644 --- a/StockDAL/StockMarketRepository.cs +++ b/StockDAL/StockMarketRepository.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Reflection; using System.Diagnostics; +using StockDAL.Interface; namespace StockDal { @@ -24,10 +25,14 @@ namespace StockDal public bool ViewBrowser { get; set; } public IWebDriver driver; + private readonly IStockPersonConnect _stockPersonConnect; + private readonly IStockRepository _stockRepository; - public StockMarketRepository() + public StockMarketRepository(IStockPersonConnect stockPersonConnect, IStockRepository stockRepository ) { ViewBrowser = false; + _stockPersonConnect = stockPersonConnect; + _stockRepository = stockRepository; } private void Find_Data() @@ -201,16 +206,23 @@ namespace StockDal } - public void LoadStockMarketList() + public void LoadStockMarketList(int persId) { StockMarketList = new Dictionary(); DumpObjects = new List(); - OpenBrowser(null); - Find_Data(); - OpenBrowser(); - Find_Data(); - OpenBrowser(true); - Find_Data(); + + //var connStocks = _stockPersonConnect.GetAllConnectionsByPersId(persId); + var groupedStocks = _stockRepository.GetStocksGroupedPerPerson(persId); + + + //OpenBrowser(null); + //Find_Data(); + //OpenBrowser(); + //Find_Data(); + //OpenBrowser(true); + //Find_Data(); + + if (DumpObjects.Any()) { SaveLogging(); @@ -218,7 +230,7 @@ namespace StockDal } - public void LoadStockMarketList(bool viewBrowser) + public void LoadStockMarketList(int persId, bool viewBrowser) { StockMarketList = new Dictionary(); ViewBrowser = viewBrowser; @@ -226,7 +238,7 @@ namespace StockDal Find_Data(); } - public void RefreshMarketList() + public void RefreshMarketList(int persId) { StockMarketList = new Dictionary(); driver.Navigate().Refresh(); diff --git a/StockDAL/StockRepository.cs b/StockDAL/StockRepository.cs index a4310c4..3710298 100644 --- a/StockDAL/StockRepository.cs +++ b/StockDAL/StockRepository.cs @@ -104,6 +104,23 @@ namespace StockDAL context.SaveChanges(); } + public IEnumerable GetStocksGroupedPerPerson(int persId) + { + using var context = new StockContext(); + var result = (from prs in context.PersonStocks + join stk in context.Stocks on prs.StockId equals stk.Id + join grp in context.StockGroups on stk.StockId equals grp.StockName + where prs.PersonId == persId + orderby grp.GroupName, grp.StockName + select new StockGrpPers + { + PersId = persId, + StockId = stk.StockId, + StockGroup = grp.GroupName + }).ToList(); + return result; + } + public void RestoreStockMembers(List stockMembers) { using var context = new StockContext(); diff --git a/StockDal.Interface/IStockMarketRepository.cs b/StockDal.Interface/IStockMarketRepository.cs index daf4e60..409d9fb 100644 --- a/StockDal.Interface/IStockMarketRepository.cs +++ b/StockDal.Interface/IStockMarketRepository.cs @@ -13,8 +13,8 @@ namespace StockDal.Interface bool ViewBrowser { get; set; } void Clean(); - void LoadStockMarketList(); - void LoadStockMarketList(bool viewBrowser); - void RefreshMarketList(); + void LoadStockMarketList(int persId); + void LoadStockMarketList(int persId, bool viewBrowser); + void RefreshMarketList(int persId); } } diff --git a/StockDal.Interface/IStockRepository.cs b/StockDal.Interface/IStockRepository.cs index 29189c5..399bf76 100644 --- a/StockDal.Interface/IStockRepository.cs +++ b/StockDal.Interface/IStockRepository.cs @@ -19,5 +19,6 @@ namespace StockDAL.Interface void SaveStockMember(StockMember stockMember); void UpdateActualForSell(int id, int sellAmount, decimal sellPrice, DateTime sellDate); void UpdateActualPrice(int id, decimal price); + IEnumerable GetStocksGroupedPerPerson(int persId); } } diff --git a/StockInfoCore/StockInfoCore.csproj b/StockInfoCore/StockInfoCore.csproj index 86e0bc1..80aec0e 100644 --- a/StockInfoCore/StockInfoCore.csproj +++ b/StockInfoCore/StockInfoCore.csproj @@ -8,6 +8,20 @@ enable + + + + + + + + Always + + + PreserveNewest + + + all @@ -33,11 +47,5 @@ Form - - - - PreserveNewest - - \ No newline at end of file diff --git a/StockInfoCore/StockInfoDISetup.cs b/StockInfoCore/StockInfoDISetup.cs index 6ede330..93ed2d9 100644 --- a/StockInfoCore/StockInfoDISetup.cs +++ b/StockInfoCore/StockInfoDISetup.cs @@ -1,4 +1,5 @@ using BrowserHelper.Driver; +using BrowserHelper.Extensions; using Microsoft.Extensions.DependencyInjection; using SqliteBackups; using SqliteBackups.Interfaces; @@ -20,6 +21,7 @@ namespace StockInfoCore { public static IServiceCollection AddDIInfo(this IServiceCollection services) { + services.UseWebDriverInitializer(); services.AddTransient(); services.AddTransient(); diff --git a/StockInfoCore/Stocks.db b/StockInfoCore/Stocks.db index a9641b4..c2d1cd9 100644 Binary files a/StockInfoCore/Stocks.db and b/StockInfoCore/Stocks.db differ diff --git a/StockInfoCore/Stocks.db-shm b/StockInfoCore/Stocks.db-shm deleted file mode 100644 index cb81175..0000000 Binary files a/StockInfoCore/Stocks.db-shm and /dev/null differ diff --git a/StockInfoCore/Stocks.db-wal b/StockInfoCore/Stocks.db-wal deleted file mode 100644 index 2e7fdb6..0000000 Binary files a/StockInfoCore/Stocks.db-wal and /dev/null differ diff --git a/StockInfoCore/appsettings.json b/StockInfoCore/appsettings.json new file mode 100644 index 0000000..431ee8e --- /dev/null +++ b/StockInfoCore/appsettings.json @@ -0,0 +1,8 @@ +{ + "BrowserType": "chrome", + "Headless" : true, + "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"] +} \ No newline at end of file diff --git a/StockInfoCore/frmInitial.cs b/StockInfoCore/frmInitial.cs index c7e3d31..411e8b9 100644 --- a/StockInfoCore/frmInitial.cs +++ b/StockInfoCore/frmInitial.cs @@ -105,7 +105,7 @@ namespace StockInfoCore private void btnTestScrapFunction_Click(object sender, EventArgs e) { - _stockMarketRepository.LoadStockMarketList(chbShowBrowser.Checked); + _stockMarketRepository.LoadStockMarketList(SelectedPersonId, chbShowBrowser.Checked); var stocklist = _stockMarketRepository.StockMarketList; lblStockRows.Text = stocklist.Count().ToString(); btnReloadShares.Enabled = true; @@ -121,7 +121,7 @@ namespace StockInfoCore private void Button1reload() { lblStockRows.Text = ""; - _stockMarketRepository.RefreshMarketList(); + _stockMarketRepository.RefreshMarketList(SelectedPersonId); var stocklist = _stockMarketRepository.StockMarketList; lblStockRows.Text = stocklist.Count().ToString(); } @@ -129,7 +129,7 @@ namespace StockInfoCore private void btnStockReg_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; - _stockMarketRepository.LoadStockMarketList(); + _stockMarketRepository.LoadStockMarketList(SelectedPersonId); _regWindow.Stocks = _stockMarketRepository.StockMarketList; Cursor.Current = DefaultCursor; _regWindow.ShowDialog(); @@ -149,9 +149,11 @@ namespace StockInfoCore { var person = _personRepository.GetPersonById(SelectedPersonId); Cursor.Current = Cursors.WaitCursor; - _stockMarketRepository.LoadStockMarketList(); + + _stockMarketRepository.LoadStockMarketList(SelectedPersonId); _stockWindow.ConnectedPerson = person; _stockWindow.Stocks = _stockMarketRepository.StockMarketList; + Cursor.Current = DefaultCursor; _stockWindow.ShowDialog(); } diff --git a/StockInfoCore/frmMyStocks.Designer.cs b/StockInfoCore/frmMyStocks.Designer.cs index f8464ea..050ed4a 100644 --- a/StockInfoCore/frmMyStocks.Designer.cs +++ b/StockInfoCore/frmMyStocks.Designer.cs @@ -58,6 +58,7 @@ namespace StockInfoCore this.txtTotalMinus = new System.Windows.Forms.TextBox(); this.label7 = new System.Windows.Forms.Label(); this.txtTotalPlus = new System.Windows.Forms.TextBox(); + this.lblOwnerName = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // @@ -80,7 +81,6 @@ namespace StockInfoCore 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"; @@ -323,11 +323,21 @@ namespace StockInfoCore this.txtTotalPlus.Size = new System.Drawing.Size(114, 33); this.txtTotalPlus.TabIndex = 14; // + // lblOwnerName + // + this.lblOwnerName.AutoSize = true; + this.lblOwnerName.Location = new System.Drawing.Point(424, 10); + this.lblOwnerName.Name = "lblOwnerName"; + this.lblOwnerName.Size = new System.Drawing.Size(145, 20); + this.lblOwnerName.TabIndex = 16; + this.lblOwnerName.Text = "Portfölj Ägare Namn"; + // // 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.lblOwnerName); this.Controls.Add(this.label7); this.Controls.Add(this.txtTotalPlus); this.Controls.Add(this.label6); @@ -385,5 +395,6 @@ namespace StockInfoCore private System.Windows.Forms.TextBox txtTotalMinus; private System.Windows.Forms.Label label7; private System.Windows.Forms.TextBox txtTotalPlus; + private Label lblOwnerName; } } \ No newline at end of file diff --git a/StockInfoCore/frmMyStocks.cs b/StockInfoCore/frmMyStocks.cs index 5e0b605..373a750 100644 --- a/StockInfoCore/frmMyStocks.cs +++ b/StockInfoCore/frmMyStocks.cs @@ -71,6 +71,7 @@ namespace StockInfoCore AddItemToListView(stk); } + lblOwnerName.Text = $"* {ConnectedPerson.FirstName} {ConnectedPerson.LastName} *"; txtBuyTotal.Text = BoughtSum.ToString(); txtBuyTotal.Refresh(); txtCurrValue.Text = CurrentSum.ToString(); @@ -96,7 +97,7 @@ namespace StockInfoCore private void TotalReload() { - _stockMarketRepository.LoadStockMarketList(); + _stockMarketRepository.LoadStockMarketList(ConnectedPerson.Id); Stocks = _stockMarketRepository.StockMarketList; ReloadData(); // lbUpdateTimes.Items.Add($"{DateTime.Now.ToLongTimeString()} - {txtTotDiff.Text.Substring(0, txtTotDiff.Text.Length-2)}"); diff --git a/StockInfoCore/frmMyStocks.resx b/StockInfoCore/frmMyStocks.resx index f298a7b..d731088 100644 --- a/StockInfoCore/frmMyStocks.resx +++ b/StockInfoCore/frmMyStocks.resx @@ -57,4 +57,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file