Generaliserat iläsning av bankdata

This commit is contained in:
2024-02-09 12:50:16 +01:00
parent 05dfd1f35b
commit a215b54d0d
7 changed files with 71 additions and 26 deletions

View File

@ -6,5 +6,6 @@ namespace WinFormDiApp.BLI
{ {
bool ReadAndSaveInvoices(string fullFileName); bool ReadAndSaveInvoices(string fullFileName);
IEnumerable<AccountRecord> readXLS(string FilePath); IEnumerable<AccountRecord> readXLS(string FilePath);
void Dispose();
} }
} }

View File

@ -7,7 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
namespace WinFormDiApp.BLR; namespace WinFormDiApp.BLR;
public class ReadingIn : IReadingIn public class ReadingIn : IReadingIn, IDisposable
{ {
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly ILogger<ReadingIn> _logger; private readonly ILogger<ReadingIn> _logger;
@ -46,9 +46,8 @@ public class ReadingIn : IReadingIn
if (prt) if (prt)
{ {
//Console.WriteLine(); //Console.WriteLine();
//// _logger.LogInformation(""); _logger.LogInformation(record.ToString());
records.Add(record); records.Add(record);
fieldNr = 0;
} }
prt = false; prt = false;
for (int col = 0; col <= colCount; col++) for (int col = 0; col <= colCount; col++)
@ -65,6 +64,14 @@ public class ReadingIn : IReadingIn
{ {
prt = true; prt = true;
record = new AccountRecord(); 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()); //Console.WriteLine(" Row:" + row + " column:" + col + " Value:" + worksheet.Cells[row, col].Value.ToString().Trim());
if (prt) if (prt)
@ -90,6 +97,14 @@ public class ReadingIn : IReadingIn
case 3: case 3:
{ {
record.Konto = _excellent.ReadCell(row, col).ToString().Trim(); 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; break;
} }
case 4: case 4:
@ -117,6 +132,11 @@ public class ReadingIn : IReadingIn
var restab = readXLS(fullFileName); var restab = readXLS(fullFileName);
if (restab != null) if (restab != null)
{ {
restab.ToList().ForEach(x =>
{
_logger.LogInformation(x.ToString());
});
try try
{ {
@ -137,4 +157,8 @@ public class ReadingIn : IReadingIn
return result; return result;
} }
public void Dispose()
{
_excellent.Dispose();
}
} }

View File

@ -11,7 +11,7 @@
}, },
"Debug": { "Debug": {
"LogLevel": { "LogLevel": {
"Default": "Warning", "Default": "Information",
"Microsoft*": "Warning" "Microsoft*": "Warning"
} }
}, },

View File

@ -92,9 +92,10 @@
// //
// btnClose // 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.Name = "btnClose";
btnClose.Size = new Size(75, 23); btnClose.Size = new Size(86, 31);
btnClose.TabIndex = 1; btnClose.TabIndex = 1;
btnClose.Text = "Stäng"; btnClose.Text = "Stäng";
btnClose.UseVisualStyleBackColor = true; btnClose.UseVisualStyleBackColor = true;
@ -105,9 +106,10 @@
lvPayouts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; lvPayouts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
lvPayouts.BackColor = Color.FromArgb(192, 255, 255); lvPayouts.BackColor = Color.FromArgb(192, 255, 255);
lvPayouts.Columns.AddRange(new ColumnHeader[] { columnHeader1, columnHeader2, columnHeader3, columnHeader4, columnHeader5, columnHeader6 }); 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.Name = "lvPayouts";
lvPayouts.Size = new Size(805, 393); lvPayouts.Size = new Size(919, 523);
lvPayouts.TabIndex = 2; lvPayouts.TabIndex = 2;
lvPayouts.UseCompatibleStateImageBehavior = false; lvPayouts.UseCompatibleStateImageBehavior = false;
lvPayouts.View = View.Details; lvPayouts.View = View.Details;
@ -143,9 +145,10 @@
// //
// btnChooseFile // 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.Name = "btnChooseFile";
btnChooseFile.Size = new Size(75, 23); btnChooseFile.Size = new Size(86, 31);
btnChooseFile.TabIndex = 3; btnChooseFile.TabIndex = 3;
btnChooseFile.Text = "Välj infil"; btnChooseFile.Text = "Välj infil";
btnChooseFile.UseVisualStyleBackColor = true; btnChooseFile.UseVisualStyleBackColor = true;
@ -159,20 +162,21 @@
// //
lblTransFileName.AutoSize = true; lblTransFileName.AutoSize = true;
lblTransFileName.Font = new Font("Segoe UI", 12F, FontStyle.Bold, GraphicsUnit.Point); 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.Name = "lblTransFileName";
lblTransFileName.Size = new Size(57, 21); lblTransFileName.Size = new Size(26, 28);
lblTransFileName.TabIndex = 4; lblTransFileName.TabIndex = 4;
lblTransFileName.Text = "label1"; lblTransFileName.Text = "[]";
// //
// btnStartRead // btnStartRead
// //
btnStartRead.BackColor = Color.Red; btnStartRead.BackColor = Color.Red;
btnStartRead.Enabled = false; btnStartRead.Enabled = false;
btnStartRead.ForeColor = Color.FromArgb(255, 255, 128); 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.Name = "btnStartRead";
btnStartRead.Size = new Size(107, 36); btnStartRead.Size = new Size(122, 48);
btnStartRead.TabIndex = 5; btnStartRead.TabIndex = 5;
btnStartRead.Text = "Starta Inläsning"; btnStartRead.Text = "Starta Inläsning";
btnStartRead.UseVisualStyleBackColor = false; btnStartRead.UseVisualStyleBackColor = false;
@ -181,14 +185,15 @@
// //
// frmReadPayments // frmReadPayments
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(856, 541); ClientSize = new Size(978, 721);
Controls.Add(btnStartRead); Controls.Add(btnStartRead);
Controls.Add(lblTransFileName); Controls.Add(lblTransFileName);
Controls.Add(btnChooseFile); Controls.Add(btnChooseFile);
Controls.Add(lvPayouts); Controls.Add(lvPayouts);
Controls.Add(btnClose); Controls.Add(btnClose);
Margin = new Padding(3, 4, 3, 4);
Name = "frmReadPayments"; Name = "frmReadPayments";
StartPosition = FormStartPosition.CenterScreen; StartPosition = FormStartPosition.CenterScreen;
Text = "frmReadPayments"; Text = "frmReadPayments";

View File

@ -40,9 +40,11 @@ namespace WinFormDiApp
private void btnStartRead_Click(object sender, EventArgs e) private void btnStartRead_Click(object sender, EventArgs e)
{ {
Cursor = Cursors.WaitCursor;
if (!_readingIn.ReadAndSaveInvoices(lblTransFileName.Text)) if (!_readingIn.ReadAndSaveInvoices(lblTransFileName.Text))
{ {
var resUlt = _readingIn.readXLS(lblTransFileName.Text); var resUlt = _readingIn.readXLS(lblTransFileName.Text);
_readingIn.Dispose();
resUlt.ToList().ForEach(rec => _logger.LogInformation("Konto :{sKonto}, {dBelopp}", rec.Konto, rec.Belopp)); resUlt.ToList().ForEach(rec => _logger.LogInformation("Konto :{sKonto}, {dBelopp}", rec.Konto, rec.Belopp));
} }
else else
@ -62,6 +64,7 @@ namespace WinFormDiApp
btnStartRead.Enabled = false; btnStartRead.Enabled = false;
btnStartRead.Visible = false; btnStartRead.Visible = false;
Cursor = Cursors.Default;
} }
private void frmReadPayments_Shown(object sender, EventArgs e) private void frmReadPayments_Shown(object sender, EventArgs e)

View File

@ -42,6 +42,8 @@ namespace WinFormDiApp
{ {
flpPanel1.Controls.Clear(); flpPanel1.Controls.Clear();
foundRecs = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value); foundRecs = _accountRecordRepository.GetAllAccBetweenDates(dtpFrom.Value, dtpTo.Value);
if (foundRecs.Any())
{
var aggregates = aggegateAccounts(foundRecs); var aggregates = aggegateAccounts(foundRecs);
foreach (var account in aggregates) foreach (var account in aggregates)
{ {
@ -49,6 +51,12 @@ namespace WinFormDiApp
flpPanel1.Controls.Add(ucCustV); flpPanel1.Controls.Add(ucCustV);
} }
} }
else
{
flpPanel1.Controls.Clear();
MessageBox.Show("Din sökning gav ingen träff");
}
}
private ucCustomerValue createAndFillUCcv(AccCount account) private ucCustomerValue createAndFillUCcv(AccCount account)
{ {
@ -56,7 +64,7 @@ namespace WinFormDiApp
result.Amount = String.Format("{0:0.00}", account.SearchedSum).adjustRight(); result.Amount = String.Format("{0:0.00}", account.SearchedSum).adjustRight();
result.Receiver = account.AcRec.Mottagare; result.Receiver = account.AcRec.Mottagare;
result.Number = Convert.ToString(account.NoOfRecs); result.Number = Convert.ToString(account.NoOfRecs);
result.Tag = account.AcRec.Konto; result.Tag = account.AcRec.Mottagare;
return result; return result;
} }
@ -99,9 +107,9 @@ namespace WinFormDiApp
return acc; return acc;
} }
public void ShowDetails(string accountNo) public void ShowDetails(string mott)
{ {
IEnumerable<AccountRecord> detailRecs = foundRecs.Where(fr => fr.Konto==accountNo); IEnumerable<AccountRecord> detailRecs = foundRecs.Where(fr => fr.Mottagare == mott);
_showPayments.CustomPayments = detailRecs; _showPayments.CustomPayments = detailRecs;
_showPayments.ShowDialog(); _showPayments.ShowDialog();
} }

View File

@ -15,6 +15,10 @@ namespace WinFormDiApp.BL.Models
public double Belopp { get; set; } public double Belopp { get; set; }
public string Avisering { get; set; } = string.Empty; public string Avisering { get; set; } = string.Empty;
public DateTime Stored { get; set;} = DateTime.Now.ToLocalTime(); 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}";
}
} }
} }