välja csv-poster klart , uppdatera klart
This commit is contained in:
3
.github/copilot-instructions.md
vendored
Normal file
3
.github/copilot-instructions.md
vendored
Normal 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.
|
||||
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
93
StockHistory/frmStockHistoryInit.Designer.cs
generated
93
StockHistory/frmStockHistoryInit.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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<PdfSida> _pdfSidor = new();
|
||||
private List<PdfSida> localPdfSida = new();
|
||||
private bool lstWait = false;
|
||||
private TaskCompletionSource<bool> _waiter;
|
||||
private TransactionNote trans = new();
|
||||
|
||||
public frmStockHistoryInit(
|
||||
IPdfOpener pdfOpener,
|
||||
@ -66,6 +61,10 @@ public partial class frmStockHistoryInit : Form
|
||||
btnAnalysera.Enabled = true;
|
||||
|
||||
}
|
||||
else if (lblFileName.Text.Length > 5 && lblFileName.Text.ToLower().EndsWith("csv"))
|
||||
{
|
||||
btnAnalysera.Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
btnAnalysera.Enabled = false;
|
||||
@ -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<TransactionNote> 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<TransactionNote> notes)
|
||||
{
|
||||
foreach (var note in notes)
|
||||
{
|
||||
txtFound.Text = note.ToString();
|
||||
|
||||
trans = note;
|
||||
|
||||
_waiter = new TaskCompletionSource<bool>();
|
||||
|
||||
await _waiter.Task; // Väntar utan att blockera UI
|
||||
}
|
||||
//List<string> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user