diff --git a/Least_Sign_To_Most_Sign.jpg b/Least_Sign_To_Most_Sign.jpg new file mode 100644 index 0000000..bc21762 Binary files /dev/null and b/Least_Sign_To_Most_Sign.jpg differ diff --git a/WinFormDi.BLR/AccountRecordRepository.cs b/WinFormDi.BLR/AccountRecordRepository.cs index 9d784ba..4ad49cc 100644 --- a/WinFormDi.BLR/AccountRecordRepository.cs +++ b/WinFormDi.BLR/AccountRecordRepository.cs @@ -29,7 +29,7 @@ public class AccountRecordRepository : IAccountRecordRepository } catch (Exception e) { - _logger.LogError($"Error occured in AddAccountRecord :{e.Message}"); + _logger.LogError("Error occured in AddAccountRecord :-->{iMessage}", e.Message); } return false; @@ -45,7 +45,7 @@ public class AccountRecordRepository : IAccountRecordRepository } catch (Exception e) { - _logger.LogError($"Error occured in DeleteAccountRecord :{e.Message}"); + _logger.LogError("Error occured in DeleteAccountRecord :-->{iMessage}", e.Message); } return false; } diff --git a/WinFormDi.BLR/ReadingIn.cs b/WinFormDi.BLR/ReadingIn.cs index 0764f92..a1151d4 100644 --- a/WinFormDi.BLR/ReadingIn.cs +++ b/WinFormDi.BLR/ReadingIn.cs @@ -129,7 +129,7 @@ public class ReadingIn : IReadingIn } catch (Exception ex) { - _logger.LogError($"MassUppdatering misslyckat: {ex.Message}"); + _logger.LogError("MassUppdatering misslyckat: -->{iMessage}", ex.Message); result = false; } } diff --git a/WinFormDi/Local.db b/WinFormDi/Local.db index 9fa637c..56cdba0 100644 Binary files a/WinFormDi/Local.db and b/WinFormDi/Local.db differ diff --git a/WinFormDi/Local.db-shm b/WinFormDi/Local.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/WinFormDi/Local.db-shm differ diff --git a/WinFormDi/Local.db-wal b/WinFormDi/Local.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/WinFormDi/Program.cs b/WinFormDi/Program.cs index 47adc1a..ab8fa4e 100644 --- a/WinFormDi/Program.cs +++ b/WinFormDi/Program.cs @@ -1,8 +1,11 @@ using DIDemoLib; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using WinFormDiApp.DAL; using WinFormDiApp.DAL.Data; +using Serilog; +using Serilog.Formatting.Json; namespace WinFormDiApp { @@ -14,12 +17,20 @@ namespace WinFormDiApp [STAThread] static void Main(string[] args) { + Log.Logger = new LoggerConfiguration() + .WriteTo.Console() + .WriteTo.File(@"D:\logs\winformApp.txt",restrictedToMinimumLevel:Serilog.Events.LogEventLevel.Information, + rollingInterval: RollingInterval.Day) + .CreateLogger(); + var host = ContainerConfig.Configure(CreateHostBuilder(args)); using var scope = host.Services.CreateScope(); try { + Log.Information("Starting of service.."); + var services = scope.ServiceProvider; var context = services.GetRequiredService(); @@ -34,13 +45,26 @@ namespace WinFormDiApp } catch (Exception ex) { - Console.WriteLine($"An error has occured: {ex.Message}"); + Log.Fatal(ex, "Exception in application"); + } + finally + { + Log.Information("Exiting service.."); + Log.CloseAndFlush(); } } public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args); + Host.CreateDefaultBuilder(args) + .UseSerilog() + .ConfigureLogging((context, logging) => + { + logging.ClearProviders(); + logging.AddConfiguration(context.Configuration.GetSection("Logging")); + logging.AddConsole(); + logging.AddDebug(); + }); diff --git a/WinFormDi/WinFormDi.csproj b/WinFormDi/WinFormDi.csproj index 9717390..a8e4289 100644 --- a/WinFormDi/WinFormDi.csproj +++ b/WinFormDi/WinFormDi.csproj @@ -17,6 +17,10 @@ + + + + diff --git a/WinFormDi/appsettings.json b/WinFormDi/appsettings.json index c51253c..fcd71cc 100644 --- a/WinFormDi/appsettings.json +++ b/WinFormDi/appsettings.json @@ -1,16 +1,26 @@ { - "EPPlus": { - "ExcelPackage": { - "LicenseContext": "Noncommercial" //The license context used - } - }, - "ConnectionStrings": { + "ConnectionStrings": { "DatabaseConnection": "Data Source=.\\Local.db" }, "Logging": { - "LogLevel": { - "Default": "Warning" - } - }, + "Console": { + "LogLevel": { + "Default": "Information", + "Microsoft*": "Warning" + } + }, + "Debug": { + "LogLevel": { + "Default": "Warning", + "Microsoft*": "Warning" + } + }, + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Warning", + "Microsoft*": "Warning" + } + }, "AllowedHosts": "*" } diff --git a/WinFormDi/frmPayments.cs b/WinFormDi/frmPayments.cs index f8be8cb..2bfdd27 100644 --- a/WinFormDi/frmPayments.cs +++ b/WinFormDi/frmPayments.cs @@ -24,6 +24,7 @@ namespace WinFormDiApp private void frmPayments_Load(object sender, EventArgs e) { + lvPayments.Items.Clear(); var payments = _accountRecordRepository.GetAllAccounts(); foreach (var account in payments) { diff --git a/WinFormDi/frmReadPayments.Designer.cs b/WinFormDi/frmReadPayments.Designer.cs index c9502c2..5913225 100644 --- a/WinFormDi/frmReadPayments.Designer.cs +++ b/WinFormDi/frmReadPayments.Designer.cs @@ -92,7 +92,7 @@ // // btnClose // - btnClose.Location = new Point(758, 418); + btnClose.Location = new Point(758, 506); btnClose.Name = "btnClose"; btnClose.Size = new Size(75, 23); btnClose.TabIndex = 1; @@ -107,7 +107,7 @@ lvPayouts.Columns.AddRange(new ColumnHeader[] { columnHeader1, columnHeader2, columnHeader3, columnHeader4, columnHeader5, columnHeader6 }); lvPayouts.Location = new Point(28, 107); lvPayouts.Name = "lvPayouts"; - lvPayouts.Size = new Size(805, 286); + lvPayouts.Size = new Size(805, 393); lvPayouts.TabIndex = 2; lvPayouts.UseCompatibleStateImageBehavior = false; lvPayouts.View = View.Details; @@ -183,7 +183,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(856, 453); + ClientSize = new Size(856, 541); Controls.Add(btnStartRead); Controls.Add(lblTransFileName); Controls.Add(btnChooseFile); diff --git a/WinFormDi/frmReadPayments.cs b/WinFormDi/frmReadPayments.cs index 4151151..db93a10 100644 --- a/WinFormDi/frmReadPayments.cs +++ b/WinFormDi/frmReadPayments.cs @@ -17,6 +17,7 @@ namespace WinFormDiApp _accountRecordRepository = accountRecordRepository; _readingIn = readingIn; _logger = logger; + } @@ -42,10 +43,11 @@ namespace WinFormDiApp if (!_readingIn.ReadAndSaveInvoices(lblTransFileName.Text)) { var resUlt = _readingIn.readXLS(lblTransFileName.Text); - resUlt.ToList().ForEach(rec => _logger.LogInformation($"Konto :{rec.Konto}, {rec.Belopp}")); + resUlt.ToList().ForEach(rec => _logger.LogInformation("Konto :{sKonto}, {dBelopp}", rec.Konto, rec.Belopp)); } else { + lvPayouts.Items.Clear(); var payments = _accountRecordRepository.GetAllAccounts(); foreach (var account in payments) { @@ -61,5 +63,7 @@ namespace WinFormDiApp btnStartRead.Enabled = false; btnStartRead.Visible = false; } + + } } diff --git a/WinFormDi/frmReadPayments.resx b/WinFormDi/frmReadPayments.resx index bb88643..b19cc54 100644 --- a/WinFormDi/frmReadPayments.resx +++ b/WinFormDi/frmReadPayments.resx @@ -120,4 +120,7 @@ 17, 17 + + 25 + \ No newline at end of file diff --git a/WinFormDiApp.BL/Models/AccountRecord.cs b/WinFormDiApp.BL/Models/AccountRecord.cs index f9045de..1db1133 100644 --- a/WinFormDiApp.BL/Models/AccountRecord.cs +++ b/WinFormDiApp.BL/Models/AccountRecord.cs @@ -14,6 +14,7 @@ namespace WinFormDiApp.BL.Models public string Konto { get; set; } = string.Empty; public double Belopp { get; set; } public string Avisering { get; set; } = string.Empty; + public DateTime Stored { get; set;} = DateTime.Now.ToLocalTime(); } } diff --git a/WinFormDiApp.DAL/ApplicationDbContext.cs b/WinFormDiApp.DAL/ApplicationDbContext.cs index 5bb5308..397a88c 100644 --- a/WinFormDiApp.DAL/ApplicationDbContext.cs +++ b/WinFormDiApp.DAL/ApplicationDbContext.cs @@ -11,8 +11,23 @@ namespace WinFormDiApp.DAL public virtual DbSet Members { get; set; } public virtual DbSet AccountRecords { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasIndex(e => new + { + e.BetalDatum, + e.Belopp, + e.Konto + }) + .IsUnique(); + } + + } + public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory { public ApplicationDbContext CreateDbContext(string[] args) diff --git a/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.Designer.cs b/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.Designer.cs new file mode 100644 index 0000000..2892aec --- /dev/null +++ b/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.Designer.cs @@ -0,0 +1,88 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WinFormDiApp.DAL; + +#nullable disable + +namespace WinFormDiApp.DAL.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230901070448_storingdate")] + partial class storingdate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.10"); + + modelBuilder.Entity("WinFormDiApp.BL.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.Property("Stored") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("AccountRecords"); + }); + + modelBuilder.Entity("WinFormDiApp.BL.Models.Member", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + 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/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.cs b/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.cs new file mode 100644 index 0000000..e186a4c --- /dev/null +++ b/WinFormDiApp.DAL/Migrations/20230901070448_storingdate.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WinFormDiApp.DAL.Migrations +{ + /// + public partial class storingdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Stored", + table: "AccountRecords", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Stored", + table: "AccountRecords"); + } + } +} diff --git a/WinFormDiApp.DAL/Migrations/20230903161124_multikey.Designer.cs b/WinFormDiApp.DAL/Migrations/20230903161124_multikey.Designer.cs new file mode 100644 index 0000000..21fbfca --- /dev/null +++ b/WinFormDiApp.DAL/Migrations/20230903161124_multikey.Designer.cs @@ -0,0 +1,91 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using WinFormDiApp.DAL; + +#nullable disable + +namespace WinFormDiApp.DAL.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230903161124_multikey")] + partial class multikey + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.10"); + + modelBuilder.Entity("WinFormDiApp.BL.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.Property("Stored") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("BetalDatum", "Belopp", "Konto") + .IsUnique(); + + b.ToTable("AccountRecords"); + }); + + modelBuilder.Entity("WinFormDiApp.BL.Models.Member", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + 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/WinFormDiApp.DAL/Migrations/20230903161124_multikey.cs b/WinFormDiApp.DAL/Migrations/20230903161124_multikey.cs new file mode 100644 index 0000000..c01c6b7 --- /dev/null +++ b/WinFormDiApp.DAL/Migrations/20230903161124_multikey.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace WinFormDiApp.DAL.Migrations +{ + /// + public partial class multikey : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_AccountRecords_BetalDatum_Belopp_Konto", + table: "AccountRecords", + columns: new[] { "BetalDatum", "Belopp", "Konto" }, + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_AccountRecords_BetalDatum_Belopp_Konto", + table: "AccountRecords"); + } + } +} diff --git a/WinFormDiApp.DAL/Migrations/ApplicationDbContextModelSnapshot.cs b/WinFormDiApp.DAL/Migrations/ApplicationDbContextModelSnapshot.cs index 744a85a..a06f728 100644 --- a/WinFormDiApp.DAL/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/WinFormDiApp.DAL/Migrations/ApplicationDbContextModelSnapshot.cs @@ -41,8 +41,14 @@ namespace WinFormDiApp.DAL.Migrations .IsRequired() .HasColumnType("TEXT"); + b.Property("Stored") + .HasColumnType("TEXT"); + b.HasKey("Id"); + b.HasIndex("BetalDatum", "Belopp", "Konto") + .IsUnique(); + b.ToTable("AccountRecords"); });