Add project files.
This commit is contained in:
25
StockTransToDB/DbConnections/SqliteDbConnectionFactory.cs
Normal file
25
StockTransToDB/DbConnections/SqliteDbConnectionFactory.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.Data.Sqlite;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.DbConnections
|
||||||
|
{
|
||||||
|
public class SqliteDbConnectionFactory
|
||||||
|
{
|
||||||
|
private string? _connectionString;
|
||||||
|
|
||||||
|
public SqliteDbConnectionFactory(string? connectionString)
|
||||||
|
{
|
||||||
|
_connectionString = connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDbConnection Connect()
|
||||||
|
{
|
||||||
|
return new SqliteConnection(_connectionString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
StockTransToDB/DbInitializers/ISqliteDbInitializer.cs
Normal file
7
StockTransToDB/DbInitializers/ISqliteDbInitializer.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace StockTransToDB.DbInitializers
|
||||||
|
{
|
||||||
|
public interface ISqliteDbInitializer
|
||||||
|
{
|
||||||
|
void Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
StockTransToDB/DbInitializers/SqliteDbInitializer.cs
Normal file
43
StockTransToDB/DbInitializers/SqliteDbInitializer.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using StockTransToDB.DbConnections;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.DbInitializers
|
||||||
|
{
|
||||||
|
public class SqliteDbInitializer : ISqliteDbInitializer
|
||||||
|
{
|
||||||
|
private const string INIT_TABLE = @"
|
||||||
|
CREATE TABLE [NewBackupRegings] (
|
||||||
|
[Id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
|
||||||
|
, [BackedUp] text NOT NULL
|
||||||
|
, [DbName]
|
||||||
|
text NULL
|
||||||
|
, [BackupDbName] text NULL
|
||||||
|
, [BackupPath] text NULL
|
||||||
|
)";
|
||||||
|
|
||||||
|
private readonly SqliteDbConnectionFactory _sqliteDbConnectionFactory;
|
||||||
|
private readonly ILogger<SqliteDbInitializer> _log;
|
||||||
|
|
||||||
|
public SqliteDbInitializer(SqliteDbConnectionFactory sqliteDbConnectionFactory, ILogger<SqliteDbInitializer> log)
|
||||||
|
{
|
||||||
|
_sqliteDbConnectionFactory = sqliteDbConnectionFactory;
|
||||||
|
_log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
_log.LogInformation(INIT_TABLE);
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
database.Execute(INIT_TABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
74
StockTransToDB/Program.cs
Normal file
74
StockTransToDB/Program.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
//
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using ReadSBAktieTrans;
|
||||||
|
using Serilog;
|
||||||
|
using StockTransToDB.DbConnections;
|
||||||
|
using StockTransToDB.DbInitializers;
|
||||||
|
using StockTransToDB.models;
|
||||||
|
using StockTransToDB.Runners;
|
||||||
|
using StockTransToDB.StocksProviders;
|
||||||
|
|
||||||
|
var builder = new ConfigurationBuilder();
|
||||||
|
BuildConfig(builder);
|
||||||
|
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(builder.Build())
|
||||||
|
.Enrich.FromLogContext()
|
||||||
|
.WriteTo.Console()
|
||||||
|
.CreateLogger();
|
||||||
|
|
||||||
|
var host = Host.CreateDefaultBuilder()
|
||||||
|
.ConfigureServices((hostContext, services) =>
|
||||||
|
{
|
||||||
|
services.AddSingleton<IFileToJson, FileToJson>();
|
||||||
|
string connectionString = hostContext.Configuration.GetConnectionString("Default");
|
||||||
|
services.AddSingleton(new SqliteDbConnectionFactory(connectionString));
|
||||||
|
services.AddSingleton<ISqliteDbInitializer, SqliteDbInitializer>();
|
||||||
|
services.AddSingleton<IDapperStocksProvider, DapperStocksProvider>();
|
||||||
|
services.AddSingleton<IFileDataCreator, FileDataCreator>();
|
||||||
|
})
|
||||||
|
.UseSerilog()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
ProcName.RunIdent = "new";
|
||||||
|
var svc = ActivatorUtilities.CreateInstance<FileToJson>(host.Services);
|
||||||
|
svc.FetchJsonData();
|
||||||
|
//await svc.StockNameTable();
|
||||||
|
//foreach (var x in svc.NameConverter)
|
||||||
|
//{
|
||||||
|
// Console.WriteLine(x.ToString());
|
||||||
|
//}
|
||||||
|
|
||||||
|
//var sdi = host.Services.GetRequiredService<ISqliteDbInitializer>();
|
||||||
|
//sdi.Initialize();
|
||||||
|
|
||||||
|
//var dsp = host.Services.GetRequiredService<IDapperStocksProvider>();
|
||||||
|
//var recs = await dsp.GetAllStocks();
|
||||||
|
|
||||||
|
//foreach (var stock in recs)
|
||||||
|
//{
|
||||||
|
// Log.Logger.Information($"{stock.Id} " +
|
||||||
|
// $"{stock.StockId} " +
|
||||||
|
// $"{stock.StockExtId} " +
|
||||||
|
// $"{stock.ActValue} " +
|
||||||
|
// $"{stock.BuyValue} " +
|
||||||
|
// $"{stock.BuyDate} " +
|
||||||
|
// $"{stock.SoldDate} " +
|
||||||
|
// $"{stock.SoldValue} " +
|
||||||
|
// $"{stock.ActAmount} " +
|
||||||
|
// $"{stock.Comment} ");
|
||||||
|
//}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
8
StockTransToDB/Properties/launchSettings.json
Normal file
8
StockTransToDB/Properties/launchSettings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"StockTransToDB": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"nativeDebugging": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
78
StockTransToDB/Runners/FileDataCreator.cs
Normal file
78
StockTransToDB/Runners/FileDataCreator.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using StockTransToDB.models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ReadSBAktieTrans
|
||||||
|
{
|
||||||
|
public class FileDataCreator : IFileDataCreator
|
||||||
|
{
|
||||||
|
public string CreateAndSave(Dictionary<int, string[]> dataStore)
|
||||||
|
{
|
||||||
|
var FileModelList = new List<FileModel>();
|
||||||
|
for (var i = 0; i < dataStore.Count - 1; i++)
|
||||||
|
{
|
||||||
|
var item = dataStore[i];
|
||||||
|
var fmRec = CreateRecord(item);
|
||||||
|
FileModelList.Add(fmRec);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileSaved = SaveUpdateFile(FileModelList);
|
||||||
|
return fileSaved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<FileModel> CreateDataList(Dictionary<int, string[]> dataStore)
|
||||||
|
{
|
||||||
|
var FileModelList = new List<FileModel>();
|
||||||
|
for (var i = 0; i < dataStore.Count - 1; i++)
|
||||||
|
{
|
||||||
|
var item = dataStore[i];
|
||||||
|
var fmRec = CreateRecord(item);
|
||||||
|
FileModelList.Add(fmRec);
|
||||||
|
}
|
||||||
|
return FileModelList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileModel CreateRecord(string[] item)
|
||||||
|
{
|
||||||
|
var record = new FileModel();
|
||||||
|
record.Bokföringsdag = DateTime.Parse(item[0]);
|
||||||
|
record.Affärsdag = DateTime.Parse(item[1]);
|
||||||
|
record.Likviddag = DateTime.Parse(item[2]);
|
||||||
|
record.Valuta = item[3];
|
||||||
|
record.ISIN = item[4];
|
||||||
|
record.Transaktionstyp = item[5];
|
||||||
|
record.Beskrivning = item[6];
|
||||||
|
record.Specifikation = item[7];
|
||||||
|
record.Antal = int.Parse(item[8] == "" ? "0" : item[8]);
|
||||||
|
record.Kurs = decimal.Parse(item[9] == "" ? "0" : item[9]);
|
||||||
|
record.Belopp = decimal.Parse(item[10] == "" ? "0" : item[10]);
|
||||||
|
record.Saldo = decimal.Parse(item[11] == "" ? "0" : item[11]);
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SaveUpdateFile(List<FileModel> DumpObjects)
|
||||||
|
{
|
||||||
|
var output = JsonConvert.SerializeObject(DumpObjects, Formatting.Indented);
|
||||||
|
// Assembly assem = typeof(ReadSBAktieTrans).Assembly;
|
||||||
|
Assembly assem = Assembly.GetExecutingAssembly();
|
||||||
|
var programPath = assem.Location.Substring(0, assem.Location.LastIndexOf("\\"));
|
||||||
|
var DataPath = new DirectoryInfo(programPath + "\\DataFiles");
|
||||||
|
if (!DataPath.Exists)
|
||||||
|
{
|
||||||
|
DataPath.Create();
|
||||||
|
}
|
||||||
|
var outFileName = $"StockData{DateTime.Now.ToShortDateString()}.txt";
|
||||||
|
File.WriteAllText($"{programPath}\\DataFiles\\{outFileName}", output);
|
||||||
|
Console.WriteLine($"Skapad fil: {outFileName}");
|
||||||
|
return outFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
346
StockTransToDB/Runners/FileToJson.cs
Normal file
346
StockTransToDB/Runners/FileToJson.cs
Normal file
@ -0,0 +1,346 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using ReadSBAktieTrans;
|
||||||
|
using StockTransToDB.models;
|
||||||
|
using StockTransToDB.StocksProviders;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.Runners
|
||||||
|
{
|
||||||
|
public class FileToJson : IFileToJson
|
||||||
|
{
|
||||||
|
//private const string BYTE_INLAGG_VP = "BYTE INLÄGG VP";
|
||||||
|
//private const string BYTE_UTTAG_VP = "BYTE UTTAG VP";
|
||||||
|
//private const string DECIMALER_LIKVID = "DECIMALER LIKVID";
|
||||||
|
//private const string DECIMALER_UTTAG_VP = "DECIMALER UTTAG VP";
|
||||||
|
//private const string INLAGG_FISSION = "INLÄGG FISSION";
|
||||||
|
//private const string INLOSEN_LIKVID = "INLÖSEN LIKVID";
|
||||||
|
//private const string INLOSEN_UTTAG_VP = "INLÖSEN UTTAG VP";
|
||||||
|
//private const string INSATTNING = "INSÄTTNING";
|
||||||
|
//private const string KOPT = "KÖPT";
|
||||||
|
//private const string SPLIT_INLÄGG_VP = "SPLIT INLÄGG VP";
|
||||||
|
//private const string SPLIT_UTTAG_VP = "SPLIT UTTAG VP";
|
||||||
|
//private const string SALT = "SÅLT";
|
||||||
|
//private const string UTDELNING = "UTDELNING";
|
||||||
|
//private const string UTL_KUPSKATT = "UTL KUPSKATT";
|
||||||
|
//private const string UTTAG = "UTTAG";
|
||||||
|
|
||||||
|
private readonly ILogger<FileToJson> _log;
|
||||||
|
private readonly IConfiguration _config;
|
||||||
|
private readonly IDapperStocksProvider _dapperStocksProvider;
|
||||||
|
private readonly IFileDataCreator _fileDataCreator;
|
||||||
|
|
||||||
|
public Dictionary<string, string> NameConverter { get; set; } = new Dictionary<string, string>();
|
||||||
|
public FileToJson(ILogger<FileToJson> log,
|
||||||
|
IConfiguration config,
|
||||||
|
IDapperStocksProvider dapperStocksProvider,
|
||||||
|
IFileDataCreator fileDataCreator)
|
||||||
|
{
|
||||||
|
_log = log;
|
||||||
|
_config = config;
|
||||||
|
_dapperStocksProvider = dapperStocksProvider;
|
||||||
|
_fileDataCreator = fileDataCreator;
|
||||||
|
}
|
||||||
|
public async Task<List<FileModel>> FetchJsonData()
|
||||||
|
{
|
||||||
|
|
||||||
|
_log.LogInformation("Starting ReadSBAktieTrans reading from xls!");
|
||||||
|
string fileName = @$"C:\Users\tommy\Downloads\" + _config.GetValue<string>("TransFile").Trim();
|
||||||
|
_log.LogInformation($"Inläst fil : {fileName}");
|
||||||
|
|
||||||
|
string contents = File.ReadAllText(fileName, System.Text.Encoding.Latin1);
|
||||||
|
string[] records = contents.Split("\r\n");
|
||||||
|
_log.LogInformation($"{records.Count()} records read");
|
||||||
|
|
||||||
|
|
||||||
|
Dictionary<int, string[]> dataStore = new Dictionary<int, string[]>();
|
||||||
|
var rNr = 0;
|
||||||
|
foreach (var record in records.Skip(1).ToArray())
|
||||||
|
{
|
||||||
|
var fieldArr = record.Split("\t");
|
||||||
|
dataStore.Add(rNr++, fieldArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
var fileModelList = _fileDataCreator.CreateDataList(dataStore).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
_log.LogInformation("InLäsning klar!");
|
||||||
|
|
||||||
|
Console.WriteLine("Create Name Converter ?");
|
||||||
|
var answ = Console.ReadLine();
|
||||||
|
|
||||||
|
if (answ == "Y" || answ == "J")
|
||||||
|
{
|
||||||
|
await PrepareNameConverter(fileModelList);
|
||||||
|
}
|
||||||
|
|
||||||
|
await UpDateNameConverter();
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("Show data ?");
|
||||||
|
answ = Console.ReadLine();
|
||||||
|
|
||||||
|
if (answ == "ok")
|
||||||
|
{
|
||||||
|
foreach (var rec in fileModelList)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Bokföringsdag {rec.Bokföringsdag} Affärsdag {rec.Affärsdag} Likviddag {rec.Likviddag}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var skrivna = 0;
|
||||||
|
foreach (var rec in fileModelList)
|
||||||
|
{
|
||||||
|
if (rec.Transaktionstyp == ProcName.KOPT)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var stockmember = new StockMember();
|
||||||
|
stockmember.StockId = NameConverter[rec.Beskrivning.Trim()];
|
||||||
|
stockmember.StockExtId = NameConverter[rec.Beskrivning.Trim()];
|
||||||
|
stockmember.BuyValue = rec.Kurs;
|
||||||
|
stockmember.BuyDate = rec.Affärsdag;
|
||||||
|
stockmember.ActValue = rec.Kurs;
|
||||||
|
stockmember.ActDate = rec.Affärsdag;
|
||||||
|
stockmember.ActAmount = rec.Antal;
|
||||||
|
stockmember.SoldValue = 0;
|
||||||
|
stockmember.SoldDate = null;
|
||||||
|
stockmember.Comment = $"{ProcName.RunIdent}from trans";
|
||||||
|
stockmember.PostAmount = rec.Antal;
|
||||||
|
stockmember.SoldStockPrice = 0;
|
||||||
|
|
||||||
|
_dapperStocksProvider.AddStock(stockmember);
|
||||||
|
skrivna++;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_log.LogError(e.Message, e.StackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.LogInformation($"Köpta klart {skrivna} st skrivna");
|
||||||
|
skrivna = 0;
|
||||||
|
foreach (var rec in fileModelList)
|
||||||
|
{
|
||||||
|
if (rec.Transaktionstyp == ProcName.SPLIT_INLÄGG_VP)
|
||||||
|
{
|
||||||
|
UpDateWithSplitPlus(rec);
|
||||||
|
|
||||||
|
skrivna++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rec.Transaktionstyp == ProcName.SPLIT_UTTAG_VP)
|
||||||
|
{
|
||||||
|
UpDateWithSplitMinus(rec);
|
||||||
|
|
||||||
|
skrivna++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.LogInformation($"Split update {skrivna} st skrivna");
|
||||||
|
|
||||||
|
skrivna = 0;
|
||||||
|
foreach (var rec in fileModelList)
|
||||||
|
{
|
||||||
|
if (rec.Transaktionstyp == ProcName.SALT)
|
||||||
|
{
|
||||||
|
UpDateWithSold(rec);
|
||||||
|
|
||||||
|
skrivna++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_log.LogInformation($"Sålda klart {skrivna} st skrivna");
|
||||||
|
|
||||||
|
|
||||||
|
await _dapperStocksProvider.ResetCommentsFromNew();
|
||||||
|
_log.LogInformation($"Comments restored");
|
||||||
|
|
||||||
|
return fileModelList;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private async Task PrepareNameConverter(List<FileModel> recList)
|
||||||
|
{
|
||||||
|
var tempListNew = new HashSet<string>();
|
||||||
|
await _dapperStocksProvider.CleanStockNames();
|
||||||
|
|
||||||
|
foreach (var rec in recList)
|
||||||
|
{
|
||||||
|
if (rec.Transaktionstyp == ProcName.KOPT)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tempListNew.Add(rec.Beskrivning);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
_log.LogInformation($"Dublett : {rec.Beskrivning}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var templist = await _dapperStocksProvider.GetStockNames();
|
||||||
|
foreach (var webName in templist)
|
||||||
|
{
|
||||||
|
_log.LogInformation($"Upplägg : {webName}, --");
|
||||||
|
await _dapperStocksProvider.AddWebStockNames(webName);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var newName in tempListNew)
|
||||||
|
{
|
||||||
|
//var founds = templist.Where(t => t.StartsWith(newName.Substring(0, 3))).ToList();
|
||||||
|
var founds = await _dapperStocksProvider.GetStockNamesByPart(newName.Substring(0, 3));
|
||||||
|
if (founds.Any())
|
||||||
|
{
|
||||||
|
if (founds.Count() > 1)
|
||||||
|
{
|
||||||
|
var choseNr = 0;
|
||||||
|
Console.WriteLine($"{newName} skall passas ihop med en av nedan nr:");
|
||||||
|
Console.WriteLine();
|
||||||
|
foreach (var found in founds)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"välj {choseNr++} for {found}");
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.Write("Chose a number: ");
|
||||||
|
var valNumber = Console.ReadLine();
|
||||||
|
if (int.Parse(valNumber) < 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{newName} skall passas ihop med ?");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.Write("Write the correct name: ");
|
||||||
|
var stockName = Console.ReadLine();
|
||||||
|
await _dapperStocksProvider.UpdateStockName(newName, stockName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _dapperStocksProvider.UpdateStockName(newName, founds[int.Parse(valNumber)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _dapperStocksProvider.UpdateStockName(newName, founds[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"{newName} skall passas ihop med ?");
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.Write("Write the correct name: ");
|
||||||
|
var valNumber = Console.ReadLine();
|
||||||
|
await _dapperStocksProvider.UpdateStockName(newName, valNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private async void UpDateWithSplitMinus(FileModel rec)
|
||||||
|
{
|
||||||
|
var members = await _dapperStocksProvider.GetStocksByStockIdPart(rec.Beskrivning, rec.Affärsdag);
|
||||||
|
var remainingInit = rec.Antal;
|
||||||
|
var remaining = rec.Antal;
|
||||||
|
foreach (var member in members)
|
||||||
|
{
|
||||||
|
if (remaining >= member.ActAmount)
|
||||||
|
{
|
||||||
|
remaining -= (int)member.ActAmount;
|
||||||
|
await _dapperStocksProvider.RemoveStockById(member.Id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
member.ActAmount -= remaining;
|
||||||
|
member.Comment += ",-Split";
|
||||||
|
await _dapperStocksProvider.UpdateStock(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.LogInformation($"Split <MINUS> {member.StockId} ({member.Id}) ändrad (minskad)");
|
||||||
|
|
||||||
|
if (remaining <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void UpDateWithSplitPlus(FileModel rec)
|
||||||
|
{
|
||||||
|
var members = await _dapperStocksProvider.GetStocksByStockIdPart(
|
||||||
|
rec.Beskrivning, rec.Affärsdag);
|
||||||
|
foreach (var member in members)
|
||||||
|
{
|
||||||
|
member.ActAmount += rec.Antal;
|
||||||
|
member.Comment += ", +split";
|
||||||
|
|
||||||
|
await _dapperStocksProvider.UpdateStock(member);
|
||||||
|
_log.LogInformation($"Split <PLUS> {member.StockId} ({member.Id}) ändrad (ökad)");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task UpDateNameConverter()
|
||||||
|
{
|
||||||
|
var stockNameList = await _dapperStocksProvider.GetStockNameTable();
|
||||||
|
NameConverter.Clear();
|
||||||
|
foreach (var stockname in stockNameList)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NameConverter.Add(stockname.StockNameBank, stockname.StockNameWeb);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.LogError($"Namnkonvert {stockname} error {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void UpDateWithSold(FileModel rec)
|
||||||
|
{
|
||||||
|
var members = await _dapperStocksProvider.GetStocksByStockId(NameConverter[rec.Beskrivning], rec.Affärsdag);
|
||||||
|
var remainingInit = rec.Antal;
|
||||||
|
var remaining = rec.Antal;
|
||||||
|
foreach (var member in members)
|
||||||
|
{
|
||||||
|
if (remaining >= member.ActAmount)
|
||||||
|
{
|
||||||
|
remaining -= (int)member.ActAmount;
|
||||||
|
member.SoldValue = ((int)member.ActAmount * rec.Belopp) / remainingInit;
|
||||||
|
member.ActAmount = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
member.ActAmount -= remaining;
|
||||||
|
member.SoldValue = (remaining * rec.Belopp) / remainingInit;
|
||||||
|
remaining = 0;
|
||||||
|
}
|
||||||
|
member.SoldDate = rec.Affärsdag;
|
||||||
|
member.Comment += ",Sold";
|
||||||
|
member.SoldStockPrice = rec.Kurs;
|
||||||
|
|
||||||
|
await _dapperStocksProvider.UpdateStock(member);
|
||||||
|
_log.LogInformation($"Såld {member.StockId} ({member.Id}) ändrad");
|
||||||
|
|
||||||
|
if (remaining <= 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
10
StockTransToDB/Runners/IFileDataCreator.cs
Normal file
10
StockTransToDB/Runners/IFileDataCreator.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using StockTransToDB.models;
|
||||||
|
|
||||||
|
namespace ReadSBAktieTrans
|
||||||
|
{
|
||||||
|
public interface IFileDataCreator
|
||||||
|
{
|
||||||
|
string CreateAndSave(Dictionary<int, string[]> dataStore);
|
||||||
|
IEnumerable<FileModel> CreateDataList(Dictionary<int, string[]> dataStore);
|
||||||
|
}
|
||||||
|
}
|
||||||
12
StockTransToDB/Runners/IFileToJson.cs
Normal file
12
StockTransToDB/Runners/IFileToJson.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using StockTransToDB.models;
|
||||||
|
|
||||||
|
namespace StockTransToDB.Runners
|
||||||
|
{
|
||||||
|
public interface IFileToJson
|
||||||
|
{
|
||||||
|
Dictionary<string, string> NameConverter { get; set; }
|
||||||
|
|
||||||
|
Task<List<FileModel>> FetchJsonData();
|
||||||
|
void UpDateWithSold(FileModel rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
StockTransToDB/StockTransToDB.csproj
Normal file
30
StockTransToDB/StockTransToDB.csproj
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Dapper" Version="2.0.123" />
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite.core" Version="6.0.8" />
|
||||||
|
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.1" />
|
||||||
|
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="2.1.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||||
|
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
334
StockTransToDB/StocksProviders/DapperStocksProvider.cs
Normal file
334
StockTransToDB/StocksProviders/DapperStocksProvider.cs
Normal file
@ -0,0 +1,334 @@
|
|||||||
|
using Dapper;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using StockTransToDB.DbConnections;
|
||||||
|
using StockTransToDB.models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.StocksProviders
|
||||||
|
{
|
||||||
|
public class DapperStocksProvider : IDapperStocksProvider
|
||||||
|
{
|
||||||
|
private const string GET_ALL_STOCKS_SQL = @"
|
||||||
|
SELECT *
|
||||||
|
FROM Stocks
|
||||||
|
WHERE Substring(Comment,1,Length(@RunId))='@RunId'";
|
||||||
|
|
||||||
|
private const string ADD_NEW_STOCKMEMBER = @"
|
||||||
|
INSERT INTO STOCKS (
|
||||||
|
StockId,
|
||||||
|
StockExtId,
|
||||||
|
BuyValue,
|
||||||
|
BuyDate,
|
||||||
|
ActValue,
|
||||||
|
ActDate,
|
||||||
|
ActAmount,
|
||||||
|
SoldValue,
|
||||||
|
SoldDate,
|
||||||
|
Comment,
|
||||||
|
PostAmount,
|
||||||
|
SoldStockPrice
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
@StockId,
|
||||||
|
@StockExtId,
|
||||||
|
@BuyValue,
|
||||||
|
@BuyDate,
|
||||||
|
@ActValue,
|
||||||
|
@ActDate,
|
||||||
|
@ActAmount,
|
||||||
|
@SoldValue,
|
||||||
|
@SoldDate,
|
||||||
|
@Comment,
|
||||||
|
@PostAmount,
|
||||||
|
@SoldStockPrice
|
||||||
|
)";
|
||||||
|
|
||||||
|
private const string UPDATE_STOCKMEMBER = @"
|
||||||
|
UPDATE Stocks
|
||||||
|
SET StockId = @StockId,
|
||||||
|
StockExtId = @StockExtId,
|
||||||
|
BuyValue = @BuyValue,
|
||||||
|
BuyDate = @BuyDate,
|
||||||
|
ActValue = @ActValue,
|
||||||
|
ActDate = @ActDate,
|
||||||
|
ActAmount = @ActAmount,
|
||||||
|
SoldValue = @SoldValue,
|
||||||
|
SoldDate = @SoldDate,
|
||||||
|
Comment = @Comment,
|
||||||
|
PostAmount = @PostAmount,
|
||||||
|
SoldStockPrice = @SoldStockPrice
|
||||||
|
WHERE Id = @Id";
|
||||||
|
|
||||||
|
private const string GET_STOCKS_BY_STOCKID = @"
|
||||||
|
SELECT *
|
||||||
|
FROM Stocks
|
||||||
|
WHERE StockId = @StockId
|
||||||
|
AND Substring(Comment,1,Length(@RunId))=@RunId
|
||||||
|
AND BuyDate <= @BuyDate
|
||||||
|
ORDER BY BuyDate DESC";
|
||||||
|
|
||||||
|
private const string GET_STOCKS_BY_STOCKIDPART = @"
|
||||||
|
SELECT *
|
||||||
|
FROM Stocks
|
||||||
|
WHERE Substring(StockId,1,@Length) = @StockIdPart
|
||||||
|
AND Substring(Comment,1,Length(@RunId))= @RunId
|
||||||
|
AND BuyDate <= @BuyDate
|
||||||
|
ORDER BY BuyDate DESC";
|
||||||
|
|
||||||
|
private const string ADD_TO_STOCKNAME = @"
|
||||||
|
Insert into StockNames (StockNameWeb, StockNameBank)
|
||||||
|
values ( @StockId, @StockId)";
|
||||||
|
|
||||||
|
private const string REMOVE_STOCKNAMES = @"
|
||||||
|
Delete
|
||||||
|
from StockNames";
|
||||||
|
|
||||||
|
private const string GET_WEB_STOCKNAMES = @"
|
||||||
|
select distinct StockId
|
||||||
|
from StocksOld";
|
||||||
|
|
||||||
|
private const string UPDATE_STOCKNAME_BANK = @"
|
||||||
|
UPDATE StockNames
|
||||||
|
SET StockNameBank = @StockNameBank
|
||||||
|
WHERE StockNameWeb = @StockNameWeb";
|
||||||
|
|
||||||
|
private const string GET_WEB_STOCKNAM_FULL = @"
|
||||||
|
SELECT *
|
||||||
|
FROM StockNames";
|
||||||
|
|
||||||
|
private const string WEB_STOCKNAMES_EXISTS = @"
|
||||||
|
SELECT CAST(
|
||||||
|
CASE WHEN EXISTS (
|
||||||
|
SELECT 1 FROM StockNames WHERE StockNameWeb = @StockNameWeb)
|
||||||
|
THEN 1 ELSE 0 END as BIT)";
|
||||||
|
|
||||||
|
private const string DELETE_STOCK_BY_ID = @"
|
||||||
|
SELECT *
|
||||||
|
FROM Stocks
|
||||||
|
WHERE Id = @Id";
|
||||||
|
|
||||||
|
private const string STOCKNAMES_BY_PART = @"
|
||||||
|
select StockName from StockGroups
|
||||||
|
where StockName like @NamePart";
|
||||||
|
|
||||||
|
private const string RESET_STOCK_COMMENTS = @"
|
||||||
|
Update Stocks
|
||||||
|
set Comment = substring(Comment,4)
|
||||||
|
where Substring(Comment,1,Length(@RunId))=@RunId";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private readonly SqliteDbConnectionFactory _sqliteDbConnectionFactory;
|
||||||
|
private readonly ILogger<DapperStocksProvider> _log;
|
||||||
|
|
||||||
|
public DapperStocksProvider(SqliteDbConnectionFactory sqliteDbConnectionFactory, ILogger<DapperStocksProvider> log)
|
||||||
|
{
|
||||||
|
_sqliteDbConnectionFactory = sqliteDbConnectionFactory;
|
||||||
|
_log = log;
|
||||||
|
}
|
||||||
|
public async Task AddStock(StockMember stockMember)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("ADD_NEW_STOCKMEMBER");
|
||||||
|
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
StockId = stockMember.StockId,
|
||||||
|
StockExtId = stockMember.StockExtId,
|
||||||
|
BuyValue = stockMember.BuyValue,
|
||||||
|
BuyDate = stockMember.BuyDate,
|
||||||
|
ActValue = stockMember.ActValue,
|
||||||
|
ActDate = stockMember.ActDate,
|
||||||
|
ActAmount = stockMember.ActAmount,
|
||||||
|
SoldValue = stockMember.SoldValue,
|
||||||
|
SoldDate = stockMember.SoldDate,
|
||||||
|
Comment = stockMember.Comment,
|
||||||
|
PostAmount = stockMember.PostAmount,
|
||||||
|
SoldStockPrice = stockMember.SoldStockPrice
|
||||||
|
};
|
||||||
|
|
||||||
|
await database.ExecuteAsync(ADD_NEW_STOCKMEMBER, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task AddWebStockNames(string stockName)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("ADD_TO_STOCKNAME");
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
StockId = stockName
|
||||||
|
};
|
||||||
|
await database.ExecuteAsync(ADD_TO_STOCKNAME, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task CleanStockNames()
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("REMOVE_STOCKNAMES");
|
||||||
|
await database.ExecuteAsync(REMOVE_STOCKNAMES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<IEnumerable<StockMember>> GetAllStocks()
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation(GET_ALL_STOCKS_SQL);
|
||||||
|
IEnumerable<StockMember> stockMembers = await database.QueryAsync<StockMember>(GET_ALL_STOCKS_SQL, new { RunId = ProcName.RunIdent });
|
||||||
|
return stockMembers.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<IEnumerable<string>> GetStockNames()
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("GET_WEB_STOCKNAMES");
|
||||||
|
|
||||||
|
IEnumerable<string> stockNames = await database.QueryAsync<string>(GET_WEB_STOCKNAMES);
|
||||||
|
return stockNames.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task<IEnumerable<StockMember>> GetStocksByStockId(string stockId, DateTime Affärsdag)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
// Obs ta hänsyn till köpdatum
|
||||||
|
_log.LogInformation("GET_STOCKS_BY_STOCKID");
|
||||||
|
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
StockId = stockId,
|
||||||
|
BuyDate = Affärsdag,
|
||||||
|
RunId = ProcName.RunIdent
|
||||||
|
};
|
||||||
|
|
||||||
|
IEnumerable<StockMember> stockMembers = await database.QueryAsync<StockMember>(GET_STOCKS_BY_STOCKID, parameters);
|
||||||
|
return stockMembers.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StockMember>> GetStocksByStockIdPart(string stockIdPart, DateTime Affärsdag)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
// Obs ta hänsyn till köpdatum
|
||||||
|
_log.LogInformation("GET_STOCKS_BY_STOCKIDPART");
|
||||||
|
var tmpstr = stockIdPart.Substring(0, stockIdPart.IndexOf(" "));
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
Length = tmpstr.Length,
|
||||||
|
StockIdPart = tmpstr,
|
||||||
|
BuyDate = Affärsdag,
|
||||||
|
RunId = ProcName.RunIdent
|
||||||
|
};
|
||||||
|
|
||||||
|
IEnumerable<StockMember> stockMembers = await database.QueryAsync<StockMember>(GET_STOCKS_BY_STOCKIDPART, parameters);
|
||||||
|
return stockMembers.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task UpdateStock(StockMember stockMember)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
Id = stockMember.Id,
|
||||||
|
StockId = stockMember.StockId,
|
||||||
|
StockExtId = stockMember.StockExtId,
|
||||||
|
BuyValue = stockMember.BuyValue,
|
||||||
|
BuyDate = stockMember.BuyDate,
|
||||||
|
ActValue = stockMember.ActValue,
|
||||||
|
ActDate = stockMember.ActDate,
|
||||||
|
ActAmount = stockMember.ActAmount,
|
||||||
|
SoldValue = stockMember.SoldValue,
|
||||||
|
SoldDate = stockMember.SoldDate,
|
||||||
|
Comment = stockMember.Comment,
|
||||||
|
PostAmount = stockMember.PostAmount,
|
||||||
|
SoldStockPrice = stockMember.SoldStockPrice
|
||||||
|
};
|
||||||
|
|
||||||
|
_log.LogInformation($"UPDATE_STOCKMEMBER {stockMember.Id} = {stockMember.StockId}");
|
||||||
|
|
||||||
|
await database.ExecuteAsync(UPDATE_STOCKMEMBER, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async Task UpdateStockName(string stockNameBank, string stockNameWeb)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
|
||||||
|
var exists = await database.ExecuteScalarAsync<bool>(WEB_STOCKNAMES_EXISTS, new { StockNameWeb = stockNameWeb });
|
||||||
|
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
await AddWebStockNames(stockNameWeb);
|
||||||
|
}
|
||||||
|
|
||||||
|
object parameters = new
|
||||||
|
{
|
||||||
|
StockNameBank = stockNameBank,
|
||||||
|
StockNameWeb = stockNameWeb,
|
||||||
|
};
|
||||||
|
|
||||||
|
_log.LogInformation($"UPDATE_STOCKNAME_BANK {stockNameBank} , {stockNameWeb}");
|
||||||
|
|
||||||
|
await database.ExecuteAsync(UPDATE_STOCKNAME_BANK, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StockNames>> GetStockNameTable()
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("GET_WEB_STOCKNAMES");
|
||||||
|
|
||||||
|
IEnumerable<StockNames> stockNames = await database.QueryAsync<StockNames>(GET_WEB_STOCKNAM_FULL);
|
||||||
|
return stockNames.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task RemoveStockById(int id)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
// Obs ta hänsyn till köpdatum
|
||||||
|
_log.LogInformation("DELETE_STOCK_BY_ID");
|
||||||
|
|
||||||
|
await database.ExecuteAsync(DELETE_STOCK_BY_ID, new { Id = id });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<List<string>> GetStockNamesByPart(string idPart)
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
_log.LogInformation("STOCKNAMES_BY_PART");
|
||||||
|
|
||||||
|
|
||||||
|
var stockNames = await database.QueryAsync<string>(STOCKNAMES_BY_PART, new { NamePart = "%" + idPart + "%" });
|
||||||
|
return stockNames.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//RESET_STOCK_COMMENTS
|
||||||
|
public async Task ResetCommentsFromNew()
|
||||||
|
{
|
||||||
|
using (IDbConnection database = _sqliteDbConnectionFactory.Connect())
|
||||||
|
{
|
||||||
|
// Obs ta hänsyn till köpdatum
|
||||||
|
_log.LogInformation("RESET_STOCK_COMMENTS");
|
||||||
|
|
||||||
|
await database.ExecuteAsync(RESET_STOCK_COMMENTS,new {RunId = ProcName.RunIdent });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
StockTransToDB/StocksProviders/IDapperStocksProvider.cs
Normal file
21
StockTransToDB/StocksProviders/IDapperStocksProvider.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using StockTransToDB.models;
|
||||||
|
|
||||||
|
namespace StockTransToDB.StocksProviders
|
||||||
|
{
|
||||||
|
public interface IDapperStocksProvider
|
||||||
|
{
|
||||||
|
Task AddStock(StockMember stockMember);
|
||||||
|
Task AddWebStockNames(string stockName);
|
||||||
|
Task CleanStockNames();
|
||||||
|
Task<IEnumerable<StockMember>> GetAllStocks();
|
||||||
|
Task<IEnumerable<string>> GetStockNames();
|
||||||
|
Task<List<string>> GetStockNamesByPart(string idPart);
|
||||||
|
Task<IEnumerable<StockNames>> GetStockNameTable();
|
||||||
|
Task<IEnumerable<StockMember>> GetStocksByStockId(string stockId, DateTime Affärsdag);
|
||||||
|
Task<IEnumerable<StockMember>> GetStocksByStockIdPart(string stockIdPart, DateTime Affärsdag);
|
||||||
|
Task RemoveStockById(int id);
|
||||||
|
Task ResetCommentsFromNew();
|
||||||
|
Task UpdateStock(StockMember stockMember);
|
||||||
|
Task UpdateStockName(string stockNameBank, string stockNameWeb);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
StockTransToDB/appsettings.json
Normal file
16
StockTransToDB/appsettings.json
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"TransFile": "Skandiabanken_transaktioner_insatsen.xls",
|
||||||
|
"StdFileName": "StockData2022-09-14.txt",
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Override": {
|
||||||
|
"Microsoft": "Information",
|
||||||
|
"System": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"Default": "Data source=C:\\Aktier\\net6.0-windows\\NewData\\Stocks.db"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
StockTransToDB/models/Address.cs
Normal file
12
StockTransToDB/models/Address.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
StockTransToDB/models/BackupRegister.cs
Normal file
11
StockTransToDB/models/BackupRegister.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
StockTransToDB/models/DiTraderStockRow.cs
Normal file
16
StockTransToDB/models/DiTraderStockRow.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
19
StockTransToDB/models/FileModel.cs
Normal file
19
StockTransToDB/models/FileModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class FileModel
|
||||||
|
{
|
||||||
|
public DateTime Bokföringsdag { get; set; }
|
||||||
|
public DateTime Affärsdag { get; set; }
|
||||||
|
public DateTime Likviddag { get; set; }
|
||||||
|
public string Valuta { get; set; }
|
||||||
|
public string ISIN { get; set; }
|
||||||
|
public string Transaktionstyp { get; set; }
|
||||||
|
public string Beskrivning { get; set; }
|
||||||
|
public string Specifikation { get; set; }
|
||||||
|
public int Antal { get; set; }
|
||||||
|
public decimal Kurs { get; set; }
|
||||||
|
public decimal Belopp { get; set; }
|
||||||
|
public decimal Saldo { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
8
StockTransToDB/models/LatestSoldStock.cs
Normal file
8
StockTransToDB/models/LatestSoldStock.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class LatestSoldStock
|
||||||
|
{
|
||||||
|
public decimal SoldStockPrice { get; set; }
|
||||||
|
public DateTime? LatestSoldDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
StockTransToDB/models/Person.cs
Normal file
16
StockTransToDB/models/Person.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace StockTransToDB.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 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
11
StockTransToDB/models/PersonStock.cs
Normal file
11
StockTransToDB/models/PersonStock.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class PersonStock
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int PersonId { get; set; }
|
||||||
|
public int StockId { get; set; }
|
||||||
|
public string Comment { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
28
StockTransToDB/models/ProcName.cs
Normal file
28
StockTransToDB/models/ProcName.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public static class ProcName
|
||||||
|
{
|
||||||
|
public const string BYTE_INLAGG_VP = "BYTE INLÄGG VP";
|
||||||
|
public const string BYTE_UTTAG_VP = "BYTE UTTAG VP";
|
||||||
|
public const string DECIMALER_LIKVID = "DECIMALER LIKVID";
|
||||||
|
public const string DECIMALER_UTTAG_VP = "DECIMALER UTTAG VP";
|
||||||
|
public const string INLAGG_FISSION = "INLÄGG FISSION";
|
||||||
|
public const string INLOSEN_LIKVID = "INLÖSEN LIKVID";
|
||||||
|
public const string INLOSEN_UTTAG_VP = "INLÖSEN UTTAG VP";
|
||||||
|
public const string INSATTNING = "INSÄTTNING";
|
||||||
|
public const string KOPT = "KÖPT";
|
||||||
|
public const string SPLIT_INLÄGG_VP = "SPLIT INLÄGG VP";
|
||||||
|
public const string SPLIT_UTTAG_VP = "SPLIT UTTAG VP";
|
||||||
|
public const string SALT = "SÅLT";
|
||||||
|
public const string UTDELNING = "UTDELNING";
|
||||||
|
public const string UTL_KUPSKATT = "UTL KUPSKATT";
|
||||||
|
public const string UTTAG = "UTTAG";
|
||||||
|
public static string RunIdent { get; set; } = "xx";
|
||||||
|
}
|
||||||
|
}
|
||||||
10
StockTransToDB/models/ShareModel.cs
Normal file
10
StockTransToDB/models/ShareModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class ShareModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string GroupName { get; set; }
|
||||||
|
public string StockName { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
9
StockTransToDB/models/StockGroupModel.cs
Normal file
9
StockTransToDB/models/StockGroupModel.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class StockGroupModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string StockGroup { get; set; }
|
||||||
|
public string StockName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
9
StockTransToDB/models/StockGrpPers.cs
Normal file
9
StockTransToDB/models/StockGrpPers.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class StockGrpPers
|
||||||
|
{
|
||||||
|
public string StockId { get; set; }
|
||||||
|
public string StockGroup { get; set; }
|
||||||
|
public int PersId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
27
StockTransToDB/models/StockMember.cs
Normal file
27
StockTransToDB/models/StockMember.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
namespace StockTransToDB.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; }
|
||||||
|
public decimal SoldStockPrice { get; set; }
|
||||||
|
|
||||||
|
//public decimal PostValue
|
||||||
|
//{
|
||||||
|
// get { return ActAmount * ActValue; }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
14
StockTransToDB/models/StockNames.cs
Normal file
14
StockTransToDB/models/StockNames.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StockTransToDB.models
|
||||||
|
{
|
||||||
|
public class StockNames
|
||||||
|
{
|
||||||
|
public string StockNameWeb { get; set; }
|
||||||
|
public string StockNameBank { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
25
StockTransToDBApp.sln
Normal file
25
StockTransToDBApp.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.3.32825.248
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StockTransToDB", "StockTransToDB\StockTransToDB.csproj", "{5362240B-812B-4980-96AF-E1AADDE72C0B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5362240B-812B-4980-96AF-E1AADDE72C0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5362240B-812B-4980-96AF-E1AADDE72C0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5362240B-812B-4980-96AF-E1AADDE72C0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5362240B-812B-4980-96AF-E1AADDE72C0B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {0442A087-824F-4B88-AD24-C5D055CCD670}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user