välja csv-poster klart , uppdatera klart

This commit is contained in:
2026-05-10 19:10:23 +02:00
parent 392d8097e3
commit 6bdcdecf90
4 changed files with 161 additions and 152 deletions

3
.github/copilot-instructions.md vendored Normal file
View File

@ -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.

View File

@ -1,8 +1,4 @@
using System; namespace StockHistory.Models;
using System.Collections.Generic;
using System.Text;
namespace StockHistory.Models;
public class TransactionNote public class TransactionNote
{ {
@ -16,7 +12,10 @@ public class TransactionNote
public decimal Commission { get; set; } public decimal Commission { get; set; }
public decimal AmountToPay { 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";
}
} }

View File

@ -44,19 +44,18 @@
CommissionHeader = new ColumnHeader(); CommissionHeader = new ColumnHeader();
AmountToPayHeader = new ColumnHeader(); AmountToPayHeader = new ColumnHeader();
btnClose = new Button(); btnClose = new Button();
btnAnalysMany = new Button(); btnNext = new Button();
txtVald = new TextBox();
lblAntal = new Label();
SuspendLayout(); SuspendLayout();
// //
// btnChooseFile // btnChooseFile
// //
btnChooseFile.BackColor = Color.FromArgb(128, 255, 128); btnChooseFile.BackColor = Color.FromArgb(128, 255, 128);
btnChooseFile.FlatStyle = FlatStyle.Flat; btnChooseFile.FlatStyle = FlatStyle.Flat;
btnChooseFile.Font = new Font("Segoe UI", 13F); btnChooseFile.Font = new Font("Segoe UI", 11F);
btnChooseFile.Location = new Point(26, 27); btnChooseFile.Location = new Point(23, 20);
btnChooseFile.Margin = new Padding(3, 2, 3, 2);
btnChooseFile.Name = "btnChooseFile"; btnChooseFile.Name = "btnChooseFile";
btnChooseFile.Size = new Size(143, 37); btnChooseFile.Size = new Size(125, 28);
btnChooseFile.TabIndex = 0; btnChooseFile.TabIndex = 0;
btnChooseFile.Text = "Välj pdf-fil"; btnChooseFile.Text = "Välj pdf-fil";
btnChooseFile.UseVisualStyleBackColor = false; btnChooseFile.UseVisualStyleBackColor = false;
@ -65,9 +64,9 @@
// lblFileName // lblFileName
// //
lblFileName.AutoSize = true; lblFileName.AutoSize = true;
lblFileName.Location = new Point(175, 38); lblFileName.Location = new Point(153, 28);
lblFileName.Name = "lblFileName"; lblFileName.Name = "lblFileName";
lblFileName.Size = new Size(39, 20); lblFileName.Size = new Size(32, 15);
lblFileName.TabIndex = 1; lblFileName.TabIndex = 1;
lblFileName.Text = "_____"; lblFileName.Text = "_____";
lblFileName.TextChanged += lblFileName_TextChanged; lblFileName.TextChanged += lblFileName_TextChanged;
@ -76,10 +75,11 @@
// //
btnAnalysera.BackColor = Color.FromArgb(128, 255, 128); btnAnalysera.BackColor = Color.FromArgb(128, 255, 128);
btnAnalysera.FlatStyle = FlatStyle.Flat; btnAnalysera.FlatStyle = FlatStyle.Flat;
btnAnalysera.Font = new Font("Segoe UI", 13F); btnAnalysera.Font = new Font("Segoe UI", 11F);
btnAnalysera.Location = new Point(26, 126); btnAnalysera.Location = new Point(23, 94);
btnAnalysera.Margin = new Padding(3, 2, 3, 2);
btnAnalysera.Name = "btnAnalysera"; btnAnalysera.Name = "btnAnalysera";
btnAnalysera.Size = new Size(143, 37); btnAnalysera.Size = new Size(125, 28);
btnAnalysera.TabIndex = 2; btnAnalysera.TabIndex = 2;
btnAnalysera.Text = "Analysera"; btnAnalysera.Text = "Analysera";
btnAnalysera.UseVisualStyleBackColor = false; btnAnalysera.UseVisualStyleBackColor = false;
@ -87,20 +87,22 @@
// //
// txtFound // 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.Multiline = true;
txtFound.Name = "txtFound"; txtFound.Name = "txtFound";
txtFound.Size = new Size(468, 303); txtFound.Size = new Size(410, 228);
txtFound.TabIndex = 3; txtFound.TabIndex = 3;
// //
// btnSaveToDb // btnSaveToDb
// //
btnSaveToDb.BackColor = Color.FromArgb(128, 255, 128); btnSaveToDb.BackColor = Color.FromArgb(128, 255, 128);
btnSaveToDb.FlatStyle = FlatStyle.Flat; btnSaveToDb.FlatStyle = FlatStyle.Flat;
btnSaveToDb.Font = new Font("Segoe UI", 13F); btnSaveToDb.Font = new Font("Segoe UI", 11F);
btnSaveToDb.Location = new Point(351, 126); btnSaveToDb.Location = new Point(307, 94);
btnSaveToDb.Margin = new Padding(3, 2, 3, 2);
btnSaveToDb.Name = "btnSaveToDb"; btnSaveToDb.Name = "btnSaveToDb";
btnSaveToDb.Size = new Size(143, 37); btnSaveToDb.Size = new Size(125, 28);
btnSaveToDb.TabIndex = 4; btnSaveToDb.TabIndex = 4;
btnSaveToDb.Text = "Spara till DB"; btnSaveToDb.Text = "Spara till DB";
btnSaveToDb.UseVisualStyleBackColor = false; btnSaveToDb.UseVisualStyleBackColor = false;
@ -111,9 +113,10 @@
lwTransactions.BackColor = Color.WhiteSmoke; lwTransactions.BackColor = Color.WhiteSmoke;
lwTransactions.Columns.AddRange(new ColumnHeader[] { StockCodeHeader, TransactionTypeHeader, TransactionDateHeader, StockQuantityHeader, StockPriceHeader, TotalAmountHeader, CommissionHeader, AmountToPayHeader }); lwTransactions.Columns.AddRange(new ColumnHeader[] { StockCodeHeader, TransactionTypeHeader, TransactionDateHeader, StockQuantityHeader, StockPriceHeader, TotalAmountHeader, CommissionHeader, AmountToPayHeader });
lwTransactions.ForeColor = SystemColors.InactiveCaptionText; 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.Name = "lwTransactions";
lwTransactions.Size = new Size(857, 456); lwTransactions.Size = new Size(750, 343);
lwTransactions.Sorting = SortOrder.Ascending; lwTransactions.Sorting = SortOrder.Ascending;
lwTransactions.TabIndex = 6; lwTransactions.TabIndex = 6;
lwTransactions.UseCompatibleStateImageBehavior = false; lwTransactions.UseCompatibleStateImageBehavior = false;
@ -162,45 +165,40 @@
// //
btnClose.BackColor = Color.Chartreuse; btnClose.BackColor = Color.Chartreuse;
btnClose.FlatStyle = FlatStyle.Popup; btnClose.FlatStyle = FlatStyle.Popup;
btnClose.Font = new Font("Segoe UI", 13F, FontStyle.Regular, GraphicsUnit.Point, 1, true); btnClose.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, 1, true);
btnClose.Location = new Point(1248, 503); btnClose.Location = new Point(1092, 377);
btnClose.Margin = new Padding(3, 2, 3, 2);
btnClose.Name = "btnClose"; btnClose.Name = "btnClose";
btnClose.Size = new Size(124, 38); btnClose.Size = new Size(108, 28);
btnClose.TabIndex = 7; btnClose.TabIndex = 7;
btnClose.Text = "Stäng"; btnClose.Text = "Stäng";
btnClose.UseVisualStyleBackColor = false; btnClose.UseVisualStyleBackColor = false;
btnClose.Click += btnClose_Click; btnClose.Click += btnClose_Click;
// //
// btnAnalysMany // btnNext
// //
btnAnalysMany.Location = new Point(0, 0); btnNext.BackColor = Color.FromArgb(255, 192, 128);
btnAnalysMany.Name = "btnAnalysMany"; btnNext.Cursor = Cursors.IBeam;
btnAnalysMany.Size = new Size(75, 23); btnNext.Enabled = false;
btnAnalysMany.TabIndex = 2; btnNext.FlatStyle = FlatStyle.Flat;
// btnNext.Font = new Font("Segoe UI", 11F);
// txtVald btnNext.Location = new Point(164, 94);
// btnNext.Margin = new Padding(3, 2, 3, 2);
txtVald.Location = new Point(0, 0); btnNext.Name = "btnNext";
txtVald.Name = "txtVald"; btnNext.Size = new Size(125, 28);
txtVald.Size = new Size(100, 27); btnNext.TabIndex = 8;
txtVald.TabIndex = 1; btnNext.Text = "Nästa";
// btnNext.UseVisualStyleBackColor = false;
// lblAntal btnNext.Visible = false;
// btnNext.Click += btnNext_Click;
lblAntal.Location = new Point(0, 0);
lblAntal.Name = "lblAntal";
lblAntal.Size = new Size(100, 23);
lblAntal.TabIndex = 0;
// //
// frmStockHistoryInit // frmStockHistoryInit
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.LightGray; BackColor = Color.LightGray;
ClientSize = new Size(1413, 553); ClientSize = new Size(1236, 415);
Controls.Add(lblAntal); Controls.Add(btnNext);
Controls.Add(txtVald);
Controls.Add(btnAnalysMany);
Controls.Add(btnClose); Controls.Add(btnClose);
Controls.Add(lwTransactions); Controls.Add(lwTransactions);
Controls.Add(btnSaveToDb); Controls.Add(btnSaveToDb);
@ -208,6 +206,7 @@
Controls.Add(btnAnalysera); Controls.Add(btnAnalysera);
Controls.Add(lblFileName); Controls.Add(lblFileName);
Controls.Add(btnChooseFile); Controls.Add(btnChooseFile);
Margin = new Padding(3, 2, 3, 2);
Name = "frmStockHistoryInit"; Name = "frmStockHistoryInit";
Text = "StockBrokerage"; Text = "StockBrokerage";
ResumeLayout(false); ResumeLayout(false);
@ -232,8 +231,6 @@
private ColumnHeader CommissionHeader; private ColumnHeader CommissionHeader;
private ColumnHeader AmountToPayHeader; private ColumnHeader AmountToPayHeader;
private Button btnClose; private Button btnClose;
private Button btnAnalysMany; private Button btnNext;
private TextBox txtVald;
private Label lblAntal;
} }
} }

View File

@ -2,15 +2,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using StockHistory.Models; using StockHistory.Models;
using StockHistory.Services; using StockHistory.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel; 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; namespace StockHistory;
@ -22,6 +14,9 @@ public partial class frmStockHistoryInit : Form
private readonly IHandleCsvNotes _handleCsvNotes; private readonly IHandleCsvNotes _handleCsvNotes;
private List<PdfSida> _pdfSidor = new(); private List<PdfSida> _pdfSidor = new();
private List<PdfSida> localPdfSida = new(); private List<PdfSida> localPdfSida = new();
private bool lstWait = false;
private TaskCompletionSource<bool> _waiter;
private TransactionNote trans = new();
public frmStockHistoryInit( public frmStockHistoryInit(
IPdfOpener pdfOpener, IPdfOpener pdfOpener,
@ -66,6 +61,10 @@ public partial class frmStockHistoryInit : Form
btnAnalysera.Enabled = true; btnAnalysera.Enabled = true;
} }
else if (lblFileName.Text.Length > 5 && lblFileName.Text.ToLower().EndsWith("csv"))
{
btnAnalysera.Enabled = true;
}
else else
{ {
btnAnalysera.Enabled = false; btnAnalysera.Enabled = false;
@ -90,41 +89,45 @@ public partial class frmStockHistoryInit : Form
lblFileName.Text = string.Empty; lblFileName.Text = string.Empty;
} }
private void SelectAvanzaPdfData(string infile) private async Task SelectAvanzaPdfData(string infile)
{ {
txtFound.Text = string.Empty; txtFound.Text = string.Empty;
List<TransactionNote> result = _handleCsvNotes.GetTransactionNotes(infile); List<TransactionNote> result = _handleCsvNotes.GetTransactionNotes(infile);
foreach (TransactionNote note in result) {
// Selected.Add(note);
txtFound.Text += note.ToString() + Environment.NewLine;
txtFound.Refresh(); txtFound.Refresh();
btnNext.Enabled = true;
btnNext.Visible = true;
btnNext.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();
} }
//List<string> selected = new();
//foreach (var line in result) private async Task ShowListAsync(List<TransactionNote> notes)
//{ {
// if (!string.IsNullOrWhiteSpace(line) && line.StartsWith("Affärsdag") foreach (var note in notes)
// || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Handelstidpunkt") {
// || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Värdepapper") txtFound.Text = note.ToString();
// || !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();
// } trans = note;
//}
_waiter = new TaskCompletionSource<bool>();
await _waiter.Task; // Väntar utan att blockera UI
}
}
private void btnNext_Click(object sender, EventArgs e)
{
_waiter?.TrySetResult(true);
} }
private void SelectPdfData(string PdfResult) private void SelectPdfData(string PdfResult)
@ -157,7 +160,11 @@ public partial class frmStockHistoryInit : Form
private async void btnSaveToDb_Click(object sender, EventArgs e) private async void btnSaveToDb_Click(object sender, EventArgs e)
{ {
TransactionNote trans = new();
if (lblFileName.Text.ToLower().EndsWith("pdf"))
{
trans = new();
foreach (var line in Selected) foreach (var line in Selected)
{ {
@ -229,6 +236,8 @@ public partial class frmStockHistoryInit : Form
} }
} }
} }
}
try try
{ {
await _transactionNotes.AddAsync(trans); await _transactionNotes.AddAsync(trans);
@ -274,5 +283,6 @@ public partial class frmStockHistoryInit : Form
this.Close(); this.Close();
} }
} }