diff --git a/MyYearlyCountings.sln b/MyYearlyCountings.sln new file mode 100644 index 0000000..ae4ede4 --- /dev/null +++ b/MyYearlyCountings.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33627.172 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyYearlyCountings", "MyYearlyCountings\MyYearlyCountings.csproj", "{8C92891D-C347-4A5C-AAE4-D50F705F00A4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C92891D-C347-4A5C-AAE4-D50F705F00A4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {305DAD26-537A-41D7-9A94-9B4911FAF44A} + EndGlobalSection +EndGlobal diff --git a/MyYearlyCountings/Data/DataContext.cs b/MyYearlyCountings/Data/DataContext.cs new file mode 100644 index 0000000..1a5b8b5 --- /dev/null +++ b/MyYearlyCountings/Data/DataContext.cs @@ -0,0 +1,26 @@ + +using Microsoft.Extensions.Configuration; +using MyYearlyCountings.Models; + +namespace MyYearlyCountings.Data; + +public class DataContext : DbContext +{ + private readonly IConfiguration _configuration; + + public DataContext(DbContextOptions options, IConfiguration configuration) : base(options) + { + _configuration = configuration; + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + base.OnConfiguring(optionsBuilder); + optionsBuilder + .UseSqlite(_configuration.GetConnectionString("DefaultConnection")); + } + + public DbSet Members { get; set; } + public DbSet AccountRecords { get; set; } + +} diff --git a/MyYearlyCountings/Facades/IReadingIn.cs b/MyYearlyCountings/Facades/IReadingIn.cs new file mode 100644 index 0000000..eed3b07 --- /dev/null +++ b/MyYearlyCountings/Facades/IReadingIn.cs @@ -0,0 +1,8 @@ +namespace MyYearlyCountings.Facades +{ + public interface IReadingIn + { + bool ReadAndSaveInvoices(string fullFileName); + IEnumerable ReadExcelInvoices(string fullFileName); + } +} \ No newline at end of file diff --git a/MyYearlyCountings/Facades/ReadingIn.cs b/MyYearlyCountings/Facades/ReadingIn.cs new file mode 100644 index 0000000..168853e --- /dev/null +++ b/MyYearlyCountings/Facades/ReadingIn.cs @@ -0,0 +1,159 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using MyYearlyCountings.Helpers; +using MyYearlyCountings.Repositories; +using System.Runtime.InteropServices; +using Excel = Microsoft.Office.Interop.Excel; + + +namespace MyYearlyCountings.Facades; + +public class ReadingIn : IReadingIn +{ + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + private readonly IAccountRecordRepository _accountRecordRepository; + + public ReadingIn( + IConfiguration configuration, + ILogger logger, + IAccountRecordRepository accountRecordRepository) + { + _configuration = configuration; + _logger = logger; + _accountRecordRepository = accountRecordRepository; + } + + // @"C:\dev\MyYearlyCountings\TransactionsTest.xls" + public IEnumerable ReadExcelInvoices(string fullFileName) + { + List records = new List(); + AccountRecord? record = null; + + Excel.Application xlApp = new Excel.Application(); + Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(fullFileName); + Excel.Worksheet xlWorksheet = xlWorkbook.Sheets[1]; + Excel.Range xlRange = xlWorksheet.UsedRange; + + var rowCount = xlRange.Rows.Count; + var colCount = xlRange.Columns.Count; + var prt = false; + + + //iterate over the rows and columns and print to the console as it appears in the file + //excel is not zero based!! + for (int i = 1; i <= rowCount; i++) + { + for (int j = 1; j <= colCount; j++) + { + //new line + if (j == 1) + { + if (prt) + { + Console.Write("\r\n"); + records.Add(record); + } + prt = false; + + } + //write the value to the console + if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null) + { + string xx = xlRange.Cells[i, j].Value2.ToString(); + if ((j == 1) && xx.IsNumeric()) + { + DateTime dt = DateTime.FromOADate(xlRange.Cells[i, j].Value2); + prt = true; + if (prt) + { + Console.Write(dt.ToShortDateString() + "\t"); + record = new AccountRecord(); + record.BetalDatum = dt; + } + } + else + { + if (prt) + { + Console.Write(xlRange.Cells[i, j].Value2.ToString() + "\t"); + switch (j) + { + case 3: + { + record.Mottagare = xlRange.Cells[i, j].Value2.ToString(); + break; + } + case 5: + { + record.Konto = xlRange.Cells[i, j].Value2.ToString(); + break; + } + case 7: + { + record.Belopp = xlRange.Cells[i, j].Value2; + break; + } + case 9: + { + record.Avisering = xlRange.Cells[i, j].Value2.ToString(); + break; + } + + } + } + } + } + //add useful things here! + } + } + + //cleanup + GC.Collect(); + GC.WaitForPendingFinalizers(); + + //rule of thumb for releasing com objects: + // never use two dots, all COM objects must be referenced and released individually + // ex: [somthing].[something].[something] is bad + + //release com objects to fully kill excel process from running in the background + Marshal.ReleaseComObject(xlRange); + Marshal.ReleaseComObject(xlWorksheet); + + //close and release + xlWorkbook.Close(); + Marshal.ReleaseComObject(xlWorkbook); + + //quit and release + xlApp.Quit(); + Marshal.ReleaseComObject(xlApp); + + return records; + } + + public bool ReadAndSaveInvoices(string fullFileName) + { + var result = true; + var restab = ReadExcelInvoices(fullFileName); + if (restab != null) + { + try + { + + restab.ToList().ForEach(x => { + _accountRecordRepository.AddAccountRecord(x); + }); + +// restab.ToList().ForEach(x => { _accountRecordRepository.AddAccountRecord(x); }); + } + catch (Exception ex) + { + _logger.LogError($"MassUppdatering misslyckat: {ex.Message}"); + result = false; + } + } + + return result; + } + +} diff --git a/MyYearlyCountings/Helpers/Extensions.cs b/MyYearlyCountings/Helpers/Extensions.cs new file mode 100644 index 0000000..b3b984f --- /dev/null +++ b/MyYearlyCountings/Helpers/Extensions.cs @@ -0,0 +1,14 @@ +namespace MyYearlyCountings.Helpers; + +public static class Extensions +{ + public static bool IsNumeric(this string value) + { + if (!string.IsNullOrEmpty(value)) + { + if (value.All(char.IsDigit)) return true; + else return false; + } + else return false; + } +} diff --git a/MyYearlyCountings/Local.db b/MyYearlyCountings/Local.db new file mode 100644 index 0000000..c59cc3f Binary files /dev/null and b/MyYearlyCountings/Local.db differ diff --git a/MyYearlyCountings/Migrations/20230526154227_Initial.Designer.cs b/MyYearlyCountings/Migrations/20230526154227_Initial.Designer.cs new file mode 100644 index 0000000..b774e9b --- /dev/null +++ b/MyYearlyCountings/Migrations/20230526154227_Initial.Designer.cs @@ -0,0 +1,81 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyYearlyCountings.Data; + +#nullable disable + +namespace MyYearlyCountings.Migrations +{ + [DbContext(typeof(DataContext))] + [Migration("20230526154227_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.5"); + + modelBuilder.Entity("MyYearlyCountings.Models.AccountRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Avisering") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Belopp") + .HasColumnType("REAL"); + + b.Property("BetalDatum") + .HasColumnType("TEXT"); + + b.Property("Konto") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Mottagare") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("AccountRecords"); + }); + + modelBuilder.Entity("MyYearlyCountings.Models.Member", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NickName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PersonType") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MyYearlyCountings/Migrations/20230526154227_Initial.cs b/MyYearlyCountings/Migrations/20230526154227_Initial.cs new file mode 100644 index 0000000..5774388 --- /dev/null +++ b/MyYearlyCountings/Migrations/20230526154227_Initial.cs @@ -0,0 +1,58 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MyYearlyCountings.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AccountRecords", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + BetalDatum = table.Column(type: "TEXT", nullable: false), + Mottagare = table.Column(type: "TEXT", nullable: false), + Konto = table.Column(type: "TEXT", nullable: false), + Belopp = table.Column(type: "REAL", nullable: false), + Avisering = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AccountRecords", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Members", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + FirstName = table.Column(type: "TEXT", nullable: false), + LastName = table.Column(type: "TEXT", nullable: false), + NickName = table.Column(type: "TEXT", nullable: false), + PersonType = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Members", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AccountRecords"); + + migrationBuilder.DropTable( + name: "Members"); + } + } +} diff --git a/MyYearlyCountings/Migrations/DataContextModelSnapshot.cs b/MyYearlyCountings/Migrations/DataContextModelSnapshot.cs new file mode 100644 index 0000000..a025b71 --- /dev/null +++ b/MyYearlyCountings/Migrations/DataContextModelSnapshot.cs @@ -0,0 +1,78 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyYearlyCountings.Data; + +#nullable disable + +namespace MyYearlyCountings.Migrations +{ + [DbContext(typeof(DataContext))] + partial class DataContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.5"); + + modelBuilder.Entity("MyYearlyCountings.Models.AccountRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Avisering") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Belopp") + .HasColumnType("REAL"); + + b.Property("BetalDatum") + .HasColumnType("TEXT"); + + b.Property("Konto") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Mottagare") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("AccountRecords"); + }); + + modelBuilder.Entity("MyYearlyCountings.Models.Member", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NickName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PersonType") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Members"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MyYearlyCountings/Models/AccountRecord.cs b/MyYearlyCountings/Models/AccountRecord.cs new file mode 100644 index 0000000..766a6d8 --- /dev/null +++ b/MyYearlyCountings/Models/AccountRecord.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyYearlyCountings.Models +{ + public class AccountRecord + { + public int Id { get; set; } + public DateTime BetalDatum { get; set; } = DateTime.MinValue; + public string Mottagare { get; set; } = string.Empty; + public string Konto { get; set; } = string.Empty; + public double Belopp { get; set;} + public string Avisering { get; set; } = string.Empty; + + } +} diff --git a/MyYearlyCountings/Models/Member.cs b/MyYearlyCountings/Models/Member.cs new file mode 100644 index 0000000..1868509 --- /dev/null +++ b/MyYearlyCountings/Models/Member.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyYearlyCountings.Models; + +public class Member +{ + public int Id { get; set; } + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string NickName { get; set; } = string.Empty; + public string PersonType { get; set; } = string.Empty; + +} diff --git a/MyYearlyCountings/MyYearlyCountings.csproj b/MyYearlyCountings/MyYearlyCountings.csproj new file mode 100644 index 0000000..6687585 --- /dev/null +++ b/MyYearlyCountings/MyYearlyCountings.csproj @@ -0,0 +1,58 @@ + + + + Exe + net7.0 + enable + enable + MyYearlyCountings + MyYearlyCountings + + + + + tlbimp + 9 + 1 + 00020813-0000-0000-c000-000000000046 + 0 + false + true + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + Always + + + Always + + + Always + + + Always + + + + + + + + diff --git a/MyYearlyCountings/Program.cs b/MyYearlyCountings/Program.cs new file mode 100644 index 0000000..599bf1e --- /dev/null +++ b/MyYearlyCountings/Program.cs @@ -0,0 +1,39 @@ +// See https://aka.ms/new-console-template for more information +global using MyYearlyCountings.Models; +global using Microsoft.EntityFrameworkCore; + +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using MyYearlyCountings.Repositories; +using MyYearlyCountings.Data; +using MyYearlyCountings.Facades; + +IHost host = CreateHostBuilder(args).Build(); +var worker = ActivatorUtilities.CreateInstance((IServiceProvider)host.Services); +worker.Run(); + +static IHostBuilder CreateHostBuilder(string[] args) +{ + return Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration((context, configuration) => + { + configuration.Sources.Clear(); + var environmentName = Environment.GetEnvironmentVariable("DOTNETCORE_ENVIRONMENT"); + configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); + configuration.AddJsonFile($"appsettings.{environmentName}.json", optional: true, reloadOnChange: true); + configuration.AddCommandLine(args); + + }) + .ConfigureServices((context, services) => + { + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddDbContext(); + + }); +} + + diff --git a/MyYearlyCountings/Properties/launchSettings.json b/MyYearlyCountings/Properties/launchSettings.json new file mode 100644 index 0000000..f967768 --- /dev/null +++ b/MyYearlyCountings/Properties/launchSettings.json @@ -0,0 +1,18 @@ +{ + "profiles": { + "StandardConsole": { + "commandName": "Project", + "commandLineArgs": "key1=val1 key2=val2 UI=XLS", + "environmentVariables": { + "DOTNETCORE_ENVIRONMENT": "Development" + } + }, + "ProductVersion": { + "commandName": "Project", + "commandLineArgs": "key1=val1 key2=val2", + "environmentVariables": { + "DOTNETCORE_ENVIRONMENT": "Production" + } + } + } +} \ No newline at end of file diff --git a/MyYearlyCountings/Repositories/AccountRecordRepository.cs b/MyYearlyCountings/Repositories/AccountRecordRepository.cs new file mode 100644 index 0000000..11e1630 --- /dev/null +++ b/MyYearlyCountings/Repositories/AccountRecordRepository.cs @@ -0,0 +1,57 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using MyYearlyCountings.Data; +using System.Reflection; + +namespace MyYearlyCountings.Repositories; + +public class AccountRecordRepository : IAccountRecordRepository +{ + private readonly DataContext _dataContext; + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public AccountRecordRepository(DataContext dataContext, IConfiguration configuration, ILogger logger) + { + _dataContext = dataContext; + _configuration = configuration; + _logger = logger; + } + + public bool AddAccountRecord(AccountRecord record) + { + try + { + _dataContext.AccountRecords.Add(record); + _dataContext.SaveChanges(); + return true; + } + catch (Exception e) + { + _logger.LogError($"Error occured in AddAccountRecord :{e.Message}"); + } + return false; + + } + + public bool DeleteAccountRecord(AccountRecord record) + { + try + { + _dataContext.AccountRecords.Remove(record); + _dataContext.SaveChanges(); + return true; + } + catch (Exception e) + { + _logger.LogError($"Error occured in DeleteAccountRecord :{e.Message}"); + } + return false; + } + + public IEnumerable GetAllAccounts() + { + return _dataContext.AccountRecords; + } + +} diff --git a/MyYearlyCountings/Repositories/IAccountRecordRepository.cs b/MyYearlyCountings/Repositories/IAccountRecordRepository.cs new file mode 100644 index 0000000..33d9b3c --- /dev/null +++ b/MyYearlyCountings/Repositories/IAccountRecordRepository.cs @@ -0,0 +1,9 @@ +namespace MyYearlyCountings.Repositories +{ + public interface IAccountRecordRepository + { + bool AddAccountRecord(AccountRecord record); + bool DeleteAccountRecord(AccountRecord record); + IEnumerable GetAllAccounts(); + } +} \ No newline at end of file diff --git a/MyYearlyCountings/Repositories/IMemberRepository.cs b/MyYearlyCountings/Repositories/IMemberRepository.cs new file mode 100644 index 0000000..8c07d20 --- /dev/null +++ b/MyYearlyCountings/Repositories/IMemberRepository.cs @@ -0,0 +1,9 @@ +using MyYearlyCountings.Models; + +namespace MyYearlyCountings.Repositories +{ + public interface IMemberRepository + { + IEnumerable InsertMember(Member member); + } +} \ No newline at end of file diff --git a/MyYearlyCountings/Repositories/ISampleRepository.cs b/MyYearlyCountings/Repositories/ISampleRepository.cs new file mode 100644 index 0000000..00416cb --- /dev/null +++ b/MyYearlyCountings/Repositories/ISampleRepository.cs @@ -0,0 +1,7 @@ +namespace MyYearlyCountings.Repositories +{ + public interface ISampleRepository + { + void DoSomething(); + } +} \ No newline at end of file diff --git a/MyYearlyCountings/Repositories/MemberRepository.cs b/MyYearlyCountings/Repositories/MemberRepository.cs new file mode 100644 index 0000000..9bf1393 --- /dev/null +++ b/MyYearlyCountings/Repositories/MemberRepository.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using MyYearlyCountings.Data; +using MyYearlyCountings.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyYearlyCountings.Repositories; + +public class MemberRepository : IMemberRepository +{ + private readonly DataContext _dataContext; + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public MemberRepository(DataContext dataContext, IConfiguration configuration, ILogger logger) + { + _dataContext = dataContext; + _configuration = configuration; + _logger = logger; + } + + public IEnumerable InsertMember(Member member) + { + _dataContext.Members.Add(member); + _dataContext.SaveChanges(); + return _dataContext.Members.ToArray(); + } + +} diff --git a/MyYearlyCountings/Repositories/SampleRepository.cs b/MyYearlyCountings/Repositories/SampleRepository.cs new file mode 100644 index 0000000..e70de92 --- /dev/null +++ b/MyYearlyCountings/Repositories/SampleRepository.cs @@ -0,0 +1,28 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyYearlyCountings.Repositories; + +public class SampleRepository : ISampleRepository +{ + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public void DoSomething() + { + _logger.LogInformation($"{nameof(SampleRepository)}.Dosomething - just did something"); + var connString = _configuration.GetConnectionString("DefaultConnection"); + _logger.LogInformation($"The Connection string from Sample Repository: {connString}"); + } + public SampleRepository(IConfiguration configuration, ILogger logger) + { + _configuration = configuration; + _logger = logger; + } + +} diff --git a/MyYearlyCountings/UI/KeyHandling.cs b/MyYearlyCountings/UI/KeyHandling.cs new file mode 100644 index 0000000..7144894 --- /dev/null +++ b/MyYearlyCountings/UI/KeyHandling.cs @@ -0,0 +1,23 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyYearlyCountings.UI +{ + public class KeyHandling + { + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public KeyHandling(IConfiguration configuration, ILogger logger) + { + _configuration = configuration; + _logger = logger; + } + + } +} diff --git a/MyYearlyCountings/Worker.cs b/MyYearlyCountings/Worker.cs new file mode 100644 index 0000000..7811122 --- /dev/null +++ b/MyYearlyCountings/Worker.cs @@ -0,0 +1,66 @@ +// See https://aka.ms/new-console-template for more information +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using MyYearlyCountings.Facades; +using MyYearlyCountings.Repositories; + +public class Worker +{ + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + private readonly ISampleRepository _sampleRepository; + private readonly IMemberRepository _memberRepository; + private readonly IAccountRecordRepository _accountRecordRepository; + private readonly IReadingIn _readingIn; + + public Worker(IConfiguration configuration, + ILogger logger, + ISampleRepository sampleRepository, + IMemberRepository memberRepository, + IAccountRecordRepository accountRecordRepository, + IReadingIn readingIn) + { + _configuration = configuration; + _logger = logger; + _sampleRepository = sampleRepository; + _memberRepository = memberRepository; + _accountRecordRepository = accountRecordRepository; + _readingIn = readingIn; + } + public void Run() + { + if (_configuration["UI"] == "NO") { + _logger.LogInformation("Hello, world!!!"); + var connString = _configuration.GetConnectionString("DefaultConnection"); + _logger.LogInformation($"Connection string: {connString}"); + _logger.LogInformation($"key1: {_configuration["key1"]}"); + _logger.LogInformation($"key2: {_configuration["key2"]}"); + _sampleRepository.DoSomething(); + } + else + { + if (_configuration["UI"] == "XLS") + { + if (!_readingIn.ReadAndSaveInvoices(@"C:\dev\MyYearlyCountings\TransactionsTest.xls")) + { + var resUlt = _readingIn.ReadExcelInvoices(@"C:\dev\MyYearlyCountings\TransactionsTest.xls"); + resUlt.ToList().ForEach(rec => _logger.LogInformation($"Konto :{rec.Konto}, {rec.Belopp}")); + } + } + else + { + var ar = new AccountRecord { Konto = "BG 0867-4533", Mottagare = "NoOne", Belopp = 1270.34, BetalDatum = DateTime.Now.AddDays(10), Avisering = "Efaktura" }; + if (_accountRecordRepository.AddAccountRecord(ar)) + { + var records = _accountRecordRepository.GetAllAccounts(); + records.ToList().ForEach(rec => _logger.LogInformation($"Konto :{rec.Konto}, {rec.Belopp}")); + } + var member = new Member { FirstName = "Per", LastName = "Persson", NickName = "Peppe", PersonType = "Kontohavare" }; + var members = _memberRepository.InsertMember(member); + members.ToList().ForEach(member => _logger.LogInformation($"medlem: {member.FirstName}, {member.LastName} ")); + } + } + + } + +} \ No newline at end of file diff --git a/MyYearlyCountings/appsettings.Development.json b/MyYearlyCountings/appsettings.Development.json new file mode 100644 index 0000000..c552cd8 --- /dev/null +++ b/MyYearlyCountings/appsettings.Development.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Data Source=.\\Local.db" + } +} diff --git a/MyYearlyCountings/appsettings.Production.json b/MyYearlyCountings/appsettings.Production.json new file mode 100644 index 0000000..58a25e9 --- /dev/null +++ b/MyYearlyCountings/appsettings.Production.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=Prodserver;Database=ProdDb;User Id==MeMyselfAndI;Password=SuperSecret" + } +} diff --git a/MyYearlyCountings/appsettings.json b/MyYearlyCountings/appsettings.json new file mode 100644 index 0000000..c552cd8 --- /dev/null +++ b/MyYearlyCountings/appsettings.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Data Source=.\\Local.db" + } +} diff --git a/TransactionsTest.xls b/TransactionsTest.xls new file mode 100644 index 0000000..a4d945e --- /dev/null +++ b/TransactionsTest.xls @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Period: 2023-05-29 till 2023-07-13 +   + Trans.typ: Alla +   + Person: TOMMY ÖMAN +   + Antal transaktioner: 9 + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + Maj +     + Räkningar o Lån 256 658 498 + + + +      +Disponibelt belopp: + +  19 165,19 + + +
Datum Mottagare Konto Belopp Avisering
2023-05-30 ST1 FINANCE MASTERCARD PG 4779504-2 2 240,79 E-faktura
2023-05-31 ECSTER - KONTO OCH KORT Bg 847-2425 2 358,00 E-faktura
2023-05-31 TRANSPORTSTYRELSEN FORDONSSKATT Bg 5051-6822 3 636,00 E-faktura
2023-05-31 VERISURE SVERIGE PG 4784604-3 1 978,00 E-faktura
+ Totalt +10 212,79 
+ + Juni + +
2023-06-01 STADSHYPOTEK HS 10272130 6 778,00 Låneavi
2023-06-05 IF SKADEFÖRSÄKRING AB Bg 5270-6009 71,00 E-faktura
2023-06-07 ERIKS FÖNSTERPUTS Bg 5787-1030 1 066,00 E-faktura
2023-06-12 AMERICAN EXPRESS 3757 Bg 730-8596 276,00 E-faktura
2023-06-22 SVEA EKONOMI AB PG 4163600-2 218,00  
+ Totalt +8 409,00 
+ + + + \ No newline at end of file