Lagt till stockisin

This commit is contained in:
2026-09-28 10:53:51 +02:00
parent 9b010ed388
commit 791adcfdfe
13 changed files with 271 additions and 4 deletions

View File

@ -19,7 +19,7 @@ public class AppDbContext : DbContext
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TransactionNote>() modelBuilder.Entity<TransactionNote>()
.HasIndex(t => new { t.StockCode, t.TransactionDate }) .HasIndex(t => new { t.StockISIN, t.StockCode, t.TransactionDate })
.IsUnique(true); .IsUnique(true);
modelBuilder.Entity<StockEquity>() modelBuilder.Entity<StockEquity>()
.HasIndex(s => new { s.Bought }) .HasIndex(s => new { s.Bought })
@ -28,7 +28,7 @@ public class AppDbContext : DbContext
.HasIndex(s => new { s.Sold }) .HasIndex(s => new { s.Sold })
.IsUnique(false); .IsUnique(false);
modelBuilder.Entity<StockEquity>() modelBuilder.Entity<StockEquity>()
.HasIndex(s => new { s.Bought, s.StockCode, s.Quantity }) .HasIndex(s => new { s.Bought, s.StockISIN, s.Quantity })
.IsUnique(false); .IsUnique(false);
modelBuilder.Entity<SglStockEquity>() modelBuilder.Entity<SglStockEquity>()
.HasIndex(s => new { s.Bought }) .HasIndex(s => new { s.Bought })

View File

@ -27,6 +27,7 @@ public class HandleCsvNotes : IHandleCsvNotes
TransactionDate = DateTime.Parse(values[NamePos(Header_table, "Datum")]), TransactionDate = DateTime.Parse(values[NamePos(Header_table, "Datum")]),
TransactionType = values[NamePos(Header_table, "Typ av transaktion")] == "Köp" ? "KÖP" : "SÄLJ", TransactionType = values[NamePos(Header_table, "Typ av transaktion")] == "Köp" ? "KÖP" : "SÄLJ",
StockCode = values[NamePos(Header_table, @"Värdepapper/beskrivning")], 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")]), StockPrice = decimal.Parse((values[NamePos(Header_table, "Kurs")] == "") ? "0" : values[NamePos(Header_table, "Kurs")]),
Currency = values[NamePos(Header_table, @"Instrumentvaluta")], Currency = values[NamePos(Header_table, @"Instrumentvaluta")],
StockQuantity = Math.Abs(ParseCsvNumber(values[NamePos(Header_table, "Antal")])), 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")]), TransactionDate = DateTime.Parse(values[NamePos(Header_table, "Affärsdag")]),
TransactionType = values[NamePos(Header_table, "Transaktion")] == "Köp" ? "KÖP" : "SÄLJ", TransactionType = values[NamePos(Header_table, "Transaktion")] == "Köp" ? "KÖP" : "SÄLJ",
StockCode = values[NamePos(Header_table, @"Värdepapper")], 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")]), StockPrice = decimal.Parse((values[NamePos(Header_table, "Kurs")] == "") ? "0" : values[NamePos(Header_table, "Kurs")]),
Currency = values[NamePos(Header_table, @"Noteringsvaluta")], Currency = values[NamePos(Header_table, @"Noteringsvaluta")],
StockQuantity = Math.Abs(ParseCsvNumber(values[NamePos(Header_table, "Innehavsförändring")])), StockQuantity = Math.Abs(ParseCsvNumber(values[NamePos(Header_table, "Innehavsförändring")])),

View File

@ -0,0 +1,155 @@
// <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("20260928083725_newfield_StockISIN")]
partial class newfield_StockISIN
{
/// <inheritdoc />
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<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.HasIndex("Bought", "StockCode", "Quantity");
b.ToTable("SglStocks");
});
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.Property<string>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<decimal>("AmountToPay")
.HasColumnType("TEXT");
b.Property<decimal>("Commission")
.HasColumnType("TEXT");
b.Property<string>("Currency")
.IsRequired()
.HasColumnType("TEXT");
b.Property<decimal>("ExchangeRate")
.HasColumnType("TEXT");
b.Property<string>("StockCode")
.HasColumnType("TEXT");
b.Property<string>("StockISIN")
.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("StockISIN", "StockCode", "TransactionDate")
.IsUnique();
b.ToTable("TransactionNotes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace StockHistory.Migrations
{
/// <inheritdoc />
public partial class newfield_StockISIN : Migration
{
/// <inheritdoc />
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<string>(
name: "StockISIN",
table: "TransactionNotes",
type: "TEXT",
nullable: true);
migrationBuilder.AddColumn<string>(
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" });
}
/// <inheritdoc />
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" });
}
}
}

View File

@ -84,13 +84,17 @@ namespace StockHistory.Migrations
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("StockISIN")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("Bought"); b.HasIndex("Bought");
b.HasIndex("Sold"); b.HasIndex("Sold");
b.HasIndex("Bought", "StockCode", "Quantity"); b.HasIndex("Bought", "StockISIN", "Quantity");
b.ToTable("Stocks"); b.ToTable("Stocks");
}); });
@ -117,6 +121,9 @@ namespace StockHistory.Migrations
b.Property<string>("StockCode") b.Property<string>("StockCode")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<string>("StockISIN")
.HasColumnType("TEXT");
b.Property<decimal>("StockPrice") b.Property<decimal>("StockPrice")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@ -134,7 +141,7 @@ namespace StockHistory.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("StockCode", "TransactionDate") b.HasIndex("StockISIN", "StockCode", "TransactionDate")
.IsUnique(); .IsUnique();
b.ToTable("TransactionNotes"); b.ToTable("TransactionNotes");

View File

@ -3,6 +3,7 @@
public class EquityTemp public class EquityTemp
{ {
public string StockCode { get; set; } = string.Empty; public string StockCode { get; set; } = string.Empty;
public string StockISIN { get; set; } = string.Empty;
public DateTime Bought { get; set; } public DateTime Bought { get; set; }
public decimal BoughtPrice { get; set; } public decimal BoughtPrice { get; set; }
public int Quantity { get; set; } public int Quantity { get; set; }

View File

@ -4,6 +4,7 @@ public class StockEquity
{ {
public int Id { get; set; } public int Id { get; set; }
public string StockCode { get; set; } = string.Empty; public string StockCode { get; set; } = string.Empty;
public string StockISIN { get; set; } = string.Empty;
public DateTime Bought { get; set; } public DateTime Bought { get; set; }
public decimal BoughtPrice { get; set; } public decimal BoughtPrice { get; set; }
public int Quantity { get; set; } public int Quantity { get; set; }

View File

@ -6,6 +6,7 @@ public class TransactionNote
public DateTime TransactionDate { get; set; } public DateTime TransactionDate { get; set; }
public string? TransactionType { get; set; } public string? TransactionType { get; set; }
public string? StockCode { get; set; } public string? StockCode { get; set; }
public string? StockISIN { get; set; }
public decimal StockPrice { get; set; } public decimal StockPrice { get; set; }
public decimal ExchangeRate { get; set; } public decimal ExchangeRate { get; set; }
public string Currency { get; set; } public string Currency { get; set; }

View File

@ -127,6 +127,7 @@ public class StockEquityServices : IStockEquityServices
var equity = new StockEquity var equity = new StockEquity
{ {
StockCode = note.StockCode, StockCode = note.StockCode,
StockISIN = note.StockISIN,
Bought = note.TransactionDate, Bought = note.TransactionDate,
BoughtPrice = note.StockPrice, BoughtPrice = note.StockPrice,
Quantity = note.StockQuantity, Quantity = note.StockQuantity,
@ -159,6 +160,7 @@ public class StockEquityServices : IStockEquityServices
//SoldPrice = note.StockPrice, //SoldPrice = note.StockPrice,
//SoldQuant = note.StockQuantity //SoldQuant = note.StockQuantity
StockCode = note.StockCode, StockCode = note.StockCode,
StockISIN = note.StockISIN,
Bought = note.TransactionDate, Bought = note.TransactionDate,
BoughtPrice = note.StockPrice * -1, BoughtPrice = note.StockPrice * -1,
Quantity = note.StockQuantity, Quantity = note.StockQuantity,
@ -201,6 +203,7 @@ public class StockEquityServices : IStockEquityServices
var splitEquity = new StockEquity var splitEquity = new StockEquity
{ {
StockCode = eq.StockCode, StockCode = eq.StockCode,
StockISIN = eq.StockISIN,
Bought = eq.Bought, Bought = eq.Bought,
BoughtPrice = eq.BoughtPrice, BoughtPrice = eq.BoughtPrice,
Quantity = soldQuant, Quantity = soldQuant,

View File

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

Binary file not shown.

View File

@ -246,6 +246,7 @@ public partial class frmStockHistoryInit : Form
if (!string.IsNullOrWhiteSpace(line) && line.StartsWith("Affärsdag") if (!string.IsNullOrWhiteSpace(line) && line.StartsWith("Affärsdag")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("Handelstidpunkt") || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Handelstidpunkt")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("Värdepapper") || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Värdepapper")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("ISIN-kod")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("Kurs") || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Kurs")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("Genomsnittlig") || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Genomsnittlig")
|| !string.IsNullOrWhiteSpace(line) && line.StartsWith("Antal") || !string.IsNullOrWhiteSpace(line) && line.StartsWith("Antal")
@ -283,6 +284,15 @@ public partial class frmStockHistoryInit : Form
else else
trans.StockCode = templist[1]; trans.StockCode = templist[1];
} }
if (line.StartsWith("ISIN-kod"))
{
var templist = line.Split(" ", StringSplitOptions.RemoveEmptyEntries);
if (templist.Length > 2)
trans.StockISIN = templist[1] + " " + templist[2];
else
trans.StockISIN = templist[1];
}
if (line.StartsWith("Kurs")) if (line.StartsWith("Kurs"))
{ {
trans.Currency = line.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1]; 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.TotalAmount.ToString());
item.SubItems.Add(t.Commission.ToString()); item.SubItems.Add(t.Commission.ToString());
item.SubItems.Add(t.AmountToPay.ToString()); item.SubItems.Add(t.AmountToPay.ToString());
item.SubItems.Add(t.StockISIN.ToString());
lwTransactions.Items.Add(item); lwTransactions.Items.Add(item);
Debug.WriteLine(t.ToString()); Debug.WriteLine(t.ToString());
} }

View File

@ -0,0 +1,4 @@
/* Visual Studio Settings File */
{
"environment.visualExperience.systemDarkTheme": "juicy-plum"
}