Import & Database Verbindung vollendet - Anfang vom Export
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
namespace Projekt_Calcan_Conze_Export;
|
||||
|
||||
internal static class Constants
|
||||
{
|
||||
public const string DateFormat = "yyyy-MM-dd";
|
||||
|
||||
public const string Separator = ";";
|
||||
|
||||
public const string MoneyFormat = "F2";
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
namespace Projekt_Calcan_Conze_Export.Models;
|
||||
|
||||
internal class Billing
|
||||
{
|
||||
public Billing(
|
||||
DateOnly startDate,
|
||||
DateOnly endDate,
|
||||
string customerNumber,
|
||||
string customerName,
|
||||
List<BillingPosition> positions)
|
||||
{
|
||||
this.StartDate = startDate;
|
||||
this.EndDate = endDate;
|
||||
this.CustomerNumber = customerNumber;
|
||||
this.CustomerName = customerName;
|
||||
this.Positions = positions;
|
||||
}
|
||||
|
||||
public DateOnly StartDate { get; }
|
||||
|
||||
public DateOnly EndDate { get; }
|
||||
|
||||
public string CustomerNumber { get; }
|
||||
|
||||
public string CustomerName { get; }
|
||||
|
||||
public double TotalAmount => this.Positions.Sum(p => p.TotalAmount);
|
||||
|
||||
public List<BillingPosition> Positions { get; }
|
||||
|
||||
public IEnumerable<string> ToCsvLines()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
this.StartDate.ToString(Constants.DateFormat)
|
||||
+ Constants.Separator
|
||||
+ this.EndDate.ToString(Constants.DateFormat)
|
||||
+ Constants.Separator
|
||||
+ this.CustomerNumber
|
||||
+ Constants.Separator
|
||||
+ this.CustomerName
|
||||
+ Constants.Separator
|
||||
+ this.TotalAmount.ToString(Constants.MoneyFormat)
|
||||
|
||||
];
|
||||
|
||||
lines.AddRange(
|
||||
this.Positions
|
||||
.Select(
|
||||
position =>
|
||||
position.Description
|
||||
+ Constants.Separator
|
||||
+ position.BaseAmount.ToString(Constants.MoneyFormat)
|
||||
+ Constants.Separator
|
||||
+ position.Count
|
||||
+ Constants.Separator
|
||||
+ position.TotalAmount.ToString(Constants.MoneyFormat)
|
||||
+ Constants.Separator));
|
||||
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
|
||||
internal class BillingPosition
|
||||
{
|
||||
public BillingPosition(string description, double baseAmount, int count)
|
||||
{
|
||||
this.Description = description;
|
||||
this.BaseAmount = baseAmount;
|
||||
this.Count = count;
|
||||
}
|
||||
|
||||
public string Description { get; }
|
||||
|
||||
public double BaseAmount { get; }
|
||||
|
||||
public int Count { get; }
|
||||
|
||||
public double TotalAmount => this.BaseAmount * this.Count;
|
||||
}
|
110
Projekt_Calcan_Conze/Projekt_Calcan_Conze_Export/Program.cs
Normal file
110
Projekt_Calcan_Conze/Projekt_Calcan_Conze_Export/Program.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using System.Globalization;
|
||||
|
||||
using Projekt_Calcan_Conze_Export;
|
||||
using Projekt_Calcan_Conze_Export.Models;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
try
|
||||
{
|
||||
string? clientNumber = null;
|
||||
|
||||
while (string.IsNullOrEmpty(clientNumber))
|
||||
{
|
||||
Console.WriteLine("Bitte gib eine Kundennummer an:");
|
||||
clientNumber = Console.ReadLine();
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
DateOnly? startDate = null;
|
||||
|
||||
while (startDate is null)
|
||||
{
|
||||
Console.WriteLine($"Bitte gib das Startdatum im folgenden Format an ({Constants.DateFormat}):");
|
||||
startDate =
|
||||
DateOnly.TryParseExact(
|
||||
Console.ReadLine() ?? string.Empty,
|
||||
Constants.DateFormat,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None,
|
||||
out var start)
|
||||
? start
|
||||
: null;
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
DateOnly? endDate = null;
|
||||
|
||||
while (endDate is null)
|
||||
{
|
||||
Console.WriteLine($"Bitte gib das Enddatum im folgenden Format an ({Constants.DateFormat}):");
|
||||
endDate =
|
||||
DateOnly.TryParseExact(
|
||||
Console.ReadLine() ?? string.Empty,
|
||||
Constants.DateFormat,
|
||||
CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None,
|
||||
out var end)
|
||||
? end
|
||||
: null;
|
||||
|
||||
if (endDate is not null
|
||||
&& endDate < startDate)
|
||||
{
|
||||
Console.WriteLine("Das Enddatum darf nicht vor dem Startdatum liegen.");
|
||||
endDate = null;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
string? directoryPath = null;
|
||||
|
||||
while (string.IsNullOrEmpty(directoryPath))
|
||||
{
|
||||
Console.WriteLine("Bitte gib einen Dateipfad für die Ausgabe an:");
|
||||
directoryPath = Console.ReadLine();
|
||||
|
||||
if (directoryPath?.StartsWith('\"') ?? false)
|
||||
{
|
||||
directoryPath = directoryPath.Substring(startIndex: 1, length: directoryPath.Length - 1);
|
||||
}
|
||||
|
||||
if (directoryPath?.EndsWith('\"') ?? false)
|
||||
{
|
||||
directoryPath = directoryPath.Substring(startIndex: 0, length: directoryPath.Length - 1);
|
||||
}
|
||||
|
||||
if (!Path.Exists(directoryPath))
|
||||
{
|
||||
Console.WriteLine("Der angegebene Dateipfad existiert nicht.");
|
||||
directoryPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
List<Billing> billings =
|
||||
[
|
||||
new Billing(
|
||||
startDate: startDate.Value,
|
||||
endDate: endDate.Value,
|
||||
customerNumber: clientNumber,
|
||||
customerName: "Max Mustermann",
|
||||
positions:
|
||||
[
|
||||
new BillingPosition(
|
||||
description: "Testposition",
|
||||
baseAmount: 100.0,
|
||||
count: 3)
|
||||
])
|
||||
];
|
||||
string fileName =
|
||||
$"{DateTime.Today.ToString(Constants.DateFormat)}_{clientNumber}_{startDate.Value.ToString(Constants.DateFormat)}_{endDate.Value.ToString(Constants.DateFormat)}.csv";
|
||||
File.WriteAllLines(
|
||||
Path.Combine(directoryPath, fileName),
|
||||
billings.SelectMany(billing => billing.ToCsvLines()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Ein Fehler ist aufgetreten: {ex.Message}");
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user