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);
IEnumerable<AccountRecord> readXLS(string FilePath);
void Dispose();
}
}

View File

@ -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<ReadingIn> _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();
}
}

View File

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

View File

@ -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";

View File

@ -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)

View File

@ -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<AccountRecord> detailRecs = foundRecs.Where(fr => fr.Konto==accountNo);
IEnumerable<AccountRecord> detailRecs = foundRecs.Where(fr => fr.Mottagare == mott);
_showPayments.CustomPayments = detailRecs;
_showPayments.ShowDialog();
}

View File

@ -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}";
}
}
}