Uppdatering från SHB och AVANZA klar

This commit is contained in:
2026-05-15 21:25:18 +02:00
parent 6bdcdecf90
commit c831b2bbd5
2 changed files with 17 additions and 13 deletions

View File

@ -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);
}

View File

@ -17,6 +17,8 @@ public partial class frmStockHistoryInit : Form
private bool lstWait = false;
private TaskCompletionSource<bool> _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<string> result = PdfResult.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).ToList();
//List<string> 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()
{