Read invoice data from CSV file
This commit is contained in:
1 parent
7128a93461
commit
b9a3c7725d
2 files changed
+55
-8
No files matched your search
@@ -1,13 +1,54 @@
|
||||
using ImportAssist.Core;
|
||||
|
||||
InvoiceRow[] rows =
|
||||
[
|
||||
new("INV-001", "C-100", "125.50", "EUR"),
|
||||
new("INV-002", "", "89.00", "EUR"),
|
||||
new("INV-003", "C-300", "abc", "EUR"),
|
||||
new("INV-004", "C-400", "-10.00", "EUR"),
|
||||
new("", "", "0", "EUR")
|
||||
];
|
||||
if (args.Length != 1)
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
"Bitte den Pfad zur CSV-Datei als Argument angeben.");
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
var path = args[0];
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Console.Error.WriteLine($"Datei nicht gefunden: {path}");
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = File.ReadAllLines(path);
|
||||
|
||||
if (lines.Length == 0 ||
|
||||
lines[0] != "InvoiceId;CustomerId;Amount;Currency")
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
"Die Datei ist leer oder die Kopfzeile stimmt nicht.");
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
var rows = new List<InvoiceRow>();
|
||||
|
||||
for (var index = 1; index < lines.Length; index++)
|
||||
{
|
||||
var line = lines[index];
|
||||
var columns = line.Split(';');
|
||||
|
||||
if (line.Contains('"') || columns.Length != 4)
|
||||
{
|
||||
Console.Error.WriteLine(
|
||||
$"Zeile {index + 1}: Erwartet werden vier Spalten ohne Anführungszeichen.");
|
||||
Environment.ExitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
rows.Add(new InvoiceRow(
|
||||
columns[0],
|
||||
columns[1],
|
||||
columns[2],
|
||||
columns[3]));
|
||||
}
|
||||
|
||||
foreach (var row in rows)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user