From 70c2d47e7bf5c64d9efc50a196d41b5df40f671b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 24 Aug 2023 11:47:44 +0200 Subject: [PATCH] Repositories inserted and new page for accounts inserted --- WinFormDi.BLI/IAccountRecordRepository.cs | 11 ++ WinFormDi.BLI/IMemberRepository.cs | 9 ++ WinFormDi.BLI/WinFormDiApp.BLI.csproj | 13 +++ WinFormDi.BLR/AccountRecordRepository.cs | 58 +++++++++++ WinFormDi.BLR/MemberRepository.cs | 29 ++++++ WinFormDi.BLR/WinFormDiApp.BLR.csproj | 15 +++ WinFormDi/ContainerConfig.cs | 11 +- WinFormDi/MainWindow.Designer.cs | 27 +++-- WinFormDi/MainWindow.cs | 15 ++- WinFormDi/MainWindow.resx | 2 +- WinFormDi/Program.cs | 2 +- WinFormDi/WinFormDi.csproj | 2 + WinFormDi/frmPayments.Designer.cs | 116 +++++++++++++++++++++ WinFormDi/frmPayments.cs | 43 ++++++++ WinFormDi/frmPayments.resx | 120 ++++++++++++++++++++++ WinFormDiApp.sln | 16 ++- 16 files changed, 472 insertions(+), 17 deletions(-) create mode 100644 WinFormDi.BLI/IAccountRecordRepository.cs create mode 100644 WinFormDi.BLI/IMemberRepository.cs create mode 100644 WinFormDi.BLI/WinFormDiApp.BLI.csproj create mode 100644 WinFormDi.BLR/AccountRecordRepository.cs create mode 100644 WinFormDi.BLR/MemberRepository.cs create mode 100644 WinFormDi.BLR/WinFormDiApp.BLR.csproj create mode 100644 WinFormDi/frmPayments.Designer.cs create mode 100644 WinFormDi/frmPayments.cs create mode 100644 WinFormDi/frmPayments.resx diff --git a/WinFormDi.BLI/IAccountRecordRepository.cs b/WinFormDi.BLI/IAccountRecordRepository.cs new file mode 100644 index 0000000..9a57c35 --- /dev/null +++ b/WinFormDi.BLI/IAccountRecordRepository.cs @@ -0,0 +1,11 @@ +using WinFormDiApp.BL.Models; + +namespace WinFormDiApp.BLI +{ + public interface IAccountRecordRepository + { + bool AddAccountRecord(AccountRecord record); + bool DeleteAccountRecord(AccountRecord record); + IEnumerable GetAllAccounts(); + } +} \ No newline at end of file diff --git a/WinFormDi.BLI/IMemberRepository.cs b/WinFormDi.BLI/IMemberRepository.cs new file mode 100644 index 0000000..858c17c --- /dev/null +++ b/WinFormDi.BLI/IMemberRepository.cs @@ -0,0 +1,9 @@ +using WinFormDiApp.BL.Models; + +namespace WinFormDiApp.BLI +{ + public interface IMemberRepository + { + IEnumerable InsertMember(Member member); + } +} \ No newline at end of file diff --git a/WinFormDi.BLI/WinFormDiApp.BLI.csproj b/WinFormDi.BLI/WinFormDiApp.BLI.csproj new file mode 100644 index 0000000..1de62b1 --- /dev/null +++ b/WinFormDi.BLI/WinFormDiApp.BLI.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/WinFormDi.BLR/AccountRecordRepository.cs b/WinFormDi.BLR/AccountRecordRepository.cs new file mode 100644 index 0000000..9d784ba --- /dev/null +++ b/WinFormDi.BLR/AccountRecordRepository.cs @@ -0,0 +1,58 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using WinFormDiApp.BL.Models; +using WinFormDiApp.BLI; +using WinFormDiApp.DAL; + +namespace WinFormDiApp.BLR; + +public class AccountRecordRepository : IAccountRecordRepository +{ + private readonly ApplicationDbContext _dataContext; + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public AccountRecordRepository(ApplicationDbContext 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/WinFormDi.BLR/MemberRepository.cs b/WinFormDi.BLR/MemberRepository.cs new file mode 100644 index 0000000..42be176 --- /dev/null +++ b/WinFormDi.BLR/MemberRepository.cs @@ -0,0 +1,29 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using WinFormDiApp.BL.Models; +using WinFormDiApp.BLI; +using WinFormDiApp.DAL; + +namespace WinFormDiApp.BLR; + +public class MemberRepository : IMemberRepository +{ + private readonly ApplicationDbContext _dataContext; + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public MemberRepository(ApplicationDbContext 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/WinFormDi.BLR/WinFormDiApp.BLR.csproj b/WinFormDi.BLR/WinFormDiApp.BLR.csproj new file mode 100644 index 0000000..25851ce --- /dev/null +++ b/WinFormDi.BLR/WinFormDiApp.BLR.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + enable + enable + + + + + + + + + diff --git a/WinFormDi/ContainerConfig.cs b/WinFormDi/ContainerConfig.cs index 06bba8b..9a116d1 100644 --- a/WinFormDi/ContainerConfig.cs +++ b/WinFormDi/ContainerConfig.cs @@ -11,8 +11,11 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using WinFormDiApp.DAL; +using WinFormDiApp.BL; +using WinFormDiApp.BLI; +using WinFormDiApp.BLR; -namespace WinFormDi +namespace WinFormDiApp { public static class ContainerConfig { @@ -34,7 +37,11 @@ namespace WinFormDi .AddDbContext(options => options.UseSqlite(conn)) .AddTransient() - .AddTransient(); + .AddTransient() + .AddTransient() + .AddTransient() + .AddTransient(); + }); return builder.Build(); } diff --git a/WinFormDi/MainWindow.Designer.cs b/WinFormDi/MainWindow.Designer.cs index 6198c60..30c87d5 100644 --- a/WinFormDi/MainWindow.Designer.cs +++ b/WinFormDi/MainWindow.Designer.cs @@ -1,4 +1,4 @@ -namespace WinFormDi +namespace WinFormDiApp { partial class MainWindow { @@ -30,33 +30,45 @@ { helloText = new Label(); goodbyeText = new Label(); + btnCheckPayments = new Button(); SuspendLayout(); // // helloText // helloText.AutoSize = true; - helloText.Font = new Font("Segoe UI", 20.25F, FontStyle.Regular, GraphicsUnit.Point); - helloText.Location = new Point(45, 55); + helloText.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point); + helloText.Location = new Point(12, 9); helloText.Name = "helloText"; - helloText.Size = new Size(83, 37); + helloText.Size = new Size(45, 19); helloText.TabIndex = 0; helloText.Text = "------"; // // goodbyeText // goodbyeText.AutoSize = true; - goodbyeText.Font = new Font("Segoe UI", 20.25F, FontStyle.Regular, GraphicsUnit.Point); - goodbyeText.Location = new Point(45, 129); + goodbyeText.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point); + goodbyeText.Location = new Point(12, 422); goodbyeText.Name = "goodbyeText"; - goodbyeText.Size = new Size(83, 37); + goodbyeText.Size = new Size(45, 19); goodbyeText.TabIndex = 1; goodbyeText.Text = "------"; // + // btnCheckPayments + // + btnCheckPayments.Location = new Point(73, 46); + btnCheckPayments.Name = "btnCheckPayments"; + btnCheckPayments.Size = new Size(156, 23); + btnCheckPayments.TabIndex = 2; + btnCheckPayments.Text = "Kontrollera Betalningar"; + btnCheckPayments.UseVisualStyleBackColor = true; + btnCheckPayments.Click += btnCheckPayments_Click; + // // MainWindow // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(btnCheckPayments); Controls.Add(goodbyeText); Controls.Add(helloText); Name = "MainWindow"; @@ -71,5 +83,6 @@ private Label helloText; private Label goodbyeText; + private Button btnCheckPayments; } } \ No newline at end of file diff --git a/WinFormDi/MainWindow.cs b/WinFormDi/MainWindow.cs index e895899..3700827 100644 --- a/WinFormDi/MainWindow.cs +++ b/WinFormDi/MainWindow.cs @@ -9,27 +9,34 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace WinFormDi +namespace WinFormDiApp { public partial class MainWindow : Form { private readonly IMessages _messages; + private readonly frmPayments _payments; - public MainWindow(IMessages messages) + public MainWindow(IMessages messages, frmPayments payments) { InitializeComponent(); _messages = messages; + _payments = payments; } private void MainWindow_Load(object sender, EventArgs e) { - helloText.Text= _messages.SayHello(); + helloText.Text = _messages.SayHello(); } private void MainWindow_FormClosing(object sender, FormClosingEventArgs e) { - goodbyeText.Text= _messages.SayGoodBye(); + goodbyeText.Text = _messages.SayGoodBye(); MessageBox.Show("Closing...", "Warning", MessageBoxButtons.OK); } + + private void btnCheckPayments_Click(object sender, EventArgs e) + { + _payments.ShowDialog(); + } } } diff --git a/WinFormDi/MainWindow.resx b/WinFormDi/MainWindow.resx index a395bff..af32865 100644 --- a/WinFormDi/MainWindow.resx +++ b/WinFormDi/MainWindow.resx @@ -18,7 +18,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, ... System.Resources.ResXResourceWriter, System.Windows.Forms, ... this is my long stringthis is a comment - Blue + Blue [base64 mime encoded serialized .NET Framework object] diff --git a/WinFormDi/Program.cs b/WinFormDi/Program.cs index de0755b..47adc1a 100644 --- a/WinFormDi/Program.cs +++ b/WinFormDi/Program.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Hosting; using WinFormDiApp.DAL; using WinFormDiApp.DAL.Data; -namespace WinFormDi +namespace WinFormDiApp { internal static class Program { diff --git a/WinFormDi/WinFormDi.csproj b/WinFormDi/WinFormDi.csproj index 8b9cb88..7ce132a 100644 --- a/WinFormDi/WinFormDi.csproj +++ b/WinFormDi/WinFormDi.csproj @@ -21,6 +21,8 @@ + + diff --git a/WinFormDi/frmPayments.Designer.cs b/WinFormDi/frmPayments.Designer.cs new file mode 100644 index 0000000..c72685e --- /dev/null +++ b/WinFormDi/frmPayments.Designer.cs @@ -0,0 +1,116 @@ +namespace WinFormDiApp +{ + partial class frmPayments + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + lvPayments = new ListView(); + ch1_Id = new ColumnHeader(); + ch2_Mottagare = new ColumnHeader(); + ch3_Konto = new ColumnHeader(); + ch4_Belopp = new ColumnHeader(); + ch5_Förfallodag = new ColumnHeader(); + ch6_Avisering = new ColumnHeader(); + btnClose = new Button(); + SuspendLayout(); + // + // lvPayments + // + lvPayments.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + lvPayments.BackColor = Color.FromArgb(192, 255, 255); + lvPayments.Columns.AddRange(new ColumnHeader[] { ch1_Id, ch2_Mottagare, ch3_Konto, ch4_Belopp, ch5_Förfallodag, ch6_Avisering }); + lvPayments.Location = new Point(28, 55); + lvPayments.Name = "lvPayments"; + lvPayments.Size = new Size(805, 286); + lvPayments.TabIndex = 0; + lvPayments.UseCompatibleStateImageBehavior = false; + lvPayments.View = View.Details; + // + // ch1_Id + // + ch1_Id.Text = "Id"; + // + // ch2_Mottagare + // + ch2_Mottagare.Text = "Mottagare"; + ch2_Mottagare.Width = 120; + // + // ch3_Konto + // + ch3_Konto.Text = "Konto"; + ch3_Konto.Width = 100; + // + // ch4_Belopp + // + ch4_Belopp.Text = "Belopp"; + ch4_Belopp.Width = 100; + // + // ch5_Förfallodag + // + ch5_Förfallodag.Text = "Förfallodag"; + ch5_Förfallodag.Width = 100; + // + // ch6_Avisering + // + ch6_Avisering.Text = "Avisering"; + ch6_Avisering.Width = 100; + // + // btnClose + // + btnClose.Location = new Point(758, 418); + btnClose.Name = "btnClose"; + btnClose.Size = new Size(75, 23); + btnClose.TabIndex = 1; + btnClose.Text = "Stäng"; + btnClose.UseVisualStyleBackColor = true; + btnClose.Click += btnClose_Click; + // + // frmPayments + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(856, 453); + Controls.Add(btnClose); + Controls.Add(lvPayments); + Name = "frmPayments"; + Text = "frmPayments"; + Load += frmPayments_Load; + ResumeLayout(false); + } + + #endregion + + private ListView lvPayments; + private ColumnHeader ch1_Id; + private ColumnHeader ch2_Mottagare; + private ColumnHeader ch3_Konto; + private ColumnHeader ch4_Belopp; + private ColumnHeader ch6_Avisering; + private Button btnClose; + private ColumnHeader ch5_Förfallodag; + } +} \ No newline at end of file diff --git a/WinFormDi/frmPayments.cs b/WinFormDi/frmPayments.cs new file mode 100644 index 0000000..49c659e --- /dev/null +++ b/WinFormDi/frmPayments.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using WinFormDiApp.BLI; + +namespace WinFormDiApp +{ + public partial class frmPayments : Form + { + private readonly IAccountRecordRepository _accountRecordRepository; + + public frmPayments(IAccountRecordRepository accountRecordRepository) + { + InitializeComponent(); + _accountRecordRepository = accountRecordRepository; + } + + private void frmPayments_Load(object sender, EventArgs e) + { + var payments = _accountRecordRepository.GetAllAccounts(); + foreach (var account in payments) + { + var lvitem = lvPayments.Items.Add(account.Id.ToString()); + lvitem.SubItems.Add(account.Mottagare); + lvitem.SubItems.Add(account.Konto); + lvitem.SubItems.Add(account.Belopp.ToString()); + lvitem.SubItems.Add(account.BetalDatum.ToShortDateString()); + lvitem.SubItems.Add(account.Avisering); + } + } + + private void btnClose_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/WinFormDi/frmPayments.resx b/WinFormDi/frmPayments.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormDi/frmPayments.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinFormDiApp.sln b/WinFormDiApp.sln index 3ef52d5..738cbde 100644 --- a/WinFormDiApp.sln +++ b/WinFormDiApp.sln @@ -7,9 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormDi", "WinFormDi\WinF EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DIDemoLib", "DIDemoLib\DIDemoLib.csproj", "{839E6DE6-4644-4279-A7B1-449BD63897A3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormDiApp.BL", "WinFormDiApp.BL\WinFormDiApp.BL.csproj", "{4D49AE4B-26D6-48C6-B1CA-48D428E95BE0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormDiApp.BL", "WinFormDiApp.BL\WinFormDiApp.BL.csproj", "{4D49AE4B-26D6-48C6-B1CA-48D428E95BE0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormDiApp.DAL", "WinFormDiApp.DAL\WinFormDiApp.DAL.csproj", "{C6E355AD-C907-45D2-815B-A1B4207656FB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormDiApp.DAL", "WinFormDiApp.DAL\WinFormDiApp.DAL.csproj", "{C6E355AD-C907-45D2-815B-A1B4207656FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormDiApp.BLR", "WinFormDi.BLR\WinFormDiApp.BLR.csproj", "{FBA37C63-042A-47DF-AABC-556CC7DBF957}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormDiApp.BLI", "WinFormDi.BLI\WinFormDiApp.BLI.csproj", "{209B0142-88FB-41C3-845F-08F2CBB3B0A2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +37,14 @@ Global {C6E355AD-C907-45D2-815B-A1B4207656FB}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6E355AD-C907-45D2-815B-A1B4207656FB}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6E355AD-C907-45D2-815B-A1B4207656FB}.Release|Any CPU.Build.0 = Release|Any CPU + {FBA37C63-042A-47DF-AABC-556CC7DBF957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBA37C63-042A-47DF-AABC-556CC7DBF957}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBA37C63-042A-47DF-AABC-556CC7DBF957}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBA37C63-042A-47DF-AABC-556CC7DBF957}.Release|Any CPU.Build.0 = Release|Any CPU + {209B0142-88FB-41C3-845F-08F2CBB3B0A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {209B0142-88FB-41C3-845F-08F2CBB3B0A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {209B0142-88FB-41C3-845F-08F2CBB3B0A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {209B0142-88FB-41C3-845F-08F2CBB3B0A2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE