diff --git a/StockHistory/Data/AppDbContext.cs b/StockHistory/Data/AppDbContext.cs index f6a60f4..7ef5a88 100644 --- a/StockHistory/Data/AppDbContext.cs +++ b/StockHistory/Data/AppDbContext.cs @@ -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 options) : base(options) @@ -14,12 +11,19 @@ public class AppDbContext: DbContext } public DbSet TransactionNotes { get; set; } + public DbSet Stocks { get; set; } override protected void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity() .HasIndex(t => new { t.StockCode, t.TransactionDate }) - .IsUnique(); + .IsUnique(true); + modelBuilder.Entity() + .HasIndex(s => new { s.Bought }) + .IsUnique(false); + modelBuilder.Entity() + .HasIndex(s => new { s.Sold }) + .IsUnique(false); } } diff --git a/StockHistory/Migrations/20260517151320_NewTableStockEquity.Designer.cs b/StockHistory/Migrations/20260517151320_NewTableStockEquity.Designer.cs new file mode 100644 index 0000000..f7a9519 --- /dev/null +++ b/StockHistory/Migrations/20260517151320_NewTableStockEquity.Designer.cs @@ -0,0 +1,100 @@ +// +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 + { + /// + 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("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.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("StockCode") + .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("StockCode", "TransactionDate") + .IsUnique(); + + b.ToTable("TransactionNotes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StockHistory/Migrations/20260517151320_NewTableStockEquity.cs b/StockHistory/Migrations/20260517151320_NewTableStockEquity.cs new file mode 100644 index 0000000..5ae9c4e --- /dev/null +++ b/StockHistory/Migrations/20260517151320_NewTableStockEquity.cs @@ -0,0 +1,51 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StockHistory.Migrations +{ + /// + public partial class NewTableStockEquity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Stocks", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + StockCode = table.Column(type: "TEXT", nullable: false), + Bought = table.Column(type: "TEXT", nullable: false), + BoughtPrice = table.Column(type: "TEXT", nullable: false), + Quantity = table.Column(type: "INTEGER", nullable: false), + Sold = table.Column(type: "TEXT", nullable: false), + SoldPrice = table.Column(type: "TEXT", nullable: false), + SoldQuant = table.Column(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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Stocks"); + } + } +} diff --git a/StockHistory/Migrations/AppDbContextModelSnapshot.cs b/StockHistory/Migrations/AppDbContextModelSnapshot.cs index a6e662d..a0700b1 100644 --- a/StockHistory/Migrations/AppDbContextModelSnapshot.cs +++ b/StockHistory/Migrations/AppDbContextModelSnapshot.cs @@ -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("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.ToTable("Stocks"); + }); + modelBuilder.Entity("StockHistory.Models.TransactionNote", b => { b.Property("Id") diff --git a/StockHistory/Models/StockEquity.cs b/StockHistory/Models/StockEquity.cs new file mode 100644 index 0000000..47881dd --- /dev/null +++ b/StockHistory/Models/StockEquity.cs @@ -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; } +} diff --git a/StockHistory/Program.cs b/StockHistory/Program.cs index bac714d..14a5f36 100644 --- a/StockHistory/Program.cs +++ b/StockHistory/Program.cs @@ -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äret via DI - var mainForm = host.Services.GetRequiredService (); + var mainForm = host.Services.GetRequiredService(); Application.Run(mainForm); } - static IHostBuilder CreateHostBuilder() => - Host.CreateDefaultBuilder() - .ConfigureServices((context, services) => - { - services.AddDbContext(options => - options.UseSqlite("Data Source=Stockbrokerage.db"), - ServiceLifetime.Transient); + static IHostBuilder CreateHostBuilder() => + Host.CreateDefaultBuilder() + .ConfigureServices((context, services) => + { + services.AddDbContext(options => + options.UseSqlite("Data Source=Stockbrokerage.db"), + ServiceLifetime.Transient); - services.AddSingleton(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - }); + services.AddSingleton(); + services.AddScoped(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + }); } } \ No newline at end of file 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 08a7062..1b4deb1 100644 Binary files a/StockHistory/Stockbrokerage.db and b/StockHistory/Stockbrokerage.db differ diff --git a/StockHistory/frmStockHistoryAnalyse1.Designer.cs b/StockHistory/frmStockHistoryAnalyse1.Designer.cs new file mode 100644 index 0000000..474516e --- /dev/null +++ b/StockHistory/frmStockHistoryAnalyse1.Designer.cs @@ -0,0 +1,61 @@ +namespace StockHistory +{ + partial class frmStockHistoryAnalyse1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/StockHistory/frmStockHistoryAnalyse1.cs b/StockHistory/frmStockHistoryAnalyse1.cs new file mode 100644 index 0000000..c1b4e8c --- /dev/null +++ b/StockHistory/frmStockHistoryAnalyse1.cs @@ -0,0 +1,10 @@ +namespace StockHistory +{ + public partial class frmStockHistoryAnalyse1 : Form + { + public frmStockHistoryAnalyse1() + { + InitializeComponent(); + } + } +} diff --git a/StockHistory/frmStockHistoryAnalyse1.resx b/StockHistory/frmStockHistoryAnalyse1.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/StockHistory/frmStockHistoryAnalyse1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StockHistory/frmStockHistoryInit.Designer.cs b/StockHistory/frmStockHistoryInit.Designer.cs index 02e8526..a94debc 100644 --- a/StockHistory/frmStockHistoryInit.Designer.cs +++ b/StockHistory/frmStockHistoryInit.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/StockHistory/frmStockHistoryInit.cs b/StockHistory/frmStockHistoryInit.cs index 6b77dff..8d58c3b 100644 --- a/StockHistory/frmStockHistoryInit.cs +++ b/StockHistory/frmStockHistoryInit.cs @@ -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 _pdfSidor = new(); private List 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(); + } }