From c831b2bbd52337d1faaafd7266f63b8026029371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Fri, 15 May 2026 21:25:18 +0200 Subject: [PATCH] =?UTF-8?q?Uppdatering=20fr=C3=A5n=20SHB=20och=20AVANZA=20?= =?UTF-8?q?klar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StockHistory/HandleCsvNotes.cs | 11 +++-------- StockHistory/frmStockHistoryInit.cs | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/StockHistory/HandleCsvNotes.cs b/StockHistory/HandleCsvNotes.cs index 46183b3..dd173c4 100644 --- a/StockHistory/HandleCsvNotes.cs +++ b/StockHistory/HandleCsvNotes.cs @@ -1,9 +1,4 @@ using StockHistory.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace StockHistory; @@ -30,10 +25,10 @@ public class HandleCsvNotes : IHandleCsvNotes TransactionType = values[NamePos(Header_table, "Typ av transaktion")], StockCode = values[NamePos(Header_table, @"Värdepapper/beskrivning")], StockPrice = decimal.Parse((values[NamePos(Header_table, "Kurs")] == "") ? "0" : values[NamePos(Header_table, "Kurs")]), - StockQuantity = int.Parse(values[NamePos(Header_table, "Antal")]), + StockQuantity = Math.Abs(int.Parse(values[NamePos(Header_table, "Antal")])), Commission = decimal.Parse((values[NamePos(Header_table, "Courtage")] == "") ? "0" : values[NamePos(Header_table, "Courtage")]), - TotalAmount = decimal.Parse((values[NamePos(Header_table, "Belopp")] == "") ? "0" : values[NamePos(Header_table, "Belopp")]) - decimal.Parse((values[NamePos(Header_table, "Courtage")] == "") ? "0" : values[NamePos(Header_table, "Courtage")]), - AmountToPay = decimal.Parse((values[NamePos(Header_table, "Belopp")] == "") ? "0" : values[NamePos(Header_table, "Belopp")]) + TotalAmount = Math.Abs(decimal.Parse((values[NamePos(Header_table, "Belopp")] == "") ? "0" : values[NamePos(Header_table, "Belopp")])) - decimal.Parse((values[NamePos(Header_table, "Courtage")] == "") ? "0" : values[NamePos(Header_table, "Courtage")]), + AmountToPay = Math.Abs(decimal.Parse((values[NamePos(Header_table, "Belopp")] == "") ? "0" : values[NamePos(Header_table, "Belopp")])) }; transactionNotes.Add(transactionNote); } diff --git a/StockHistory/frmStockHistoryInit.cs b/StockHistory/frmStockHistoryInit.cs index b3d038f..6b77dff 100644 --- a/StockHistory/frmStockHistoryInit.cs +++ b/StockHistory/frmStockHistoryInit.cs @@ -17,6 +17,8 @@ public partial class frmStockHistoryInit : Form private bool lstWait = false; private TaskCompletionSource _waiter; private TransactionNote trans = new(); + private bool SHB = false; + private string pdfFilePath = string.Empty; public frmStockHistoryInit( IPdfOpener pdfOpener, @@ -59,11 +61,13 @@ public partial class frmStockHistoryInit : Form _pdfSidor = _pdfOpener.PdfSidor; btnAnalysera.Enabled = true; + SHB = true; } else if (lblFileName.Text.Length > 5 && lblFileName.Text.ToLower().EndsWith("csv")) { btnAnalysera.Enabled = true; + SHB = false; } else { @@ -75,7 +79,8 @@ public partial class frmStockHistoryInit : Form private void btnAnalysera_Click(object sender, EventArgs e) { string PdfResult = string.Empty; - if (lblFileName.Text.ToLower().EndsWith("csv")) + // if (lblFileName.Text.ToLower().EndsWith("csv")) + if (!SHB) { var Result = string.Empty; //DocoticPdfReading.ExtractText(lblFileName.Text); SelectAvanzaPdfData(lblFileName.Text); @@ -86,6 +91,7 @@ public partial class frmStockHistoryInit : Form SelectPdfData(PdfResult); } btnAnalysera.Enabled = false; + pdfFilePath = lblFileName.Text; lblFileName.Text = string.Empty; } @@ -134,7 +140,6 @@ public partial class frmStockHistoryInit : Form { txtFound.Text = string.Empty; List result = PdfResult.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList(); - //List selected = new(); foreach (var line in result) { @@ -160,9 +165,7 @@ public partial class frmStockHistoryInit : Form private async void btnSaveToDb_Click(object sender, EventArgs e) { - - - if (lblFileName.Text.ToLower().EndsWith("pdf")) + if (SHB) { trans = new(); @@ -242,6 +245,7 @@ public partial class frmStockHistoryInit : Form { await _transactionNotes.AddAsync(trans); txtFound.Text = string.Empty; + if (SHB) RenameHandledFile(pdfFilePath); } catch (DbUpdateException ex) when (ex.InnerException is SqliteException sqlite && sqlite.SqliteErrorCode == 19) { @@ -258,6 +262,11 @@ public partial class frmStockHistoryInit : Form } + private void RenameHandledFile(string pdfFilePath) + { + File.Move(pdfFilePath, Path.Combine(Path.GetDirectoryName(pdfFilePath), "Handled_" + Path.GetFileName(pdfFilePath))); + } + private async Task LoadBusinessAsync() {