Überlegungen & Ansätze erweitert
This commit is contained in:
parent
de62de21ab
commit
0156f3e3ac
Binary file not shown.
Binary file not shown.
@ -24,7 +24,7 @@
|
||||
"RelativeDocumentMoniker": "Projekt_Calcan_Conze\\Program.cs",
|
||||
"ToolTip": "C:\\Jan_bib_Module\\PMC\\Projekt\\Projekt_Calcan_Conze\\Projekt_Calcan_Conze\\Program.cs",
|
||||
"RelativeToolTip": "Projekt_Calcan_Conze\\Program.cs",
|
||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAEAAAAiAAAA",
|
||||
"ViewState": "AQIAAAwAAAAAAAAAAAAAAB4AAAAgAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
||||
"WhenOpened": "2024-05-24T09:06:25.212Z",
|
||||
"EditorCaption": ""
|
||||
|
@ -27,3 +27,207 @@
|
||||
//
|
||||
// • Nicht valide Datensätze von Nutzern sollen in einem Protokoll erfasst werden, ebenso bereits vorhandene Nutzer.
|
||||
// Der komplette Datensatz eines Nutzers darf dann nicht importiert werden
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
class Programm {
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Willkommen");
|
||||
Console.Write("Bitte geben Sie nun die Kundenummer ein: ");
|
||||
String kundennummer = Console.ReadLine();
|
||||
Console.Write("Bitte geben Sie die Datei-Parameter ein: ");
|
||||
String dateiParameter = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
//Überlegung mit File.Exist zu arbeiten.
|
||||
/*
|
||||
* using System;
|
||||
using System.IO;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
string filePath = "path/to/your/VARIABLE";
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine("File does not exist.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("File exists.");
|
||||
}
|
||||
}
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Die wunderbare Lösung von unserem Kollegen. Nicht getestet aber an den Ansätzen können wir uns orientieren
|
||||
*
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("Usage: ImportUsers <csv-file> <customer-id>");
|
||||
return;
|
||||
}
|
||||
|
||||
string filePath = args[0];
|
||||
string customerId = args[1];
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine("File does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
var users = ReadCsvFile(filePath);
|
||||
var invalidUsers = new List<string>();
|
||||
var validUsers = new List<User>();
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (ValidateUser(user, out string validationError))
|
||||
{
|
||||
if (!IsUserAlreadyExists(user, customerId))
|
||||
{
|
||||
validUsers.Add(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
invalidUsers.Add($"User already exists: {user.FirstName} {user.LastName}, Email: {user.Email}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
invalidUsers.Add(validationError);
|
||||
}
|
||||
}
|
||||
|
||||
ImportValidUsers(validUsers, customerId);
|
||||
LogInvalidUsers(invalidUsers);
|
||||
|
||||
Console.WriteLine("Import completed.");
|
||||
}
|
||||
|
||||
static List<User> ReadCsvFile(string filePath)
|
||||
{
|
||||
var users = new List<User>();
|
||||
var lines = File.ReadAllLines(filePath);
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var columns = line.Split(',');
|
||||
|
||||
var user = new User
|
||||
{
|
||||
Salutation = columns[0],
|
||||
FirstName = columns[1],
|
||||
LastName = columns[2],
|
||||
BirthDate = columns[3],
|
||||
Street = columns[4],
|
||||
PostalCode = columns[5],
|
||||
City = columns[6],
|
||||
Email = columns[7],
|
||||
PhoneNumbers = columns.Skip(8).ToList()
|
||||
};
|
||||
|
||||
users.Add(user);
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
static bool ValidateUser(User user, out string error)
|
||||
{
|
||||
error = string.Empty;
|
||||
DateTime birthDate;
|
||||
|
||||
if (!DateTime.TryParseExact(user.BirthDate, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out birthDate))
|
||||
{
|
||||
error = $"Invalid birth date: {user.BirthDate}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Regex.IsMatch(user.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
|
||||
{
|
||||
error = $"Invalid email: {user.Email}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Regex.IsMatch(user.PostalCode, @"^\d{5}$"))
|
||||
{
|
||||
error = $"Invalid postal code: {user.PostalCode}";
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var phone in user.PhoneNumbers)
|
||||
{
|
||||
var parts = phone.Split('-');
|
||||
if (parts.Length != 2 || !Regex.IsMatch(parts[0], @"^\d{3,5}$") || !Regex.IsMatch(parts[1], @"^\d{4,10}$"))
|
||||
{
|
||||
error = $"Invalid phone number: {phone}";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool IsUserAlreadyExists(User user, string customerId)
|
||||
{
|
||||
// Hier sollte die Logik implementiert werden, um zu prüfen, ob der Nutzer bereits in der Datenbank vorhanden ist.
|
||||
// Dies ist ein Platzhalter für die tatsächliche Überprüfung in der Datenbank.
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ImportValidUsers(List<User> users, string customerId)
|
||||
{
|
||||
// Hier sollte die Logik implementiert werden, um die gültigen Nutzer in die Datenbank zu importieren.
|
||||
// Dies ist ein Platzhalter für den tatsächlichen Datenbankimport.
|
||||
}
|
||||
|
||||
static void LogInvalidUsers(List<string> invalidUsers)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter("invalid_users.log"))
|
||||
{
|
||||
foreach (var error in invalidUsers)
|
||||
{
|
||||
sw.WriteLine(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class User
|
||||
{
|
||||
public string Salutation { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string BirthDate { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Email { get; set; }
|
||||
public List<string> PhoneNumbers { get; set; }
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -7,4 +7,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="8.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -14,7 +14,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("Projekt_Calcan_Conze")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8e94f38b7ba8a1e3eace1ca65482c727aef83a97")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+de62de21abb1de57a65dd5960d62b45cf006ac5d")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("Projekt_Calcan_Conze")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("Projekt_Calcan_Conze")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
@ -1 +1 @@
|
||||
841a378c2579e703915ea8b9bbdd50e0150b78b0eebe40187e6ced7d9248969c
|
||||
1c2cdb08063daf28dd2818f9df6cf00cda259386521b83514442f74250bde24d
|
||||
|
Loading…
Reference in New Issue
Block a user