Add project files.
This commit is contained in:
25
MyYearlyCountings.sln
Normal file
25
MyYearlyCountings.sln
Normal file
@ -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
|
||||
26
MyYearlyCountings/Data/DataContext.cs
Normal file
26
MyYearlyCountings/Data/DataContext.cs
Normal file
@ -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<DataContext> options, IConfiguration configuration) : base(options)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder
|
||||
.UseSqlite(_configuration.GetConnectionString("DefaultConnection"));
|
||||
}
|
||||
|
||||
public DbSet<Member> Members { get; set; }
|
||||
public DbSet<AccountRecord> AccountRecords { get; set; }
|
||||
|
||||
}
|
||||
8
MyYearlyCountings/Facades/IReadingIn.cs
Normal file
8
MyYearlyCountings/Facades/IReadingIn.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace MyYearlyCountings.Facades
|
||||
{
|
||||
public interface IReadingIn
|
||||
{
|
||||
bool ReadAndSaveInvoices(string fullFileName);
|
||||
IEnumerable<AccountRecord> ReadExcelInvoices(string fullFileName);
|
||||
}
|
||||
}
|
||||
159
MyYearlyCountings/Facades/ReadingIn.cs
Normal file
159
MyYearlyCountings/Facades/ReadingIn.cs
Normal file
@ -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<ReadingIn> _logger;
|
||||
private readonly IAccountRecordRepository _accountRecordRepository;
|
||||
|
||||
public ReadingIn(
|
||||
IConfiguration configuration,
|
||||
ILogger<ReadingIn> logger,
|
||||
IAccountRecordRepository accountRecordRepository)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
_accountRecordRepository = accountRecordRepository;
|
||||
}
|
||||
|
||||
// @"C:\dev\MyYearlyCountings\TransactionsTest.xls"
|
||||
public IEnumerable<AccountRecord> ReadExcelInvoices(string fullFileName)
|
||||
{
|
||||
List<AccountRecord> records = new List<AccountRecord>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
14
MyYearlyCountings/Helpers/Extensions.cs
Normal file
14
MyYearlyCountings/Helpers/Extensions.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
BIN
MyYearlyCountings/Local.db
Normal file
BIN
MyYearlyCountings/Local.db
Normal file
Binary file not shown.
81
MyYearlyCountings/Migrations/20230526154227_Initial.Designer.cs
generated
Normal file
81
MyYearlyCountings/Migrations/20230526154227_Initial.Designer.cs
generated
Normal file
@ -0,0 +1,81 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Avisering")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Belopp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTime>("BetalDatum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Konto")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Mottagare")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AccountRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MyYearlyCountings.Models.Member", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NickName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PersonType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Members");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
58
MyYearlyCountings/Migrations/20230526154227_Initial.cs
Normal file
58
MyYearlyCountings/Migrations/20230526154227_Initial.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MyYearlyCountings.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Initial : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "AccountRecords",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
BetalDatum = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Mottagare = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Konto = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Belopp = table.Column<double>(type: "REAL", nullable: false),
|
||||
Avisering = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_AccountRecords", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Members",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
FirstName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
LastName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
NickName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
PersonType = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Members", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "AccountRecords");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Members");
|
||||
}
|
||||
}
|
||||
}
|
||||
78
MyYearlyCountings/Migrations/DataContextModelSnapshot.cs
Normal file
78
MyYearlyCountings/Migrations/DataContextModelSnapshot.cs
Normal file
@ -0,0 +1,78 @@
|
||||
// <auto-generated />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Avisering")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("Belopp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTime>("BetalDatum")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Konto")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Mottagare")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("AccountRecords");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MyYearlyCountings.Models.Member", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("NickName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PersonType")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Members");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
19
MyYearlyCountings/Models/AccountRecord.cs
Normal file
19
MyYearlyCountings/Models/AccountRecord.cs
Normal file
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
17
MyYearlyCountings/Models/Member.cs
Normal file
17
MyYearlyCountings/Models/Member.cs
Normal file
@ -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;
|
||||
|
||||
}
|
||||
58
MyYearlyCountings/MyYearlyCountings.csproj
Normal file
58
MyYearlyCountings/MyYearlyCountings.csproj
Normal file
@ -0,0 +1,58 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>MyYearlyCountings</AssemblyName>
|
||||
<RootNamespace>MyYearlyCountings</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<COMReference Include="Microsoft.Office.Interop.Excel">
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<VersionMinor>9</VersionMinor>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<Guid>00020813-0000-0000-c000-000000000046</Guid>
|
||||
<Lcid>0</Lcid>
|
||||
<Isolated>false</Isolated>
|
||||
<EmbedInteropTypes>true</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.5" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.Production.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Local.db">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
39
MyYearlyCountings/Program.cs
Normal file
39
MyYearlyCountings/Program.cs
Normal file
@ -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<Worker>((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<ISampleRepository, SampleRepository>();
|
||||
services.AddScoped<IMemberRepository, MemberRepository>();
|
||||
services.AddScoped<IAccountRecordRepository, AccountRecordRepository>();
|
||||
services.AddScoped<IReadingIn, ReadingIn>();
|
||||
services.AddDbContext<DataContext>();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
18
MyYearlyCountings/Properties/launchSettings.json
Normal file
18
MyYearlyCountings/Properties/launchSettings.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
57
MyYearlyCountings/Repositories/AccountRecordRepository.cs
Normal file
57
MyYearlyCountings/Repositories/AccountRecordRepository.cs
Normal file
@ -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<MemberRepository> _logger;
|
||||
|
||||
public AccountRecordRepository(DataContext dataContext, IConfiguration configuration, ILogger<MemberRepository> 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<AccountRecord> GetAllAccounts()
|
||||
{
|
||||
return _dataContext.AccountRecords;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
namespace MyYearlyCountings.Repositories
|
||||
{
|
||||
public interface IAccountRecordRepository
|
||||
{
|
||||
bool AddAccountRecord(AccountRecord record);
|
||||
bool DeleteAccountRecord(AccountRecord record);
|
||||
IEnumerable<AccountRecord> GetAllAccounts();
|
||||
}
|
||||
}
|
||||
9
MyYearlyCountings/Repositories/IMemberRepository.cs
Normal file
9
MyYearlyCountings/Repositories/IMemberRepository.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using MyYearlyCountings.Models;
|
||||
|
||||
namespace MyYearlyCountings.Repositories
|
||||
{
|
||||
public interface IMemberRepository
|
||||
{
|
||||
IEnumerable<Member> InsertMember(Member member);
|
||||
}
|
||||
}
|
||||
7
MyYearlyCountings/Repositories/ISampleRepository.cs
Normal file
7
MyYearlyCountings/Repositories/ISampleRepository.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace MyYearlyCountings.Repositories
|
||||
{
|
||||
public interface ISampleRepository
|
||||
{
|
||||
void DoSomething();
|
||||
}
|
||||
}
|
||||
33
MyYearlyCountings/Repositories/MemberRepository.cs
Normal file
33
MyYearlyCountings/Repositories/MemberRepository.cs
Normal file
@ -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<MemberRepository> logger)
|
||||
{
|
||||
_dataContext = dataContext;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IEnumerable<Member> InsertMember(Member member)
|
||||
{
|
||||
_dataContext.Members.Add(member);
|
||||
_dataContext.SaveChanges();
|
||||
return _dataContext.Members.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
28
MyYearlyCountings/Repositories/SampleRepository.cs
Normal file
28
MyYearlyCountings/Repositories/SampleRepository.cs
Normal file
@ -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<SampleRepository> _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<SampleRepository> logger)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
}
|
||||
23
MyYearlyCountings/UI/KeyHandling.cs
Normal file
23
MyYearlyCountings/UI/KeyHandling.cs
Normal file
@ -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<KeyHandling> _logger;
|
||||
|
||||
public KeyHandling(IConfiguration configuration, ILogger<KeyHandling> logger)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
66
MyYearlyCountings/Worker.cs
Normal file
66
MyYearlyCountings/Worker.cs
Normal file
@ -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<Worker> _logger;
|
||||
private readonly ISampleRepository _sampleRepository;
|
||||
private readonly IMemberRepository _memberRepository;
|
||||
private readonly IAccountRecordRepository _accountRecordRepository;
|
||||
private readonly IReadingIn _readingIn;
|
||||
|
||||
public Worker(IConfiguration configuration,
|
||||
ILogger<Worker> 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} "));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
MyYearlyCountings/appsettings.Development.json
Normal file
5
MyYearlyCountings/appsettings.Development.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=.\\Local.db"
|
||||
}
|
||||
}
|
||||
5
MyYearlyCountings/appsettings.Production.json
Normal file
5
MyYearlyCountings/appsettings.Production.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=Prodserver;Database=ProdDb;User Id==MeMyselfAndI;Password=SuperSecret"
|
||||
}
|
||||
}
|
||||
5
MyYearlyCountings/appsettings.json
Normal file
5
MyYearlyCountings/appsettings.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=.\\Local.db"
|
||||
}
|
||||
}
|
||||
177
TransactionsTest.xls
Normal file
177
TransactionsTest.xls
Normal file
@ -0,0 +1,177 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<HTML>
|
||||
|
||||
<HEAD>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<style type="text/css">
|
||||
.personInfo {
|
||||
font-size: 10pt;
|
||||
font-weight: bold;
|
||||
}
|
||||
.SHBHeader {
|
||||
font-weight: bold;
|
||||
}
|
||||
.eventSum {
|
||||
font-weight: bold;
|
||||
}
|
||||
.colBelopp, .totalSeparatorExcel, .amountSeparatorExcel {
|
||||
mso-number-format: #\ ##0\.00;
|
||||
}
|
||||
</style>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<span class="person">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="585">
|
||||
<tbody>
|
||||
<tr><td colspan="9" nowrap>
|
||||
<span class="personInfo">
|
||||
Period: 2023-05-29 till 2023-07-13
|
||||
|
||||
Trans.typ: Alla
|
||||
|
||||
Person: TOMMY <20>MAN
|
||||
|
||||
Antal transaktioner: 9
|
||||
</span>
|
||||
</td></tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<table class="eventTable" border="0" cellpadding="0" cellspacing="0" width="585">
|
||||
<tbody>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<tr class="groupSeparator"><td colspan="9"></td></tr>
|
||||
|
||||
<tr class="groupHeader"><td colspan="9">
|
||||
|
||||
<b>
|
||||
Maj
|
||||
|
||||
R<>kningar o L<>n 256 658 498
|
||||
</b>
|
||||
|
||||
|
||||
|
||||
<b>Disponibelt belopp:
|
||||
|
||||
19 165,19
|
||||
|
||||
</b>
|
||||
</td></tr>
|
||||
|
||||
|
||||
|
||||
<TR><TD class="SHBHeader">Datum</TD><TD width="5" class="SHBHeader"> </TD><TD class="SHBHeader">Mottagare</TD><TD width="5" class="SHBHeader"> </TD><TD class="SHBHeader">Konto</TD><TD width="5" class="SHBHeader"> </TD><TD align="right" class="SHBHeader">Belopp</TD><TD width="5" class="SHBHeader"> </TD><TD class="SHBHeader">Avisering</TD></TR>
|
||||
<TR><TD height="15" align="left">2023-05-30</TD><TD> </TD><TD align="left">ST1 FINANCE MASTERCARD</TD><TD> </TD><TD align="left">PG 4779504-2</TD><TD> </TD><TD align="right" class="colBelopp">2 240,79</TD><TD> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR BGCOLOR="#F0F0F0"><TD height="15" align="left">2023-05-31</TD><TD> </TD><TD align="left">ECSTER - KONTO OCH KORT</TD><TD> </TD><TD align="left">Bg 847-2425</TD><TD> </TD><TD align="right" class="colBelopp">2 358,00</TD><TD> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR><TD height="15" align="left">2023-05-31</TD><TD> </TD><TD align="left">TRANSPORTSTYRELSEN FORDONSSKATT</TD><TD> </TD><TD align="left">Bg 5051-6822</TD><TD> </TD><TD align="right" class="colBelopp">3 636,00</TD><TD> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR BGCOLOR="#F0F0F0"><TD height="15" align="left">2023-05-31</TD><TD> </TD><TD align="left">VERISURE SVERIGE</TD><TD> </TD><TD align="left">PG 4784604-3</TD><TD> </TD><TD align="right" class="colBelopp">1 978,00</TD><TD> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
|
||||
|
||||
|
||||
|
||||
<tr><td height="4" colspan="9"></td></tr>
|
||||
|
||||
<tr class="groupFooter">
|
||||
<td colspan="6">
|
||||
<b>Totalt</b>
|
||||
</td>
|
||||
<td align="right" class="amountSeparatorExcel"><b><b>10 212,79</b></b></td>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<tr class="groupHeader"><td colspan="9" class="monthSeparator">
|
||||
<b>
|
||||
Juni
|
||||
</b>
|
||||
</td></tr>
|
||||
|
||||
|
||||
|
||||
<TR><TD height="15" align="left">2023-06-01</TD><TD width="5"> </TD><TD align="left">STADSHYPOTEK</TD><TD width="5"> </TD><TD align="left">HS 10272130</TD><TD width="5"> </TD><TD align="right" class="colBelopp">6 778,00</TD><TD width="5"> </TD><TD nowrap>L<>neavi</TD></TR>
|
||||
<TR BGCOLOR="#F0F0F0"><TD height="15" align="left">2023-06-05</TD><TD width="5"> </TD><TD align="left">IF SKADEF<45>RS<52>KRING AB</TD><TD width="5"> </TD><TD align="left">Bg 5270-6009</TD><TD width="5"> </TD><TD align="right" class="colBelopp">71,00</TD><TD width="5"> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR><TD height="15" align="left">2023-06-07</TD><TD width="5"> </TD><TD align="left">ERIKS F<>NSTERPUTS</TD><TD width="5"> </TD><TD align="left">Bg 5787-1030</TD><TD width="5"> </TD><TD align="right" class="colBelopp">1 066,00</TD><TD width="5"> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR BGCOLOR="#F0F0F0"><TD height="15" align="left">2023-06-12</TD><TD width="5"> </TD><TD align="left">AMERICAN EXPRESS 3757</TD><TD width="5"> </TD><TD align="left">Bg 730-8596</TD><TD width="5"> </TD><TD align="right" class="colBelopp">276,00</TD><TD width="5"> </TD><TD nowrap>E-faktura</TD></TR>
|
||||
<TR><TD height="15" align="left">2023-06-22</TD><TD width="5"> </TD><TD align="left">SVEA EKONOMI AB</TD><TD width="5"> </TD><TD align="left">PG 4163600-2</TD><TD width="5"> </TD><TD align="right" class="colBelopp">218,00</TD><TD width="5"> </TD><TD nowrap> </TD></TR>
|
||||
|
||||
|
||||
|
||||
|
||||
<tr><td height="4" colspan="9"></td></tr>
|
||||
|
||||
<tr class="groupFooter">
|
||||
<td colspan="6">
|
||||
<b>Totalt</b>
|
||||
</td>
|
||||
<td align="right" class="amountSeparatorExcel"><b><b>8 409,00</b></b></td>
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</span>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
Reference in New Issue
Block a user