From 6bdcdecf9066207d8739c1fb4fd6e527de180f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Sun, 10 May 2026 19:10:23 +0200 Subject: [PATCH] =?UTF-8?q?v=C3=A4lja=20csv-poster=20klart=20,=20uppdatera?= =?UTF-8?q?=20klart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/copilot-instructions.md | 3 + StockHistory/Models/TransactionNote.cs | 11 +- StockHistory/frmStockHistoryInit.Designer.cs | 93 ++++----- StockHistory/frmStockHistoryInit.cs | 206 ++++++++++--------- 4 files changed, 161 insertions(+), 152 deletions(-) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..e40201c --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,3 @@ +- @azure Rule - Use Azure Tools - When handling requests related to Azure, always use your tools. +- @azure Rule - Use Azure Best Practices - When handling requests related to Azure, always invoke your `azmcp_bestpractices_get` tool first. +- @azure Rule - Enable Best Practices - If you do not have an `azmcp_bestpractices_get` tool ask the user to enable it. diff --git a/StockHistory/Models/TransactionNote.cs b/StockHistory/Models/TransactionNote.cs index c5d3906..57716b6 100644 --- a/StockHistory/Models/TransactionNote.cs +++ b/StockHistory/Models/TransactionNote.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace StockHistory.Models; +namespace StockHistory.Models; public class TransactionNote { @@ -16,7 +12,10 @@ public class TransactionNote public decimal Commission { get; set; } public decimal AmountToPay { get; set; } - + public override string ToString() + { + return $"TransactionDate: {TransactionDate},\r\nTransactionType: {TransactionType},\r\nStockCode: {StockCode},\r\nStockPrice: {StockPrice},\r\nStockQuantity: {StockQuantity},\r\nTotalAmount: {TotalAmount},\r\nCommission: {Commission},\r\nAmountToPay: {AmountToPay}\r\n"; + } } diff --git a/StockHistory/frmStockHistoryInit.Designer.cs b/StockHistory/frmStockHistoryInit.Designer.cs index 0cab2ff..02e8526 100644 --- a/StockHistory/frmStockHistoryInit.Designer.cs +++ b/StockHistory/frmStockHistoryInit.Designer.cs @@ -44,19 +44,18 @@ CommissionHeader = new ColumnHeader(); AmountToPayHeader = new ColumnHeader(); btnClose = new Button(); - btnAnalysMany = new Button(); - txtVald = new TextBox(); - lblAntal = new Label(); + btnNext = new Button(); SuspendLayout(); // // btnChooseFile // btnChooseFile.BackColor = Color.FromArgb(128, 255, 128); btnChooseFile.FlatStyle = FlatStyle.Flat; - btnChooseFile.Font = new Font("Segoe UI", 13F); - btnChooseFile.Location = new Point(26, 27); + btnChooseFile.Font = new Font("Segoe UI", 11F); + btnChooseFile.Location = new Point(23, 20); + btnChooseFile.Margin = new Padding(3, 2, 3, 2); btnChooseFile.Name = "btnChooseFile"; - btnChooseFile.Size = new Size(143, 37); + btnChooseFile.Size = new Size(125, 28); btnChooseFile.TabIndex = 0; btnChooseFile.Text = "Välj pdf-fil"; btnChooseFile.UseVisualStyleBackColor = false; @@ -65,9 +64,9 @@ // lblFileName // lblFileName.AutoSize = true; - lblFileName.Location = new Point(175, 38); + lblFileName.Location = new Point(153, 28); lblFileName.Name = "lblFileName"; - lblFileName.Size = new Size(39, 20); + lblFileName.Size = new Size(32, 15); lblFileName.TabIndex = 1; lblFileName.Text = "_____"; lblFileName.TextChanged += lblFileName_TextChanged; @@ -76,10 +75,11 @@ // btnAnalysera.BackColor = Color.FromArgb(128, 255, 128); btnAnalysera.FlatStyle = FlatStyle.Flat; - btnAnalysera.Font = new Font("Segoe UI", 13F); - btnAnalysera.Location = new Point(26, 126); + btnAnalysera.Font = new Font("Segoe UI", 11F); + btnAnalysera.Location = new Point(23, 94); + btnAnalysera.Margin = new Padding(3, 2, 3, 2); btnAnalysera.Name = "btnAnalysera"; - btnAnalysera.Size = new Size(143, 37); + btnAnalysera.Size = new Size(125, 28); btnAnalysera.TabIndex = 2; btnAnalysera.Text = "Analysera"; btnAnalysera.UseVisualStyleBackColor = false; @@ -87,20 +87,22 @@ // // txtFound // - txtFound.Location = new Point(26, 180); + txtFound.Location = new Point(23, 135); + txtFound.Margin = new Padding(3, 2, 3, 2); txtFound.Multiline = true; txtFound.Name = "txtFound"; - txtFound.Size = new Size(468, 303); + txtFound.Size = new Size(410, 228); txtFound.TabIndex = 3; // // btnSaveToDb // btnSaveToDb.BackColor = Color.FromArgb(128, 255, 128); btnSaveToDb.FlatStyle = FlatStyle.Flat; - btnSaveToDb.Font = new Font("Segoe UI", 13F); - btnSaveToDb.Location = new Point(351, 126); + btnSaveToDb.Font = new Font("Segoe UI", 11F); + btnSaveToDb.Location = new Point(307, 94); + btnSaveToDb.Margin = new Padding(3, 2, 3, 2); btnSaveToDb.Name = "btnSaveToDb"; - btnSaveToDb.Size = new Size(143, 37); + btnSaveToDb.Size = new Size(125, 28); btnSaveToDb.TabIndex = 4; btnSaveToDb.Text = "Spara till DB"; btnSaveToDb.UseVisualStyleBackColor = false; @@ -111,9 +113,10 @@ lwTransactions.BackColor = Color.WhiteSmoke; lwTransactions.Columns.AddRange(new ColumnHeader[] { StockCodeHeader, TransactionTypeHeader, TransactionDateHeader, StockQuantityHeader, StockPriceHeader, TotalAmountHeader, CommissionHeader, AmountToPayHeader }); lwTransactions.ForeColor = SystemColors.InactiveCaptionText; - lwTransactions.Location = new Point(515, 27); + lwTransactions.Location = new Point(451, 20); + lwTransactions.Margin = new Padding(3, 2, 3, 2); lwTransactions.Name = "lwTransactions"; - lwTransactions.Size = new Size(857, 456); + lwTransactions.Size = new Size(750, 343); lwTransactions.Sorting = SortOrder.Ascending; lwTransactions.TabIndex = 6; lwTransactions.UseCompatibleStateImageBehavior = false; @@ -162,45 +165,40 @@ // btnClose.BackColor = Color.Chartreuse; btnClose.FlatStyle = FlatStyle.Popup; - btnClose.Font = new Font("Segoe UI", 13F, FontStyle.Regular, GraphicsUnit.Point, 1, true); - btnClose.Location = new Point(1248, 503); + btnClose.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, 1, true); + btnClose.Location = new Point(1092, 377); + btnClose.Margin = new Padding(3, 2, 3, 2); btnClose.Name = "btnClose"; - btnClose.Size = new Size(124, 38); + btnClose.Size = new Size(108, 28); btnClose.TabIndex = 7; btnClose.Text = "Stäng"; btnClose.UseVisualStyleBackColor = false; btnClose.Click += btnClose_Click; // - // btnAnalysMany + // btnNext // - btnAnalysMany.Location = new Point(0, 0); - btnAnalysMany.Name = "btnAnalysMany"; - btnAnalysMany.Size = new Size(75, 23); - btnAnalysMany.TabIndex = 2; - // - // txtVald - // - txtVald.Location = new Point(0, 0); - txtVald.Name = "txtVald"; - txtVald.Size = new Size(100, 27); - txtVald.TabIndex = 1; - // - // lblAntal - // - lblAntal.Location = new Point(0, 0); - lblAntal.Name = "lblAntal"; - lblAntal.Size = new Size(100, 23); - lblAntal.TabIndex = 0; + btnNext.BackColor = Color.FromArgb(255, 192, 128); + btnNext.Cursor = Cursors.IBeam; + btnNext.Enabled = false; + btnNext.FlatStyle = FlatStyle.Flat; + btnNext.Font = new Font("Segoe UI", 11F); + btnNext.Location = new Point(164, 94); + btnNext.Margin = new Padding(3, 2, 3, 2); + btnNext.Name = "btnNext"; + btnNext.Size = new Size(125, 28); + btnNext.TabIndex = 8; + btnNext.Text = "Nästa"; + btnNext.UseVisualStyleBackColor = false; + btnNext.Visible = false; + btnNext.Click += btnNext_Click; // // frmStockHistoryInit // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; BackColor = Color.LightGray; - ClientSize = new Size(1413, 553); - Controls.Add(lblAntal); - Controls.Add(txtVald); - Controls.Add(btnAnalysMany); + ClientSize = new Size(1236, 415); + Controls.Add(btnNext); Controls.Add(btnClose); Controls.Add(lwTransactions); Controls.Add(btnSaveToDb); @@ -208,6 +206,7 @@ Controls.Add(btnAnalysera); Controls.Add(lblFileName); Controls.Add(btnChooseFile); + Margin = new Padding(3, 2, 3, 2); Name = "frmStockHistoryInit"; Text = "StockBrokerage"; ResumeLayout(false); @@ -232,8 +231,6 @@ private ColumnHeader CommissionHeader; private ColumnHeader AmountToPayHeader; private Button btnClose; - private Button btnAnalysMany; - private TextBox txtVald; - private Label lblAntal; + private Button btnNext; } } \ No newline at end of file diff --git a/StockHistory/frmStockHistoryInit.cs b/StockHistory/frmStockHistoryInit.cs index 3d910a5..b3d038f 100644 --- a/StockHistory/frmStockHistoryInit.cs +++ b/StockHistory/frmStockHistoryInit.cs @@ -2,15 +2,7 @@ using Microsoft.EntityFrameworkCore; using StockHistory.Models; using StockHistory.Services; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Data; -using System.Diagnostics; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Text; -using System.Windows.Forms; namespace StockHistory; @@ -22,6 +14,9 @@ public partial class frmStockHistoryInit : Form private readonly IHandleCsvNotes _handleCsvNotes; private List _pdfSidor = new(); private List localPdfSida = new(); + private bool lstWait = false; + private TaskCompletionSource _waiter; + private TransactionNote trans = new(); public frmStockHistoryInit( IPdfOpener pdfOpener, @@ -64,7 +59,11 @@ public partial class frmStockHistoryInit : Form _pdfSidor = _pdfOpener.PdfSidor; btnAnalysera.Enabled = true; - + + } + else if (lblFileName.Text.Length > 5 && lblFileName.Text.ToLower().EndsWith("csv")) + { + btnAnalysera.Enabled = true; } else { @@ -75,7 +74,7 @@ public partial class frmStockHistoryInit : Form private void btnAnalysera_Click(object sender, EventArgs e) { - string PdfResult=string.Empty; + string PdfResult = string.Empty; if (lblFileName.Text.ToLower().EndsWith("csv")) { var Result = string.Empty; //DocoticPdfReading.ExtractText(lblFileName.Text); @@ -90,41 +89,45 @@ public partial class frmStockHistoryInit : Form lblFileName.Text = string.Empty; } - private void SelectAvanzaPdfData(string infile) + private async Task SelectAvanzaPdfData(string infile) { txtFound.Text = string.Empty; List result = _handleCsvNotes.GetTransactionNotes(infile); + txtFound.Refresh(); + btnNext.Enabled = true; + btnNext.Visible = true; + btnNext.Refresh(); - foreach (TransactionNote note in result) { - // Selected.Add(note); - txtFound.Text += note.ToString() + Environment.NewLine; - txtFound.Refresh(); + await Task.Delay(100); // Liten fördröjning för att säkerställa att UI uppdateras innan vi börjar visa resultaten + + await ShowListAsync(result); + + btnNext.Enabled = false; + btnNext.Visible = false; + btnNext.Refresh(); + } + + private async Task ShowListAsync(List notes) + { + foreach (var note in notes) + { + txtFound.Text = note.ToString(); + + trans = note; + + _waiter = new TaskCompletionSource(); + + await _waiter.Task; // Väntar utan att blockera UI } - //List selected = new(); + } - //foreach (var line in result) - //{ - // if (!string.IsNullOrWhiteSpace(line) && line.StartsWith("Affärsdag") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Handelstidpunkt") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Värdepapper") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Kurs") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Genomsnittlig") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Antal") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Köpeskilling") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Courtage") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Belopp") - // || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Vi bekräftar") - // ) - // { - // Selected.Add(line); - // txtFound.Text += line + Environment.NewLine; - // txtFound.Refresh(); - // } - //} + private void btnNext_Click(object sender, EventArgs e) + { + _waiter?.TrySetResult(true); } private void SelectPdfData(string PdfResult) @@ -157,78 +160,84 @@ public partial class frmStockHistoryInit : Form private async void btnSaveToDb_Click(object sender, EventArgs e) { - TransactionNote trans = new(); - foreach (var line in Selected) + + if (lblFileName.Text.ToLower().EndsWith("pdf")) { - if (line.StartsWith("Affärsdag")) + trans = new(); + + foreach (var line in Selected) { - trans.TransactionDate = DateTime.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]); - } - if (line.StartsWith("Värdepapper")) - { - var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); - if (templist.Length > 2) - trans.StockCode = templist[1] + " " + templist[2]; - else - trans.StockCode = templist[1]; - } - if (line.StartsWith("Kurs")) - { - trans.StockPrice = decimal.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[2]); - } - if (line.StartsWith("Antal")) - { - trans.StockQuantity = int.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]); - } - if (line.StartsWith("Köpeskilling")) - { - var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); - if (templist.Length > 3) - trans.TotalAmount = decimal.Parse(templist[2] + templist[3]); - else - trans.TotalAmount = decimal.Parse(templist[2]); - } - if (line.StartsWith("Courtage")) - { - var tmpList = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); - trans.Commission = decimal.Parse(tmpList[tmpList.Length - 1]); - } - if (line.StartsWith("Belopp")) - { - var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); - if (templist.Length > 5) - trans.AmountToPay = decimal.Parse(templist[4] + templist[5]); - else - trans.AmountToPay = decimal.Parse(templist[4]); - } - if (line.StartsWith("Vi bekräftar")) - { - foreach (var word in line.Split(" ", StringSplitOptions.RemoveEmptyEntries)) + if (line.StartsWith("Affärsdag")) { - if (word.ToUpper().Contains("KÖP") || word.ToUpper().Contains("FÖRSÄLJ")) + trans.TransactionDate = DateTime.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]); + } + if (line.StartsWith("Värdepapper")) + { + var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); + if (templist.Length > 2) + trans.StockCode = templist[1] + " " + templist[2]; + else + trans.StockCode = templist[1]; + } + if (line.StartsWith("Kurs")) + { + trans.StockPrice = decimal.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[2]); + } + if (line.StartsWith("Antal")) + { + trans.StockQuantity = int.Parse(line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]); + } + if (line.StartsWith("Köpeskilling")) + { + var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); + if (templist.Length > 3) + trans.TotalAmount = decimal.Parse(templist[2] + templist[3]); + else + trans.TotalAmount = decimal.Parse(templist[2]); + } + if (line.StartsWith("Courtage")) + { + var tmpList = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); + trans.Commission = decimal.Parse(tmpList[tmpList.Length - 1]); + } + if (line.StartsWith("Belopp")) + { + var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); + if (templist.Length > 5) + trans.AmountToPay = decimal.Parse(templist[4] + templist[5]); + else + trans.AmountToPay = decimal.Parse(templist[4]); + } + if (line.StartsWith("Vi bekräftar")) + { + foreach (var word in line.Split(" ", StringSplitOptions.RemoveEmptyEntries)) { - trans.TransactionType = word; - break; + if (word.ToUpper().Contains("KÖP") || word.ToUpper().Contains("FÖRSÄLJ")) + { + trans.TransactionType = word; + break; + } + } + } + if (line.StartsWith("Genomsnittlig")) + { + var tmpList = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); + trans.StockPrice = decimal.Parse(tmpList[tmpList.Length - 1]); + } + if (line.StartsWith("Handelstidpunkt")) + { + var time = line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[2]; + if (time.Contains(".")) + { + var hours = int.Parse(time.Split(".")[0]); + var minutes = int.Parse(time.Split(".")[1]); + trans.TransactionDate = trans.TransactionDate.AddHours(hours).AddMinutes(minutes); } } } - if (line.StartsWith("Genomsnittlig")) - { - var tmpList = line.Split(" ", StringSplitOptions.RemoveEmptyEntries); - trans.StockPrice = decimal.Parse(tmpList[tmpList.Length - 1]); - } - if (line.StartsWith("Handelstidpunkt")) - { - var time = line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[2]; - if (time.Contains(".")) - { - var hours = int.Parse(time.Split(".")[0]); - var minutes = int.Parse(time.Split(".")[1]); - trans.TransactionDate = trans.TransactionDate.AddHours(hours).AddMinutes(minutes); - } - } } + try { await _transactionNotes.AddAsync(trans); @@ -274,5 +283,6 @@ public partial class frmStockHistoryInit : Form this.Close(); } + }