From a215b54d0d6de3857b8795d6a0efe924683ed40e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Fri, 9 Feb 2024 12:50:16 +0100 Subject: [PATCH] =?UTF-8?q?Generaliserat=20il=C3=A4sning=20av=20bankdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormDi.BLI/IReadingIn.cs | 1 + WinFormDi.BLR/ReadingIn.cs | 30 +++++++++++++++++++++--- WinFormDi/appsettings.json | 2 +- WinFormDi/frmReadPayments.Designer.cs | 31 ++++++++++++++----------- WinFormDi/frmReadPayments.cs | 3 +++ WinFormDi/frmSearchData.cs | 24 ++++++++++++------- WinFormDiApp.BL/Models/AccountRecord.cs | 6 ++++- 7 files changed, 71 insertions(+), 26 deletions(-) diff --git a/WinFormDi.BLI/IReadingIn.cs b/WinFormDi.BLI/IReadingIn.cs index 039a305..5b2a69f 100644 --- a/WinFormDi.BLI/IReadingIn.cs +++ b/WinFormDi.BLI/IReadingIn.cs @@ -6,5 +6,6 @@ namespace WinFormDiApp.BLI { bool ReadAndSaveInvoices(string fullFileName); IEnumerable readXLS(string FilePath); + void Dispose(); } } \ No newline at end of file diff --git a/WinFormDi.BLR/ReadingIn.cs b/WinFormDi.BLR/ReadingIn.cs index a1151d4..9a8ada4 100644 --- a/WinFormDi.BLR/ReadingIn.cs +++ b/WinFormDi.BLR/ReadingIn.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection; namespace WinFormDiApp.BLR; -public class ReadingIn : IReadingIn +public class ReadingIn : IReadingIn, IDisposable { private readonly IConfiguration _configuration; private readonly ILogger _logger; @@ -46,9 +46,8 @@ public class ReadingIn : IReadingIn if (prt) { //Console.WriteLine(); - //// _logger.LogInformation(""); + _logger.LogInformation(record.ToString()); records.Add(record); - fieldNr = 0; } prt = false; for (int col = 0; col <= colCount; col++) @@ -65,6 +64,14 @@ public class ReadingIn : IReadingIn { prt = true; record = new AccountRecord(); + fieldNr = 0; + } + else + { + if (col == 0) + { + col = colCount; + } } //Console.WriteLine(" Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row, col].Value.ToString().Trim()); if (prt) @@ -90,6 +97,14 @@ public class ReadingIn : IReadingIn case 3: { record.Konto = _excellent.ReadCell(row, col).ToString().Trim(); + if (record.Konto.ToLower().StartsWith("bg") + || record.Konto.ToLower().StartsWith("pg") + || record.Konto.ToLower().StartsWith("hs")){} + else + { + prt = false; + col = colCount; + } break; } case 4: @@ -117,6 +132,11 @@ public class ReadingIn : IReadingIn var restab = readXLS(fullFileName); if (restab != null) { + restab.ToList().ForEach(x => + { + _logger.LogInformation(x.ToString()); + }); + try { @@ -137,4 +157,8 @@ public class ReadingIn : IReadingIn return result; } + public void Dispose() + { + _excellent.Dispose(); + } } diff --git a/WinFormDi/appsettings.json b/WinFormDi/appsettings.json index fcd71cc..c51e44b 100644 --- a/WinFormDi/appsettings.json +++ b/WinFormDi/appsettings.json @@ -11,7 +11,7 @@ }, "Debug": { "LogLevel": { - "Default": "Warning", + "Default": "Information", "Microsoft*": "Warning" } }, diff --git a/WinFormDi/frmReadPayments.Designer.cs b/WinFormDi/frmReadPayments.Designer.cs index 66d7453..e20676a 100644 --- a/WinFormDi/frmReadPayments.Designer.cs +++ b/WinFormDi/frmReadPayments.Designer.cs @@ -92,9 +92,10 @@ // // btnClose // - btnClose.Location = new Point(758, 506); + btnClose.Location = new Point(866, 675); + btnClose.Margin = new Padding(3, 4, 3, 4); btnClose.Name = "btnClose"; - btnClose.Size = new Size(75, 23); + btnClose.Size = new Size(86, 31); btnClose.TabIndex = 1; btnClose.Text = "Stäng"; btnClose.UseVisualStyleBackColor = true; @@ -105,9 +106,10 @@ lvPayouts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; lvPayouts.BackColor = Color.FromArgb(192, 255, 255); lvPayouts.Columns.AddRange(new ColumnHeader[] { columnHeader1, columnHeader2, columnHeader3, columnHeader4, columnHeader5, columnHeader6 }); - lvPayouts.Location = new Point(28, 107); + lvPayouts.Location = new Point(32, 143); + lvPayouts.Margin = new Padding(3, 4, 3, 4); lvPayouts.Name = "lvPayouts"; - lvPayouts.Size = new Size(805, 393); + lvPayouts.Size = new Size(919, 523); lvPayouts.TabIndex = 2; lvPayouts.UseCompatibleStateImageBehavior = false; lvPayouts.View = View.Details; @@ -143,9 +145,10 @@ // // btnChooseFile // - btnChooseFile.Location = new Point(30, 28); + btnChooseFile.Location = new Point(34, 37); + btnChooseFile.Margin = new Padding(3, 4, 3, 4); btnChooseFile.Name = "btnChooseFile"; - btnChooseFile.Size = new Size(75, 23); + btnChooseFile.Size = new Size(86, 31); btnChooseFile.TabIndex = 3; btnChooseFile.Text = "Välj infil"; btnChooseFile.UseVisualStyleBackColor = true; @@ -159,20 +162,21 @@ // lblTransFileName.AutoSize = true; lblTransFileName.Font = new Font("Segoe UI", 12F, FontStyle.Bold, GraphicsUnit.Point); - lblTransFileName.Location = new Point(125, 27); + lblTransFileName.Location = new Point(143, 36); lblTransFileName.Name = "lblTransFileName"; - lblTransFileName.Size = new Size(57, 21); + lblTransFileName.Size = new Size(26, 28); lblTransFileName.TabIndex = 4; - lblTransFileName.Text = "label1"; + lblTransFileName.Text = "[]"; // // btnStartRead // btnStartRead.BackColor = Color.Red; btnStartRead.Enabled = false; btnStartRead.ForeColor = Color.FromArgb(255, 255, 128); - btnStartRead.Location = new Point(726, 21); + btnStartRead.Location = new Point(830, 28); + btnStartRead.Margin = new Padding(3, 4, 3, 4); btnStartRead.Name = "btnStartRead"; - btnStartRead.Size = new Size(107, 36); + btnStartRead.Size = new Size(122, 48); btnStartRead.TabIndex = 5; btnStartRead.Text = "Starta Inläsning"; btnStartRead.UseVisualStyleBackColor = false; @@ -181,14 +185,15 @@ // // frmReadPayments // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(856, 541); + ClientSize = new Size(978, 721); Controls.Add(btnStartRead); Controls.Add(lblTransFileName); Controls.Add(btnChooseFile); Controls.Add(lvPayouts); Controls.Add(btnClose); + Margin = new Padding(3, 4, 3, 4); Name = "frmReadPayments"; StartPosition = FormStartPosition.CenterScreen; Text = "frmReadPayments"; diff --git a/WinFormDi/frmReadPayments.cs b/WinFormDi/frmReadPayments.cs index 6e9143c..aeda228 100644 --- a/WinFormDi/frmReadPayments.cs +++ b/WinFormDi/frmReadPayments.cs @@ -40,9 +40,11 @@ namespace WinFormDiApp private void btnStartRead_Click(object sender, EventArgs e) { + Cursor = Cursors.WaitCursor; if (!_readingIn.ReadAndSaveInvoices(lblTransFileName.Text)) { var resUlt = _readingIn.readXLS(lblTransFileName.Text); + _readingIn.Dispose(); resUlt.ToList().ForEach(rec => _logger.LogInformation("Konto :{sKonto}, {dBelopp}", rec.Konto, rec.Belopp)); } else @@ -62,6 +64,7 @@ namespace WinFormDiApp btnStartRead.Enabled = false; btnStartRead.Visible = false; + Cursor = Cursors.Default; } private void frmReadPayments_Shown(object sender, EventArgs e) diff --git a/WinFormDi/frmSearchData.cs b/WinFormDi/frmSearchData.cs index d5953d1..384de0b 100644 --- a/WinFormDi/frmSearchData.cs +++ b/WinFormDi/frmSearchData.cs @@ -26,7 +26,7 @@ namespace WinFormDiApp private readonly IAccountRecordRepository _accountRecordRepository; private readonly frmPayments _showPayments; - public frmSearchData(IAccountRecordRepository accountRecordRepository,frmPayments showPayments) + public frmSearchData(IAccountRecordRepository accountRecordRepository, frmPayments showPayments) { InitializeComponent(); _accountRecordRepository = accountRecordRepository; @@ -42,11 +42,19 @@ namespace WinFormDiApp { flpPanel1.Controls.Clear(); foundRecs = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value); - var aggregates = aggegateAccounts(foundRecs); - foreach (var account in aggregates) + if (foundRecs.Any()) { - var ucCustV = createAndFillUCcv(account); - flpPanel1.Controls.Add(ucCustV); + var aggregates = aggegateAccounts(foundRecs); + foreach (var account in aggregates) + { + var ucCustV = createAndFillUCcv(account); + flpPanel1.Controls.Add(ucCustV); + } + } + else + { + flpPanel1.Controls.Clear(); + MessageBox.Show("Din sökning gav ingen träff"); } } @@ -56,7 +64,7 @@ namespace WinFormDiApp result.Amount = String.Format("{0:0.00}", account.SearchedSum).adjustRight(); result.Receiver = account.AcRec.Mottagare; result.Number = Convert.ToString(account.NoOfRecs); - result.Tag = account.AcRec.Konto; + result.Tag = account.AcRec.Mottagare; return result; } @@ -99,9 +107,9 @@ namespace WinFormDiApp return acc; } - public void ShowDetails(string accountNo) + public void ShowDetails(string mott) { - IEnumerable detailRecs = foundRecs.Where(fr => fr.Konto==accountNo); + IEnumerable detailRecs = foundRecs.Where(fr => fr.Mottagare == mott); _showPayments.CustomPayments = detailRecs; _showPayments.ShowDialog(); } diff --git a/WinFormDiApp.BL/Models/AccountRecord.cs b/WinFormDiApp.BL/Models/AccountRecord.cs index 1db1133..478a40c 100644 --- a/WinFormDiApp.BL/Models/AccountRecord.cs +++ b/WinFormDiApp.BL/Models/AccountRecord.cs @@ -15,6 +15,10 @@ namespace WinFormDiApp.BL.Models public double Belopp { get; set; } public string Avisering { get; set; } = string.Empty; public DateTime Stored { get; set;} = DateTime.Now.ToLocalTime(); - + public override string ToString() + { + //return base.ToString(); + return $"BetalDatum:{BetalDatum}, Mottagare:{Mottagare}, Konto:{Konto}, Belopp:{Belopp}, Avisering:{Avisering}"; + } } }