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..538eeac
--- /dev/null
+++ b/DataDomain/Person.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 Person
+ {
+ public int Id { get; set; }
+ public string? FirstName { get; set; }
+ public string? LastName { get; set; }
+ public string? NickName { get; set; }
+ public DateTime? Born { 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/StockContextModelSnapshot.cs b/DatamodelLibrary/Migrations/StockContextModelSnapshot.cs
new file mode 100644
index 0000000..0e83c2c
--- /dev/null
+++ b/DatamodelLibrary/Migrations/StockContextModelSnapshot.cs
@@ -0,0 +1,88 @@
+//
+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.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/StockContext.cs b/DatamodelLibrary/StockContext.cs
new file mode 100644
index 0000000..3ad6722
--- /dev/null
+++ b/DatamodelLibrary/StockContext.cs
@@ -0,0 +1,19 @@
+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; }
+
+ protected override void OnConfiguring(DbContextOptionsBuilder options)
+ => options.UseSqlite("Data Source=Stocks.db");
+ }
+}
diff --git a/StockDAL/StockDAL.csproj b/StockDAL/StockDAL.csproj
new file mode 100644
index 0000000..f812ae5
--- /dev/null
+++ b/StockDAL/StockDAL.csproj
@@ -0,0 +1,19 @@
+
+
+
+ net5.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/StockDAL/StockMarketRepository.cs b/StockDAL/StockMarketRepository.cs
new file mode 100644
index 0000000..deae040
--- /dev/null
+++ b/StockDAL/StockMarketRepository.cs
@@ -0,0 +1,230 @@
+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;
+
+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);
+ File.WriteAllText($"D:\\TimCoDemos\\DemoLogs\\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 ae)
+ {
+ 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/StockRepository.cs b/StockDAL/StockRepository.cs
new file mode 100644
index 0000000..473fe47
--- /dev/null
+++ b/StockDAL/StockRepository.cs
@@ -0,0 +1,60 @@
+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 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
+ select stk).ToList();
+ return output;
+ }
+
+ public void InsertMany(List stockMembers)
+ {
+ using var context = new StockContext();
+ context.Stocks.AddRange(stockMembers);
+ context.SaveChanges();
+ }
+
+ }
+}
diff --git a/StockDBEF/GreetingService.cs b/StockDBEF/GreetingService.cs
new file mode 100644
index 0000000..baef16c
--- /dev/null
+++ b/StockDBEF/GreetingService.cs
@@ -0,0 +1,48 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using StockDBEF.Models;
+using System;
+using System.Threading.Tasks;
+
+// DI, SeriLog, Settings
+
+namespace StockDBEF
+{
+ public class GreetingService : IGreetingService
+ {
+ private readonly ILogger _log;
+ private readonly IConfiguration _config;
+ private readonly StockDBContext _stockDBContext;
+
+ public GreetingService(ILogger log, IConfiguration config, StockDBContext stockDBContext)
+ {
+ _log = log;
+ _config = config;
+ _stockDBContext = stockDBContext;
+ }
+ public async void Run()
+ {
+ for (int i = 0; i < _config.GetValue("LoopTimes"); i++)
+ {
+ _log.LogInformation("Run number {runNumber}", i);
+ }
+
+ await SaveInitialStock();
+ await SaveInitialPerson();
+ }
+
+ public async Task SaveInitialStock()
+ {
+ StockMember sm = new StockMember { BuyValue = 120M, ActAmount = 100, BuyDate = DateTime.Parse("2021-03-01"), PostAmount = 100, Comment = "Initial aktiepost" };
+ _stockDBContext.StockMembers.Add(sm);
+ await _stockDBContext.SaveChangesAsync();
+ }
+ public async Task SaveInitialPerson()
+ {
+ Person p = new Person { FirstName="Nisse", LastName="Pärlemo", Born=DateTime.Parse("1995-10-15"), NickName="Nippe" };
+ _stockDBContext.Persons.Add(p);
+ await _stockDBContext.SaveChangesAsync();
+ }
+ }
+
+}
diff --git a/StockDBEF/IGreetingService.cs b/StockDBEF/IGreetingService.cs
new file mode 100644
index 0000000..73ec99a
--- /dev/null
+++ b/StockDBEF/IGreetingService.cs
@@ -0,0 +1,8 @@
+
+namespace StockDBEF
+{
+ public interface IGreetingService
+ {
+ void Run();
+ }
+}
\ No newline at end of file
diff --git a/StockDBEF/Models/Person.cs b/StockDBEF/Models/Person.cs
new file mode 100644
index 0000000..7182d46
--- /dev/null
+++ b/StockDBEF/Models/Person.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace StockDBEF.Models
+{
+ public class Person
+ {
+ public int Id { get; set; }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ public string NickName { get; set; }
+ public DateTime Born { get; set; }
+ }
+}
diff --git a/StockDBEF/Models/StockDBContext.cs b/StockDBEF/Models/StockDBContext.cs
new file mode 100644
index 0000000..99c5150
--- /dev/null
+++ b/StockDBEF/Models/StockDBContext.cs
@@ -0,0 +1,28 @@
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace StockDBEF.Models
+{
+ public class StockDBContext : DbContext
+ {
+ private readonly IConfiguration _configuration;
+
+ public StockDBContext(IConfiguration configuration)
+ {
+ _configuration = configuration;
+ }
+ public DbSet Persons { get; set; }
+ public DbSet StockMembers { get; set; }
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ var connectionString = _configuration.GetValue("ConnectionStrings:Stocks");
+ optionsBuilder.UseSqlite(connectionString);
+ //optionsBuilder.UseSqlite("Data Source=Facts.db");
+ }
+ }
+}
diff --git a/StockDBEF/Models/StockMember.cs b/StockDBEF/Models/StockMember.cs
new file mode 100644
index 0000000..8cbea17
--- /dev/null
+++ b/StockDBEF/Models/StockMember.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace StockDBEF.Models
+{
+ 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/StockDBEF/Program.cs b/StockDBEF/Program.cs
new file mode 100644
index 0000000..01369dd
--- /dev/null
+++ b/StockDBEF/Program.cs
@@ -0,0 +1,83 @@
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Serilog;
+using StockDBEF.Models;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using System.Threading;
+
+// DI, SeriLog, Settings
+
+namespace StockDBEF
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ var builder = new ConfigurationBuilder();
+ BuildConfig(builder);
+
+ Log.Logger = new LoggerConfiguration()
+ .ReadFrom.Configuration(builder.Build())
+ .Enrich.FromLogContext()
+ .WriteTo.Console()
+ .CreateLogger();
+
+ Log.Logger.Information("Application starting");
+
+ var host = Host.CreateDefaultBuilder()
+ .ConfigureServices((context, services) =>
+ {
+ services.AddEntityFrameworkSqlite();
+ services.AddHostedService();
+ //services.AddDbContext();
+ services.AddDbContextPool(o =>
+ {
+ o.UseSqlite("Data Source=Stocks.db");
+ });
+
+ services.AddTransient();
+ })
+ .UseSerilog()
+ .Build();
+
+ var svc = ActivatorUtilities.CreateInstance(host.Services);
+ svc.Run();
+ }
+
+ static void BuildConfig(IConfigurationBuilder builder)
+ {
+ builder.SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
+ .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
+ .AddEnvironmentVariables();
+ }
+
+
+ }
+
+ public class DatabaseStartup : IHostedService
+ {
+ private readonly IServiceProvider serviceProvider;
+ public DatabaseStartup(IServiceProvider serviceProvider)
+ {
+ this.serviceProvider = serviceProvider;
+ }
+
+ public async Task StartAsync(CancellationToken cancellationToken)
+ {
+ using (var scope = serviceProvider.CreateScope())
+ {
+ var db = scope.ServiceProvider.GetRequiredService();
+ await db.Database.EnsureCreated();
+ // or
+ await db.Database.MigrateAsync();
+ }
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+ }
+
+}
diff --git a/StockDBEF/StockDBEF.csproj b/StockDBEF/StockDBEF.csproj
new file mode 100644
index 0000000..40bca97
--- /dev/null
+++ b/StockDBEF/StockDBEF.csproj
@@ -0,0 +1,32 @@
+
+
+
+ Exe
+ net5.0
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
diff --git a/StockDBEF/appsettings.json b/StockDBEF/appsettings.json
new file mode 100644
index 0000000..2804c64
--- /dev/null
+++ b/StockDBEF/appsettings.json
@@ -0,0 +1,15 @@
+{
+ "LoopTimes": 15,
+ "Serilog": {
+ "MinimumLevel": {
+ "Default": "Information",
+ "Override": {
+ "Microsft": "Information",
+ "System": "Warning"
+ }
+ }
+ },
+ "ConnectionStrings": {
+ "Stocks": "Data Source=Stocks.db"
+ }
+}
\ No newline at end of file
diff --git a/StockDBEFApp.sln b/StockDBEFApp.sln
new file mode 100644
index 0000000..47568ef
--- /dev/null
+++ b/StockDBEFApp.sln
@@ -0,0 +1,49 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.31005.135
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatamodelLibrary", "DatamodelLibrary\DatamodelLibrary.csproj", "{160EC9C2-0273-43FE-8CEF-D8687722F0B2}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataDomain", "DataDomain\DataDomain.csproj", "{D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDAL", "StockDAL\StockDAL.csproj", "{E84394CB-98B8-48C0-A65F-008BC97E34A3}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockDAL.Interface", "StockDal.Interface\StockDAL.Interface.csproj", "{7B0D0A18-D071-40ED-8788-120D432D16D8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockInfo", "StockInfo\StockInfo.csproj", "{EC122B56-FCE0-4BBD-956D-7BF46D617CF8}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {160EC9C2-0273-43FE-8CEF-D8687722F0B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {160EC9C2-0273-43FE-8CEF-D8687722F0B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {160EC9C2-0273-43FE-8CEF-D8687722F0B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {160EC9C2-0273-43FE-8CEF-D8687722F0B2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D8057A61-F1CE-4467-9F9E-5E1DA180B3C4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E84394CB-98B8-48C0-A65F-008BC97E34A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E84394CB-98B8-48C0-A65F-008BC97E34A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E84394CB-98B8-48C0-A65F-008BC97E34A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E84394CB-98B8-48C0-A65F-008BC97E34A3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7B0D0A18-D071-40ED-8788-120D432D16D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7B0D0A18-D071-40ED-8788-120D432D16D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7B0D0A18-D071-40ED-8788-120D432D16D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7B0D0A18-D071-40ED-8788-120D432D16D8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EC122B56-FCE0-4BBD-956D-7BF46D617CF8}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {FD15FE95-060F-455A-9AEC-B0DA11261CE7}
+ EndGlobalSection
+EndGlobal
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/IStockRepository.cs b/StockDal.Interface/IStockRepository.cs
new file mode 100644
index 0000000..e7be085
--- /dev/null
+++ b/StockDal.Interface/IStockRepository.cs
@@ -0,0 +1,18 @@
+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 SaveStockMember(StockMember stockMember);
+ 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..9b430d5
--- /dev/null
+++ b/StockDal.Interface/StockDAL.Interface.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net5.0
+
+
+
+
+
+
+
+
+
+
+
diff --git a/StockInfo/Program.cs b/StockInfo/Program.cs
new file mode 100644
index 0000000..2e30d09
--- /dev/null
+++ b/StockInfo/Program.cs
@@ -0,0 +1,40 @@
+using Autofac;
+using StockDal;
+using StockDal.Interface;
+using StockDAL;
+using StockDAL.Interface;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace StockInfo
+{
+ static class Program
+ {
+ public static IContainer Container;
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ Application.SetHighDpiMode(HighDpiMode.SystemAware);
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Container = Configure();
+ Application.Run(new frmInitial( Container.Resolve(), Container.Resolve()));
+ }
+
+ static IContainer Configure()
+ {
+ var builder = new ContainerBuilder();
+ builder.RegisterType().As();
+ builder.RegisterType().As();
+ builder.RegisterType();
+ return builder.Build();
+ }
+
+ }
+}
diff --git a/StockInfo/StockInfo.csproj b/StockInfo/StockInfo.csproj
new file mode 100644
index 0000000..3e2f4ca
--- /dev/null
+++ b/StockInfo/StockInfo.csproj
@@ -0,0 +1,40 @@
+
+
+
+ WinExe
+ net5.0-windows
+ true
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+
\ No newline at end of file
diff --git a/StockInfo/Stocks.db b/StockInfo/Stocks.db
new file mode 100644
index 0000000..737a194
Binary files /dev/null and b/StockInfo/Stocks.db differ
diff --git a/StockInfo/frmInitial.Designer.cs b/StockInfo/frmInitial.Designer.cs
new file mode 100644
index 0000000..0a67429
--- /dev/null
+++ b/StockInfo/frmInitial.Designer.cs
@@ -0,0 +1,199 @@
+
+namespace StockInfo
+{
+ 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.btnReload = new System.Windows.Forms.Button();
+ this.btnTestScrapFunction = new System.Windows.Forms.Button();
+ this.lblStockRows = new System.Windows.Forms.Label();
+ this.button1 = new System.Windows.Forms.Button();
+ this.chbShowBrowser = new System.Windows.Forms.CheckBox();
+ this.gbStockMgmnt = new System.Windows.Forms.GroupBox();
+ this.btnValueView = new System.Windows.Forms.Button();
+ this.btnStockReg = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.gB1.SuspendLayout();
+ this.gbStockMgmnt.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | 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(776, 389);
+ this.dataGridView.TabIndex = 0;
+ //
+ // lblTotalRecords
+ //
+ this.lblTotalRecords.AutoSize = true;
+ this.lblTotalRecords.Location = new System.Drawing.Point(12, 408);
+ 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.Controls.Add(this.btnReload);
+ this.gB1.Location = new System.Drawing.Point(157, 411);
+ this.gB1.Name = "gB1";
+ this.gB1.Size = new System.Drawing.Size(248, 35);
+ this.gB1.TabIndex = 3;
+ this.gB1.TabStop = false;
+ //
+ // btnReload
+ //
+ this.btnReload.Location = new System.Drawing.Point(0, 9);
+ this.btnReload.Name = "btnReload";
+ this.btnReload.Size = new System.Drawing.Size(75, 23);
+ this.btnReload.TabIndex = 2;
+ this.btnReload.Text = "Reload";
+ this.btnReload.UseVisualStyleBackColor = true;
+ this.btnReload.Click += new System.EventHandler(this.btnReload_Click);
+ //
+ // btnTestScrapFunction
+ //
+ this.btnTestScrapFunction.Location = new System.Drawing.Point(12, 452);
+ 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);
+ //
+ // lblStockRows
+ //
+ this.lblStockRows.AutoSize = true;
+ this.lblStockRows.Location = new System.Drawing.Point(93, 456);
+ this.lblStockRows.Name = "lblStockRows";
+ this.lblStockRows.Size = new System.Drawing.Size(14, 15);
+ this.lblStockRows.TabIndex = 5;
+ this.lblStockRows.Text = "#";
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(157, 452);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(75, 23);
+ this.button1.TabIndex = 6;
+ this.button1.Text = "ReLoad";
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.button1_Click);
+ //
+ // chbShowBrowser
+ //
+ this.chbShowBrowser.AutoSize = true;
+ this.chbShowBrowser.Location = new System.Drawing.Point(12, 478);
+ 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.Controls.Add(this.btnValueView);
+ this.gbStockMgmnt.Controls.Add(this.btnStockReg);
+ this.gbStockMgmnt.Location = new System.Drawing.Point(411, 411);
+ this.gbStockMgmnt.Name = "gbStockMgmnt";
+ this.gbStockMgmnt.Size = new System.Drawing.Size(257, 123);
+ this.gbStockMgmnt.TabIndex = 8;
+ this.gbStockMgmnt.TabStop = false;
+ //
+ // btnValueView
+ //
+ this.btnValueView.Location = new System.Drawing.Point(7, 39);
+ 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.Location = new System.Drawing.Point(6, 9);
+ 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);
+ //
+ // frmInitial
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 546);
+ this.Controls.Add(this.gbStockMgmnt);
+ this.Controls.Add(this.chbShowBrowser);
+ this.Controls.Add(this.button1);
+ this.Controls.Add(this.lblStockRows);
+ 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 = "Repository Pattern";
+ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmInitial_FormClosing);
+ this.Load += new System.EventHandler(this.Form1_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.gB1.ResumeLayout(false);
+ this.gbStockMgmnt.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.Label lblStockRows;
+ private System.Windows.Forms.Button button1;
+ private System.Windows.Forms.CheckBox chbShowBrowser;
+ private System.Windows.Forms.GroupBox gbStockMgmnt;
+ private System.Windows.Forms.Button btnStockReg;
+ private System.Windows.Forms.Button btnValueView;
+ }
+}
+
diff --git a/StockInfo/frmInitial.cs b/StockInfo/frmInitial.cs
new file mode 100644
index 0000000..dca3911
--- /dev/null
+++ b/StockInfo/frmInitial.cs
@@ -0,0 +1,117 @@
+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;
+
+namespace StockInfo
+{
+ public partial class frmInitial : Form
+ {
+ private readonly IStockRepository _stockRepository;
+ private readonly IStockMarketRepository _stockMarketRepository;
+
+ private frmRegisterStock regWindow;
+ private frmMyStocks stockWindow;
+
+ public frmInitial(IStockRepository stockMemberRepository, IStockMarketRepository stockMarketRepository)
+ {
+ InitializeComponent();
+ _stockRepository = stockMemberRepository;
+ _stockMarketRepository = stockMarketRepository;
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ ReloadData();
+ }
+
+ private void ReloadData()
+ {
+ var allStocks = _stockRepository.GetAllStocks();
+ dataGridView.DataSource = allStocks;
+ // SaveStocks(allStocks);
+ lblTotalRecords.Text = $"Total records: {dataGridView.RowCount}";
+ }
+
+ //private static async void SaveStocks(IEnumerable allStocks)
+ //{
+
+ // allStocks.ToList().ForEach(async s => await StockProcessor.SaveStockMember(new ApiClient.StockMember
+ // {
+ // ActAmount = s.ActAmount,
+ // ActDate = s.ActDate,
+ // ActValue = (double)s.ActValue,
+ // BuyDate = s.BuyDate,
+ // BuyValue = (double)s.BuyValue,
+ // Comment = s.Comment,
+ // PostAmount = s.PostAmount,
+ // SoldDate = s.SoldDate,
+ // SoldValue = (double)s.SoldValue,
+ // StockExtId = s.StockExtId,
+ // StockId = s.StockId
+ // }));
+
+ //}
+
+ //private async void GetApiStocks()
+ //{
+ // dataGridView.DataSource = await StockProcessor.LoadStocksInformation();
+ //}
+
+
+ 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();
+ }
+
+ private void frmInitial_FormClosing(object sender, FormClosingEventArgs e)
+ {
+ _stockMarketRepository.Clean();
+ }
+
+ private void button1_Click(object sender, EventArgs e)
+ {
+ 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 = new frmRegisterStock();
+ regWindow.Stocks = _stockMarketRepository.StockMarketList;
+ Cursor.Current = DefaultCursor;
+ regWindow.ShowDialog();
+
+ _stockRepository.InsertMany(regWindow.RegisteredStocks);
+ }
+
+ private void btnValueView_Click(object sender, EventArgs e)
+ {
+ Cursor.Current = Cursors.WaitCursor;
+ _stockMarketRepository.LoadStockMarketList();
+ stockWindow = new frmMyStocks( _stockRepository, _stockMarketRepository);
+ stockWindow.Stocks = _stockMarketRepository.StockMarketList;
+ Cursor.Current = DefaultCursor;
+ stockWindow.ShowDialog();
+ }
+ }
+}
diff --git a/StockInfo/frmInitial.resx b/StockInfo/frmInitial.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/StockInfo/frmInitial.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/StockInfo/frmMyStocks.Designer.cs b/StockInfo/frmMyStocks.Designer.cs
new file mode 100644
index 0000000..2a8484c
--- /dev/null
+++ b/StockInfo/frmMyStocks.Designer.cs
@@ -0,0 +1,389 @@
+
+namespace StockInfo
+{
+ 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(415, 419);
+ 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(200, 476);
+ 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(295, 474);
+ 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(438, 476);
+ 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(533, 474);
+ 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/StockInfo/frmMyStocks.cs b/StockInfo/frmMyStocks.cs
new file mode 100644
index 0000000..726db6c
--- /dev/null
+++ b/StockInfo/frmMyStocks.cs
@@ -0,0 +1,166 @@
+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 StockInfo
+{
+ public partial class frmMyStocks : Form
+ {
+ Color hdrColor;
+ private readonly IStockRepository _stockRepository;
+ private readonly IStockMarketRepository _stockMarketRepository;
+ 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 frmMyStocks(IStockRepository stockRepository, IStockMarketRepository stockMarketRepository)
+ {
+ hdrColor = Color.CadetBlue;
+ InitializeComponent();
+ _stockRepository = stockRepository;
+ _stockMarketRepository = stockMarketRepository;
+ 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();
+ 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);
+ }
+ foreach(var stk in tmpStocks.OrderByDescending(s => s.PostAmount * (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.PostAmount.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)
+ {
+ 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/StockInfo/frmMyStocks.resx b/StockInfo/frmMyStocks.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/StockInfo/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/StockInfo/frmRegisterStock.Designer.cs b/StockInfo/frmRegisterStock.Designer.cs
new file mode 100644
index 0000000..2e055ea
--- /dev/null
+++ b/StockInfo/frmRegisterStock.Designer.cs
@@ -0,0 +1,377 @@
+
+namespace StockInfo
+{
+ 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/StockInfo/frmRegisterStock.cs b/StockInfo/frmRegisterStock.cs
new file mode 100644
index 0000000..804c4a2
--- /dev/null
+++ b/StockInfo/frmRegisterStock.cs
@@ -0,0 +1,129 @@
+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 StockInfo
+{
+ 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.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/StockInfo/frmRegisterStock.resx b/StockInfo/frmRegisterStock.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/StockInfo/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/Z_Backup/Stocks.db b/Z_Backup/Stocks.db
new file mode 100644
index 0000000..737a194
Binary files /dev/null and b/Z_Backup/Stocks.db differ