diff --git a/DataDomain/Address.cs b/DataDomain/Address.cs new file mode 100644 index 0000000..72c3865 --- /dev/null +++ b/DataDomain/Address.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class Address + { + public int Id { get; set; } + public string Street { get; set; } + public string Street2 { get; set; } + public int Zipcode { get; set; } + public string Destination { get; set; } + public string Nation { get; set; } + } +} diff --git a/DataDomain/BackupRegister.cs b/DataDomain/BackupRegister.cs new file mode 100644 index 0000000..1b476b7 --- /dev/null +++ b/DataDomain/BackupRegister.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class BackupRegister + { + public int Id { get; set; } + public DateTime BackedUp { get; set; } + public string DbName { get; set; } + public string BackupDbName { get; set; } + public string BackupPath { get; set; } + } +} diff --git a/DataDomain/DataDomain.csproj b/DataDomain/DataDomain.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/DataDomain/DataDomain.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/DataDomain/DiTraderStockRow.cs b/DataDomain/DiTraderStockRow.cs new file mode 100644 index 0000000..fbc48bb --- /dev/null +++ b/DataDomain/DiTraderStockRow.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class DiTraderStockRow + { + public string StockName { get; set; } + public decimal ProcChange { get; set; } + public decimal RealChange { get; set; } + public decimal BuyPrice { get; set; } + public decimal SellPrice { get; set; } + public decimal LatestPrice { get; set; } + public decimal HighestPrice { get; set; } + public decimal LowestPrice { get; set; } + public long Volume { get; set; } + public TimeSpan TimeOfDay { get; set; } + } +} diff --git a/DataDomain/Person.cs b/DataDomain/Person.cs new file mode 100644 index 0000000..f291288 --- /dev/null +++ b/DataDomain/Person.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class Person + { + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string NickName { get; set; } + public String Born { get; set; } + public string Comments { get; set; } + public int HomeAddress { get; set; } + public int InvoiceAddress { get; set; } + public int ClearingNo { get; set; } + public long AccountNo { get; set; } + } +} diff --git a/DataDomain/PersonStock.cs b/DataDomain/PersonStock.cs new file mode 100644 index 0000000..dc646ba --- /dev/null +++ b/DataDomain/PersonStock.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class PersonStock + { + public int Id { get; set; } + public int PersonId { get; set; } + public int StockId { get; set; } + public string Comment { get; set; } + } +} diff --git a/DataDomain/StockMember.cs b/DataDomain/StockMember.cs new file mode 100644 index 0000000..f32d888 --- /dev/null +++ b/DataDomain/StockMember.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataDomain +{ + public class StockMember + { + public int Id { get; set; } + public string StockId { get; set; } + public string StockExtId { get; set; } + public decimal BuyValue { get; set; } + public DateTime BuyDate { get; set; } + public decimal ActValue { get; set; } + public DateTime? ActDate { get; set; } + public long ActAmount { get; set; } + public decimal? SoldValue { get; set; } + public DateTime? SoldDate { get; set; } + // public string PostId { get; set; } + public string Comment { get; set; } + public long PostAmount { get; set; } + + } +} diff --git a/DatamodelLibrary/DatamodelLibrary.csproj b/DatamodelLibrary/DatamodelLibrary.csproj new file mode 100644 index 0000000..ce8d401 --- /dev/null +++ b/DatamodelLibrary/DatamodelLibrary.csproj @@ -0,0 +1,23 @@ + + + + net5.0 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + diff --git a/DatamodelLibrary/Migrations/20210301205458_initial.Designer.cs b/DatamodelLibrary/Migrations/20210301205458_initial.Designer.cs new file mode 100644 index 0000000..e0dcfeb --- /dev/null +++ b/DatamodelLibrary/Migrations/20210301205458_initial.Designer.cs @@ -0,0 +1,90 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + [Migration("20210301205458_initial")] + partial class initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/Migrations/20210301205458_initial.cs b/DatamodelLibrary/Migrations/20210301205458_initial.cs new file mode 100644 index 0000000..69e9559 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210301205458_initial.cs @@ -0,0 +1,59 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatamodelLibrary.Migrations +{ + public partial class initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Persons", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + FirstName = table.Column(type: "TEXT", nullable: true), + LastName = table.Column(type: "TEXT", nullable: true), + NickName = table.Column(type: "TEXT", nullable: true), + Born = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Persons", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Stocks", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + StockId = table.Column(type: "TEXT", nullable: true), + StockExtId = table.Column(type: "TEXT", nullable: true), + BuyValue = table.Column(type: "TEXT", nullable: false), + BuyDate = table.Column(type: "TEXT", nullable: false), + ActValue = table.Column(type: "TEXT", nullable: false), + ActDate = table.Column(type: "TEXT", nullable: true), + ActAmount = table.Column(type: "INTEGER", nullable: false), + SoldValue = table.Column(type: "TEXT", nullable: true), + SoldDate = table.Column(type: "TEXT", nullable: true), + Comment = table.Column(type: "TEXT", nullable: true), + PostAmount = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Stocks", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Persons"); + + migrationBuilder.DropTable( + name: "Stocks"); + } + } +} diff --git a/DatamodelLibrary/Migrations/20210306151633_completion_person_address.Designer.cs b/DatamodelLibrary/Migrations/20210306151633_completion_person_address.Designer.cs new file mode 100644 index 0000000..5192534 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210306151633_completion_person_address.Designer.cs @@ -0,0 +1,125 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + [Migration("20210306151633_completion_person_address")] + partial class completion_person_address + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Gata") + .HasColumnType("TEXT"); + + b.Property("Gata2") + .HasColumnType("TEXT"); + + b.Property("Nation") + .HasColumnType("TEXT"); + + b.Property("PostNr") + .HasColumnType("INTEGER"); + + b.Property("PostOrt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("Comments") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("HomeAddress") + .HasColumnType("INTEGER"); + + b.Property("InvoiceAddress") + .HasColumnType("INTEGER"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/Migrations/20210306151633_completion_person_address.cs b/DatamodelLibrary/Migrations/20210306151633_completion_person_address.cs new file mode 100644 index 0000000..2078fb3 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210306151633_completion_person_address.cs @@ -0,0 +1,65 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatamodelLibrary.Migrations +{ + public partial class completion_person_address : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Comments", + table: "Persons", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "HomeAddress", + table: "Persons", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "InvoiceAddress", + table: "Persons", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Addresses", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Gata = table.Column(type: "TEXT", nullable: true), + Gata2 = table.Column(type: "TEXT", nullable: true), + PostNr = table.Column(type: "INTEGER", nullable: false), + PostOrt = table.Column(type: "TEXT", nullable: true), + Nation = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Addresses", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Addresses"); + + migrationBuilder.DropColumn( + name: "Comments", + table: "Persons"); + + migrationBuilder.DropColumn( + name: "HomeAddress", + table: "Persons"); + + migrationBuilder.DropColumn( + name: "InvoiceAddress", + table: "Persons"); + } + } +} diff --git a/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.Designer.cs b/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.Designer.cs new file mode 100644 index 0000000..963374f --- /dev/null +++ b/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.Designer.cs @@ -0,0 +1,145 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + [Migration("20210307074530_completion_person_stock")] + partial class completion_person_stock + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Gata") + .HasColumnType("TEXT"); + + b.Property("Gata2") + .HasColumnType("TEXT"); + + b.Property("Nation") + .HasColumnType("TEXT"); + + b.Property("PostNr") + .HasColumnType("INTEGER"); + + b.Property("PostOrt") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("Comments") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("HomeAddress") + .HasColumnType("INTEGER"); + + b.Property("InvoiceAddress") + .HasColumnType("INTEGER"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.PersonStock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("StockId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PersonStocks"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.cs b/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.cs new file mode 100644 index 0000000..a15cc94 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210307074530_completion_person_stock.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatamodelLibrary.Migrations +{ + public partial class completion_person_stock : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "PersonStocks", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PersonId = table.Column(type: "INTEGER", nullable: false), + StockId = table.Column(type: "INTEGER", nullable: false), + Comment = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PersonStocks", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "PersonStocks"); + } + } +} diff --git a/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.Designer.cs b/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.Designer.cs new file mode 100644 index 0000000..352329a --- /dev/null +++ b/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.Designer.cs @@ -0,0 +1,151 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + [Migration("20210307212939_ChangedFormat_Person_Address")] + partial class ChangedFormat_Person_Address + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Destination") + .HasColumnType("TEXT"); + + b.Property("Nation") + .HasColumnType("TEXT"); + + b.Property("Street") + .HasColumnType("TEXT"); + + b.Property("Street2") + .HasColumnType("TEXT"); + + b.Property("Zipcode") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountNo") + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("ClearingNo") + .HasColumnType("INTEGER"); + + b.Property("Comments") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("HomeAddress") + .HasColumnType("INTEGER"); + + b.Property("InvoiceAddress") + .HasColumnType("INTEGER"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.PersonStock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("StockId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PersonStocks"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.cs b/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.cs new file mode 100644 index 0000000..949c9ca --- /dev/null +++ b/DatamodelLibrary/Migrations/20210307212939_ChangedFormat_Person_Address.cs @@ -0,0 +1,75 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatamodelLibrary.Migrations +{ + public partial class ChangedFormat_Person_Address : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "PostOrt", + table: "Addresses", + newName: "Street2"); + + migrationBuilder.RenameColumn( + name: "PostNr", + table: "Addresses", + newName: "Zipcode"); + + migrationBuilder.RenameColumn( + name: "Gata2", + table: "Addresses", + newName: "Street"); + + migrationBuilder.RenameColumn( + name: "Gata", + table: "Addresses", + newName: "Destination"); + + migrationBuilder.AddColumn( + name: "AccountNo", + table: "Persons", + type: "INTEGER", + nullable: false, + defaultValue: 0L); + + migrationBuilder.AddColumn( + name: "ClearingNo", + table: "Persons", + type: "INTEGER", + nullable: false, + defaultValue: 0); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "AccountNo", + table: "Persons"); + + migrationBuilder.DropColumn( + name: "ClearingNo", + table: "Persons"); + + migrationBuilder.RenameColumn( + name: "Zipcode", + table: "Addresses", + newName: "PostNr"); + + migrationBuilder.RenameColumn( + name: "Street2", + table: "Addresses", + newName: "PostOrt"); + + migrationBuilder.RenameColumn( + name: "Street", + table: "Addresses", + newName: "Gata2"); + + migrationBuilder.RenameColumn( + name: "Destination", + table: "Addresses", + newName: "Gata"); + } + } +} diff --git a/DatamodelLibrary/Migrations/20210316200448_backupregister.Designer.cs b/DatamodelLibrary/Migrations/20210316200448_backupregister.Designer.cs new file mode 100644 index 0000000..277cad6 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210316200448_backupregister.Designer.cs @@ -0,0 +1,174 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + [Migration("20210316200448_backupregister")] + partial class backupregister + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Destination") + .HasColumnType("TEXT"); + + b.Property("Nation") + .HasColumnType("TEXT"); + + b.Property("Street") + .HasColumnType("TEXT"); + + b.Property("Street2") + .HasColumnType("TEXT"); + + b.Property("Zipcode") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("DataDomain.BackupRegister", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BackedUp") + .HasColumnType("TEXT"); + + b.Property("BackupDbName") + .HasColumnType("TEXT"); + + b.Property("BackupPath") + .HasColumnType("TEXT"); + + b.Property("DbName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("BackupRegings"); + }); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountNo") + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("ClearingNo") + .HasColumnType("INTEGER"); + + b.Property("Comments") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("HomeAddress") + .HasColumnType("INTEGER"); + + b.Property("InvoiceAddress") + .HasColumnType("INTEGER"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.PersonStock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("StockId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PersonStocks"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/Migrations/20210316200448_backupregister.cs b/DatamodelLibrary/Migrations/20210316200448_backupregister.cs new file mode 100644 index 0000000..4843482 --- /dev/null +++ b/DatamodelLibrary/Migrations/20210316200448_backupregister.cs @@ -0,0 +1,33 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatamodelLibrary.Migrations +{ + public partial class backupregister : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "BackupRegings", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + BackedUp = table.Column(type: "TEXT", nullable: false), + DbName = table.Column(type: "TEXT", nullable: true), + BackupDbName = table.Column(type: "TEXT", nullable: true), + BackupPath = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_BackupRegings", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "BackupRegings"); + } + } +} diff --git a/DatamodelLibrary/Migrations/StockContextModelSnapshot.cs b/DatamodelLibrary/Migrations/StockContextModelSnapshot.cs new file mode 100644 index 0000000..0b733a7 --- /dev/null +++ b/DatamodelLibrary/Migrations/StockContextModelSnapshot.cs @@ -0,0 +1,172 @@ +// +using System; +using DatamodelLibrary; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatamodelLibrary.Migrations +{ + [DbContext(typeof(StockContext))] + partial class StockContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.3"); + + modelBuilder.Entity("DataDomain.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Destination") + .HasColumnType("TEXT"); + + b.Property("Nation") + .HasColumnType("TEXT"); + + b.Property("Street") + .HasColumnType("TEXT"); + + b.Property("Street2") + .HasColumnType("TEXT"); + + b.Property("Zipcode") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("DataDomain.BackupRegister", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("BackedUp") + .HasColumnType("TEXT"); + + b.Property("BackupDbName") + .HasColumnType("TEXT"); + + b.Property("BackupPath") + .HasColumnType("TEXT"); + + b.Property("DbName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("BackupRegings"); + }); + + modelBuilder.Entity("DataDomain.Person", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("AccountNo") + .HasColumnType("INTEGER"); + + b.Property("Born") + .HasColumnType("TEXT"); + + b.Property("ClearingNo") + .HasColumnType("INTEGER"); + + b.Property("Comments") + .HasColumnType("TEXT"); + + b.Property("FirstName") + .HasColumnType("TEXT"); + + b.Property("HomeAddress") + .HasColumnType("INTEGER"); + + b.Property("InvoiceAddress") + .HasColumnType("INTEGER"); + + b.Property("LastName") + .HasColumnType("TEXT"); + + b.Property("NickName") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Persons"); + }); + + modelBuilder.Entity("DataDomain.PersonStock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PersonId") + .HasColumnType("INTEGER"); + + b.Property("StockId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("PersonStocks"); + }); + + modelBuilder.Entity("DataDomain.StockMember", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ActAmount") + .HasColumnType("INTEGER"); + + b.Property("ActDate") + .HasColumnType("TEXT"); + + b.Property("ActValue") + .HasColumnType("TEXT"); + + b.Property("BuyDate") + .HasColumnType("TEXT"); + + b.Property("BuyValue") + .HasColumnType("TEXT"); + + b.Property("Comment") + .HasColumnType("TEXT"); + + b.Property("PostAmount") + .HasColumnType("INTEGER"); + + b.Property("SoldDate") + .HasColumnType("TEXT"); + + b.Property("SoldValue") + .HasColumnType("TEXT"); + + b.Property("StockExtId") + .HasColumnType("TEXT"); + + b.Property("StockId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Stocks"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatamodelLibrary/StockContext.cs b/DatamodelLibrary/StockContext.cs new file mode 100644 index 0000000..6bce6ae --- /dev/null +++ b/DatamodelLibrary/StockContext.cs @@ -0,0 +1,22 @@ +using DataDomain; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatamodelLibrary +{ + public class StockContext : DbContext + { + public DbSet Stocks { get; set; } + public DbSet Persons { get; set; } + public DbSet
Addresses { get; set; } + public DbSet PersonStocks { get; set; } + public DbSet BackupRegings { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder options) + => options.UseSqlite("Data Source=Stocks.db"); + } +} diff --git a/Helpers/ComboboxItem.cs b/Helpers/ComboboxItem.cs new file mode 100644 index 0000000..f2f8442 --- /dev/null +++ b/Helpers/ComboboxItem.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Helpers +{ + public class ComboboxItem + { + private readonly string _display; + private readonly int _hidden; + + public ComboboxItem(string display,int hidden) + { + _display = display; + _hidden = hidden; + } + public int HiddenValue + { + get + { + return _hidden; + } + } + + public override string ToString() + { + return _display; + } + } +} diff --git a/Helpers/Helpers.csproj b/Helpers/Helpers.csproj new file mode 100644 index 0000000..f208d30 --- /dev/null +++ b/Helpers/Helpers.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/Helpers/StringExtensions.cs b/Helpers/StringExtensions.cs new file mode 100644 index 0000000..b8978fc --- /dev/null +++ b/Helpers/StringExtensions.cs @@ -0,0 +1,13 @@ +using System; +using System.Globalization; + +namespace Helpers +{ + public static class StringExtensions + { + public static bool IsNumeric(this string s) + { + return float.TryParse(s, NumberStyles.Float | NumberStyles.Integer, CultureInfo.CurrentUICulture, out _); + } + } +} diff --git a/SqliteBackups/BackupRoutines.cs b/SqliteBackups/BackupRoutines.cs new file mode 100644 index 0000000..3e7dbc8 --- /dev/null +++ b/SqliteBackups/BackupRoutines.cs @@ -0,0 +1,22 @@ +using SqliteBackups.Interfaces; +using System; +using System.Collections.Generic; +using System.Data.SQLite; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SqliteBackups +{ + public class BackupRoutines : IBackupRoutines + { + public void BackupSqliteDb(string fromDb, string toDb) + { + using var source = new SQLiteConnection($"Data Source={fromDb}; Version=3;"); + using var destination = new SQLiteConnection($"Data Source={toDb}; Version=3;"); + source.Open(); + destination.Open(); + source.BackupDatabase(destination, "main", "main", -1, null, 0); + } + } +} diff --git a/SqliteBackups/Interfaces/IBackupRoutines.cs b/SqliteBackups/Interfaces/IBackupRoutines.cs new file mode 100644 index 0000000..ca94ef1 --- /dev/null +++ b/SqliteBackups/Interfaces/IBackupRoutines.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SqliteBackups.Interfaces +{ + public interface IBackupRoutines + { + void BackupSqliteDb(string fromDb, string toDb); + } +} diff --git a/SqliteBackups/SqliteBackups.csproj b/SqliteBackups/SqliteBackups.csproj new file mode 100644 index 0000000..596e5c1 --- /dev/null +++ b/SqliteBackups/SqliteBackups.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/StockBL.Interface/IPersonStockFacade.cs b/StockBL.Interface/IPersonStockFacade.cs new file mode 100644 index 0000000..a8462f8 --- /dev/null +++ b/StockBL.Interface/IPersonStockFacade.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using DataDomain; + +namespace StockBL.Interface +{ + public interface IPersonStockFacade + { + IEnumerable GetAllSharesConnectedTo(int personId); + System.Collections.Generic.IEnumerable GetUnconnectedShares(); + } +} diff --git a/StockBL.Interface/StockBL.Interface.csproj b/StockBL.Interface/StockBL.Interface.csproj new file mode 100644 index 0000000..a3f6e2a --- /dev/null +++ b/StockBL.Interface/StockBL.Interface.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/StockBL/PersonStockFacade.cs b/StockBL/PersonStockFacade.cs new file mode 100644 index 0000000..4bb078e --- /dev/null +++ b/StockBL/PersonStockFacade.cs @@ -0,0 +1,47 @@ +using DataDomain; +using StockBL.Interface; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StockBL +{ + public class PersonStockFacade : IPersonStockFacade + { + private readonly IStockPersonConnect _stockPersonConnect; + private readonly IStockRepository _stockRepository; + + public PersonStockFacade(IStockPersonConnect stockPersonConnect, IStockRepository stockRepository) + { + _stockPersonConnect = stockPersonConnect; + _stockRepository = stockRepository; + } + + public IEnumerable GetUnconnectedShares() + { + var stockList = _stockRepository.GetAllStocks(); + var connectList = _stockPersonConnect.GetAllConnectedStocks(); + + + var stcList = (from st in stockList + where connectList.Any(co => st.Id == co.StockId) + select st).ToList(); + + var sList = stockList.Except(stcList).ToList(); + + return sList; + } + + public IEnumerable GetAllSharesConnectedTo(int personId) + { + var personConnections = _stockPersonConnect.GetAllConnectionsByPersId(personId); + var stockList = _stockRepository.GetAllStocks(); + + var stcList = (from st in stockList + where personConnections.Any(pc => st.Id == pc.StockId) + select st).ToList(); + return stcList; + } + } +} diff --git a/StockBL/StockBL.csproj b/StockBL/StockBL.csproj new file mode 100644 index 0000000..087b712 --- /dev/null +++ b/StockBL/StockBL.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + + + + + + + + + + diff --git a/StockDAL/AddressRepository.cs b/StockDAL/AddressRepository.cs new file mode 100644 index 0000000..8d71f46 --- /dev/null +++ b/StockDAL/AddressRepository.cs @@ -0,0 +1,55 @@ +using DataDomain; +using DatamodelLibrary; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL +{ + public class AddressRepository : IAddressRepository + { + public Address GetAddressById(int AddressId) + { + using var context = new StockContext(); + var entity = (from adr in context.Addresses + where adr.Id == AddressId + select adr).FirstOrDefault(); + return entity; + } + + public Address SaveAddress(Address address) + { + using var context = new StockContext(); + var entity = (from adr in context.Addresses + where adr.Id == address.Id + select adr).FirstOrDefault(); + + if (entity == null) + { + entity = new Address + { + Street = address.Street, + Street2 = address.Street2, + Zipcode = address.Zipcode, + Destination = address.Destination, + Nation = address.Nation + }; + context.Addresses.Add(entity); + } + else + { + entity.Street = address.Street; + entity.Street2 = address.Street2; + entity.Zipcode = address.Zipcode; + entity.Destination = address.Destination; + entity.Nation = address.Nation; + } + + context.SaveChanges(); + return entity; + } + } +} diff --git a/StockDAL/BackupRepository.cs b/StockDAL/BackupRepository.cs new file mode 100644 index 0000000..50e44c7 --- /dev/null +++ b/StockDAL/BackupRepository.cs @@ -0,0 +1,61 @@ +using DataDomain; +using DatamodelLibrary; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL +{ + public class BackupRepository : IBackupRepository + { + public BackupRegister SaveBackupReging(BackupRegister backupRegister) + { + using var context = new StockContext(); + var entity = (from brr in context.BackupRegings + where brr.Id == backupRegister.Id + select brr).FirstOrDefault(); + if (entity == null) + { + entity = new BackupRegister + { + BackedUp = DateTime.Now, + DbName = "Stocks.db", + BackupDbName = backupRegister.BackupDbName, + BackupPath = backupRegister.BackupPath + }; + context.BackupRegings.Add(entity); + } + else + { + entity.BackedUp = backupRegister.BackedUp; + entity.DbName = backupRegister.DbName; + entity.BackupDbName = backupRegister.BackupDbName; + entity.BackupPath = backupRegister.BackupPath; + } + + context.SaveChanges(); + return entity; + } + + + public BackupRegister GetBackupRegisterById(int brId) + { + using var context = new StockContext(); + var entity = (from br in context.BackupRegings + where br.Id == brId + select br).FirstOrDefault(); + return entity; + } + + + public IEnumerable GetAllBackupRegisters() + { + using var context = new StockContext(); + var entities = context.BackupRegings; + return entities.ToList(); + } + } +} diff --git a/StockDAL/PersonRepository.cs b/StockDAL/PersonRepository.cs new file mode 100644 index 0000000..3ada103 --- /dev/null +++ b/StockDAL/PersonRepository.cs @@ -0,0 +1,75 @@ +using DataDomain; +using DatamodelLibrary; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL +{ + public class PersonRepository : IPersonRepository + { + public Person GetPersonById(int personId) + { + using var context = new StockContext(); + var entity = (from prs in context.Persons + where prs.Id == personId + select prs).FirstOrDefault(); + return entity; + } + + public IEnumerable GetAllOwners() + { + using var context = new StockContext(); + var output = context.Persons; + return output.ToList(); + } + + + public Person SavePerson(Person person) + { + using var context = new StockContext(); + + var entity = (from prs in context.Persons + where prs.Id == person.Id + select prs).FirstOrDefault(); + + if (entity == null) + { + entity = new Person + { + AccountNo = person.AccountNo, + Born = person.Born, + ClearingNo = person.ClearingNo, + Comments = person.Comments, + FirstName = person.FirstName, + HomeAddress = person.HomeAddress, + InvoiceAddress = person.InvoiceAddress, + LastName = person.LastName, + NickName = person.NickName + }; + context.Persons.Add(entity); + } + else + { + entity.AccountNo = person.AccountNo; + entity.Born = person.Born; + entity.ClearingNo = person.ClearingNo; + entity.Comments = person.Comments; + entity.FirstName = person.FirstName; + entity.HomeAddress = person.HomeAddress; + entity.InvoiceAddress = person.InvoiceAddress; + entity.LastName = person.LastName; + entity.NickName = person.NickName; + } + + context.SaveChanges(); + + return entity; + } + } + + +} diff --git a/StockDAL/StockDAL.csproj b/StockDAL/StockDAL.csproj new file mode 100644 index 0000000..dfc2f83 --- /dev/null +++ b/StockDAL/StockDAL.csproj @@ -0,0 +1,20 @@ + + + + net5.0 + + + + + + + + + + + + + + + + diff --git a/StockDAL/StockMarketRepository.cs b/StockDAL/StockMarketRepository.cs new file mode 100644 index 0000000..37d9d76 --- /dev/null +++ b/StockDAL/StockMarketRepository.cs @@ -0,0 +1,239 @@ +using Newtonsoft.Json; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using StockDal.Interface; +using DataDomain; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Reflection; +using System.Diagnostics; + +namespace StockDal +{ + public class StockMarketRepository : IStockMarketRepository + { + public Dictionary StockMarketList { get; set; } + + public List DumpObjects { get; set; } = new List(); + public DiTraderStockRow SaveRow { get; set; } + public StringBuilder TextResults { get; set; } + public bool ViewBrowser { get; set; } + + public IWebDriver driver; + + public StockMarketRepository() + { + ViewBrowser = false; + } + + private void Find_Data() + { + TextResults = new StringBuilder(); + IList searchElements = driver.FindElements(By.TagName("tbody")); + foreach (IWebElement i in searchElements) + { + + HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); + var text = i.GetAttribute("innerHTML"); + htmlDocument.LoadHtml(text); + var inputs = htmlDocument.DocumentNode.Descendants("tr").ToList(); + foreach (var items in inputs) + { + HtmlAgilityPack.HtmlDocument htmlDocument1 = new HtmlAgilityPack.HtmlDocument(); + htmlDocument1.LoadHtml(items.InnerHtml); + var tds = htmlDocument1.DocumentNode.Descendants("td").ToList(); + var appendText = ""; + var fNr = 0; + foreach (var item in tds) + { + var intext = item.InnerText.Replace("\r\n", ""); + appendText += appendText.Length == 0 ? intext : " " + intext; + if (tds.Count == 10) + { + AddValueToListRow(fNr++, intext); + } + } + if (!string.IsNullOrEmpty(appendText)) + { + TextResults.Append(appendText + "\r\n"); + } + htmlDocument1 = null; + } + htmlDocument = null; + + TextResults.Append("\r\n"); + } + + // var oxe = StockMarketList; + } + + private void SaveLogging() + { + var output = JsonConvert.SerializeObject(DumpObjects, Formatting.Indented); + Assembly assem = typeof(StockMarketRepository).Assembly; + var programPath = assem.Location.Substring(0, assem.Location.LastIndexOf("\\")); + var logPath = new DirectoryInfo(programPath + "\\Loggings"); + if (!logPath.Exists) + { + logPath.Create(); + } + File.WriteAllText($"{programPath}\\Loggings\\Log{DateTime.Now.ToShortDateString()}.txt", output); + } + + private void AddValueToListRow(int pos, string value) + { + switch (pos) + { + case 0: + { + SaveRow = new DiTraderStockRow(); + SaveRow.StockName = value; + break; + } + case 1: + { + SaveRow.ProcChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 2: + { + SaveRow.RealChange = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 3: + { + SaveRow.BuyPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 4: + { + SaveRow.SellPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 5: + { + SaveRow.LatestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 6: + { + SaveRow.HighestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 7: + { + SaveRow.LowestPrice = string.IsNullOrWhiteSpace(value) ? 0 : decimal.Parse(value); + break; + } + case 8: + { + + SaveRow.Volume = string.IsNullOrWhiteSpace(value) ? 0 : long.Parse(value.Replace(" ", "")); + break; + } + case 9: + { + SaveRow.TimeOfDay = value==""?TimeSpan.Parse("00:01"): TimeSpan.Parse(value); + //StockMarketList.Add(SaveRow.StockName, SaveRow); + try + { + StockMarketList.Add(SaveRow.StockName, SaveRow); + } + catch (ArgumentException ) + { + try + { + StockMarketList.Add(SaveRow.StockName + "-2", SaveRow); + } + catch (Exception) + { + DumpObjects.Add(SaveRow); + } + + } + break; + } + default: + break; + } + } + + private void OpenBrowser(bool burl2 = false) + { + var driverService = ChromeDriverService.CreateDefaultService(); + driverService.HideCommandPromptWindow = true; + + if (ViewBrowser) + { + if (driver == null) + { + driver = new ChromeDriver(driverService); + } + } + else + { + if (driver == null) + { + var options = new ChromeOptions(); + options.AddArgument("headless"); + driver = new ChromeDriver(driverService, options); + } + } + + try + { + //var url0 = "https://money.cnn.com/data/hotstocks/index.html"; + var url = "https://trader.di.se/index.php/stocklist/index/2055?list=7126"; + var url2 = "https://trader.di.se/index.php/stocklist/index/2055?list=7116"; + //var url1 = "https://www.finansportalen.se/aktiekurser/"; + driver.Navigate().GoToUrl(burl2 ? url2 : url); + + } + catch + { + throw; + } + + } + + public void LoadStockMarketList() + { + StockMarketList = new Dictionary(); + DumpObjects = new List(); + OpenBrowser(); + Find_Data(); + OpenBrowser(true); + Find_Data(); + if (DumpObjects.Any()) + { + SaveLogging(); + } + } + + + public void LoadStockMarketList(bool viewBrowser) + { + StockMarketList = new Dictionary(); + ViewBrowser = viewBrowser; + OpenBrowser(); + Find_Data(); + } + + public void RefreshMarketList() + { + StockMarketList = new Dictionary(); + driver.Navigate().Refresh(); + Find_Data(); + } + + public void Clean() + { + driver?.Quit(); + } + + } +} diff --git a/StockDAL/StockPersonConnect.cs b/StockDAL/StockPersonConnect.cs new file mode 100644 index 0000000..afd9634 --- /dev/null +++ b/StockDAL/StockPersonConnect.cs @@ -0,0 +1,72 @@ +using DataDomain; +using DatamodelLibrary; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL +{ + public class StockPersonConnect : IStockPersonConnect + { + public IEnumerable GetAllConnectionsByPersId(int personId) + { + using var context = new StockContext(); + var connections = (from spc in context.PersonStocks + where spc.PersonId == personId + select spc).ToList(); + return connections; + } + + public IEnumerable GetAllConnectedStocks() + { + using var context = new StockContext(); + var entities = (from spc in context.PersonStocks + where spc.PersonId != 0 + select spc).ToList(); + return entities; + } + + public PersonStock SavePersonStockConnection(PersonStock personStock) + { + using var context = new StockContext(); + var entity = (from ps in context.PersonStocks + where ps.Id == personStock.Id + select ps).FirstOrDefault(); + if (entity == null) + { + entity = new PersonStock + { + PersonId = personStock.PersonId, + StockId = personStock.StockId, + Comment = personStock.Comment + }; + context.PersonStocks.Add(entity); + } + else + { + entity.PersonId = personStock.PersonId; + entity.StockId = personStock.StockId; + entity.Comment = personStock.Comment; + } + context.SaveChanges(); + + return entity; + } + + public void RemoveConnectedShare(PersonStock personStock) + { + using var context = new StockContext(); + var entity = (from ps in context.PersonStocks + where ps.StockId == personStock.StockId + select ps).FirstOrDefault(); + if (entity != null) + { + context.PersonStocks.Remove(entity); + context.SaveChanges(); + } + } + } +} \ No newline at end of file diff --git a/StockDAL/StockRepository.cs b/StockDAL/StockRepository.cs new file mode 100644 index 0000000..6d1a292 --- /dev/null +++ b/StockDAL/StockRepository.cs @@ -0,0 +1,115 @@ +using DataDomain; +using DatamodelLibrary; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL +{ + public class StockRepository : IStockRepository + { + public void SaveStockMember(StockMember stockMember) + { + using (var context = new StockContext()) + { + var sm = context.Stocks.Add(stockMember); + context.SaveChanges(); + } + } + + public void UpdateActualPrice(int id, decimal price) + { + using var context = new StockContext(); + var entity = (from stk in context.Stocks + where stk.Id == id + select stk).FirstOrDefault(); + + entity.ActValue = price; + entity.ActDate = DateTime.Today; + + context.SaveChanges(); + } + + public void UpdateActualForSell(int id, int sellAmount, decimal sellPrice, DateTime sellDate) + { + using var context = new StockContext(); + var entity = (from stk in context.Stocks + where stk.Id == id + select stk).FirstOrDefault(); + var rest = entity.ActAmount - sellAmount; + entity.ActAmount = rest < 0 ? 0 : rest; + entity.SoldDate = DateTime.Today; + entity.SoldValue = sellAmount * sellPrice; + + context.SaveChanges(); + } + + + public IEnumerable GetAllStocks() + { + using var context = new StockContext(); + var output = context.Stocks; + return output.ToList(); + } + + public IEnumerable GetAllRemainingStocks() + { + using var context = new StockContext(); + var output = (from stk in context.Stocks + where stk.SoldDate == null || stk.ActAmount > 0 + select stk).ToList(); + return output; + } + + public void RemoveAllStocks() + { + using var context = new StockContext(); + context.Stocks.RemoveRange(GetAllStocks()); + context.SaveChanges(); + } + + public void InsertMany(List stockMembers) + { + using var context = new StockContext(); + context.Stocks.AddRange(stockMembers); + context.SaveChanges(); + } + + public void RestoreStockMembers(List stockMembers) + { + using var context = new StockContext(); + using var transaction = context.Database.BeginTransaction(); + + try + { + var stocksToRemove = context.Stocks; + context.Stocks.RemoveRange(stocksToRemove); + var insertStocks = stockMembers.Select(o => new StockMember + { + Id = 0, + StockId = o.StockId, + StockExtId = o.StockExtId, + BuyDate = o.BuyDate, + BuyValue = o.BuyValue, + ActAmount = o.ActAmount, + ActValue = o.ActValue, + ActDate = o.ActDate, + SoldValue = o.SoldValue, + SoldDate = o.SoldDate, + Comment = o.Comment, + PostAmount = o.PostAmount + }).ToList(); + context.Stocks.AddRange(insertStocks); + context.SaveChanges(); + transaction.Commit(); + } + catch (Exception ex) + { + throw new InvalidOperationException(ex.Message); + } + } + } +} diff --git a/StockDal.Interface/IAddressRepository.cs b/StockDal.Interface/IAddressRepository.cs new file mode 100644 index 0000000..65e6688 --- /dev/null +++ b/StockDal.Interface/IAddressRepository.cs @@ -0,0 +1,15 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL.Interface +{ + public interface IAddressRepository + { + Address GetAddressById(int AddressId); + Address SaveAddress(Address address); + } +} diff --git a/StockDal.Interface/IBackupRepository.cs b/StockDal.Interface/IBackupRepository.cs new file mode 100644 index 0000000..90060bb --- /dev/null +++ b/StockDal.Interface/IBackupRepository.cs @@ -0,0 +1,16 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL.Interface +{ + public interface IBackupRepository + { + IEnumerable GetAllBackupRegisters(); + BackupRegister GetBackupRegisterById(int brId); + BackupRegister SaveBackupReging(BackupRegister backupRegister); + } +} diff --git a/StockDal.Interface/IPersonRepository.cs b/StockDal.Interface/IPersonRepository.cs new file mode 100644 index 0000000..ac99c40 --- /dev/null +++ b/StockDal.Interface/IPersonRepository.cs @@ -0,0 +1,16 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL.Interface +{ + public interface IPersonRepository + { + IEnumerable GetAllOwners(); + Person GetPersonById(int personId); + Person SavePerson(Person person); + } +} diff --git a/StockDal.Interface/IStockMarketRepository.cs b/StockDal.Interface/IStockMarketRepository.cs new file mode 100644 index 0000000..daf4e60 --- /dev/null +++ b/StockDal.Interface/IStockMarketRepository.cs @@ -0,0 +1,20 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDal.Interface +{ + public interface IStockMarketRepository + { + Dictionary StockMarketList { get; set; } + bool ViewBrowser { get; set; } + + void Clean(); + void LoadStockMarketList(); + void LoadStockMarketList(bool viewBrowser); + void RefreshMarketList(); + } +} diff --git a/StockDal.Interface/IStockPersonConnect.cs b/StockDal.Interface/IStockPersonConnect.cs new file mode 100644 index 0000000..45cb133 --- /dev/null +++ b/StockDal.Interface/IStockPersonConnect.cs @@ -0,0 +1,17 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL.Interface +{ + public interface IStockPersonConnect + { + IEnumerable GetAllConnectedStocks(); + IEnumerable GetAllConnectionsByPersId(int personId); + void RemoveConnectedShare(PersonStock personStock); + PersonStock SavePersonStockConnection(PersonStock personStock); + } +} diff --git a/StockDal.Interface/IStockRepository.cs b/StockDal.Interface/IStockRepository.cs new file mode 100644 index 0000000..cdb4a88 --- /dev/null +++ b/StockDal.Interface/IStockRepository.cs @@ -0,0 +1,21 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockDAL.Interface +{ + public interface IStockRepository + { + IEnumerable GetAllRemainingStocks(); + IEnumerable GetAllStocks(); + void InsertMany(List stockMembers); + void RemoveAllStocks(); + void RestoreStockMembers(List stockMembers); + void SaveStockMember(StockMember stockMember); + void UpdateActualForSell(int id, int sellAmount, decimal sellPrice, DateTime sellDate); + void UpdateActualPrice(int id, decimal price); + } +} diff --git a/StockDal.Interface/StockDAL.Interface.csproj b/StockDal.Interface/StockDAL.Interface.csproj new file mode 100644 index 0000000..8229020 --- /dev/null +++ b/StockDal.Interface/StockDAL.Interface.csproj @@ -0,0 +1,16 @@ + + + + net5.0 + + + + + + + + + + + + diff --git a/StockInfoCore/Program.cs b/StockInfoCore/Program.cs new file mode 100644 index 0000000..cb4315a --- /dev/null +++ b/StockInfoCore/Program.cs @@ -0,0 +1,49 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfoCore +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + + static void Main() + { + var builder = new HostBuilder() + .ConfigureServices((_, services) => + { + services.AddDIInfo(); + }); + + var host = builder.Build(); + using var scope = host.Services.CreateScope(); + + try + { + var services = scope.ServiceProvider; + + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + var frm = services.GetRequiredService(); + + Application.Run(frm); + } + catch (Exception ex) + { + Console.WriteLine($"An error has occured: { ex.Message}"); + } + + } + + } +} diff --git a/StockInfoCore/StockInfoCore.csproj b/StockInfoCore/StockInfoCore.csproj new file mode 100644 index 0000000..c17cd41 --- /dev/null +++ b/StockInfoCore/StockInfoCore.csproj @@ -0,0 +1,34 @@ + + + + WinExe + net5.0-windows + true + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + + \ No newline at end of file diff --git a/StockInfoCore/StockInfoDISetup.cs b/StockInfoCore/StockInfoDISetup.cs new file mode 100644 index 0000000..06a48b4 --- /dev/null +++ b/StockInfoCore/StockInfoDISetup.cs @@ -0,0 +1,43 @@ +using Microsoft.Extensions.DependencyInjection; +using SqliteBackups; +using SqliteBackups.Interfaces; +using StockBL; +using StockBL.Interface; +using StockDal; +using StockDal.Interface; +using StockDAL; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StockInfoCore +{ + public static class StockInfoDISetup + { + public static IServiceCollection AddDIInfo(this IServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + return services; + } + } +} diff --git a/StockInfoCore/Stocks.db b/StockInfoCore/Stocks.db new file mode 100644 index 0000000..6ef8603 Binary files /dev/null and b/StockInfoCore/Stocks.db differ diff --git a/StockInfoCore/frmBackup.Designer.cs b/StockInfoCore/frmBackup.Designer.cs new file mode 100644 index 0000000..6417939 --- /dev/null +++ b/StockInfoCore/frmBackup.Designer.cs @@ -0,0 +1,142 @@ + +namespace StockInfoCore +{ + partial class frmBackup + { + /// + /// 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() + { + this.label1 = new System.Windows.Forms.Label(); + this.sfdChoosePlaceAndFile = new System.Windows.Forms.SaveFileDialog(); + this.btnChooseBackupDest = new System.Windows.Forms.Button(); + this.txtBackupPath = new System.Windows.Forms.TextBox(); + this.txtBackupFile = new System.Windows.Forms.TextBox(); + this.lstBackups = new System.Windows.Forms.ListBox(); + this.btnClose = new System.Windows.Forms.Button(); + this.btnRestore = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(226, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Backup Local database to where you wish"; + // + // sfdChoosePlaceAndFile + // + this.sfdChoosePlaceAndFile.Title = "Choose path and filename"; + // + // btnChooseBackupDest + // + this.btnChooseBackupDest.Location = new System.Drawing.Point(13, 31); + this.btnChooseBackupDest.Name = "btnChooseBackupDest"; + this.btnChooseBackupDest.Size = new System.Drawing.Size(152, 23); + this.btnChooseBackupDest.TabIndex = 1; + this.btnChooseBackupDest.Text = "Choose BU destination"; + this.btnChooseBackupDest.UseVisualStyleBackColor = true; + this.btnChooseBackupDest.Click += new System.EventHandler(this.btnChooseBackupDest_Click); + // + // txtBackupPath + // + this.txtBackupPath.Location = new System.Drawing.Point(171, 32); + this.txtBackupPath.Name = "txtBackupPath"; + this.txtBackupPath.ReadOnly = true; + this.txtBackupPath.Size = new System.Drawing.Size(148, 23); + this.txtBackupPath.TabIndex = 2; + // + // txtBackupFile + // + this.txtBackupFile.Location = new System.Drawing.Point(325, 31); + this.txtBackupFile.Name = "txtBackupFile"; + this.txtBackupFile.ReadOnly = true; + this.txtBackupFile.Size = new System.Drawing.Size(100, 23); + this.txtBackupFile.TabIndex = 3; + // + // lstBackups + // + this.lstBackups.FormattingEnabled = true; + this.lstBackups.ItemHeight = 15; + this.lstBackups.Location = new System.Drawing.Point(13, 70); + this.lstBackups.Name = "lstBackups"; + this.lstBackups.Size = new System.Drawing.Size(306, 184); + this.lstBackups.TabIndex = 4; + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(350, 259); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 5; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // btnRestore + // + this.btnRestore.Location = new System.Drawing.Point(350, 70); + this.btnRestore.Name = "btnRestore"; + this.btnRestore.Size = new System.Drawing.Size(75, 23); + this.btnRestore.TabIndex = 6; + this.btnRestore.Text = "Restore"; + this.btnRestore.UseVisualStyleBackColor = true; + this.btnRestore.Click += new System.EventHandler(this.btnRestore_Click); + // + // frmBackup + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(438, 294); + this.Controls.Add(this.btnRestore); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.lstBackups); + this.Controls.Add(this.txtBackupFile); + this.Controls.Add(this.txtBackupPath); + this.Controls.Add(this.btnChooseBackupDest); + this.Controls.Add(this.label1); + this.Name = "frmBackup"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmBackup"; + this.Shown += new System.EventHandler(this.frmBackup_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.SaveFileDialog sfdChoosePlaceAndFile; + private System.Windows.Forms.Button btnChooseBackupDest; + private System.Windows.Forms.TextBox txtBackupPath; + private System.Windows.Forms.TextBox txtBackupFile; + private System.Windows.Forms.ListBox lstBackups; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Button btnRestore; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmBackup.cs b/StockInfoCore/frmBackup.cs new file mode 100644 index 0000000..b9bd87f --- /dev/null +++ b/StockInfoCore/frmBackup.cs @@ -0,0 +1,106 @@ +using DataDomain; +using Helpers; +using SqliteBackups.Interfaces; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfoCore +{ + public partial class frmBackup : Form + { + private readonly IBackupRepository _backupRepository; + private readonly IBackupRoutines _backupRoutines; + public List CurrentBackups { get; set; } = new List(); + public frmBackup(IBackupRepository backupRepository,IBackupRoutines backupRoutines) + { + InitializeComponent(); + _backupRepository = backupRepository; + _backupRoutines = backupRoutines; + } + + private void btnChooseBackupDest_Click(object sender, EventArgs e) + { + sfdChoosePlaceAndFile.Filter = "Database files (*.db)|*.db|All files (*.*)|*.*"; + if (sfdChoosePlaceAndFile.ShowDialog() == DialogResult.OK) + { + var wholeFile = sfdChoosePlaceAndFile.FileName; + var lastBackslash = wholeFile.LastIndexOf('\\') + 1; + var dir = wholeFile.Substring(0, lastBackslash); + var file = wholeFile.Substring(lastBackslash, wholeFile.Length - lastBackslash); + //Debug.WriteLine($"Chosen file:{wholeFile}"); + //Debug.WriteLine($"Path: {dir} , File {file}"); + BackupRegister reg = new(); + reg.BackupDbName = file; + reg.BackupPath = dir; + reg = _backupRepository.SaveBackupReging(reg); + txtBackupPath.Text = dir; + txtBackupFile.Text = file; + _backupRoutines.BackupSqliteDb(reg.DbName, Path.Combine(dir, file)); + var cmbItem = new ComboboxItem($"{reg.BackedUp.ToLocalTime()} {wholeFile}", reg.Id); + lstBackups.Items.Add(cmbItem); + CurrentBackups = _backupRepository.GetAllBackupRegisters().ToList(); + }; + + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void frmBackup_Shown(object sender, EventArgs e) + { + CurrentBackups =_backupRepository.GetAllBackupRegisters().ToList(); + lstBackups.Items.Clear(); + foreach(var bckrg in CurrentBackups) + { + var cmbItem = new ComboboxItem($"{bckrg.BackedUp.ToLocalTime()} {Path.Combine(bckrg.BackupPath, bckrg.BackupDbName)}", bckrg.Id); + lstBackups.Items.Add(cmbItem); + } + } + + private void btnRestore_Click(object sender, EventArgs e) + { + if (lstBackups.SelectedIndex != -1) + { + BackupRegister br = new(); + br.Id = ((ComboboxItem)lstBackups.SelectedItem).HiddenValue; + var backupReg = _backupRepository.GetBackupRegisterById(br.Id); + if (File.Exists(backupReg.DbName)) + { + File.Move(backupReg.DbName, "tempFile.bak",true); + } + _backupRoutines.BackupSqliteDb(Path.Combine(backupReg.BackupPath, backupReg.BackupDbName), backupReg.DbName); + UpdateBackupRegs(CurrentBackups); + MessageBox.Show($"Backup {Path.Combine(backupReg.BackupPath, backupReg.BackupDbName)} loaded !"); + } + } + + private void UpdateBackupRegs(List currentBackups) + { + var backupRegs = _backupRepository.GetAllBackupRegisters(); + var result = currentBackups.Where(cb => backupRegs.All(br => br.BackupDbName != cb.BackupDbName || br.BackupPath != cb.BackupPath)); + foreach(var br in result) + { + _backupRepository.SaveBackupReging(new BackupRegister + { + BackedUp = br.BackedUp, + BackupDbName = br.BackupDbName, + BackupPath = br.BackupPath, + DbName = br.DbName, + Id = 0 + }); + } + } + } +} diff --git a/StockInfoCore/frmBackup.resx b/StockInfoCore/frmBackup.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmBackup.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StockInfoCore/frmInitial.Designer.cs b/StockInfoCore/frmInitial.Designer.cs new file mode 100644 index 0000000..cf7940c --- /dev/null +++ b/StockInfoCore/frmInitial.Designer.cs @@ -0,0 +1,342 @@ + +namespace StockInfoCore +{ + partial class frmInitial + { + /// + /// 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.lblTotalRecords = new System.Windows.Forms.Label(); + this.gB1 = new System.Windows.Forms.GroupBox(); + this.btnBackupAll = new System.Windows.Forms.Button(); + this.chkEnableBackRes = new System.Windows.Forms.CheckBox(); + this.btnRestoreShares = new System.Windows.Forms.Button(); + this.btnBackupShares = new System.Windows.Forms.Button(); + this.btnReload = new System.Windows.Forms.Button(); + this.btnTestScrapFunction = new System.Windows.Forms.Button(); + this.btnReloadShares = new System.Windows.Forms.Button(); + this.chbShowBrowser = new System.Windows.Forms.CheckBox(); + this.gbStockMgmnt = new System.Windows.Forms.GroupBox(); + this.btnStockSale = new System.Windows.Forms.Button(); + this.btnValueView = new System.Windows.Forms.Button(); + this.btnStockReg = new System.Windows.Forms.Button(); + this.sfdSaver = new System.Windows.Forms.SaveFileDialog(); + this.ofdOpener = new System.Windows.Forms.OpenFileDialog(); + this.lblStockRows = new System.Windows.Forms.Label(); + this.gpOwners = new System.Windows.Forms.GroupBox(); + this.btnConnShares = new System.Windows.Forms.Button(); + this.btnEditPerson = new System.Windows.Forms.Button(); + this.cmbOwners = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.gB1.SuspendLayout(); + this.gbStockMgmnt.SuspendLayout(); + this.gpOwners.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 16); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(871, 360); + this.dataGridView.TabIndex = 0; + // + // lblTotalRecords + // + this.lblTotalRecords.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblTotalRecords.AutoSize = true; + this.lblTotalRecords.Location = new System.Drawing.Point(12, 385); + this.lblTotalRecords.Name = "lblTotalRecords"; + this.lblTotalRecords.Size = new System.Drawing.Size(98, 15); + this.lblTotalRecords.TabIndex = 2; + this.lblTotalRecords.Text = "Total Records: ???"; + // + // gB1 + // + this.gB1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.gB1.Controls.Add(this.btnBackupAll); + this.gB1.Controls.Add(this.chkEnableBackRes); + this.gB1.Controls.Add(this.btnRestoreShares); + this.gB1.Controls.Add(this.btnBackupShares); + this.gB1.Controls.Add(this.btnReload); + this.gB1.Location = new System.Drawing.Point(157, 385); + this.gB1.Name = "gB1"; + this.gB1.Size = new System.Drawing.Size(245, 144); + this.gB1.TabIndex = 3; + this.gB1.TabStop = false; + this.gB1.Text = "Sharelist"; + // + // btnBackupAll + // + this.btnBackupAll.Location = new System.Drawing.Point(130, 82); + this.btnBackupAll.Name = "btnBackupAll"; + this.btnBackupAll.Size = new System.Drawing.Size(105, 23); + this.btnBackupAll.TabIndex = 6; + this.btnBackupAll.Text = "Backup / Restore"; + this.btnBackupAll.UseVisualStyleBackColor = true; + this.btnBackupAll.Click += new System.EventHandler(this.btnBackupAll_Click); + // + // chkEnableBackRes + // + this.chkEnableBackRes.AutoSize = true; + this.chkEnableBackRes.Location = new System.Drawing.Point(6, 61); + this.chkEnableBackRes.Name = "chkEnableBackRes"; + this.chkEnableBackRes.Size = new System.Drawing.Size(144, 19); + this.chkEnableBackRes.TabIndex = 5; + this.chkEnableBackRes.Text = "Enable backup/restore"; + this.chkEnableBackRes.UseVisualStyleBackColor = true; + this.chkEnableBackRes.CheckedChanged += new System.EventHandler(this.chkEnableBackRes_CheckedChanged); + // + // btnRestoreShares + // + this.btnRestoreShares.Location = new System.Drawing.Point(6, 111); + this.btnRestoreShares.Name = "btnRestoreShares"; + this.btnRestoreShares.Size = new System.Drawing.Size(118, 23); + this.btnRestoreShares.TabIndex = 4; + this.btnRestoreShares.Text = "Restore Share data"; + this.btnRestoreShares.UseVisualStyleBackColor = true; + this.btnRestoreShares.Click += new System.EventHandler(this.btnRestoreShares_Click); + // + // btnBackupShares + // + this.btnBackupShares.Location = new System.Drawing.Point(6, 82); + this.btnBackupShares.Name = "btnBackupShares"; + this.btnBackupShares.Size = new System.Drawing.Size(118, 23); + this.btnBackupShares.TabIndex = 3; + this.btnBackupShares.Text = "Backup Share data"; + this.btnBackupShares.UseVisualStyleBackColor = true; + this.btnBackupShares.Click += new System.EventHandler(this.btnBackupShares_Click); + // + // btnReload + // + this.btnReload.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnReload.Location = new System.Drawing.Point(6, 32); + this.btnReload.Name = "btnReload"; + this.btnReload.Size = new System.Drawing.Size(112, 23); + this.btnReload.TabIndex = 2; + this.btnReload.Text = "Reload Share list"; + this.btnReload.UseVisualStyleBackColor = true; + this.btnReload.Click += new System.EventHandler(this.btnReload_Click); + // + // btnTestScrapFunction + // + this.btnTestScrapFunction.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnTestScrapFunction.Location = new System.Drawing.Point(12, 467); + this.btnTestScrapFunction.Name = "btnTestScrapFunction"; + this.btnTestScrapFunction.Size = new System.Drawing.Size(75, 23); + this.btnTestScrapFunction.TabIndex = 4; + this.btnTestScrapFunction.Text = "LoadScrap"; + this.btnTestScrapFunction.UseVisualStyleBackColor = true; + this.btnTestScrapFunction.Click += new System.EventHandler(this.btnTestScrapFunction_Click); + // + // btnReloadShares + // + this.btnReloadShares.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnReloadShares.Location = new System.Drawing.Point(12, 417); + this.btnReloadShares.Name = "btnReloadShares"; + this.btnReloadShares.Size = new System.Drawing.Size(75, 23); + this.btnReloadShares.TabIndex = 6; + this.btnReloadShares.Text = "ReLoad"; + this.btnReloadShares.UseVisualStyleBackColor = true; + this.btnReloadShares.Click += new System.EventHandler(this.btnReloadShares_Click); + // + // chbShowBrowser + // + this.chbShowBrowser.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chbShowBrowser.AutoSize = true; + this.chbShowBrowser.Location = new System.Drawing.Point(12, 497); + this.chbShowBrowser.Name = "chbShowBrowser"; + this.chbShowBrowser.Size = new System.Drawing.Size(100, 22); + this.chbShowBrowser.TabIndex = 7; + this.chbShowBrowser.Text = "Show Browser"; + this.chbShowBrowser.UseCompatibleTextRendering = true; + this.chbShowBrowser.UseVisualStyleBackColor = true; + // + // gbStockMgmnt + // + this.gbStockMgmnt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.gbStockMgmnt.Controls.Add(this.btnStockSale); + this.gbStockMgmnt.Controls.Add(this.btnValueView); + this.gbStockMgmnt.Controls.Add(this.btnStockReg); + this.gbStockMgmnt.Location = new System.Drawing.Point(408, 385); + this.gbStockMgmnt.Name = "gbStockMgmnt"; + this.gbStockMgmnt.Size = new System.Drawing.Size(216, 144); + this.gbStockMgmnt.TabIndex = 8; + this.gbStockMgmnt.TabStop = false; + this.gbStockMgmnt.Text = "Working"; + // + // btnStockSale + // + this.btnStockSale.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnStockSale.Location = new System.Drawing.Point(108, 82); + this.btnStockSale.Name = "btnStockSale"; + this.btnStockSale.Size = new System.Drawing.Size(96, 23); + this.btnStockSale.TabIndex = 2; + this.btnStockSale.Text = "Stock Sell"; + this.btnStockSale.UseVisualStyleBackColor = true; + this.btnStockSale.Click += new System.EventHandler(this.btnStockSale_Click); + // + // btnValueView + // + this.btnValueView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnValueView.Location = new System.Drawing.Point(6, 32); + this.btnValueView.Name = "btnValueView"; + this.btnValueView.Size = new System.Drawing.Size(95, 23); + this.btnValueView.TabIndex = 1; + this.btnValueView.Text = "See values"; + this.btnValueView.UseVisualStyleBackColor = true; + this.btnValueView.Click += new System.EventHandler(this.btnValueView_Click); + // + // btnStockReg + // + this.btnStockReg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnStockReg.Location = new System.Drawing.Point(6, 82); + this.btnStockReg.Name = "btnStockReg"; + this.btnStockReg.Size = new System.Drawing.Size(96, 23); + this.btnStockReg.TabIndex = 0; + this.btnStockReg.Text = "Stock Purchase"; + this.btnStockReg.UseVisualStyleBackColor = true; + this.btnStockReg.Click += new System.EventHandler(this.btnStockReg_Click); + // + // ofdOpener + // + this.ofdOpener.FileName = "openFileDialog1"; + // + // lblStockRows + // + this.lblStockRows.AutoSize = true; + this.lblStockRows.Location = new System.Drawing.Point(13, 446); + this.lblStockRows.Name = "lblStockRows"; + this.lblStockRows.Size = new System.Drawing.Size(0, 15); + this.lblStockRows.TabIndex = 9; + // + // gpOwners + // + this.gpOwners.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.gpOwners.Controls.Add(this.btnConnShares); + this.gpOwners.Controls.Add(this.btnEditPerson); + this.gpOwners.Controls.Add(this.cmbOwners); + this.gpOwners.Location = new System.Drawing.Point(630, 385); + this.gpOwners.Name = "gpOwners"; + this.gpOwners.Size = new System.Drawing.Size(252, 141); + this.gpOwners.TabIndex = 10; + this.gpOwners.TabStop = false; + this.gpOwners.Text = "ShareOwners"; + // + // btnConnShares + // + this.btnConnShares.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnConnShares.Location = new System.Drawing.Point(120, 82); + this.btnConnShares.Name = "btnConnShares"; + this.btnConnShares.Size = new System.Drawing.Size(108, 23); + this.btnConnShares.TabIndex = 4; + this.btnConnShares.Text = "Connect Shares"; + this.btnConnShares.UseVisualStyleBackColor = true; + this.btnConnShares.Click += new System.EventHandler(this.btnConnShares_Click); + // + // btnEditPerson + // + this.btnEditPerson.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnEditPerson.Location = new System.Drawing.Point(6, 82); + this.btnEditPerson.Name = "btnEditPerson"; + this.btnEditPerson.Size = new System.Drawing.Size(108, 23); + this.btnEditPerson.TabIndex = 3; + this.btnEditPerson.Text = "Add/Edit Person"; + this.btnEditPerson.UseVisualStyleBackColor = true; + this.btnEditPerson.Click += new System.EventHandler(this.btnEditPerson_Click); + // + // cmbOwners + // + this.cmbOwners.FormattingEnabled = true; + this.cmbOwners.Location = new System.Drawing.Point(6, 33); + this.cmbOwners.Name = "cmbOwners"; + this.cmbOwners.Size = new System.Drawing.Size(152, 23); + this.cmbOwners.TabIndex = 0; + this.cmbOwners.SelectedIndexChanged += new System.EventHandler(this.cmbOwners_SelectedIndexChanged); + // + // frmInitial + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(895, 538); + this.Controls.Add(this.gpOwners); + this.Controls.Add(this.lblStockRows); + this.Controls.Add(this.gbStockMgmnt); + this.Controls.Add(this.chbShowBrowser); + this.Controls.Add(this.btnReloadShares); + this.Controls.Add(this.btnTestScrapFunction); + this.Controls.Add(this.gB1); + this.Controls.Add(this.lblTotalRecords); + this.Controls.Add(this.dataGridView); + this.MinimizeBox = false; + this.Name = "frmInitial"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Stock Overview"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmInitial_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); + this.Shown += new System.EventHandler(this.frmInitial_Shown); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.gB1.ResumeLayout(false); + this.gB1.PerformLayout(); + this.gbStockMgmnt.ResumeLayout(false); + this.gpOwners.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Label lblTotalRecords; + private System.Windows.Forms.GroupBox gB1; + private System.Windows.Forms.Button btnReload; + private System.Windows.Forms.Button btnTestScrapFunction; + private System.Windows.Forms.Button btnReloadShares; + private System.Windows.Forms.CheckBox chbShowBrowser; + private System.Windows.Forms.GroupBox gbStockMgmnt; + private System.Windows.Forms.Button btnStockReg; + private System.Windows.Forms.Button btnValueView; + private System.Windows.Forms.Button btnStockSale; + private System.Windows.Forms.CheckBox chkEnableBackRes; + private System.Windows.Forms.Button btnRestoreShares; + private System.Windows.Forms.Button btnBackupShares; + private System.Windows.Forms.SaveFileDialog sfdSaver; + private System.Windows.Forms.OpenFileDialog ofdOpener; + private System.Windows.Forms.Label lblStockRows; + private System.Windows.Forms.GroupBox gpOwners; + private System.Windows.Forms.Button btnConnShares; + private System.Windows.Forms.Button btnEditPerson; + private System.Windows.Forms.ComboBox cmbOwners; + private System.Windows.Forms.Button btnBackupAll; + } +} + diff --git a/StockInfoCore/frmInitial.cs b/StockInfoCore/frmInitial.cs new file mode 100644 index 0000000..3a4b821 --- /dev/null +++ b/StockInfoCore/frmInitial.cs @@ -0,0 +1,268 @@ +using StockDal.Interface; +using StockDAL.Interface; +using DataDomain; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Text.Json; +using System.IO; +using Helpers; +using StockBL.Interface; +using SqliteBackups.Interfaces; + +namespace StockInfoCore +{ + public partial class frmInitial : Form + { + private readonly IStockRepository _stockRepository; + private readonly IStockMarketRepository _stockMarketRepository; + private readonly IPersonRepository _personRepository; + private readonly IAddressRepository _addressRepository; + private readonly IStockPersonConnect _stockPersonConnect; + private readonly IBackupRepository _backupRepository; + private readonly IBackupRoutines _backupRoutines; + private readonly IPersonStockFacade _personStockFacade; + private readonly frmRegisterStock _regWindow; + private readonly frmMyStocks _stockWindow; + private readonly frmSelling _sellWindow; + private readonly frmPerson _personWindow; + private readonly frmPersonShareConnect _personShareConnect; + private readonly frmBackup _backupWindow; + + //private frmRegisterStock regWindow; + //private frmMyStocks stockWindow; + //private frmSelling sellWindow; + //private frmPerson personWindow; + //private frmPersonShareConnect personShareConnect; + //private frmBackup backupWindow; + public int SelectedPersonId { get; set; } = 0; + + public frmInitial( + IStockRepository stockMemberRepository, + IStockMarketRepository stockMarketRepository, + IPersonRepository personRepository, + IAddressRepository addressRepository, + IStockPersonConnect stockPersonConnect, + IBackupRepository backupRepository, + IBackupRoutines backupRoutines, + IPersonStockFacade personStockFacade, + frmRegisterStock regWindow, + frmMyStocks stockWindow, + frmSelling sellWindow, + frmPerson personWindow, + frmPersonShareConnect personShareConnect, + frmBackup backupWindow + ) + { + InitializeComponent(); + _stockRepository = stockMemberRepository; + _stockMarketRepository = stockMarketRepository; + _personRepository = personRepository; + _addressRepository = addressRepository; + _stockPersonConnect = stockPersonConnect; + _backupRepository = backupRepository; + _backupRoutines = backupRoutines; + _personStockFacade = personStockFacade; + _regWindow = regWindow; + _stockWindow = stockWindow; + _sellWindow = sellWindow; + _personWindow = personWindow; + _personShareConnect = personShareConnect; + _backupWindow = backupWindow; + } + + private void Form1_Load(object sender, EventArgs e) + { + ReloadData(); + btnRestoreShares.Enabled = false; + btnBackupShares.Enabled = false; + btnReloadShares.Enabled = false; + btnBackupAll.Enabled = false; + } + + private void ReloadData() + { + var allStocks = _stockRepository.GetAllStocks(); + dataGridView.DataSource = allStocks; + // SaveStocks(allStocks); + lblTotalRecords.Text = $"Total records: {dataGridView.RowCount}"; + } + + + private void btnReload_Click(object sender, EventArgs e) + { + ReloadData(); + } + + private void btnTestScrapFunction_Click(object sender, EventArgs e) + { + _stockMarketRepository.LoadStockMarketList(chbShowBrowser.Checked); + var stocklist = _stockMarketRepository.StockMarketList; + lblStockRows.Text = stocklist.Count().ToString(); + btnReloadShares.Enabled = true; + } + + private void frmInitial_FormClosing(object sender, FormClosingEventArgs e) + { + _stockMarketRepository.Clean(); + } + + + + private void Button1reload() + { + lblStockRows.Text = ""; + _stockMarketRepository.RefreshMarketList(); + var stocklist = _stockMarketRepository.StockMarketList; + lblStockRows.Text = stocklist.Count().ToString(); + } + + private void btnStockReg_Click(object sender, EventArgs e) + { + Cursor.Current = Cursors.WaitCursor; + _stockMarketRepository.LoadStockMarketList(); + _regWindow.Stocks = _stockMarketRepository.StockMarketList; + Cursor.Current = DefaultCursor; + _regWindow.ShowDialog(); + + _stockRepository.InsertMany(_regWindow.RegisteredStocks); + + ReloadData(); + } + + private void btnValueView_Click(object sender, EventArgs e) + { + if (SelectedPersonId == 0) + { + MessageBox.Show($"Ingen person vald ({SelectedPersonId})"); + } + else + { + var person = _personRepository.GetPersonById(SelectedPersonId); + Cursor.Current = Cursors.WaitCursor; + _stockMarketRepository.LoadStockMarketList(); + _stockWindow.ConnectedPerson = person; + _stockWindow.Stocks = _stockMarketRepository.StockMarketList; + Cursor.Current = DefaultCursor; + _stockWindow.ShowDialog(); + } + } + + + + private void chkEnableBackRes_CheckedChanged(object sender, EventArgs e) + { + if (chkEnableBackRes.Checked) + { + btnRestoreShares.Enabled = true; + btnBackupShares.Enabled = true; + btnBackupAll.Enabled = true; + } + else + { + btnRestoreShares.Enabled = false; + btnBackupShares.Enabled = false; + btnBackupAll.Enabled = false; + } + } + + private void btnBackupShares_Click(object sender, EventArgs e) + { + var stockList = _stockRepository.GetAllStocks(); + var jsonStr = JsonSerializer.Serialize(stockList); + sfdSaver.Title = "Backup your sharedata"; + sfdSaver.Filter = "Backup file (.json)|*.json"; + sfdSaver.FileName = $"StockBackup{DateTime.Now.ToFileTime()}"; + + if (sfdSaver.ShowDialog() == DialogResult.OK) + { + File.WriteAllText(sfdSaver.FileName, jsonStr); + } + } + + private void btnRestoreShares_Click(object sender, EventArgs e) + { + ofdOpener.Title = "Restore your share data"; + ofdOpener.Filter = "Restore file (.json)|*.json"; + ofdOpener.CheckFileExists = true; + if (ofdOpener.ShowDialog() == DialogResult.OK) + { + var jsonStr = File.ReadAllText(ofdOpener.FileName); + var stockList = JsonSerializer.Deserialize>(jsonStr); + + _stockRepository.RestoreStockMembers(stockList); + }; + } + + private void btnReloadShares_Click(object sender, EventArgs e) + { + Button1reload(); + } + + private void btnStockSale_Click(object sender, EventArgs e) + { + _sellWindow.ShowDialog(); + ReloadData(); + } + private void btnEditPerson_Click(object sender, EventArgs e) + { + Cursor.Current = Cursors.WaitCursor; + _personWindow.PersonId = SelectedPersonId; + Cursor.Current = DefaultCursor; + _personWindow.ShowDialog(); + LoadCmbOwners(); + } + + private void btnConnShares_Click(object sender, EventArgs e) + { + if (SelectedPersonId == 0) + { + MessageBox.Show($"Ingen person vald ({SelectedPersonId})"); + } + else + { + var person = _personRepository.GetPersonById(SelectedPersonId); + Cursor.Current = Cursors.WaitCursor; + _personShareConnect.ConnectPerson = person; + Cursor.Current = DefaultCursor; + _personShareConnect.ShowDialog(); + } + } + + private void frmInitial_Shown(object sender, EventArgs e) + { + LoadCmbOwners(); + } + + private void LoadCmbOwners() + { + cmbOwners.Items.Clear(); + var owners = _personRepository.GetAllOwners(); + if (owners.Count() > 0) + { + foreach (var person in owners) + { + var itemIndex = cmbOwners.Items.Add(new ComboboxItem($"{person.FirstName} {person.LastName} ({person.NickName})", person.Id)); + } + } + cmbOwners.Items.Add(new ComboboxItem($"< ny person> ", 0)); + } + + private void cmbOwners_SelectedIndexChanged(object sender, EventArgs e) + { + SelectedPersonId = ((ComboboxItem)cmbOwners.SelectedItem).HiddenValue; + } + + private void btnBackupAll_Click(object sender, EventArgs e) + { + // backupWindow = new frmBackup(_backupRepository, _backupRoutines); + _backupWindow.ShowDialog(); + } + } +} diff --git a/StockInfoCore/frmInitial.resx b/StockInfoCore/frmInitial.resx new file mode 100644 index 0000000..a28f390 --- /dev/null +++ b/StockInfoCore/frmInitial.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 27 + + \ No newline at end of file diff --git a/StockInfoCore/frmMyStocks.Designer.cs b/StockInfoCore/frmMyStocks.Designer.cs new file mode 100644 index 0000000..f8464ea --- /dev/null +++ b/StockInfoCore/frmMyStocks.Designer.cs @@ -0,0 +1,389 @@ + +namespace StockInfoCore +{ + partial class frmMyStocks + { + /// + /// 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() + { + this.components = new System.ComponentModel.Container(); + this.lvMyStocks = new System.Windows.Forms.ListView(); + this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader2 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader7 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader11 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader3 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader4 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader5 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader6 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader8 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader9 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader10 = new System.Windows.Forms.ColumnHeader(); + this.txtBuyTotal = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtTotDiff = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtCurrValue = new System.Windows.Forms.TextBox(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.chkAutoReload = new System.Windows.Forms.CheckBox(); + this.lbUpdateTimes = new System.Windows.Forms.ListBox(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.txtTotalMinus = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.txtTotalPlus = new System.Windows.Forms.TextBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.SuspendLayout(); + // + // lvMyStocks + // + this.lvMyStocks.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lvMyStocks.BackColor = System.Drawing.SystemColors.InactiveCaption; + this.lvMyStocks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1, + this.columnHeader2, + this.columnHeader7, + this.columnHeader11, + this.columnHeader3, + this.columnHeader4, + this.columnHeader5, + this.columnHeader6, + this.columnHeader8, + this.columnHeader9, + this.columnHeader10}); + this.lvMyStocks.GridLines = true; + this.lvMyStocks.HideSelection = false; + this.lvMyStocks.Location = new System.Drawing.Point(14, 43); + this.lvMyStocks.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.lvMyStocks.Name = "lvMyStocks"; + this.lvMyStocks.Size = new System.Drawing.Size(1191, 369); + this.lvMyStocks.TabIndex = 0; + this.lvMyStocks.UseCompatibleStateImageBehavior = false; + this.lvMyStocks.View = System.Windows.Forms.View.Details; + this.lvMyStocks.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.lvMyStocks_DrawColumnHeader); + // + // columnHeader1 + // + this.columnHeader1.Name = "columnHeader1"; + this.columnHeader1.Text = "Stock Name"; + this.columnHeader1.Width = 120; + // + // columnHeader2 + // + this.columnHeader2.Name = "columnHeader2"; + this.columnHeader2.Text = "Buy Price"; + this.columnHeader2.Width = 80; + // + // columnHeader7 + // + this.columnHeader7.Name = "columnHeader7"; + this.columnHeader7.Text = "Market price"; + this.columnHeader7.Width = 100; + // + // columnHeader11 + // + this.columnHeader11.Name = "columnHeader11"; + this.columnHeader11.Text = "Price Diff"; + this.columnHeader11.Width = 100; + // + // columnHeader3 + // + this.columnHeader3.Name = "columnHeader3"; + this.columnHeader3.Text = "Amount Stk"; + this.columnHeader3.Width = 100; + // + // columnHeader4 + // + this.columnHeader4.Name = "columnHeader4"; + this.columnHeader4.Text = "Buy Date"; + this.columnHeader4.Width = 100; + // + // columnHeader5 + // + this.columnHeader5.Name = "columnHeader5"; + this.columnHeader5.Text = "Value diff"; + this.columnHeader5.Width = 100; + // + // columnHeader6 + // + this.columnHeader6.Name = "columnHeader6"; + this.columnHeader6.Text = "Value diff %"; + this.columnHeader6.Width = 80; + // + // columnHeader8 + // + this.columnHeader8.Name = "columnHeader8"; + this.columnHeader8.Text = "Market Date"; + this.columnHeader8.Width = 100; + // + // columnHeader9 + // + this.columnHeader9.Name = "columnHeader9"; + this.columnHeader9.Text = "Current value"; + this.columnHeader9.Width = 80; + // + // columnHeader10 + // + this.columnHeader10.Name = "columnHeader10"; + this.columnHeader10.Text = "Owned days"; + // + // txtBuyTotal + // + this.txtBuyTotal.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtBuyTotal.Location = new System.Drawing.Point(186, 428); + this.txtBuyTotal.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtBuyTotal.Name = "txtBuyTotal"; + this.txtBuyTotal.ReadOnly = true; + this.txtBuyTotal.Size = new System.Drawing.Size(114, 27); + this.txtBuyTotal.TabIndex = 1; + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label1.Location = new System.Drawing.Point(64, 425); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(101, 21); + this.label1.TabIndex = 2; + this.label1.Text = "Bought Totalt"; + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label2.Location = new System.Drawing.Point(338, 430); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(55, 21); + this.label2.TabIndex = 4; + this.label2.Text = "TotDiff"; + // + // txtTotDiff + // + this.txtTotDiff.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtTotDiff.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.txtTotDiff.Location = new System.Drawing.Point(439, 422); + this.txtTotDiff.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtTotDiff.Name = "txtTotDiff"; + this.txtTotDiff.ReadOnly = true; + this.txtTotDiff.Size = new System.Drawing.Size(114, 33); + this.txtTotDiff.TabIndex = 3; + // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label3.Location = new System.Drawing.Point(582, 425); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(105, 21); + this.label3.TabIndex = 6; + this.label3.Text = "Current Value"; + // + // txtCurrValue + // + this.txtCurrValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtCurrValue.Location = new System.Drawing.Point(709, 428); + this.txtCurrValue.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtCurrValue.Name = "txtCurrValue"; + this.txtCurrValue.ReadOnly = true; + this.txtCurrValue.Size = new System.Drawing.Size(114, 27); + this.txtCurrValue.TabIndex = 5; + // + // timer1 + // + this.timer1.Interval = 150000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // chkAutoReload + // + this.chkAutoReload.AutoSize = true; + this.chkAutoReload.Location = new System.Drawing.Point(15, 9); + this.chkAutoReload.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.chkAutoReload.Name = "chkAutoReload"; + this.chkAutoReload.Size = new System.Drawing.Size(148, 24); + this.chkAutoReload.TabIndex = 7; + this.chkAutoReload.Text = "Automatic Reload"; + this.chkAutoReload.UseVisualStyleBackColor = true; + this.chkAutoReload.CheckedChanged += new System.EventHandler(this.chkAutoReload_CheckedChanged); + // + // lbUpdateTimes + // + this.lbUpdateTimes.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lbUpdateTimes.FormattingEnabled = true; + this.lbUpdateTimes.ItemHeight = 20; + this.lbUpdateTimes.Location = new System.Drawing.Point(16, 500); + this.lbUpdateTimes.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.lbUpdateTimes.Name = "lbUpdateTimes"; + this.lbUpdateTimes.Size = new System.Drawing.Size(164, 124); + this.lbUpdateTimes.TabIndex = 8; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(14, 472); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(97, 20); + this.label4.TabIndex = 9; + this.label4.Text = "LatestUpdate"; + // + // numericUpDown1 + // + this.numericUpDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.numericUpDown1.Location = new System.Drawing.Point(186, 593); + this.numericUpDown1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(119, 27); + this.numericUpDown1.TabIndex = 10; + this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); + // + // label5 + // + this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(186, 569); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(132, 20); + this.label5.TabIndex = 11; + this.label5.Text = "Uppdatering (min)"; + // + // label6 + // + this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label6.Location = new System.Drawing.Point(208, 457); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(89, 21); + this.label6.TabIndex = 13; + this.label6.Text = "Total Minus"; + // + // txtTotalMinus + // + this.txtTotalMinus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtTotalMinus.BackColor = System.Drawing.Color.Pink; + this.txtTotalMinus.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.txtTotalMinus.Location = new System.Drawing.Point(312, 455); + this.txtTotalMinus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtTotalMinus.Name = "txtTotalMinus"; + this.txtTotalMinus.ReadOnly = true; + this.txtTotalMinus.Size = new System.Drawing.Size(114, 33); + this.txtTotalMinus.TabIndex = 12; + // + // label7 + // + this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label7.AutoSize = true; + this.label7.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.label7.Location = new System.Drawing.Point(478, 459); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(75, 21); + this.label7.TabIndex = 15; + this.label7.Text = "Total Plus"; + // + // txtTotalPlus + // + this.txtTotalPlus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.txtTotalPlus.BackColor = System.Drawing.Color.LightGreen; + this.txtTotalPlus.Font = new System.Drawing.Font("Segoe UI", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.txtTotalPlus.Location = new System.Drawing.Point(573, 455); + this.txtTotalPlus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.txtTotalPlus.Name = "txtTotalPlus"; + this.txtTotalPlus.ReadOnly = true; + this.txtTotalPlus.Size = new System.Drawing.Size(114, 33); + this.txtTotalPlus.TabIndex = 14; + // + // frmMyStocks + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1217, 651); + this.Controls.Add(this.label7); + this.Controls.Add(this.txtTotalPlus); + this.Controls.Add(this.label6); + this.Controls.Add(this.txtTotalMinus); + this.Controls.Add(this.label5); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.label4); + this.Controls.Add(this.lbUpdateTimes); + this.Controls.Add(this.chkAutoReload); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtCurrValue); + this.Controls.Add(this.label2); + this.Controls.Add(this.txtTotDiff); + this.Controls.Add(this.label1); + this.Controls.Add(this.txtBuyTotal); + this.Controls.Add(this.lvMyStocks); + this.Font = new System.Drawing.Font("Segoe UI", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.Name = "frmMyStocks"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmMyStocks"; + this.Shown += new System.EventHandler(this.frmMyStocks_Shown); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListView lvMyStocks; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.ColumnHeader columnHeader2; + private System.Windows.Forms.ColumnHeader columnHeader3; + private System.Windows.Forms.ColumnHeader columnHeader4; + private System.Windows.Forms.ColumnHeader columnHeader5; + private System.Windows.Forms.ColumnHeader columnHeader6; + private System.Windows.Forms.ColumnHeader columnHeader7; + private System.Windows.Forms.ColumnHeader columnHeader8; + private System.Windows.Forms.ColumnHeader columnHeader9; + private System.Windows.Forms.ColumnHeader columnHeader10; + private System.Windows.Forms.TextBox txtBuyTotal; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtTotDiff; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtCurrValue; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.CheckBox chkAutoReload; + private System.Windows.Forms.ListBox lbUpdateTimes; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ColumnHeader columnHeader11; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtTotalMinus; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox txtTotalPlus; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmMyStocks.cs b/StockInfoCore/frmMyStocks.cs new file mode 100644 index 0000000..b0dbe81 --- /dev/null +++ b/StockInfoCore/frmMyStocks.cs @@ -0,0 +1,178 @@ +using StockDal.Interface; +using DataDomain; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using StockDAL.Interface; +// +namespace StockInfoCore +{ + public partial class frmMyStocks : Form + { + Color hdrColor; + private readonly IStockRepository _stockRepository; + private readonly IStockMarketRepository _stockMarketRepository; + private readonly IStockPersonConnect _stockPersonConnect; + + public decimal BoughtSum { get; set; } + public decimal TotalDiff { get; set; } + public decimal CurrentSum { get; set; } + public decimal TotalPlus { get; set; } + public decimal TotalMinus { get; set; } + + public Dictionary Stocks { get; set; } + public IEnumerable CurrentStocks { get; set; } + public Person ConnectedPerson { get; set; } + + public frmMyStocks(IStockRepository stockRepository, + IStockMarketRepository stockMarketRepository, + IStockPersonConnect stockPersonConnect) + { + hdrColor = Color.CadetBlue; + InitializeComponent(); + _stockRepository = stockRepository; + _stockMarketRepository = stockMarketRepository; + _stockPersonConnect = stockPersonConnect; + numericUpDown1.Value = timer1.Interval / 60000; + numericUpDown1.Enabled = false; + } + + + private void ReloadData() + { + CurrentStocks = _stockRepository.GetAllRemainingStocks(); + lvMyStocks.Items.Clear(); + BoughtSum = 0m; + TotalDiff = 0m; + CurrentSum = 0m; + TotalMinus = 0m; + TotalPlus = 0m; + var tmpStocks = new List(); + var personStocks = new List(); + //Update all handled shares + foreach (var stock in CurrentStocks) + { + stock.ActValue = Stocks[stock.StockId.Trim()].LatestPrice; + stock.ActDate = DateTime.Today; + _stockRepository.UpdateActualPrice(stock.Id, stock.ActValue); + tmpStocks.Add(stock); + } + //Use only Stocks belonging to person + var connects =_stockPersonConnect.GetAllConnectionsByPersId(ConnectedPerson.Id); + personStocks.AddRange(tmpStocks.Where(ts => connects.Any(c => c.StockId == ts.Id)).ToList()); + foreach(var stk in personStocks.OrderByDescending(s => s.ActAmount * (s.ActValue -s.BuyValue))) + { + AddItemToListView(stk); + } + + txtBuyTotal.Text = BoughtSum.ToString(); + txtBuyTotal.Refresh(); + txtCurrValue.Text = CurrentSum.ToString(); + txtCurrValue.Refresh(); + txtTotDiff.Text = TotalDiff.ToString(); + if (TotalDiff < 0) + { + txtTotDiff.BackColor = Color.Pink; + } + else + { + txtTotDiff.BackColor = Color.LightGreen; + } + txtTotDiff.Refresh(); + txtTotalMinus.Text = TotalMinus.ToString(); + txtTotalMinus.Refresh(); + txtTotalPlus.Text = TotalPlus.ToString(); + txtTotalPlus.Refresh(); + + + } + + private void TotalReload() + { + _stockMarketRepository.LoadStockMarketList(); + Stocks = _stockMarketRepository.StockMarketList; + ReloadData(); + lbUpdateTimes.Items.Add($"{DateTime.Now.ToLongTimeString()} - {txtTotDiff.Text.Substring(0, txtTotDiff.Text.Length-2)}"); + } + + private void lvMyStocks_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) + { + using (Brush hBr = new SolidBrush(hdrColor)) + { + e.Graphics.FillRectangle(hBr, e.Bounds); + e.DrawText(); + } + } + + private void AddItemToListView(StockMember currStock) + { + var lv = lvMyStocks.Items.Add(currStock.StockId); + lv.SubItems.Add(currStock.BuyValue.ToString()); + var currValue = lv.SubItems.Add(currStock.ActValue.ToString()); + //var saveBcolor = currValue.BackColor; + //var valueLevel = currStock.ActValue - currStock.BuyValue; + //currValue.ForeColor = valueLevel > 5 ? Color.Red : saveBcolor; + var priceDiff = currStock.ActValue - currStock.BuyValue; + lv.SubItems.Add(priceDiff.ToString()); + lv.SubItems.Add(currStock.ActAmount.ToString()); + lv.SubItems.Add(currStock.BuyDate.ToString()); + var buyValue = currStock.PostAmount * currStock.BuyValue; + var actValue = currStock.PostAmount * currStock.ActValue; + var diffValue = actValue - buyValue; + var diffproc = diffValue / buyValue * 100; + BoughtSum += buyValue; + TotalDiff += diffValue; + CurrentSum += actValue; + if (diffValue < 0) + { + TotalMinus += diffValue; + } + else + { + TotalPlus += diffValue; + } + var lvs = lv.SubItems.Add(diffValue.ToString()); + lv.SubItems.Add(Math.Round(diffproc, 2).ToString()); + lv.SubItems.Add(currStock.ActDate.ToString()); + lv.SubItems.Add(actValue.ToString()); + var owned = (DateTime.Today - currStock.BuyDate).TotalDays; + lv.SubItems.Add(owned.ToString()); + if (diffValue < 0) + { + lv.BackColor = Color.Pink; + } + else + { + lv.BackColor = Color.LightGreen; + } + } + + private void frmMyStocks_Shown(object sender, EventArgs e) + { + this.Text = $"{ConnectedPerson.Id} - {ConnectedPerson.FirstName} {ConnectedPerson.LastName}'s Shares"; + ReloadData(); + } + + private void timer1_Tick(object sender, EventArgs e) + { + TotalReload(); + } + + private void chkAutoReload_CheckedChanged(object sender, EventArgs e) + { + timer1.Enabled = chkAutoReload.Checked; + numericUpDown1.Enabled = chkAutoReload.Checked; + } + + private void numericUpDown1_ValueChanged(object sender, EventArgs e) + { + timer1.Interval = Convert.ToInt32(numericUpDown1.Value * 60000); + } + } +} diff --git a/StockInfoCore/frmMyStocks.resx b/StockInfoCore/frmMyStocks.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmMyStocks.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StockInfoCore/frmPerson.Designer.cs b/StockInfoCore/frmPerson.Designer.cs new file mode 100644 index 0000000..1a5801f --- /dev/null +++ b/StockInfoCore/frmPerson.Designer.cs @@ -0,0 +1,362 @@ + +namespace StockInfoCore +{ + partial class frmPerson + { + /// + /// 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() + { + this.label1 = new System.Windows.Forms.Label(); + this.txtFirstName = new System.Windows.Forms.TextBox(); + this.txtComment = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtPersonNr = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtNickName = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtLastName = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.gbAddress = new System.Windows.Forms.GroupBox(); + this.txtDestination = new System.Windows.Forms.TextBox(); + this.txtNation = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.txtZipCode = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.txtStreet2 = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.txtStreet = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.rdbInvoiceAddr = new System.Windows.Forms.RadioButton(); + this.rdbHome = new System.Windows.Forms.RadioButton(); + this.txtClearingNo = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.txtAccountNr = new System.Windows.Forms.TextBox(); + this.btnAddSave = new System.Windows.Forms.Button(); + this.btnClose = new System.Windows.Forms.Button(); + this.gbAddress.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 49); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 15); + this.label1.TabIndex = 0; + this.label1.Text = "First Name"; + // + // txtFirstName + // + this.txtFirstName.Location = new System.Drawing.Point(113, 46); + this.txtFirstName.Name = "txtFirstName"; + this.txtFirstName.Size = new System.Drawing.Size(188, 23); + this.txtFirstName.TabIndex = 1; + // + // txtComment + // + this.txtComment.Location = new System.Drawing.Point(113, 162); + this.txtComment.Name = "txtComment"; + this.txtComment.Size = new System.Drawing.Size(188, 23); + this.txtComment.TabIndex = 5; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 165); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(61, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Comment"; + // + // txtPersonNr + // + this.txtPersonNr.Location = new System.Drawing.Point(113, 133); + this.txtPersonNr.Name = "txtPersonNr"; + this.txtPersonNr.Size = new System.Drawing.Size(188, 23); + this.txtPersonNr.TabIndex = 4; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(13, 136); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(56, 15); + this.label3.TabIndex = 4; + this.label3.Text = "PersonNr"; + // + // txtNickName + // + this.txtNickName.Location = new System.Drawing.Point(113, 104); + this.txtNickName.Name = "txtNickName"; + this.txtNickName.Size = new System.Drawing.Size(188, 23); + this.txtNickName.TabIndex = 3; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(13, 104); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(63, 15); + this.label4.TabIndex = 6; + this.label4.Text = "NickName"; + // + // txtLastName + // + this.txtLastName.Location = new System.Drawing.Point(113, 75); + this.txtLastName.Name = "txtLastName"; + this.txtLastName.Size = new System.Drawing.Size(188, 23); + this.txtLastName.TabIndex = 2; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(13, 78); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(63, 15); + this.label5.TabIndex = 8; + this.label5.Text = "Last Name"; + // + // gbAddress + // + this.gbAddress.Controls.Add(this.txtDestination); + this.gbAddress.Controls.Add(this.txtNation); + this.gbAddress.Controls.Add(this.label10); + this.gbAddress.Controls.Add(this.txtZipCode); + this.gbAddress.Controls.Add(this.label9); + this.gbAddress.Controls.Add(this.txtStreet2); + this.gbAddress.Controls.Add(this.label8); + this.gbAddress.Controls.Add(this.txtStreet); + this.gbAddress.Controls.Add(this.label7); + this.gbAddress.Controls.Add(this.rdbInvoiceAddr); + this.gbAddress.Controls.Add(this.rdbHome); + this.gbAddress.Location = new System.Drawing.Point(13, 221); + this.gbAddress.Name = "gbAddress"; + this.gbAddress.Size = new System.Drawing.Size(300, 177); + this.gbAddress.TabIndex = 10; + this.gbAddress.TabStop = false; + this.gbAddress.Text = "Addresses"; + // + // txtDestination + // + this.txtDestination.Location = new System.Drawing.Point(148, 106); + this.txtDestination.Name = "txtDestination"; + this.txtDestination.Size = new System.Drawing.Size(146, 23); + this.txtDestination.TabIndex = 12; + // + // txtNation + // + this.txtNation.Location = new System.Drawing.Point(84, 135); + this.txtNation.Name = "txtNation"; + this.txtNation.Size = new System.Drawing.Size(210, 23); + this.txtNation.TabIndex = 13; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(6, 138); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(43, 15); + this.label10.TabIndex = 8; + this.label10.Text = "Nation"; + // + // txtZipCode + // + this.txtZipCode.Location = new System.Drawing.Point(84, 106); + this.txtZipCode.Name = "txtZipCode"; + this.txtZipCode.Size = new System.Drawing.Size(58, 23); + this.txtZipCode.TabIndex = 11; + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(6, 109); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(58, 15); + this.label9.TabIndex = 6; + this.label9.Text = "Zip / Dest"; + // + // txtStreet2 + // + this.txtStreet2.Location = new System.Drawing.Point(84, 77); + this.txtStreet2.Name = "txtStreet2"; + this.txtStreet2.Size = new System.Drawing.Size(210, 23); + this.txtStreet2.TabIndex = 10; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(6, 80); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(46, 15); + this.label8.TabIndex = 4; + this.label8.Text = "Street 2"; + // + // txtStreet + // + this.txtStreet.Location = new System.Drawing.Point(84, 48); + this.txtStreet.Name = "txtStreet"; + this.txtStreet.Size = new System.Drawing.Size(210, 23); + this.txtStreet.TabIndex = 9; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(6, 51); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(37, 15); + this.label7.TabIndex = 2; + this.label7.Text = "Street"; + // + // rdbInvoiceAddr + // + this.rdbInvoiceAddr.AutoSize = true; + this.rdbInvoiceAddr.Location = new System.Drawing.Point(116, 23); + this.rdbInvoiceAddr.Name = "rdbInvoiceAddr"; + this.rdbInvoiceAddr.Size = new System.Drawing.Size(108, 19); + this.rdbInvoiceAddr.TabIndex = 1; + this.rdbInvoiceAddr.Text = "Invoice Address"; + this.rdbInvoiceAddr.UseVisualStyleBackColor = true; + this.rdbInvoiceAddr.CheckedChanged += new System.EventHandler(this.rdbInvoiceAddr_CheckedChanged); + // + // rdbHome + // + this.rdbHome.AutoSize = true; + this.rdbHome.Checked = true; + this.rdbHome.Location = new System.Drawing.Point(7, 23); + this.rdbHome.Name = "rdbHome"; + this.rdbHome.Size = new System.Drawing.Size(103, 19); + this.rdbHome.TabIndex = 8; + this.rdbHome.TabStop = true; + this.rdbHome.Text = "Home Address"; + this.rdbHome.UseVisualStyleBackColor = true; + this.rdbHome.CheckedChanged += new System.EventHandler(this.rdbInvoiceAddr_CheckedChanged); + // + // txtClearingNo + // + this.txtClearingNo.Location = new System.Drawing.Point(113, 191); + this.txtClearingNo.Name = "txtClearingNo"; + this.txtClearingNo.Size = new System.Drawing.Size(42, 23); + this.txtClearingNo.TabIndex = 6; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(13, 194); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(52, 15); + this.label6.TabIndex = 11; + this.label6.Text = "Account"; + // + // txtAccountNr + // + this.txtAccountNr.Location = new System.Drawing.Point(161, 191); + this.txtAccountNr.Name = "txtAccountNr"; + this.txtAccountNr.Size = new System.Drawing.Size(152, 23); + this.txtAccountNr.TabIndex = 7; + // + // btnAddSave + // + this.btnAddSave.Location = new System.Drawing.Point(319, 355); + this.btnAddSave.Name = "btnAddSave"; + this.btnAddSave.Size = new System.Drawing.Size(107, 23); + this.btnAddSave.TabIndex = 14; + this.btnAddSave.Text = "Add/Save Owner"; + this.btnAddSave.UseVisualStyleBackColor = true; + this.btnAddSave.Click += new System.EventHandler(this.btnAddSave_Click); + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(432, 355); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 15; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // frmPerson + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(534, 419); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.btnAddSave); + this.Controls.Add(this.txtAccountNr); + this.Controls.Add(this.txtClearingNo); + this.Controls.Add(this.label6); + this.Controls.Add(this.gbAddress); + this.Controls.Add(this.txtLastName); + this.Controls.Add(this.label5); + this.Controls.Add(this.txtNickName); + this.Controls.Add(this.label4); + this.Controls.Add(this.txtPersonNr); + this.Controls.Add(this.label3); + this.Controls.Add(this.txtComment); + this.Controls.Add(this.label2); + this.Controls.Add(this.txtFirstName); + this.Controls.Add(this.label1); + this.Name = "frmPerson"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmPerson"; + this.Load += new System.EventHandler(this.frmPerson_Load); + this.gbAddress.ResumeLayout(false); + this.gbAddress.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtFirstName; + private System.Windows.Forms.TextBox txtComment; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtPersonNr; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtNickName; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox txtLastName; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.GroupBox gbAddress; + private System.Windows.Forms.RadioButton rdbInvoiceAddr; + private System.Windows.Forms.RadioButton rdbHome; + private System.Windows.Forms.TextBox txtClearingNo; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtAccountNr; + private System.Windows.Forms.TextBox txtNation; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.TextBox txtZipCode; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txtStreet2; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox txtStreet; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Button btnAddSave; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.TextBox txtDestination; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmPerson.cs b/StockInfoCore/frmPerson.cs new file mode 100644 index 0000000..b541233 --- /dev/null +++ b/StockInfoCore/frmPerson.cs @@ -0,0 +1,214 @@ +using DataDomain; +using Helpers; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfoCore +{ + public partial class frmPerson : Form + { + private readonly IPersonRepository _personRepository; + private readonly IAddressRepository _addressRepository; + private bool radioOk = false; + + public frmPerson(IPersonRepository personRepository, IAddressRepository addressRepository) + { + InitializeComponent(); + _personRepository = personRepository; + _addressRepository = addressRepository; + } + + public int PersonId { get; set; } + public int HomeAddressId { get; set; } + public int CheckHomeAddressId { get; set; } + public int InvoiceAddressId { get; set; } + public int CheckInvoiceAddressId { get; set; } + + + private void btnAddSave_Click(object sender, EventArgs e) + { + + (Person person, bool OK) = validatePerson(); + if (OK) + { + person = _personRepository.SavePerson(person); + initializeAllFields(); + PersonId = 0; + } + else + { + + } + + } + + private (Person person, bool OK) validatePerson() + { + var person = new Person(); + person.Id = PersonId; + person.FirstName = txtFirstName.Text; + person.LastName = txtLastName.Text; + person.NickName = txtNickName.Text; + person.ClearingNo = txtClearingNo.Text.IsNumeric()?int.Parse(txtClearingNo.Text):0; + person.AccountNo = txtAccountNr.Text.IsNumeric() ? int.Parse(txtAccountNr.Text) : 0; + person.Born = txtPersonNr.Text; + person.Comments = txtComment.Text; + if (rdbHome.Checked) + { + HomeAddressId = AddressSave(HomeAddressId); + } + else + { + InvoiceAddressId = AddressSave(InvoiceAddressId); + } + person.HomeAddress = HomeAddressId; + CheckHomeAddressId = HomeAddressId; + person.InvoiceAddress = InvoiceAddressId; + CheckInvoiceAddressId = InvoiceAddressId; + return (person, true); + } + + private int AddressSave(int AddressId) + { + var retval = 0; + bool changed = false; + Address address = new Address(); + (address.Id, changed) = checkInt(AddressId.ToString()); + (address.Street, changed) = checkString(txtStreet.Text); + (address.Street2, changed) = checkString(txtStreet2.Text); + (address.Zipcode, changed) = checkInt(txtZipCode.Text); + (address.Destination, changed) = checkString(txtDestination.Text); + (address.Nation, changed) = checkString(txtNation.Text); + if (changed) + { + retval =_addressRepository.SaveAddress(address).Id; + } + return retval; + } + + private (string, bool ) checkString(string text) + { + bool chgd = !string.IsNullOrWhiteSpace(text); + return (text, chgd); + } + private (int, bool) checkInt(string text) + { + bool chgd = false; + if(!string.IsNullOrWhiteSpace(text)) + { + chgd = int.Parse(text) > 0; + } + return (chgd?int.Parse(text):0, chgd); + } + + private void frmPerson_Load(object sender, EventArgs e) + { + var person = _personRepository.GetPersonById(PersonId); + initializeAllFields(); + if (person != null) + { + HomeAddressId = person.HomeAddress; + CheckHomeAddressId = person.HomeAddress; + InvoiceAddressId = person.InvoiceAddress; + CheckInvoiceAddressId = person.InvoiceAddress; + fillFieldsFromPerson(person); + } + } + + private void fillFieldsFromPerson(Person person) + { + txtFirstName.Text = person.FirstName; + txtLastName.Text = person.LastName; + txtNickName.Text = person.NickName; + txtPersonNr.Text = person.Born; + txtComment.Text = person.Comments; + txtClearingNo.Text = person.ClearingNo.ToString(); + txtAccountNr.Text = person.AccountNo.ToString(); + ShowAddressFrom(HomeAddressId); + } + + private void ShowAddressFrom(int AddrId) + { + var address = _addressRepository.GetAddressById(AddrId); + if (address != null) + { + txtStreet.Text = address.Street; + txtStreet2.Text = address.Street2; + txtZipCode.Text = address.Zipcode.ToString(); + txtDestination.Text = address.Destination; + txtNation.Text = address.Nation; + } + } + + private void initializeAllFields() + { + txtFirstName.Text = ""; + txtLastName.Text = ""; + txtNickName.Text = ""; + txtPersonNr.Text = ""; + txtComment.Text = ""; + txtClearingNo.Text = ""; + txtAccountNr.Text = ""; + ClearAddress(); + HomeAddressId = 0; + InvoiceAddressId = 0; + CheckHomeAddressId = 0; + CheckInvoiceAddressId = 0; + rdbHome.Checked = true; + } + + private void ClearAddress() + { + txtStreet.Text = ""; + txtStreet2.Text = ""; + txtZipCode.Text = ""; + txtDestination.Text = ""; + txtNation.Text = ""; + } + + private void rdbInvoiceAddr_CheckedChanged(object sender, EventArgs e) + { + if (!radioOk) + { + if (rdbInvoiceAddr.Checked) + { + HomeAddressId = AddressSave(HomeAddressId); + ClearAddress(); + ShowAddressFrom(InvoiceAddressId); + radioOk = true; + } + else + { + InvoiceAddressId = AddressSave(InvoiceAddressId); + ClearAddress(); + ShowAddressFrom(HomeAddressId); + radioOk = true; + } + } + else + { + radioOk = false; + } + } + + private void btnClose_Click(object sender, EventArgs e) + { + if (HomeAddressId != CheckHomeAddressId || InvoiceAddressId != CheckInvoiceAddressId) + { + MessageBox.Show("NB Save info first to insure not losing addresses"); + } + else + { + this.Close(); + } + } + } +} diff --git a/StockInfoCore/frmPerson.resx b/StockInfoCore/frmPerson.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmPerson.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StockInfoCore/frmPersonShareConnect.Designer.cs b/StockInfoCore/frmPersonShareConnect.Designer.cs new file mode 100644 index 0000000..84ab6a9 --- /dev/null +++ b/StockInfoCore/frmPersonShareConnect.Designer.cs @@ -0,0 +1,139 @@ + +namespace StockInfoCore +{ + partial class frmPersonShareConnect + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPersonShareConnect)); + this.lstShares = new System.Windows.Forms.ListBox(); + this.lstPersConnected = new System.Windows.Forms.ListBox(); + this.btnDisconnect = new System.Windows.Forms.Button(); + this.lblShareHolder = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.btnConnect = new System.Windows.Forms.Button(); + this.btnClose = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // lstShares + // + this.lstShares.FormattingEnabled = true; + this.lstShares.ItemHeight = 15; + this.lstShares.Location = new System.Drawing.Point(35, 35); + this.lstShares.Name = "lstShares"; + this.lstShares.Size = new System.Drawing.Size(173, 349); + this.lstShares.TabIndex = 0; + // + // lstPersConnected + // + this.lstPersConnected.FormattingEnabled = true; + this.lstPersConnected.ItemHeight = 15; + this.lstPersConnected.Location = new System.Drawing.Point(270, 35); + this.lstPersConnected.Name = "lstPersConnected"; + this.lstPersConnected.Size = new System.Drawing.Size(173, 349); + this.lstPersConnected.TabIndex = 1; + // + // btnDisconnect + // + this.btnDisconnect.Image = ((System.Drawing.Image)(resources.GetObject("btnDisconnect.Image"))); + this.btnDisconnect.Location = new System.Drawing.Point(214, 202); + this.btnDisconnect.Name = "btnDisconnect"; + this.btnDisconnect.Size = new System.Drawing.Size(49, 23); + this.btnDisconnect.TabIndex = 2; + this.btnDisconnect.UseVisualStyleBackColor = true; + this.btnDisconnect.Click += new System.EventHandler(this.btnDisconnect_Click); + // + // lblShareHolder + // + this.lblShareHolder.AutoSize = true; + this.lblShareHolder.Location = new System.Drawing.Point(270, 12); + this.lblShareHolder.Name = "lblShareHolder"; + this.lblShareHolder.Size = new System.Drawing.Size(80, 15); + this.lblShareHolder.TabIndex = 3; + this.lblShareHolder.Text = "[share holder]"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(35, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(102, 15); + this.label1.TabIndex = 4; + this.label1.Text = "Uncoupled Shares"; + // + // btnConnect + // + this.btnConnect.Image = ((System.Drawing.Image)(resources.GetObject("btnConnect.Image"))); + this.btnConnect.Location = new System.Drawing.Point(215, 173); + this.btnConnect.Name = "btnConnect"; + this.btnConnect.Size = new System.Drawing.Size(49, 23); + this.btnConnect.TabIndex = 5; + this.btnConnect.UseVisualStyleBackColor = true; + this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click); + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(422, 415); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 6; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // frmPersonShareConnect + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(509, 450); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.btnConnect); + this.Controls.Add(this.label1); + this.Controls.Add(this.lblShareHolder); + this.Controls.Add(this.btnDisconnect); + this.Controls.Add(this.lstPersConnected); + this.Controls.Add(this.lstShares); + this.Name = "frmPersonShareConnect"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmPersonShareConnect"; + this.Shown += new System.EventHandler(this.frmPersonShareConnect_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ListBox lstShares; + private System.Windows.Forms.ListBox lstPersConnected; + private System.Windows.Forms.Button btnDisconnect; + private System.Windows.Forms.Label lblShareHolder; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button btnConnect; + private System.Windows.Forms.Button btnClose; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmPersonShareConnect.cs b/StockInfoCore/frmPersonShareConnect.cs new file mode 100644 index 0000000..58bd735 --- /dev/null +++ b/StockInfoCore/frmPersonShareConnect.cs @@ -0,0 +1,89 @@ +using DataDomain; +using StockBL.Interface; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfoCore +{ + public partial class frmPersonShareConnect : Form + { + private readonly IPersonStockFacade _personStockFacade; + private readonly IStockPersonConnect _stockPersonConnect; + private readonly IStockRepository _stockRepository; + + public Person ConnectPerson { get; set; } + public frmPersonShareConnect(IPersonStockFacade personStockFacade, IStockPersonConnect stockPersonConnect,IStockRepository stockRepository) + { + InitializeComponent(); + _personStockFacade = personStockFacade; + _stockPersonConnect = stockPersonConnect; + _stockRepository = stockRepository; + } + + private void frmPersonShareConnect_Shown(object sender, EventArgs e) + { + this.Text = $"{ConnectPerson.Id} - {ConnectPerson.FirstName} {ConnectPerson.LastName}'s Shares"; + this.lblShareHolder.Text = $"{ConnectPerson.FirstName} {ConnectPerson.LastName}'s Shares"; + RefreshShareList(); + RefreshConnectedList(); + } + + private void RefreshShareList() + { + var dataSource = _personStockFacade.GetUnconnectedShares(); + lstShares.DataSource = dataSource; + lstShares.DisplayMember = "StockId"; + lstShares.ValueMember = "Id"; + lstShares.Refresh(); + } + + private void RefreshConnectedList() + { + var dataSource = _personStockFacade.GetAllSharesConnectedTo(ConnectPerson.Id); + lstPersConnected.DataSource = dataSource; + lstPersConnected.DisplayMember = "StockId"; + lstPersConnected.ValueMember = "Id"; + lstPersConnected.Refresh(); + } + + + private void btnConnect_Click(object sender, EventArgs e) + { + if (lstShares.SelectedIndex != -1) + { + PersonStock ps = new PersonStock(); + ps.PersonId = ConnectPerson.Id; + ps.StockId = int.Parse(lstShares.SelectedValue.ToString()); + _stockPersonConnect.SavePersonStockConnection(ps); + RefreshShareList(); + RefreshConnectedList(); + } + } + + private void btnDisconnect_Click(object sender, EventArgs e) + { + if (lstPersConnected.SelectedIndex != -1) + { + PersonStock ps = new PersonStock(); + ps.PersonId = ConnectPerson.Id; + ps.StockId = int.Parse(lstPersConnected.SelectedValue.ToString()); + _stockPersonConnect.RemoveConnectedShare(ps); + RefreshShareList(); + RefreshConnectedList(); + } + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/StockInfoCore/frmPersonShareConnect.resx b/StockInfoCore/frmPersonShareConnect.resx new file mode 100644 index 0000000..dd3e491 --- /dev/null +++ b/StockInfoCore/frmPersonShareConnect.resx @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vwAADr8BOAVTJAAAAKJJREFUOE9jQAffvn3jA+J7QPwfiKGiJACgpiWrV68GaSbdAKCGqBs3bvz38PAg + 3QCgYoWPQJCUlPTfyckJZgBBDNPMDMRHJ06cCNaMjkEKcbFhBtQfOXIELoGO8RoAJKyeP3/+Jzg4GC6B + jgkZcK+iogIuiA3T3ADKvEBxIEINoCwaQQDIIT8hwQBQACMpE8IYACiIkpkIYQwAFCQhOzMwAABkGA25 + 6rPaRQAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vwAADr8BOAVTJAAAAKZJREFUOE9jIAZ8+/btPxDfA2I+qBBpAGTA2rVrQYYsgQqRBkAGeHh4/L958ybI + kCioMASAJInBTk5O/1NSUv5/BAIgXwGqHWIASBKEcbGR8eTJk0FyR4GYmSwDQPjo0aMg+XqyDQgJCfn/ + 4sWLP0A1VmQZAMKVlZUgNfcGxgCKvUBRIGKNRmIwSDPWhPT//3+QIYQw7qQMAmiKsWHKMxMQY8nODAwA + Xb3/nf2Zot8AAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/StockInfoCore/frmRegisterStock.Designer.cs b/StockInfoCore/frmRegisterStock.Designer.cs new file mode 100644 index 0000000..58d306e --- /dev/null +++ b/StockInfoCore/frmRegisterStock.Designer.cs @@ -0,0 +1,377 @@ + +namespace StockInfoCore +{ + partial class frmRegisterStock + { + /// + /// 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() + { + this.cmbStockChoser = new System.Windows.Forms.ComboBox(); + this.btnClose = new System.Windows.Forms.Button(); + this.lblStockExtId = new System.Windows.Forms.Label(); + this.txtStockExtId = new System.Windows.Forms.TextBox(); + this.txtBuyPrice = new System.Windows.Forms.TextBox(); + this.lblBuyPrice = new System.Windows.Forms.Label(); + this.txtBuyDate = new System.Windows.Forms.TextBox(); + this.lblBuyDate = new System.Windows.Forms.Label(); + this.txtBoughtAmount = new System.Windows.Forms.TextBox(); + this.lblBoughtAmount = new System.Windows.Forms.Label(); + this.txtActValue = new System.Windows.Forms.TextBox(); + this.lblActValue = new System.Windows.Forms.Label(); + this.txtActDate = new System.Windows.Forms.TextBox(); + this.lblActDate = new System.Windows.Forms.Label(); + this.txtActAmount = new System.Windows.Forms.TextBox(); + this.lblRemaining = new System.Windows.Forms.Label(); + this.txtSoldPrice = new System.Windows.Forms.TextBox(); + this.lblSoldValue = new System.Windows.Forms.Label(); + this.txtSoldDate = new System.Windows.Forms.TextBox(); + this.lblSoldDate = new System.Windows.Forms.Label(); + this.txtComment = new System.Windows.Forms.TextBox(); + this.lblComment = new System.Windows.Forms.Label(); + this.btnSaveStock = new System.Windows.Forms.Button(); + this.lwRegBuffer = new System.Windows.Forms.ListView(); + this.Stock = new System.Windows.Forms.ColumnHeader(); + this.Price = new System.Windows.Forms.ColumnHeader(); + this.Number = new System.Windows.Forms.ColumnHeader(); + this.Comment = new System.Windows.Forms.ColumnHeader(); + this.btnSaveToDB = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // cmbStockChoser + // + this.cmbStockChoser.FormattingEnabled = true; + this.cmbStockChoser.Location = new System.Drawing.Point(38, 39); + this.cmbStockChoser.Name = "cmbStockChoser"; + this.cmbStockChoser.Size = new System.Drawing.Size(179, 23); + this.cmbStockChoser.TabIndex = 0; + this.cmbStockChoser.SelectedIndexChanged += new System.EventHandler(this.cmbStockChoser_SelectedIndexChanged); + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(347, 567); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 1; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // lblStockExtId + // + this.lblStockExtId.AutoSize = true; + this.lblStockExtId.Location = new System.Drawing.Point(38, 78); + this.lblStockExtId.Name = "lblStockExtId"; + this.lblStockExtId.Size = new System.Drawing.Size(62, 15); + this.lblStockExtId.TabIndex = 2; + this.lblStockExtId.Text = "StockExtId"; + // + // txtStockExtId + // + this.txtStockExtId.Location = new System.Drawing.Point(153, 75); + this.txtStockExtId.Name = "txtStockExtId"; + this.txtStockExtId.Size = new System.Drawing.Size(269, 23); + this.txtStockExtId.TabIndex = 3; + // + // txtBuyPrice + // + this.txtBuyPrice.Location = new System.Drawing.Point(153, 104); + this.txtBuyPrice.Name = "txtBuyPrice"; + this.txtBuyPrice.Size = new System.Drawing.Size(111, 23); + this.txtBuyPrice.TabIndex = 5; + // + // lblBuyPrice + // + this.lblBuyPrice.AutoSize = true; + this.lblBuyPrice.Location = new System.Drawing.Point(38, 107); + this.lblBuyPrice.Name = "lblBuyPrice"; + this.lblBuyPrice.Size = new System.Drawing.Size(56, 15); + this.lblBuyPrice.TabIndex = 4; + this.lblBuyPrice.Text = "Buy price"; + // + // txtBuyDate + // + this.txtBuyDate.Location = new System.Drawing.Point(153, 133); + this.txtBuyDate.Name = "txtBuyDate"; + this.txtBuyDate.Size = new System.Drawing.Size(142, 23); + this.txtBuyDate.TabIndex = 7; + // + // lblBuyDate + // + this.lblBuyDate.AutoSize = true; + this.lblBuyDate.Location = new System.Drawing.Point(38, 136); + this.lblBuyDate.Name = "lblBuyDate"; + this.lblBuyDate.Size = new System.Drawing.Size(73, 15); + this.lblBuyDate.TabIndex = 6; + this.lblBuyDate.Text = "Bought Date"; + // + // txtBoughtAmount + // + this.txtBoughtAmount.Location = new System.Drawing.Point(153, 162); + this.txtBoughtAmount.Name = "txtBoughtAmount"; + this.txtBoughtAmount.Size = new System.Drawing.Size(111, 23); + this.txtBoughtAmount.TabIndex = 9; + this.txtBoughtAmount.TextChanged += new System.EventHandler(this.txtBoughtAmount_TextChanged); + // + // lblBoughtAmount + // + this.lblBoughtAmount.AutoSize = true; + this.lblBoughtAmount.Location = new System.Drawing.Point(38, 165); + this.lblBoughtAmount.Name = "lblBoughtAmount"; + this.lblBoughtAmount.Size = new System.Drawing.Size(93, 15); + this.lblBoughtAmount.TabIndex = 8; + this.lblBoughtAmount.Text = "Bought Number"; + // + // txtActValue + // + this.txtActValue.Location = new System.Drawing.Point(153, 191); + this.txtActValue.Name = "txtActValue"; + this.txtActValue.Size = new System.Drawing.Size(111, 23); + this.txtActValue.TabIndex = 11; + // + // lblActValue + // + this.lblActValue.AutoSize = true; + this.lblActValue.Location = new System.Drawing.Point(38, 194); + this.lblActValue.Name = "lblActValue"; + this.lblActValue.Size = new System.Drawing.Size(76, 15); + this.lblActValue.TabIndex = 10; + this.lblActValue.Text = "Current price"; + // + // txtActDate + // + this.txtActDate.Location = new System.Drawing.Point(153, 220); + this.txtActDate.Name = "txtActDate"; + this.txtActDate.Size = new System.Drawing.Size(142, 23); + this.txtActDate.TabIndex = 13; + // + // lblActDate + // + this.lblActDate.AutoSize = true; + this.lblActDate.Location = new System.Drawing.Point(38, 223); + this.lblActDate.Name = "lblActDate"; + this.lblActDate.Size = new System.Drawing.Size(61, 15); + this.lblActDate.TabIndex = 12; + this.lblActDate.Text = "Value date"; + // + // txtActAmount + // + this.txtActAmount.Location = new System.Drawing.Point(153, 249); + this.txtActAmount.Name = "txtActAmount"; + this.txtActAmount.Size = new System.Drawing.Size(111, 23); + this.txtActAmount.TabIndex = 15; + // + // lblRemaining + // + this.lblRemaining.AutoSize = true; + this.lblRemaining.Location = new System.Drawing.Point(38, 252); + this.lblRemaining.Name = "lblRemaining"; + this.lblRemaining.Size = new System.Drawing.Size(109, 15); + this.lblRemaining.TabIndex = 14; + this.lblRemaining.Text = "Remaining number"; + // + // txtSoldPrice + // + this.txtSoldPrice.Location = new System.Drawing.Point(153, 278); + this.txtSoldPrice.Name = "txtSoldPrice"; + this.txtSoldPrice.Size = new System.Drawing.Size(111, 23); + this.txtSoldPrice.TabIndex = 17; + // + // lblSoldValue + // + this.lblSoldValue.AutoSize = true; + this.lblSoldValue.Location = new System.Drawing.Point(38, 281); + this.lblSoldValue.Name = "lblSoldValue"; + this.lblSoldValue.Size = new System.Drawing.Size(59, 15); + this.lblSoldValue.TabIndex = 16; + this.lblSoldValue.Text = "Sold price"; + // + // txtSoldDate + // + this.txtSoldDate.Location = new System.Drawing.Point(153, 307); + this.txtSoldDate.Name = "txtSoldDate"; + this.txtSoldDate.Size = new System.Drawing.Size(142, 23); + this.txtSoldDate.TabIndex = 19; + // + // lblSoldDate + // + this.lblSoldDate.AutoSize = true; + this.lblSoldDate.Location = new System.Drawing.Point(38, 310); + this.lblSoldDate.Name = "lblSoldDate"; + this.lblSoldDate.Size = new System.Drawing.Size(57, 15); + this.lblSoldDate.TabIndex = 18; + this.lblSoldDate.Text = "Sold Date"; + // + // txtComment + // + this.txtComment.Location = new System.Drawing.Point(153, 336); + this.txtComment.Multiline = true; + this.txtComment.Name = "txtComment"; + this.txtComment.Size = new System.Drawing.Size(269, 72); + this.txtComment.TabIndex = 21; + // + // lblComment + // + this.lblComment.AutoSize = true; + this.lblComment.Location = new System.Drawing.Point(39, 339); + this.lblComment.Name = "lblComment"; + this.lblComment.Size = new System.Drawing.Size(61, 15); + this.lblComment.TabIndex = 20; + this.lblComment.Text = "Comment"; + // + // btnSaveStock + // + this.btnSaveStock.Location = new System.Drawing.Point(39, 385); + this.btnSaveStock.Name = "btnSaveStock"; + this.btnSaveStock.Size = new System.Drawing.Size(75, 23); + this.btnSaveStock.TabIndex = 23; + this.btnSaveStock.Text = "Register"; + this.btnSaveStock.UseVisualStyleBackColor = true; + this.btnSaveStock.Click += new System.EventHandler(this.btnSaveStock_Click); + // + // lwRegBuffer + // + this.lwRegBuffer.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.Stock, + this.Price, + this.Number, + this.Comment}); + this.lwRegBuffer.GridLines = true; + this.lwRegBuffer.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; + this.lwRegBuffer.HideSelection = false; + this.lwRegBuffer.Location = new System.Drawing.Point(39, 427); + this.lwRegBuffer.Name = "lwRegBuffer"; + this.lwRegBuffer.Size = new System.Drawing.Size(383, 119); + this.lwRegBuffer.TabIndex = 24; + this.lwRegBuffer.UseCompatibleStateImageBehavior = false; + this.lwRegBuffer.View = System.Windows.Forms.View.Details; + this.lwRegBuffer.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.lwRegBuffer_DrawColumnHeader); + // + // Stock + // + this.Stock.Name = "Stock"; + this.Stock.Text = "Stock"; + this.Stock.Width = 120; + // + // Price + // + this.Price.Name = "Price"; + this.Price.Text = "Price"; + this.Price.Width = 80; + // + // Number + // + this.Number.Name = "Number"; + this.Number.Text = "Number"; + this.Number.Width = 80; + // + // Comment + // + this.Comment.Name = "Comment"; + this.Comment.Text = "Comment"; + this.Comment.Width = 120; + // + // btnSaveToDB + // + this.btnSaveToDB.Location = new System.Drawing.Point(266, 567); + this.btnSaveToDB.Name = "btnSaveToDB"; + this.btnSaveToDB.Size = new System.Drawing.Size(75, 23); + this.btnSaveToDB.TabIndex = 25; + this.btnSaveToDB.Text = "Save"; + this.btnSaveToDB.UseVisualStyleBackColor = true; + this.btnSaveToDB.Click += new System.EventHandler(this.btnSaveToDB_Click); + // + // frmRegisterStock + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(441, 602); + this.Controls.Add(this.btnSaveToDB); + this.Controls.Add(this.lwRegBuffer); + this.Controls.Add(this.btnSaveStock); + this.Controls.Add(this.txtComment); + this.Controls.Add(this.lblComment); + this.Controls.Add(this.txtSoldDate); + this.Controls.Add(this.lblSoldDate); + this.Controls.Add(this.txtSoldPrice); + this.Controls.Add(this.lblSoldValue); + this.Controls.Add(this.txtActAmount); + this.Controls.Add(this.lblRemaining); + this.Controls.Add(this.txtActDate); + this.Controls.Add(this.lblActDate); + this.Controls.Add(this.txtActValue); + this.Controls.Add(this.lblActValue); + this.Controls.Add(this.txtBoughtAmount); + this.Controls.Add(this.lblBoughtAmount); + this.Controls.Add(this.txtBuyDate); + this.Controls.Add(this.lblBuyDate); + this.Controls.Add(this.txtBuyPrice); + this.Controls.Add(this.lblBuyPrice); + this.Controls.Add(this.txtStockExtId); + this.Controls.Add(this.lblStockExtId); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.cmbStockChoser); + this.Name = "frmRegisterStock"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmRegisterStock"; + this.Shown += new System.EventHandler(this.frmRegisterStock_Shown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox cmbStockChoser; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Label lblStockExtId; + private System.Windows.Forms.TextBox txtStockExtId; + private System.Windows.Forms.TextBox txtBuyPrice; + private System.Windows.Forms.Label lblBuyPrice; + private System.Windows.Forms.TextBox txtBuyDate; + private System.Windows.Forms.Label lblBuyDate; + private System.Windows.Forms.TextBox txtBoughtAmount; + private System.Windows.Forms.Label lblBoughtAmount; + private System.Windows.Forms.TextBox txtActValue; + private System.Windows.Forms.Label lblActValue; + private System.Windows.Forms.TextBox txtActDate; + private System.Windows.Forms.Label lblActDate; + private System.Windows.Forms.TextBox txtActAmount; + private System.Windows.Forms.Label lblRemaining; + private System.Windows.Forms.TextBox txtSoldPrice; + private System.Windows.Forms.Label lblSoldValue; + private System.Windows.Forms.TextBox txtSoldDate; + private System.Windows.Forms.Label lblSoldDate; + private System.Windows.Forms.TextBox txtComment; + private System.Windows.Forms.Label lblComment; + private System.Windows.Forms.Button btnSaveStock; + private System.Windows.Forms.ListView lwRegBuffer; + private System.Windows.Forms.ColumnHeader Stock; + private System.Windows.Forms.ColumnHeader Price; + private System.Windows.Forms.ColumnHeader Number; + private System.Windows.Forms.ColumnHeader Comment; + private System.Windows.Forms.Button btnSaveToDB; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmRegisterStock.cs b/StockInfoCore/frmRegisterStock.cs new file mode 100644 index 0000000..b194c1e --- /dev/null +++ b/StockInfoCore/frmRegisterStock.cs @@ -0,0 +1,130 @@ +using DataDomain; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace StockInfoCore +{ + public partial class frmRegisterStock : Form + { + Color hdr = Color.Red; + public Dictionary Stocks { get; set; } + public List RegisteredStocks { get; set; } = new List(); + + public frmRegisterStock() + { + InitializeComponent(); + } + + private void LoadStockCombo() + { + if (Stocks.Count() > 0) + { + foreach (var key in Stocks.Keys) + { + cmbStockChoser.Items.Add(key); + } + } + + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void frmRegisterStock_Shown(object sender, EventArgs e) + { + LoadStockCombo(); + } + + private void cmbStockChoser_SelectedIndexChanged(object sender, EventArgs e) + { + var stockChosen = Stocks[cmbStockChoser.SelectedItem.ToString()]; + txtStockExtId.Text = stockChosen.StockName; + txtActValue.Text = stockChosen.LatestPrice.ToString(); + txtActDate.Text = (DateTime.Today + stockChosen.TimeOfDay).ToString(); + } + + private void btnSaveStock_Click(object sender, EventArgs e) + { + AddValidateData(); + RefreshListViewFromRegList(); + } + + private void RefreshListViewFromRegList() + { + lwRegBuffer.Items.Clear(); + foreach (var currStock in RegisteredStocks) + { + AddItemToListView(currStock); + } + } + + private void AddItemToListView(StockMember currStock) + { + var lv = lwRegBuffer.Items.Add(currStock.StockId); + lv.SubItems.Add(currStock.BuyValue.ToString()); + lv.SubItems.Add(currStock.PostAmount.ToString()); + lv.SubItems.Add(currStock.Comment); + //lv.BackColor = Color.Aquamarine; + } + + private void AddValidateData() + { + var currentStock = new StockMember(); + currentStock.StockId = cmbStockChoser.SelectedItem.ToString(); + currentStock.StockExtId = txtStockExtId.Text; + currentStock.BuyValue = decimal.Parse(string.IsNullOrEmpty(txtBuyPrice.Text) ? "0" : txtBuyPrice.Text); + currentStock.PostAmount = long.Parse(string.IsNullOrEmpty(txtBoughtAmount.Text) ? "0" : txtBoughtAmount.Text); + currentStock.ActDate = DateTime.Parse(txtActDate.Text); + currentStock.BuyDate = string.IsNullOrWhiteSpace(txtBuyDate.Text) ? DateTime.Today : DateTime.Parse(txtBuyDate.Text); + currentStock.ActValue = decimal.Parse(string.IsNullOrEmpty(txtActValue.Text) ? "0" : txtActValue.Text); + currentStock.ActAmount = long.Parse(string.IsNullOrEmpty(txtActAmount.Text) ? "0" : txtActAmount.Text); + currentStock.SoldDate = null; //DateTime.MaxValue; + currentStock.SoldValue = decimal.Parse("0"); + currentStock.Comment = txtComment.Text; + RegisteredStocks.Add(currentStock); + initiateRegWin(); + } + + private void initiateRegWin() + { + txtStockExtId.Text = ""; + txtBuyPrice.Text = ""; + txtBuyDate.Text = ""; + txtBoughtAmount.Text = ""; + txtActValue.Text = ""; + txtActDate.Text = ""; + txtActAmount.Text = ""; + txtSoldPrice.Text = ""; + txtSoldDate.Text = ""; + txtComment.Text = ""; + } + + private void btnSaveToDB_Click(object sender, EventArgs e) + { + + } + + private void txtBoughtAmount_TextChanged(object sender, EventArgs e) + { + txtActAmount.Text = txtBoughtAmount.Text; + } + + private void lwRegBuffer_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) + { + using (Brush hBr = new SolidBrush(hdr)) + { + e.Graphics.FillRectangle(hBr, e.Bounds); + e.DrawText(); + } + } + } +} diff --git a/StockInfoCore/frmRegisterStock.resx b/StockInfoCore/frmRegisterStock.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmRegisterStock.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StockInfoCore/frmSelling.Designer.cs b/StockInfoCore/frmSelling.Designer.cs new file mode 100644 index 0000000..8cab4e8 --- /dev/null +++ b/StockInfoCore/frmSelling.Designer.cs @@ -0,0 +1,452 @@ + +namespace StockInfoCore +{ + partial class frmSelling + { + /// + /// 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() + { + this.lvSellCandidates = new System.Windows.Forms.ListView(); + this.StockName = new System.Windows.Forms.ColumnHeader(); + this.Buydate = new System.Windows.Forms.ColumnHeader(); + this.BuyPrice = new System.Windows.Forms.ColumnHeader(); + this.LeftNumber = new System.Windows.Forms.ColumnHeader(); + this.ActPrice = new System.Windows.Forms.ColumnHeader(); + this.TotalValue = new System.Windows.Forms.ColumnHeader(); + this.gbInfo = new System.Windows.Forms.GroupBox(); + this.txtBuyValue = new System.Windows.Forms.TextBox(); + this.label6 = new System.Windows.Forms.Label(); + this.txtBuyPrice = new System.Windows.Forms.TextBox(); + this.label5 = new System.Windows.Forms.Label(); + this.txtBuyNumber = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.txtBuyDate = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.txtStockId = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.txtId = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.gbSell = new System.Windows.Forms.GroupBox(); + this.txtGainLoose = new System.Windows.Forms.TextBox(); + this.label12 = new System.Windows.Forms.Label(); + this.btnConfirm = new System.Windows.Forms.Button(); + this.txtRemainingNo = new System.Windows.Forms.TextBox(); + this.label11 = new System.Windows.Forms.Label(); + this.txtSellValue = new System.Windows.Forms.TextBox(); + this.label10 = new System.Windows.Forms.Label(); + this.txtSoldAmount = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.txtSoldPrice = new System.Windows.Forms.TextBox(); + this.label8 = new System.Windows.Forms.Label(); + this.txtSoldDate = new System.Windows.Forms.TextBox(); + this.label7 = new System.Windows.Forms.Label(); + this.btnClose = new System.Windows.Forms.Button(); + this.gbInfo.SuspendLayout(); + this.gbSell.SuspendLayout(); + this.SuspendLayout(); + // + // lvSellCandidates + // + this.lvSellCandidates.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.StockName, + this.Buydate, + this.BuyPrice, + this.LeftNumber, + this.ActPrice, + this.TotalValue}); + this.lvSellCandidates.FullRowSelect = true; + this.lvSellCandidates.HideSelection = false; + this.lvSellCandidates.Location = new System.Drawing.Point(13, 13); + this.lvSellCandidates.MultiSelect = false; + this.lvSellCandidates.Name = "lvSellCandidates"; + this.lvSellCandidates.Size = new System.Drawing.Size(519, 128); + this.lvSellCandidates.TabIndex = 0; + this.lvSellCandidates.UseCompatibleStateImageBehavior = false; + this.lvSellCandidates.View = System.Windows.Forms.View.Details; + this.lvSellCandidates.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvSellCandidates_MouseUp); + // + // StockName + // + this.StockName.Name = "StockName"; + this.StockName.Text = "StockId"; + this.StockName.Width = 80; + // + // Buydate + // + this.Buydate.Name = "Buydate"; + this.Buydate.Text = "Date of Buy"; + this.Buydate.Width = 80; + // + // BuyPrice + // + this.BuyPrice.Name = "BuyPrice"; + this.BuyPrice.Text = "Price per stock"; + this.BuyPrice.Width = 80; + // + // LeftNumber + // + this.LeftNumber.Name = "LeftNumber"; + this.LeftNumber.Text = "Remaining Nr"; + this.LeftNumber.Width = 80; + // + // ActPrice + // + this.ActPrice.Name = "ActPrice"; + this.ActPrice.Text = "Price today"; + this.ActPrice.Width = 80; + // + // TotalValue + // + this.TotalValue.Name = "TotalValue"; + this.TotalValue.Text = "Value Today"; + this.TotalValue.Width = 80; + // + // gbInfo + // + this.gbInfo.Controls.Add(this.txtBuyValue); + this.gbInfo.Controls.Add(this.label6); + this.gbInfo.Controls.Add(this.txtBuyPrice); + this.gbInfo.Controls.Add(this.label5); + this.gbInfo.Controls.Add(this.txtBuyNumber); + this.gbInfo.Controls.Add(this.label4); + this.gbInfo.Controls.Add(this.txtBuyDate); + this.gbInfo.Controls.Add(this.label3); + this.gbInfo.Controls.Add(this.txtStockId); + this.gbInfo.Controls.Add(this.label2); + this.gbInfo.Controls.Add(this.txtId); + this.gbInfo.Controls.Add(this.label1); + this.gbInfo.Location = new System.Drawing.Point(13, 170); + this.gbInfo.Name = "gbInfo"; + this.gbInfo.Size = new System.Drawing.Size(276, 250); + this.gbInfo.TabIndex = 1; + this.gbInfo.TabStop = false; + this.gbInfo.Text = "Actual Stock"; + // + // txtBuyValue + // + this.txtBuyValue.Location = new System.Drawing.Point(116, 165); + this.txtBuyValue.Name = "txtBuyValue"; + this.txtBuyValue.ReadOnly = true; + this.txtBuyValue.Size = new System.Drawing.Size(73, 23); + this.txtBuyValue.TabIndex = 11; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(7, 168); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(58, 15); + this.label6.TabIndex = 10; + this.label6.Text = "Buy value"; + // + // txtBuyPrice + // + this.txtBuyPrice.Location = new System.Drawing.Point(116, 136); + this.txtBuyPrice.Name = "txtBuyPrice"; + this.txtBuyPrice.ReadOnly = true; + this.txtBuyPrice.Size = new System.Drawing.Size(73, 23); + this.txtBuyPrice.TabIndex = 9; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(7, 139); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(56, 15); + this.label5.TabIndex = 8; + this.label5.Text = "Buy price"; + // + // txtBuyNumber + // + this.txtBuyNumber.Location = new System.Drawing.Point(116, 107); + this.txtBuyNumber.Name = "txtBuyNumber"; + this.txtBuyNumber.ReadOnly = true; + this.txtBuyNumber.Size = new System.Drawing.Size(73, 23); + this.txtBuyNumber.TabIndex = 7; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(7, 110); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(93, 15); + this.label4.TabIndex = 6; + this.label4.Text = "Bought Number"; + // + // txtBuyDate + // + this.txtBuyDate.Location = new System.Drawing.Point(116, 78); + this.txtBuyDate.Name = "txtBuyDate"; + this.txtBuyDate.ReadOnly = true; + this.txtBuyDate.Size = new System.Drawing.Size(73, 23); + this.txtBuyDate.TabIndex = 5; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(7, 81); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(72, 15); + this.label3.TabIndex = 4; + this.label3.Text = "Bought date"; + // + // txtStockId + // + this.txtStockId.Location = new System.Drawing.Point(116, 49); + this.txtStockId.Name = "txtStockId"; + this.txtStockId.ReadOnly = true; + this.txtStockId.Size = new System.Drawing.Size(154, 23); + this.txtStockId.TabIndex = 3; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 52); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(49, 15); + this.label2.TabIndex = 2; + this.label2.Text = "Stock Id"; + // + // txtId + // + this.txtId.Location = new System.Drawing.Point(116, 20); + this.txtId.Name = "txtId"; + this.txtId.ReadOnly = true; + this.txtId.Size = new System.Drawing.Size(73, 23); + this.txtId.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 23); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(48, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Local Id"; + // + // gbSell + // + this.gbSell.Controls.Add(this.txtGainLoose); + this.gbSell.Controls.Add(this.label12); + this.gbSell.Controls.Add(this.btnConfirm); + this.gbSell.Controls.Add(this.txtRemainingNo); + this.gbSell.Controls.Add(this.label11); + this.gbSell.Controls.Add(this.txtSellValue); + this.gbSell.Controls.Add(this.label10); + this.gbSell.Controls.Add(this.txtSoldAmount); + this.gbSell.Controls.Add(this.label9); + this.gbSell.Controls.Add(this.txtSoldPrice); + this.gbSell.Controls.Add(this.label8); + this.gbSell.Controls.Add(this.txtSoldDate); + this.gbSell.Controls.Add(this.label7); + this.gbSell.Location = new System.Drawing.Point(296, 170); + this.gbSell.Name = "gbSell"; + this.gbSell.Size = new System.Drawing.Size(236, 250); + this.gbSell.TabIndex = 2; + this.gbSell.TabStop = false; + this.gbSell.Text = "Sell decision"; + // + // txtGainLoose + // + this.txtGainLoose.Location = new System.Drawing.Point(121, 165); + this.txtGainLoose.Name = "txtGainLoose"; + this.txtGainLoose.ReadOnly = true; + this.txtGainLoose.Size = new System.Drawing.Size(73, 23); + this.txtGainLoose.TabIndex = 14; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Location = new System.Drawing.Point(12, 168); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(73, 15); + this.label12.TabIndex = 13; + this.label12.Text = "Gain / Loose"; + // + // btnConfirm + // + this.btnConfirm.Location = new System.Drawing.Point(121, 221); + this.btnConfirm.Name = "btnConfirm"; + this.btnConfirm.Size = new System.Drawing.Size(75, 23); + this.btnConfirm.TabIndex = 12; + this.btnConfirm.Text = "Confirm"; + this.btnConfirm.UseVisualStyleBackColor = true; + this.btnConfirm.Click += new System.EventHandler(this.btnConfirm_Click); + // + // txtRemainingNo + // + this.txtRemainingNo.Location = new System.Drawing.Point(121, 136); + this.txtRemainingNo.Name = "txtRemainingNo"; + this.txtRemainingNo.ReadOnly = true; + this.txtRemainingNo.Size = new System.Drawing.Size(73, 23); + this.txtRemainingNo.TabIndex = 11; + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Location = new System.Drawing.Point(12, 139); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(80, 15); + this.label11.TabIndex = 10; + this.label11.Text = "Remaining Nr"; + // + // txtSellValue + // + this.txtSellValue.Location = new System.Drawing.Point(121, 107); + this.txtSellValue.Name = "txtSellValue"; + this.txtSellValue.ReadOnly = true; + this.txtSellValue.Size = new System.Drawing.Size(73, 23); + this.txtSellValue.TabIndex = 9; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(12, 110); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(56, 15); + this.label10.TabIndex = 8; + this.label10.Text = "Sell Value"; + // + // txtSoldAmount + // + this.txtSoldAmount.Location = new System.Drawing.Point(121, 78); + this.txtSoldAmount.Name = "txtSoldAmount"; + this.txtSoldAmount.Size = new System.Drawing.Size(73, 23); + this.txtSoldAmount.TabIndex = 7; + this.txtSoldAmount.TextChanged += new System.EventHandler(this.txtSoldAmount_TextChanged); + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(12, 81); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(77, 15); + this.label9.TabIndex = 6; + this.label9.Text = "Sold Number"; + // + // txtSoldPrice + // + this.txtSoldPrice.Location = new System.Drawing.Point(121, 49); + this.txtSoldPrice.Name = "txtSoldPrice"; + this.txtSoldPrice.Size = new System.Drawing.Size(73, 23); + this.txtSoldPrice.TabIndex = 5; + this.txtSoldPrice.TextChanged += new System.EventHandler(this.txtSoldPrice_TextChanged); + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Location = new System.Drawing.Point(12, 52); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(71, 15); + this.label8.TabIndex = 4; + this.label8.Text = "Selling Price"; + // + // txtSoldDate + // + this.txtSoldDate.Location = new System.Drawing.Point(121, 20); + this.txtSoldDate.Name = "txtSoldDate"; + this.txtSoldDate.Size = new System.Drawing.Size(73, 23); + this.txtSoldDate.TabIndex = 3; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.Location = new System.Drawing.Point(12, 23); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(57, 15); + this.label7.TabIndex = 2; + this.label7.Text = "Sold Date"; + // + // btnClose + // + this.btnClose.Location = new System.Drawing.Point(417, 440); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 3; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // frmSelling + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(543, 478); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.gbSell); + this.Controls.Add(this.gbInfo); + this.Controls.Add(this.lvSellCandidates); + this.Name = "frmSelling"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "frmSelling"; + this.Load += new System.EventHandler(this.frmSelling_Load); + this.gbInfo.ResumeLayout(false); + this.gbInfo.PerformLayout(); + this.gbSell.ResumeLayout(false); + this.gbSell.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView lvSellCandidates; + private System.Windows.Forms.ColumnHeader StockName; + private System.Windows.Forms.ColumnHeader Buydate; + private System.Windows.Forms.ColumnHeader BuyPrice; + private System.Windows.Forms.ColumnHeader LeftNumber; + private System.Windows.Forms.ColumnHeader ActPrice; + private System.Windows.Forms.ColumnHeader TotalValue; + private System.Windows.Forms.GroupBox gbInfo; + private System.Windows.Forms.TextBox txtStockId; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtId; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox txtBuyDate; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox txtBuyValue; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.TextBox txtBuyPrice; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox txtBuyNumber; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.GroupBox gbSell; + private System.Windows.Forms.Button btnConfirm; + private System.Windows.Forms.TextBox txtRemainingNo; + private System.Windows.Forms.Label label11; + private System.Windows.Forms.TextBox txtSellValue; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.TextBox txtSoldAmount; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txtSoldPrice; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.TextBox txtSoldDate; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.TextBox txtGainLoose; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.Button btnClose; + } +} \ No newline at end of file diff --git a/StockInfoCore/frmSelling.cs b/StockInfoCore/frmSelling.cs new file mode 100644 index 0000000..5ddc2a9 --- /dev/null +++ b/StockInfoCore/frmSelling.cs @@ -0,0 +1,145 @@ +using DataDomain; +using Helpers; +using StockDAL.Interface; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace StockInfoCore +{ + public partial class frmSelling : Form + { + private readonly IStockRepository _stockRepository; + private List remainingStocks = new(); + public StockMember stkMemSelected { get; set; } = null; + + public frmSelling(IStockRepository stockRepository) + { + InitializeComponent(); + _stockRepository = stockRepository; + } + + private void frmSelling_Load(object sender, EventArgs e) + { + Cursor.Current = Cursors.WaitCursor; + ReloadRemainingStocks(); + Cursor.Current = DefaultCursor; + + } + + private void ReloadRemainingStocks() + { + remainingStocks = _stockRepository.GetAllRemainingStocks().ToList(); + foreach (var stock in remainingStocks) + { + var lvRow = lvSellCandidates.Items.Add(stock.StockId); + lvRow.Tag = stock.Id; + lvRow.SubItems.Add(stock.BuyDate.ToShortDateString()); + lvRow.SubItems.Add(stock.BuyValue.ToString()); + lvRow.SubItems.Add(stock.ActAmount.ToString()); + lvRow.SubItems.Add(stock.ActValue.ToString()); + lvRow.SubItems.Add((stock.ActValue * stock.ActAmount).ToString()); + } + } + + private void SelectStock(object tag) + { + //Debug.WriteLine($"selected item {(int)tag}"); + foreach (var remStk in remainingStocks) + { + if (remStk.Id == (int)tag) + { + stkMemSelected = remStk; + break; + } + } + + EditStockForSelling(stkMemSelected); + } + + private void EditStockForSelling(StockMember stkMemSelected) + { + txtId.Text = stkMemSelected.Id.ToString(); + txtStockId.Text = stkMemSelected.StockId; + txtBuyDate.Text = stkMemSelected.BuyDate.ToShortDateString(); + txtBuyNumber.Text = stkMemSelected.PostAmount.ToString(); + txtBuyPrice.Text = stkMemSelected.BuyValue.ToString("N2"); + txtBuyValue.Text = (stkMemSelected.BuyValue * stkMemSelected.PostAmount).ToString("N2"); + + txtSoldDate.Text = DateTime.Today.ToShortDateString(); + txtSoldPrice.Text = stkMemSelected.ActValue.ToString("N2"); + txtSoldAmount.Text = stkMemSelected.ActAmount.ToString(); + } + + + private void lvSellCandidates_MouseUp(object sender, MouseEventArgs e) + { + var selRows = lvSellCandidates.SelectedItems; + SelectStock(selRows[0].Tag); + } + + private void txtSoldPrice_TextChanged(object sender, EventArgs e) + { + CalcNumberAndValue(); + } + + private void txtSoldAmount_TextChanged(object sender, EventArgs e) + { + CalcNumberAndValue(); + } + + private void CalcNumberAndValue() + { + if (txtSoldPrice.Text.IsNumeric() && txtSoldAmount.Text.IsNumeric()) + { + txtSellValue.Text = (decimal.Parse(txtSoldPrice.Text) * long.Parse(txtSoldAmount.Text)).ToString(); + txtRemainingNo.Text = stkMemSelected.ActAmount > 0 ? (stkMemSelected.PostAmount - long.Parse(txtSoldAmount.Text)).ToString() : 0.ToString(); + var gainLoose = (decimal.Parse(txtSellValue.Text) - decimal.Parse(txtBuyPrice.Text)*long.Parse(txtSoldAmount.Text)); + txtGainLoose.Text = gainLoose.ToString(); + if (gainLoose > 0) + { + txtGainLoose.BackColor = Color.LightGreen; + } + else if (gainLoose == 0) + { + txtGainLoose.BackColor = default; + } + else + { + txtGainLoose.BackColor = Color.LightPink; + } + } + } + + private void btnConfirm_Click(object sender, EventArgs e) + { + SellCurrentStock(); + } + + private void SellCurrentStock() + { + if (txtSoldAmount.Text.IsNumeric() && txtSoldPrice.Text.IsNumeric()) + { + _stockRepository.UpdateActualForSell(stkMemSelected.Id, int.Parse(txtSoldAmount.Text), decimal.Parse(txtSoldPrice.Text), DateTime.Parse(txtSoldDate.Text)); + var answer = MessageBox.Show($"Ok att sälja {stkMemSelected.StockId} ?","Selling" , MessageBoxButtons.OKCancel); + if (DialogResult.OK == answer) + { + ReloadRemainingStocks(); + } + } + else + { + MessageBox.Show("Something wrong with amounts"); + } + + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + + } +} diff --git a/StockInfoCore/frmSelling.resx b/StockInfoCore/frmSelling.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/StockInfoCore/frmSelling.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/StockInfoCoreApp.sln b/StockInfoCoreApp.sln new file mode 100644 index 0000000..3b668a5 --- /dev/null +++ b/StockInfoCoreApp.sln @@ -0,0 +1,73 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31205.134 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockInfoCore", "StockInfoCore\StockInfoCore.csproj", "{99122CA3-5625-4004-BED6-5423873FACAC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataDomain", "DataDomain\DataDomain.csproj", "{3E7E4CBD-FDBE-4424-880E-0BA24D29B599}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Helpers", "Helpers\Helpers.csproj", "{F415D933-B9A7-4418-948B-8937296B9D0E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqliteBackups", "SqliteBackups\SqliteBackups.csproj", "{71EF72E9-5A60-41E6-8649-2B9FDFFED8F2}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDAL", "StockDAL\StockDAL.csproj", "{DD041C3F-0883-456C-A3E1-26868BDE2363}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockDAL.Interface", "StockDal.Interface\StockDAL.Interface.csproj", "{90C9E06C-4774-4FD0-B15E-2BE6E23328E6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatamodelLibrary", "DatamodelLibrary\DatamodelLibrary.csproj", "{D08DA97B-3B26-4A81-B778-440DA9BC55FF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockBL", "StockBL\StockBL.csproj", "{BA58D226-460C-41B8-8C7D-7A43B75151E1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StockBL.Interface", "StockBL.Interface\StockBL.Interface.csproj", "{BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {99122CA3-5625-4004-BED6-5423873FACAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99122CA3-5625-4004-BED6-5423873FACAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99122CA3-5625-4004-BED6-5423873FACAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99122CA3-5625-4004-BED6-5423873FACAC}.Release|Any CPU.Build.0 = Release|Any CPU + {3E7E4CBD-FDBE-4424-880E-0BA24D29B599}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E7E4CBD-FDBE-4424-880E-0BA24D29B599}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E7E4CBD-FDBE-4424-880E-0BA24D29B599}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E7E4CBD-FDBE-4424-880E-0BA24D29B599}.Release|Any CPU.Build.0 = Release|Any CPU + {F415D933-B9A7-4418-948B-8937296B9D0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F415D933-B9A7-4418-948B-8937296B9D0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F415D933-B9A7-4418-948B-8937296B9D0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F415D933-B9A7-4418-948B-8937296B9D0E}.Release|Any CPU.Build.0 = Release|Any CPU + {71EF72E9-5A60-41E6-8649-2B9FDFFED8F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {71EF72E9-5A60-41E6-8649-2B9FDFFED8F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {71EF72E9-5A60-41E6-8649-2B9FDFFED8F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {71EF72E9-5A60-41E6-8649-2B9FDFFED8F2}.Release|Any CPU.Build.0 = Release|Any CPU + {DD041C3F-0883-456C-A3E1-26868BDE2363}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD041C3F-0883-456C-A3E1-26868BDE2363}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD041C3F-0883-456C-A3E1-26868BDE2363}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD041C3F-0883-456C-A3E1-26868BDE2363}.Release|Any CPU.Build.0 = Release|Any CPU + {90C9E06C-4774-4FD0-B15E-2BE6E23328E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90C9E06C-4774-4FD0-B15E-2BE6E23328E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90C9E06C-4774-4FD0-B15E-2BE6E23328E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90C9E06C-4774-4FD0-B15E-2BE6E23328E6}.Release|Any CPU.Build.0 = Release|Any CPU + {D08DA97B-3B26-4A81-B778-440DA9BC55FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D08DA97B-3B26-4A81-B778-440DA9BC55FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D08DA97B-3B26-4A81-B778-440DA9BC55FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D08DA97B-3B26-4A81-B778-440DA9BC55FF}.Release|Any CPU.Build.0 = Release|Any CPU + {BA58D226-460C-41B8-8C7D-7A43B75151E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA58D226-460C-41B8-8C7D-7A43B75151E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA58D226-460C-41B8-8C7D-7A43B75151E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA58D226-460C-41B8-8C7D-7A43B75151E1}.Release|Any CPU.Build.0 = Release|Any CPU + {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEAD00C3-74AD-416B-9B36-EBE40DAFF16F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {540C3730-0438-4FF3-823A-0FA1BF296A10} + EndGlobalSection +EndGlobal