Början på analys av notorna inledd

This commit is contained in:
2026-05-19 09:51:43 +02:00
parent c831b2bbd5
commit 80ace6f110
13 changed files with 449 additions and 24 deletions

View File

@ -1,12 +1,9 @@
using Microsoft.EntityFrameworkCore;
using StockHistory.Models;
using System;
using System.Collections.Generic;
using System.Text;
namespace StockHistory.Data;
public class AppDbContext: DbContext
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
@ -14,12 +11,19 @@ public class AppDbContext: DbContext
}
public DbSet<TransactionNote> TransactionNotes { get; set; }
public DbSet<StockEquity> Stocks { get; set; }
override protected void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TransactionNote>()
.HasIndex(t => new { t.StockCode, t.TransactionDate })
.IsUnique();
.IsUnique(true);
modelBuilder.Entity<StockEquity>()
.HasIndex(s => new { s.Bought })
.IsUnique(false);
modelBuilder.Entity<StockEquity>()
.HasIndex(s => new { s.Sold })
.IsUnique(false);
}
}

View File

@ -0,0 +1,100 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StockHistory.Data;
#nullable disable
namespace StockHistory.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20260517151320_NewTableStockEquity")]
partial class NewTableStockEquity
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.6");
modelBuilder.Entity("StockHistory.Models.StockEquity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("Bought")
.HasColumnType("TEXT");
b.Property<decimal>("BoughtPrice")
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("Sold")
.HasColumnType("TEXT");
b.Property<decimal>("SoldPrice")
.HasColumnType("TEXT");
b.Property<int>("SoldQuant")
.HasColumnType("INTEGER");
b.Property<string>("StockCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Bought");
b.HasIndex("Sold");
b.ToTable("Stocks");
});
modelBuilder.Entity("StockHistory.Models.TransactionNote", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<decimal>("AmountToPay")
.HasColumnType("TEXT");
b.Property<decimal>("Commission")
.HasColumnType("TEXT");
b.Property<string>("StockCode")
.HasColumnType("TEXT");
b.Property<decimal>("StockPrice")
.HasColumnType("TEXT");
b.Property<int>("StockQuantity")
.HasColumnType("INTEGER");
b.Property<decimal>("TotalAmount")
.HasColumnType("TEXT");
b.Property<DateTime>("TransactionDate")
.HasColumnType("TEXT");
b.Property<string>("TransactionType")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("StockCode", "TransactionDate")
.IsUnique();
b.ToTable("TransactionNotes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StockHistory.Migrations
{
/// <inheritdoc />
public partial class NewTableStockEquity : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Stocks",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
StockCode = table.Column<string>(type: "TEXT", nullable: false),
Bought = table.Column<DateTime>(type: "TEXT", nullable: false),
BoughtPrice = table.Column<decimal>(type: "TEXT", nullable: false),
Quantity = table.Column<int>(type: "INTEGER", nullable: false),
Sold = table.Column<DateTime>(type: "TEXT", nullable: false),
SoldPrice = table.Column<decimal>(type: "TEXT", nullable: false),
SoldQuant = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stocks", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Stocks_Bought",
table: "Stocks",
column: "Bought");
migrationBuilder.CreateIndex(
name: "IX_Stocks_Sold",
table: "Stocks",
column: "Sold");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Stocks");
}
}
}

View File

@ -17,6 +17,43 @@ namespace StockHistory.Migrations
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.6");
modelBuilder.Entity("StockHistory.Models.StockEquity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("Bought")
.HasColumnType("TEXT");
b.Property<decimal>("BoughtPrice")
.HasColumnType("TEXT");
b.Property<int>("Quantity")
.HasColumnType("INTEGER");
b.Property<DateTime>("Sold")
.HasColumnType("TEXT");
b.Property<decimal>("SoldPrice")
.HasColumnType("TEXT");
b.Property<int>("SoldQuant")
.HasColumnType("INTEGER");
b.Property<string>("StockCode")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Bought");
b.HasIndex("Sold");
b.ToTable("Stocks");
});
modelBuilder.Entity("StockHistory.Models.TransactionNote", b =>
{
b.Property<int>("Id")

View File

@ -0,0 +1,13 @@
namespace StockHistory.Models;
public class StockEquity
{
public int Id { get; set; }
public string StockCode { get; set; } = string.Empty;
public DateTime Bought { get; set; }
public decimal BoughtPrice { get; set; }
public int Quantity { get; set; }
public DateTime Sold { get; set; }
public decimal SoldPrice { get; set; }
public int SoldQuant { get; set; }
}

View File

@ -1,6 +1,6 @@
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using StockHistory.Data;
using StockHistory.Services;
@ -26,23 +26,24 @@ namespace StockHistory
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
// Starta huvudformul<75>ret via DI
var mainForm = host.Services.GetRequiredService <frmStockHistoryInit>();
var mainForm = host.Services.GetRequiredService<frmStockHistoryInit>();
Application.Run(mainForm);
}
static IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
services.AddDbContext<AppDbContext>(options =>
options.UseSqlite("Data Source=Stockbrokerage.db"),
ServiceLifetime.Transient);
static IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder()
.ConfigureServices((context, services) =>
{
services.AddDbContext<AppDbContext>(options =>
options.UseSqlite("Data Source=Stockbrokerage.db"),
ServiceLifetime.Transient);
services.AddSingleton<frmStockHistoryInit>();
services.AddTransient<IPdfOpener, PdfOpener>();
services.AddTransient<IPdfFormatter, PdfFormatter>();
services.AddTransient<ITransactionNotesServices, TransactionNotesServices>();
services.AddTransient<IHandleCsvNotes, HandleCsvNotes>();
});
services.AddSingleton<frmStockHistoryInit>();
services.AddScoped<frmStockHistoryAnalyse1>();
services.AddTransient<IPdfOpener, PdfOpener>();
services.AddTransient<IPdfFormatter, PdfFormatter>();
services.AddTransient<ITransactionNotesServices, TransactionNotesServices>();
services.AddTransient<IHandleCsvNotes, HandleCsvNotes>();
});
}
}

View File

@ -35,4 +35,9 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Stockbrokerage.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

Binary file not shown.

View File

@ -0,0 +1,61 @@
namespace StockHistory
{
partial class frmStockHistoryAnalyse1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
label1 = new Label();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Font = new Font("Segoe UI", 13F, FontStyle.Bold);
label1.Location = new Point(12, 9);
label1.Name = "label1";
label1.Size = new Size(428, 25);
label1.TabIndex = 0;
label1.Text = "Analysera existerande Avräkningsnotor (Affärer)";
//
// frmStockHistoryAnalyse1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.Gainsboro;
ClientSize = new Size(922, 481);
Controls.Add(label1);
Name = "frmStockHistoryAnalyse1";
Text = "Form1frmStockHistoryAnalyse1";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
}
}

View File

@ -0,0 +1,10 @@
namespace StockHistory
{
public partial class frmStockHistoryAnalyse1 : Form
{
public frmStockHistoryAnalyse1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -45,6 +45,7 @@
AmountToPayHeader = new ColumnHeader();
btnClose = new Button();
btnNext = new Button();
btnDtaAnalyse1 = new Button();
SuspendLayout();
//
// btnChooseFile
@ -166,7 +167,7 @@
btnClose.BackColor = Color.Chartreuse;
btnClose.FlatStyle = FlatStyle.Popup;
btnClose.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, 1, true);
btnClose.Location = new Point(1092, 377);
btnClose.Location = new Point(1093, 378);
btnClose.Margin = new Padding(3, 2, 3, 2);
btnClose.Name = "btnClose";
btnClose.Size = new Size(108, 28);
@ -192,12 +193,27 @@
btnNext.Visible = false;
btnNext.Click += btnNext_Click;
//
// btnDtaAnalyse1
//
btnDtaAnalyse1.BackColor = Color.Chartreuse;
btnDtaAnalyse1.FlatStyle = FlatStyle.Popup;
btnDtaAnalyse1.Font = new Font("Segoe UI", 11F, FontStyle.Regular, GraphicsUnit.Point, 1, true);
btnDtaAnalyse1.Location = new Point(23, 384);
btnDtaAnalyse1.Margin = new Padding(3, 2, 3, 2);
btnDtaAnalyse1.Name = "btnDtaAnalyse1";
btnDtaAnalyse1.Size = new Size(108, 28);
btnDtaAnalyse1.TabIndex = 9;
btnDtaAnalyse1.Text = "Data analys";
btnDtaAnalyse1.UseVisualStyleBackColor = false;
btnDtaAnalyse1.Click += btnDtaAnalyse1_Click;
//
// frmStockHistoryInit
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.LightGray;
ClientSize = new Size(1236, 415);
ClientSize = new Size(1236, 423);
Controls.Add(btnDtaAnalyse1);
Controls.Add(btnNext);
Controls.Add(btnClose);
Controls.Add(lwTransactions);
@ -232,5 +248,6 @@
private ColumnHeader AmountToPayHeader;
private Button btnClose;
private Button btnNext;
private Button btnDtaAnalyse1;
}
}

View File

@ -12,6 +12,7 @@ public partial class frmStockHistoryInit : Form
private readonly IPdfFormatter _pdfFormatter;
private readonly ITransactionNotesServices _transactionNotes;
private readonly IHandleCsvNotes _handleCsvNotes;
private readonly frmStockHistoryAnalyse1 _analyseForm;
private List<PdfSida> _pdfSidor = new();
private List<PdfSida> localPdfSida = new();
private bool lstWait = false;
@ -24,7 +25,8 @@ public partial class frmStockHistoryInit : Form
IPdfOpener pdfOpener,
IPdfFormatter pdfFormatter,
ITransactionNotesServices transactionNotes,
IHandleCsvNotes handleCsvNotes
IHandleCsvNotes handleCsvNotes,
frmStockHistoryAnalyse1 analyseForm
)
{
InitializeComponent();
@ -32,6 +34,7 @@ public partial class frmStockHistoryInit : Form
_pdfFormatter = pdfFormatter;
_transactionNotes = transactionNotes;
_handleCsvNotes = handleCsvNotes;
_analyseForm = analyseForm;
btnAnalysera.Enabled = false;
Shown += async (s, e) => await LoadBusinessAsync();
@ -292,6 +295,9 @@ public partial class frmStockHistoryInit : Form
this.Close();
}
private void btnDtaAnalyse1_Click(object sender, EventArgs e)
{
_analyseForm.Show();
}
}