From 791adcfdfee5b96873b1328e2010e8c83af6bb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Mon, 28 Sep 2026 10:53:51 +0200 Subject: [PATCH] Lagt till stockisin --- StockHistory/Data/AppDbContext.cs | 4 +- StockHistory/HandleCsvNotes.cs | 2 + ...60928083725_newfield_StockISIN.Designer.cs | 155 ++++++++++++++++++ .../20260928083725_newfield_StockISIN.cs | 77 +++++++++ .../Migrations/AppDbContextModelSnapshot.cs | 11 +- StockHistory/Models/EquityTemp.cs | 1 + StockHistory/Models/StockEquity.cs | 1 + StockHistory/Models/TransactionNote.cs | 1 + StockHistory/Services/StockEquityServices.cs | 3 + StockHistory/StockHistory.csproj | 5 + StockHistory/Stockbrokerage.db | Bin 61440 -> 61440 bytes StockHistory/frmStockHistoryInit.cs | 11 ++ settings.VisualStudio.json | 4 + 13 files changed, 271 insertions(+), 4 deletions(-) create mode 100644 StockHistory/Migrations/20260928083725_newfield_StockISIN.Designer.cs create mode 100644 StockHistory/Migrations/20260928083725_newfield_StockISIN.cs create mode 100644 settings.VisualStudio.json diff --git a/StockHistory/Data/AppDbContext.cs b/StockHistory/Data/AppDbContext.cs index e15a104..f5239d4 100644 --- a/StockHistory/Data/AppDbContext.cs +++ b/StockHistory/Data/AppDbContext.cs @@ -19,7 +19,7 @@ public class AppDbContext : DbContext { base.OnModelCreating(modelBuilder); modelBuilder.Entity() - .HasIndex(t => new { t.StockCode, t.TransactionDate }) + .HasIndex(t => new { t.StockISIN, t.StockCode, t.TransactionDate }) .IsUnique(true); modelBuilder.Entity() .HasIndex(s => new { s.Bought }) @@ -28,7 +28,7 @@ public class AppDbContext : DbContext .HasIndex(s => new { s.Sold }) .IsUnique(false); modelBuilder.Entity() - .HasIndex(s => new { s.Bought, s.StockCode, s.Quantity }) + .HasIndex(s => new { s.Bought, s.StockISIN, s.Quantity }) .IsUnique(false); modelBuilder.Entity() .HasIndex(s => new { s.Bought }) diff --git a/StockHistory/HandleCsvNotes.cs b/StockHistory/HandleCsvNotes.cs index 3fb567d..36dcb56 100644 --- a/StockHistory/HandleCsvNotes.cs +++ b/StockHistory/HandleCsvNotes.cs @@ -27,6 +27,7 @@ public class HandleCsvNotes : IHandleCsvNotes TransactionDate = DateTime.Parse(values[NamePos(Header_table, "Datum")]), TransactionType = values[NamePos(Header_table, "Typ av transaktion")] == "Köp" ? "KÖP" : "SÄLJ", StockCode = values[NamePos(Header_table, @"Värdepapper/beskrivning")], + StockISIN = values[NamePos(Header_table, "ISIN")], StockPrice = decimal.Parse((values[NamePos(Header_table, "Kurs")] == "") ? "0" : values[NamePos(Header_table, "Kurs")]), Currency = values[NamePos(Header_table, @"Instrumentvaluta")], StockQuantity = Math.Abs(ParseCsvNumber(values[NamePos(Header_table, "Antal")])), @@ -64,6 +65,7 @@ public class HandleCsvNotes : IHandleCsvNotes TransactionDate = DateTime.Parse(values[NamePos(Header_table, "Affärsdag")]), TransactionType = values[NamePos(Header_table, "Transaktion")] == "Köp" ? "KÖP" : "SÄLJ", StockCode = values[NamePos(Header_table, @"Värdepapper")], + StockISIN = values[NamePos(Header_table, "ISIN")], StockPrice = decimal.Parse((values[NamePos(Header_table, "Kurs")] == "") ? "0" : values[NamePos(Header_table, "Kurs")]), Currency = values[NamePos(Header_table, @"Noteringsvaluta")], StockQuantity = Math.Abs(ParseCsvNumber(values[NamePos(Header_table, "Innehavsförändring")])), diff --git a/StockHistory/Migrations/20260928083725_newfield_StockISIN.Designer.cs b/StockHistory/Migrations/20260928083725_newfield_StockISIN.Designer.cs new file mode 100644 index 0000000..30487a8 --- /dev/null +++ b/StockHistory/Migrations/20260928083725_newfield_StockISIN.Designer.cs @@ -0,0 +1,155 @@ +// +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("20260928083725_newfield_StockISIN")] + partial class newfield_StockISIN + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "9.0.6"); + + modelBuilder.Entity("StockHistory.Models.SglStockEquity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bought") + .HasColumnType("TEXT"); + + b.Property("BoughtPrice") + .HasColumnType("TEXT"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("Sold") + .HasColumnType("TEXT"); + + b.Property("SoldPrice") + .HasColumnType("TEXT"); + + b.Property("SoldQuant") + .HasColumnType("INTEGER"); + + b.Property("StockCode") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Bought"); + + b.HasIndex("Sold"); + + b.HasIndex("Bought", "StockCode", "Quantity"); + + b.ToTable("SglStocks"); + }); + + modelBuilder.Entity("StockHistory.Models.StockEquity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Bought") + .HasColumnType("TEXT"); + + b.Property("BoughtPrice") + .HasColumnType("TEXT"); + + b.Property("Quantity") + .HasColumnType("INTEGER"); + + b.Property("Sold") + .HasColumnType("TEXT"); + + b.Property("SoldPrice") + .HasColumnType("TEXT"); + + b.Property("SoldQuant") + .HasColumnType("INTEGER"); + + b.Property("StockCode") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("StockISIN") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Bought"); + + b.HasIndex("Sold"); + + b.HasIndex("Bought", "StockISIN", "Quantity"); + + b.ToTable("Stocks"); + }); + + modelBuilder.Entity("StockHistory.Models.TransactionNote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AmountToPay") + .HasColumnType("TEXT"); + + b.Property("Commission") + .HasColumnType("TEXT"); + + b.Property("Currency") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ExchangeRate") + .HasColumnType("TEXT"); + + b.Property("StockCode") + .HasColumnType("TEXT"); + + b.Property("StockISIN") + .HasColumnType("TEXT"); + + b.Property("StockPrice") + .HasColumnType("TEXT"); + + b.Property("StockQuantity") + .HasColumnType("INTEGER"); + + b.Property("TotalAmount") + .HasColumnType("TEXT"); + + b.Property("TransactionDate") + .HasColumnType("TEXT"); + + b.Property("TransactionType") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("StockISIN", "StockCode", "TransactionDate") + .IsUnique(); + + b.ToTable("TransactionNotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StockHistory/Migrations/20260928083725_newfield_StockISIN.cs b/StockHistory/Migrations/20260928083725_newfield_StockISIN.cs new file mode 100644 index 0000000..f9655cd --- /dev/null +++ b/StockHistory/Migrations/20260928083725_newfield_StockISIN.cs @@ -0,0 +1,77 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StockHistory.Migrations +{ + /// + public partial class newfield_StockISIN : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_TransactionNotes_StockCode_TransactionDate", + table: "TransactionNotes"); + + migrationBuilder.DropIndex( + name: "IX_Stocks_Bought_StockCode_Quantity", + table: "Stocks"); + + migrationBuilder.AddColumn( + name: "StockISIN", + table: "TransactionNotes", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "StockISIN", + table: "Stocks", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.CreateIndex( + name: "IX_TransactionNotes_StockISIN_StockCode_TransactionDate", + table: "TransactionNotes", + columns: new[] { "StockISIN", "StockCode", "TransactionDate" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_Bought_StockISIN_Quantity", + table: "Stocks", + columns: new[] { "Bought", "StockISIN", "Quantity" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_TransactionNotes_StockISIN_StockCode_TransactionDate", + table: "TransactionNotes"); + + migrationBuilder.DropIndex( + name: "IX_Stocks_Bought_StockISIN_Quantity", + table: "Stocks"); + + migrationBuilder.DropColumn( + name: "StockISIN", + table: "TransactionNotes"); + + migrationBuilder.DropColumn( + name: "StockISIN", + table: "Stocks"); + + migrationBuilder.CreateIndex( + name: "IX_TransactionNotes_StockCode_TransactionDate", + table: "TransactionNotes", + columns: new[] { "StockCode", "TransactionDate" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Stocks_Bought_StockCode_Quantity", + table: "Stocks", + columns: new[] { "Bought", "StockCode", "Quantity" }); + } + } +} diff --git a/StockHistory/Migrations/AppDbContextModelSnapshot.cs b/StockHistory/Migrations/AppDbContextModelSnapshot.cs index 9907137..b3e57aa 100644 --- a/StockHistory/Migrations/AppDbContextModelSnapshot.cs +++ b/StockHistory/Migrations/AppDbContextModelSnapshot.cs @@ -84,13 +84,17 @@ namespace StockHistory.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("StockISIN") + .IsRequired() + .HasColumnType("TEXT"); + b.HasKey("Id"); b.HasIndex("Bought"); b.HasIndex("Sold"); - b.HasIndex("Bought", "StockCode", "Quantity"); + b.HasIndex("Bought", "StockISIN", "Quantity"); b.ToTable("Stocks"); }); @@ -117,6 +121,9 @@ namespace StockHistory.Migrations b.Property("StockCode") .HasColumnType("TEXT"); + b.Property("StockISIN") + .HasColumnType("TEXT"); + b.Property("StockPrice") .HasColumnType("TEXT"); @@ -134,7 +141,7 @@ namespace StockHistory.Migrations b.HasKey("Id"); - b.HasIndex("StockCode", "TransactionDate") + b.HasIndex("StockISIN", "StockCode", "TransactionDate") .IsUnique(); b.ToTable("TransactionNotes"); diff --git a/StockHistory/Models/EquityTemp.cs b/StockHistory/Models/EquityTemp.cs index aeeb9d0..a648625 100644 --- a/StockHistory/Models/EquityTemp.cs +++ b/StockHistory/Models/EquityTemp.cs @@ -3,6 +3,7 @@ public class EquityTemp { public string StockCode { get; set; } = string.Empty; + public string StockISIN { get; set; } = string.Empty; public DateTime Bought { get; set; } public decimal BoughtPrice { get; set; } public int Quantity { get; set; } diff --git a/StockHistory/Models/StockEquity.cs b/StockHistory/Models/StockEquity.cs index 52f84df..c8a3baa 100644 --- a/StockHistory/Models/StockEquity.cs +++ b/StockHistory/Models/StockEquity.cs @@ -4,6 +4,7 @@ public class StockEquity { public int Id { get; set; } public string StockCode { get; set; } = string.Empty; + public string StockISIN { get; set; } = string.Empty; public DateTime Bought { get; set; } public decimal BoughtPrice { get; set; } public int Quantity { get; set; } diff --git a/StockHistory/Models/TransactionNote.cs b/StockHistory/Models/TransactionNote.cs index 38e6525..bc216b8 100644 --- a/StockHistory/Models/TransactionNote.cs +++ b/StockHistory/Models/TransactionNote.cs @@ -6,6 +6,7 @@ public class TransactionNote public DateTime TransactionDate { get; set; } public string? TransactionType { get; set; } public string? StockCode { get; set; } + public string? StockISIN { get; set; } public decimal StockPrice { get; set; } public decimal ExchangeRate { get; set; } public string Currency { get; set; } diff --git a/StockHistory/Services/StockEquityServices.cs b/StockHistory/Services/StockEquityServices.cs index 07fde43..506682b 100644 --- a/StockHistory/Services/StockEquityServices.cs +++ b/StockHistory/Services/StockEquityServices.cs @@ -127,6 +127,7 @@ public class StockEquityServices : IStockEquityServices var equity = new StockEquity { StockCode = note.StockCode, + StockISIN = note.StockISIN, Bought = note.TransactionDate, BoughtPrice = note.StockPrice, Quantity = note.StockQuantity, @@ -159,6 +160,7 @@ public class StockEquityServices : IStockEquityServices //SoldPrice = note.StockPrice, //SoldQuant = note.StockQuantity StockCode = note.StockCode, + StockISIN = note.StockISIN, Bought = note.TransactionDate, BoughtPrice = note.StockPrice * -1, Quantity = note.StockQuantity, @@ -201,6 +203,7 @@ public class StockEquityServices : IStockEquityServices var splitEquity = new StockEquity { StockCode = eq.StockCode, + StockISIN = eq.StockISIN, Bought = eq.Bought, BoughtPrice = eq.BoughtPrice, Quantity = soldQuant, diff --git a/StockHistory/StockHistory.csproj b/StockHistory/StockHistory.csproj index 7c37198..6328792 100644 --- a/StockHistory/StockHistory.csproj +++ b/StockHistory/StockHistory.csproj @@ -35,4 +35,9 @@ Resources.Designer.cs + + + PreserveNewest + + \ No newline at end of file diff --git a/StockHistory/Stockbrokerage.db b/StockHistory/Stockbrokerage.db index 21078bcaec71739f41b1e59d8d0fedfbf18a982e..1b4df0dfab028cbd09ef92ef3b9c32d31682da0a 100644 GIT binary patch delta 519 zcmZp8z})bFd4jYcGXnzyKM=!!$V44uO=bqYszP4Qn+$x+lNk7I`1tr z|-PJG;1~Bx7sx=Et02j6BFzP0nMLn#2>z#Bh0XIL~?h z##DZG@oHVhCjHF3l+=pJbGRiT2CnCpnq0;$z{owhom&qkWT^^vEzCUU{FGEBASa|K zF|Rl=xg;|`&n2-WRcSLX-wi=SOI;%i1p^B!V+$)2Lp>8CV`D=L6Kw+nD+2>wU|6#A zooC>`#lM-qoj;Oai|-fT`OSg?JNdLV*_r*tjSP&;3@nW-3@nVzjZEY7Qp?jaQ*%<{ z;UQ+JXP{@c`IjCSqYyjaX9oTU{QLN)^XKuq@JsT21{!piPfL~ApOK(B>{`r`jFbQC fscm+)KcT?Ly;;!VJ^#c2)yk(lkalQoqU1)Ag2o( zyLh@TV-w?K175kwTX{t$=kN+JvQMt%)dTX3Cx7LYoXp4*!o;|HayZZV$*C;QH}mq{ z5Y)HOH8xN%G_f) 2) + trans.StockISIN = templist[1] + " " + templist[2]; + else + trans.StockISIN = templist[1]; + } + if (line.StartsWith("Kurs")) { trans.Currency = line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]; @@ -423,6 +433,7 @@ public partial class frmStockHistoryInit : Form item.SubItems.Add(t.TotalAmount.ToString()); item.SubItems.Add(t.Commission.ToString()); item.SubItems.Add(t.AmountToPay.ToString()); + item.SubItems.Add(t.StockISIN.ToString()); lwTransactions.Items.Add(item); Debug.WriteLine(t.ToString()); } diff --git a/settings.VisualStudio.json b/settings.VisualStudio.json new file mode 100644 index 0000000..d75b745 --- /dev/null +++ b/settings.VisualStudio.json @@ -0,0 +1,4 @@ +/* Visual Studio Settings File */ +{ + "environment.visualExperience.systemDarkTheme": "juicy-plum" +} \ No newline at end of file