From 6d6b872e1c592909391de8a1ac944adc19c12303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sat, 22 Aug 2026 14:17:48 +0200 Subject: [PATCH] =?UTF-8?q?B=C3=B6rjan=20till=20enskild=20analys=20av=20ak?= =?UTF-8?q?tierna?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StockHistory/Models/StockEquity.cs | 4 +++ .../frmStockHistoryAnalyse.Designer.cs | 2 ++ StockHistory/frmStockHistoryAnalyse.cs | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/StockHistory/Models/StockEquity.cs b/StockHistory/Models/StockEquity.cs index 47881dd..52f84df 100644 --- a/StockHistory/Models/StockEquity.cs +++ b/StockHistory/Models/StockEquity.cs @@ -10,4 +10,8 @@ public class StockEquity public DateTime Sold { get; set; } public decimal SoldPrice { get; set; } public int SoldQuant { get; set; } + public override string ToString() + { + return $"{Id} {StockCode} {Bought} {BoughtPrice} {Quantity} {Sold} {SoldPrice} {SoldQuant}"; + } } diff --git a/StockHistory/frmStockHistoryAnalyse.Designer.cs b/StockHistory/frmStockHistoryAnalyse.Designer.cs index e138903..a8134c0 100644 --- a/StockHistory/frmStockHistoryAnalyse.Designer.cs +++ b/StockHistory/frmStockHistoryAnalyse.Designer.cs @@ -98,12 +98,14 @@ // lwStocks // lwStocks.Columns.AddRange(new ColumnHeader[] { chStock, chBought, chPrize, chNumber, chValue }); + lwStocks.FullRowSelect = true; lwStocks.Location = new Point(111, 103); lwStocks.Name = "lwStocks"; lwStocks.Size = new Size(676, 154); lwStocks.TabIndex = 9; lwStocks.UseCompatibleStateImageBehavior = false; lwStocks.View = View.Details; + lwStocks.MouseClick += lwStocks_MouseClick; // // chStock // diff --git a/StockHistory/frmStockHistoryAnalyse.cs b/StockHistory/frmStockHistoryAnalyse.cs index 6c072c9..7ee4a80 100644 --- a/StockHistory/frmStockHistoryAnalyse.cs +++ b/StockHistory/frmStockHistoryAnalyse.cs @@ -1,5 +1,6 @@ using StockHistory.Models; using StockHistory.Services; +using System.Diagnostics; namespace StockHistory; @@ -100,4 +101,35 @@ public partial class frmStockHistoryAnalyse : Form { } + + private void lwStocks_MouseClick(object sender, MouseEventArgs e) + { + if (lwStocks.SelectedItems.Count > 0) + { + var item = lwStocks.SelectedItems[0]; + LoadHistoryRecsAsync(item.Text).Wait(); + } + } + private async Task LoadHistoryRecsAsync(string stockName) + { + //MessageBox.Show("Du klickade på: " + item.Text); + var result = _equityServices.GetByCodeAsync(stockName); + if (result != null) + { + lwStockHistory.Items.Clear(); + foreach (var histRec in await result) + { + var l_item = new ListViewItem(histRec.StockCode); + l_item.SubItems.Add(histRec.Bought.ToString()); + l_item.SubItems.Add(histRec.BoughtPrice.ToString()); + l_item.SubItems.Add(histRec.Quantity.ToString()); + Debug.WriteLine(histRec.ToString()); + var totval = (histRec.SoldQuant > 0) ? histRec.SoldQuant * histRec.SoldPrice - histRec.BoughtPrice * histRec.Quantity : histRec.BoughtPrice * histRec.Quantity; + l_item.SubItems.Add((totval).ToString("C")); + lwStockHistory.Items.Add(l_item); + } + } + lwStockHistory.Refresh(); + } + }