diff --git a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/DesignTimeBuild/.dtbcache.v2 b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/DesignTimeBuild/.dtbcache.v2 index feac31f..27f5349 100644 Binary files a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/DesignTimeBuild/.dtbcache.v2 and b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/DesignTimeBuild/.dtbcache.v2 differ diff --git a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.futdcache.v2 b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.futdcache.v2 index dafa8ef..6d9d001 100644 Binary files a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.futdcache.v2 and b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.futdcache.v2 differ diff --git a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.suo b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.suo index e835f05..d1add5d 100644 Binary files a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.suo and b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/.suo differ diff --git a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/DocumentLayout.json b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/DocumentLayout.json index 45b5883..975cc27 100644 --- a/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/DocumentLayout.json +++ b/Projekt_Calcan_Conze/.vs/Projekt_Calcan_Conze/v17/DocumentLayout.json @@ -1,12 +1,37 @@ { "Version": 1, "WorkspaceRootPath": "C:\\Jan_bib_Module\\PMC\\Projekt\\Projekt_Calcan_Conze\\", - "Documents": [], + "Documents": [ + { + "AbsoluteMoniker": "D:0:0:{44DD7752-6BB5-4C3A-9053-671D8ADE49C4}|Projekt_Calcan_Conze\\Projekt_Calcan_Conze.csproj|c:\\jan_bib_module\\pmc\\projekt\\projekt_calcan_conze\\projekt_calcan_conze\\programm.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", + "RelativeMoniker": "D:0:0:{44DD7752-6BB5-4C3A-9053-671D8ADE49C4}|Projekt_Calcan_Conze\\Projekt_Calcan_Conze.csproj|solutionrelative:projekt_calcan_conze\\programm.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" + } + ], "DocumentGroupContainers": [ { "Orientation": 0, "VerticalTabListWidth": 256, - "DocumentGroups": [] + "DocumentGroups": [ + { + "DockedWidth": 200, + "SelectedChildIndex": 0, + "Children": [ + { + "$type": "Document", + "DocumentIndex": 0, + "Title": "Programm.cs", + "DocumentMoniker": "C:\\Jan_bib_Module\\PMC\\Projekt\\Projekt_Calcan_Conze\\Projekt_Calcan_Conze\\Programm.cs", + "RelativeDocumentMoniker": "Projekt_Calcan_Conze\\Programm.cs", + "ToolTip": "C:\\Jan_bib_Module\\PMC\\Projekt\\Projekt_Calcan_Conze\\Projekt_Calcan_Conze\\Programm.cs", + "RelativeToolTip": "Projekt_Calcan_Conze\\Programm.cs", + "ViewState": "AgIAAAAAAAAAAAAAAAAAABYAAAApAAAAAAAAAA==", + "Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", + "WhenOpened": "2024-08-23T08:36:46.981Z", + "EditorCaption": "" + } + ] + } + ] } ] } \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Constants.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Constants.cs new file mode 100644 index 0000000..d31bd50 --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Constants.cs @@ -0,0 +1,12 @@ +namespace Projekt_Calcan_Conze; + +internal static class Constants +{ + public const char Separator = ';'; + public const string FemaleAttributeIdentifier = "Frau"; + public const string MaleAttributeIdentifier = "Herr"; + public const string AddressAttributeIdentifier = "Adresse"; + public const string EmailAttributeIdentifier = "E-Mail"; + public const string PhoneNumberAttributeIdentifier = "Telefon"; + public const string DateOfBirthFormat = "dd.MM.yyyy"; +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerAttributeDto.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerAttributeDto.cs new file mode 100644 index 0000000..85f96f1 --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerAttributeDto.cs @@ -0,0 +1,11 @@ +namespace Projekt_Calcan_Conze.DTOs; + +internal class CustomerAttributeDto +{ + public CustomerAttributeDto(List parts) + { + this.Parts = parts; + } + + public List Parts { get; } +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerDto.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerDto.cs new file mode 100644 index 0000000..dfa412c --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/DTOs/CustomerDto.cs @@ -0,0 +1,13 @@ +using Projekt_Calcan_Conze.DTOs; + +namespace Projekt_Calcan_Conze.DTOs; + +internal class CustomerDto +{ + public CustomerDto(List attributes) + { + this.Attributes = attributes; + } + + public List Attributes { get; } +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Address.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Address.cs new file mode 100644 index 0000000..e24a85e --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Address.cs @@ -0,0 +1,17 @@ +namespace Projekt_Calcan_Conze.Models; + +internal class Address +{ + public Address(string streetAndHouseNumber, string postalCode, string city) + { + this.StreetAndHouseNumber = streetAndHouseNumber; + this.PostalCode = postalCode; + this.City = city; + } + + public string StreetAndHouseNumber { get; } + + public string PostalCode { get; } + + public string City { get; } +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Customer.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Customer.cs new file mode 100644 index 0000000..7f597c7 --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/Customer.cs @@ -0,0 +1,65 @@ +using Projekt_Calcan_Conze.Models; +using System.Text; + +namespace Projekt_Calcan_Conze.Models; + +internal class Customer +{ + public Customer( + string title, + string firstName, + string lastName, + DateOnly dateOfBirth, + string? email, + Address? address, + List phoneNumbers) + { + this.Title = title; + this.FirstName = firstName; + this.LastName = lastName; + this.DateOfBirth = dateOfBirth; + this.Email = email; + this.Address = address; + this.PhoneNumbers = phoneNumbers; + } + + public string Title { get; } + + public string FirstName { get; } + + public string LastName { get; } + + public DateOnly DateOfBirth { get; } + + public string? Email { get; } + + public Address? Address { get; } + + public List PhoneNumbers { get; } + + public override string ToString() + { + StringBuilder builder = new(); + + builder.Append($"{this.Title} {this.FirstName} {this.LastName}"); + builder.Append($"{Constants.Separator} {this.DateOfBirth.ToString(Constants.DateOfBirthFormat)}"); + + if (this.Email is not null) + { + builder.Append($"{Constants.Separator} {this.Email}"); + } + + if (this.Address is not null) + { + builder.Append($"{Constants.Separator} {this.Address.StreetAndHouseNumber}"); + builder.Append($"{Constants.Separator} {this.Address.PostalCode} {this.Address.City}"); + } + + foreach (PhoneNumber phoneNumber in this.PhoneNumbers) + { + builder.Append($"{Constants.Separator} {phoneNumber.AreaCode} {phoneNumber.Number}"); + } + + return builder.ToString(); + } +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/PhoneNumber.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/PhoneNumber.cs new file mode 100644 index 0000000..54eafbf --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Models/PhoneNumber.cs @@ -0,0 +1,14 @@ +namespace Projekt_Calcan_Conze.Models; + +internal class PhoneNumber +{ + public PhoneNumber(string areaCode, string number) + { + this.AreaCode = areaCode; + this.Number = number; + } + + public string AreaCode { get; } + + public string Number { get; } +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Programm.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Programm.cs new file mode 100644 index 0000000..4c7ddd1 --- /dev/null +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/Programm.cs @@ -0,0 +1,36 @@ +using Projekt_Calcan_Conze; +using Projekt_Calcan_Conze.Models; + +string? filePath = null; + +while (filePath is null) +{ + Console.WriteLine("Bitte gib einen Dateipfad an:"); + filePath = Console.ReadLine(); +} + +string? customerId = null; + +while (customerId is null) +{ + Console.WriteLine("Bitte gib eine Kundennummer an:"); + customerId = Console.ReadLine(); +} + +var (customers, protocol) = Import.For(filePath); + +Console.WriteLine(); +Console.WriteLine("Importierte Kunden:"); + +foreach (Customer customer in customers) +{ + Console.WriteLine(customer.ToString()); +} + +Console.WriteLine(); +Console.WriteLine("Ungültige nicht importierte Zeilen/Kunden:"); + +foreach (string protocolLine in protocol) +{ + Console.WriteLine(protocolLine); +} diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/export.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/export.cs deleted file mode 100644 index d4a616a..0000000 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/export.cs +++ /dev/null @@ -1,113 +0,0 @@ -// 2. Export -// -// • Ein Sachbearbeiter ruft eine Konsolen-App auf, in welcher er die Kundennummer sowie den Zeitraum für die Abrechnung angibt -// • Wird eine Aktion abgerechnet, darf diese zukünftig nicht nochmal berechnet werden (z.B. bei Überschneidung der Zeiträume) -// • Die Ausgabe der Daten erfolgt als CSV-Datei. Der Dateiname folgt diesem Schema: Abrechnungsdatum_Kundennummer_vonDatum_bisDatum.csv -// • Das Datum ist immer im folgenden Format anzugeben: yyyy-mm-dd -// • Ein Abrechnungslauf muss folgende Daten umfassen: -// ○ Zeitraum (von / bis Datum) der Abrechnung -// ○ Name und Nummer des Kunden -// ○ Gesamtsumme der Abrechnung -// ○ Übersicht der einzelnen Posten wie folgt: -// Bereich | Grundbetrag | Anzahl | Betrag -// Newsletter wöchentlich | 0.001 | 24 | 0.024 -// Tarif Orange M 12 Monate | 7.00 | 0 | 0.000 -// Tarif Orange S 12 Monate | 5.00 | 1 | 5.000 -// Tarif Orange XL 12 Monate | 12.00 | 2 | 24.000 -// Verkaufsgespräch | 0.030 | 8 | 0.240 -// - -using System; -using System.Collections.Generic; -using System.IO; -using MySql.Data.MySqlClient; - -class Export -{ - static void Main(string[] args) - { - string customerNumber = args[0]; - string startDatum = args[1]; - string endDatum = args[2]; - - ExportData(customerNumber, startDatum, endDatum); - } - - static void ExportData(string kundennummer, string startDatum, string endDatum) - { - string myConnectionString = "server=localhost;uid=root;pwd=root;database=vr_contact"; - using (MySqlConnection myConnection = new MySqlConnection(myConnectionString)) - { - try - { - myConnection.Open(); - - // Kundendaten abrufen - string clientQuery = "SELECT name, id FROM customers WHERE id = @clientId"; - MySqlCommand clientCmd = new MySqlCommand(clientQuery, myConnection); - clientCmd.Parameters.AddWithValue("@clientId", kundennummer); - - using (MySqlDataReader clientReader = clientCmd.ExecuteReader()) - { - if (clientReader.Read()) - { - string clientName = clientReader.GetString("name"); - int clientId = clientReader.GetInt32("id"); - clientReader.Close(); - - // Abrechnungsdaten abrufen - string invoiceQuery = @" - SELECT area, base_amount, quantity, amount - FROM invoices - WHERE client_id = @clientId - AND invoice_date BETWEEN @startDatum AND @endDatum"; - - MySqlCommand invoiceCmd = new MySqlCommand(invoiceQuery, myConnection); - invoiceCmd.Parameters.AddWithValue("@clientId", clientId); - invoiceCmd.Parameters.AddWithValue("@startDatum", startDatum); - invoiceCmd.Parameters.AddWithValue("@endDatum", endDatum); - - using (MySqlDataReader invoiceReader = invoiceCmd.ExecuteReader()) - { - List invoiceLines = new List(); - decimal totalAmount = 0; - - while (invoiceReader.Read()) - { - string area = invoiceReader.GetString("area"); - decimal baseAmount = invoiceReader.GetDecimal("base_amount"); - int quantity = invoiceReader.GetInt32("quantity"); - decimal amount = invoiceReader.GetDecimal("amount"); - totalAmount += amount; - - invoiceLines.Add($"{area};{baseAmount};{quantity};{amount}"); - } - invoiceReader.Close(); - - // CSV-Datei schreiben - string filename = $"{DateTime.Now:yyyy-MM-dd}_{kundennummer}_{startDatum}_{endDatum}.csv"; - using (StreamWriter sw = new StreamWriter(filename)) - { - sw.WriteLine($"Zeitraum: {startDatum} bis {endDatum}"); - sw.WriteLine($"Name und Nummer des Kunden: {clientName}, {clientId}"); - sw.WriteLine($"Gesamtsumme der Abrechnung: {totalAmount}"); - sw.WriteLine("Bereich;Grundbetrag;Anzahl;Betrag"); - - foreach (string line in invoiceLines) - { - sw.WriteLine(line); - } - } - } - } - } - myConnection.Close(); - } - catch (MySqlException ex) - { - Console.WriteLine($"Database error: {ex.Message}"); - } - } - } -} - diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/import.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/import.cs index 6c3e31c..14b0b6b 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/import.cs +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/import.cs @@ -1,243 +1,217 @@ -//Aufgabenstellung -// -//1.Import -// -//Als Teil des Entwicklungsteams sollen Sie einen Import für neue Nutzer der jeweiligen Kunden entwickeln. -//Die Kunden schicken zu diesem Zweck CSV-Dateien mit den Daten von neuen Nutzern. -//Diese Daten müssen in die bestehenden Datentabellen eingespielt werden. -//Dafür sind folgende Anforderungen formuliert: -// -// • Ein Sachbearbeiter ruft eine Konsolen-App auf, in welcher er die Datei und die -// Kundennummer des Kunden als Parameter übergibt: Die Beispieldatei hat den Namen "import_yutani.csv" und -// gehört zum Kunden mit der Nummer "K2-002" -// -// • Die Datei hat den Aufbau: -// - Ein Nutzer mit Anrede, Vorname, Nachname und Geburtsdatum -// - Ggf. Adresse: Straße mit Hausnummer, PLZ, Stadt -// - Ggf. E-Mail -// - Ggf. eine oder mehrere Telefonnummern: Vorwahl ohne führende 0 und Nummer -// -// • Ein Nutzer darf für einen Kunden nicht mehrmals importiert werden. -// -// • Die Daten sollen wie folgt validiert werden: -// ○ Geburtsdatum: TT.MM.JJJJ -// ○ Valide E-Mail-Adresse -// ○ PLZ: exakt 5 Nummern -// ○ Telefonnummer 3 bis 5 Nummern für die Vorwahl und 4 bis 10 Nummern für die Hauptnummer. Keine Sonderzeichen -// -// • 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.Net.Mail; -/* - * Das ist der Beispielcode für die Verbindung zum Datenbankserver - * -using MySql.Data; -using MySql.Data.MySqlClient; -using MySqlX.XDevAPI; -using System.Data.Common; -using System.Reflection.PortableExecutable; -using System.Xml; +using Projekt_Calcan_Conze.DTOs; +using Projekt_Calcan_Conze.Models; +using Microsoft.VisualBasic; +namespace Projekt_Calcan_Conze; - MySql.Data.MySqlClient.MySqlConnection myConnection; - string myConnectionString; - //set the correct values for your server, user, password and database name - myConnectionString = "server=localhost;uid=root;pwd=root;database=vr_contact"; - - try - { - myConnection = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString); - //open a connection - myConnection.Open(); - - // create a MySQL command and set the SQL statement with parameters - MySqlCommand myCommand = new MySqlCommand(); - myCommand.Connection = myConnection; - myCommand.CommandText = @"SELECT * FROM workshop WHERE maxParticipants = @code;"; - myCommand.Parameters.AddWithValue("@code", "12"); - - // execute the command and read the results - using MySqlDataReader myReader = myCommand.ExecuteReader(); - - while (myReader.Read()) - { - int id = myReader.GetInt32("maxParticipants"); - string name = myReader.GetString("title"); - Console.WriteLine(id + " " + name); -} - - myConnection.Close(); - } - catch (MySql.Data.MySqlClient.MySqlException ex) +internal static class Import { - -} - * - */ - -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.RegularExpressions; -using MySql.Data.MySqlClient; - -class Import -{ - static void Main(string[] args) + public static (List Customers, List Protocol) For(string filePath) { - string filePath = args[0]; - string customerNumber = args[1]; - - ImportData(filePath, customerNumber); + var (customerDtos, protocol) = Import.ReadCustomerDtos(filePath); + var customers = Import.ParseCustomers(customerDtos, protocol); + return (customers, protocol); } - static void ImportData(string filePath, string customerNumber) + private static (List CustomerDtos, List Protocol) ReadCustomerDtos( + string filePath) { - List errorLog = new List(); + List protocol = []; + List customerDtos = []; + List lines; - using (StreamReader sr = new StreamReader(filePath)) + try { - string line; - while ((line = sr.ReadLine()) != null) + lines = + File.ReadAllLines(filePath) + .Where(line => !string.IsNullOrWhiteSpace(line)) // remove empty lines + .ToList(); + } + catch (Exception) + { + Console.WriteLine("The file does not exist or is currently used by another program."); + return (customerDtos, protocol); + } + + CustomerDto? currentCustomer = null; + + foreach (string line in lines) + { + var lineParts = + line.Split(Constants.Separator) + .Select(linePart => linePart.Trim()) + .Where(linePart => !string.IsNullOrWhiteSpace(linePart)) // remove empty parts + .ToList(); // remove whitespace + + string title = lineParts[0]; + + if (title is Constants.FemaleAttributeIdentifier or Constants.MaleAttributeIdentifier) { - string[] parts = line.Split(';'); - User user = new User + if (currentCustomer is not null) { - Gender = parts[0], - Firstname = parts[1], - Lastname = parts[2], - Birthdate = parts[3], - Address = new Address + customerDtos.Add(currentCustomer); + } + + currentCustomer = new CustomerDto([new CustomerAttributeDto(lineParts)]); + } + else if (currentCustomer is not null) + { + currentCustomer.Attributes.Add(new CustomerAttributeDto(lineParts)); + } + else + { + protocol.Add(line); + } + } + + if (currentCustomer is not null) + { + customerDtos.Add(currentCustomer); + } + + return (customerDtos, protocol); + } + + private static List ParseCustomers(List customerDtos, + List protocol) + { + List customers = []; + + foreach (CustomerDto customerDto in customerDtos) + { + Customer? customer = Import.ParseCustomer(customerDto); + + if (customer is not null) + { + customers.Add(customer); + } + else + { + Import.LogInvalidCustomer(protocol, customerDto); + } + } + + return customers; + } + + private static Customer? ParseCustomer(CustomerDto customer) + { + CustomerAttributeDto firstAttribute = customer.Attributes[0]; + + if (firstAttribute.Parts.Count != 4) + { + return null; + } + + string title = firstAttribute.Parts[0]; + string fistName = firstAttribute.Parts[1]; + string lastName = firstAttribute.Parts[2]; + + DateOnly? dateOfBirth = + DateOnly.TryParseExact(firstAttribute.Parts[3], Constants.DateOfBirthFormat, + out DateOnly date) + ? date + : null; + + if (dateOfBirth is null) + { + return null; + } + + string? email = null; + Address? address = null; + List phoneNumbers = []; + + foreach (CustomerAttributeDto attribute in customer.Attributes.Skip(1)) + { + var attributeParts = attribute.Parts; + string identifier = attributeParts[0]; + + switch (identifier) + { + case Constants.AddressAttributeIdentifier: + if (attributeParts.Count == 4) { - Street = parts[4], - PostalCode = parts[5], - City = parts[6] - }, - Email = parts[7], - Phones = new List - { - new Phone { Prefix = parts[8], Number = parts[9] } + string postalCode = attributeParts[2]; + + if (postalCode.Length == 5) + { + address = + new Address( + streetAndHouseNumber: attributeParts[1], + postalCode: postalCode, + city: attributeParts[3]); + } + else + { + return null; + } } - }; - if (ValidateUser(user, out string error)) - { - InsertUser(user, customerNumber, errorLog); - } - else - { - errorLog.Add(error); - } + break; + + case Constants.EmailAttributeIdentifier: + if (attributeParts.Count == 2) + { + try + { + email = attributeParts[1]; + + _ = new MailAddress( + email); // validate the format of the email address + } + catch (Exception) + { + return null; + } + } + else + { + return null; + } + + break; + + case Constants.PhoneNumberAttributeIdentifier: + if (attributeParts.Count == 3) + { + string areaCode = attributeParts[1]; + string number = attributeParts[2]; + + if (areaCode.Length is >= 3 and <= 5 + && number.Length is >= 4 and <= 10) + { + phoneNumbers.Add(new PhoneNumber(areaCode, number)); + } + } + else + { + return null; + } + + break; + + default: return null; } } - File.WriteAllLines("error_log.txt", errorLog); + return new Customer( + title: title, + firstName: fistName, + lastName: lastName, + dateOfBirth: dateOfBirth.Value, + email: email, + address: address, + phoneNumbers: phoneNumbers); } - static bool ValidateUser(User user, out string error) + private static void LogInvalidCustomer(List protocol, CustomerDto customerDto) { - error = ""; - - if (!Regex.IsMatch(user.Birthdate, @"^\d{2}\.\d{2}\.\d{4}$")) - { - error = "Invalid birthdate format."; - return false; - } - - if (!string.IsNullOrEmpty(user.Email) && !Regex.IsMatch(user.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) - { - error = "Invalid email format."; - return false; - } - - if (!Regex.IsMatch(user.Address.PostalCode, @"^\d{5}$")) - { - error = "Invalid postal code format."; - return false; - } - - foreach (var phone in user.Phones) - { - if (!Regex.IsMatch(phone.Prefix, @"^\d{3,5}$") || !Regex.IsMatch(phone.Number, @"^\d{4,10}$")) - { - error = "Invalid phone number format."; - return false; - } - } - - return true; + protocol.AddRange( + customerDto + .Attributes + .Select(attribute => string.Join(Constants.Separator, attribute.Parts))); } - - static void InsertUser(User user, string customerNumber, List errorLog) - { - string myConnectionString = "server=localhost;uid=root;pwd=root;database=vr_contact"; - using (MySqlConnection myConnection = new MySqlConnection(myConnectionString)) - { - try - { - myConnection.Open(); - - // Check if user already exists for the customer - string checkQuery = "SELECT COUNT(*) FROM users WHERE firstname = @firstname AND lastname = @lastname AND customer_id = @customer_id"; - MySqlCommand checkCmd = new MySqlCommand(checkQuery, myConnection); - checkCmd.Parameters.AddWithValue("@firstname", user.Firstname); - checkCmd.Parameters.AddWithValue("@lastname", user.Lastname); - checkCmd.Parameters.AddWithValue("@customer_id", customerNumber); - - int userCount = Convert.ToInt32(checkCmd.ExecuteScalar()); - - if (userCount > 0) - { - errorLog.Add($"User {user.Firstname} {user.Lastname} already exists for customer {customerNumber}."); - return; - } - - // Insert user - string insertQuery = @" - INSERT INTO users (gender, firstname, lastname, birthdate, street, postal_code, city, email, customer_id) - VALUES (@gender, @firstname, @lastname, @birthdate, @street, @postal_code, @city, @Email, @customer_id)"; - MySqlCommand insertCmd = new MySqlCommand(insertQuery, myConnection); - insertCmd.Parameters.AddWithValue("@gender", user.Gender); - insertCmd.Parameters.AddWithValue("@firstname", user.Firstname); - insertCmd.Parameters.AddWithValue("@lastname", user.Lastname); - insertCmd.Parameters.AddWithValue("@birthdate", user.Birthdate); - insertCmd.Parameters.AddWithValue("@street", user.Address.Street); - insertCmd.Parameters.AddWithValue("@postal_code", user.Address.PostalCode); - insertCmd.Parameters.AddWithValue("@city", user.Address.City); - insertCmd.Parameters.AddWithValue("@Email", user.Email); - insertCmd.Parameters.AddWithValue("@customer_id", customerNumber); - - insertCmd.ExecuteNonQuery(); - myConnection.Close(); - } - catch (MySqlException ex) - { - errorLog.Add($"Database error: {ex.Message}"); - } - } - } -} - -class User -{ - public string Gender { get; set; } - public string Firstname { get; set; } - public string Lastname { get; set; } - public string Birthdate { get; set; } - public Address Address { get; set; } - public string Email { get; set; } - public List Phones { get; set; } = new List(); -} - -class Address -{ - public string Street { get; set; } - public string PostalCode { get; set; } - public string City { get; set; } -} - -class Phone -{ - public string Prefix { get; set; } - public string Number { get; set; } -} +} \ No newline at end of file diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfo.cs b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfo.cs index 7373c4d..560e172 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfo.cs +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfo.cs @@ -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+5c51f68e6cd6355fd53b485ad50b2778d47b8dc0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9f2e9cbec8646502e9f8d8e82a8d93ceb2077c93")] [assembly: System.Reflection.AssemblyProductAttribute("Projekt_Calcan_Conze")] [assembly: System.Reflection.AssemblyTitleAttribute("Projekt_Calcan_Conze")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfoInputs.cache b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfoInputs.cache index aa7de51..54a967d 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfoInputs.cache +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.AssemblyInfoInputs.cache @@ -1 +1 @@ -eae42f1b5ea27ad223d9cfc838d7801feb8aee718629ae41759404b6e801f0e1 +b7a6e87d6dec130dcc98889acb8324098d6ecce8b407916d22fbac7ae0858d76 diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.assets.cache b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.assets.cache index 6d68d5e..c5cac35 100644 Binary files a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.assets.cache and b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Debug/net8.0/Projekt_Calcan_Conze.assets.cache differ diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.dgspec.json b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.dgspec.json index 153c628..d7a113c 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.dgspec.json +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.dgspec.json @@ -66,7 +66,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.302/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json" } } } diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.g.props b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.g.props index 718cb55..86c23a6 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.g.props +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/Projekt_Calcan_Conze.csproj.nuget.g.props @@ -7,7 +7,7 @@ $(UserProfile)\.nuget\packages\ C:\Users\bib\.nuget\packages\ PackageReference - 6.10.1 + 6.11.0 diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.assets.json b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.assets.json index c4cf230..a795b00 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.assets.json +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.assets.json @@ -1850,7 +1850,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.302/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.400/PortableRuntimeIdentifierGraph.json" } } } diff --git a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.nuget.cache b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.nuget.cache index 0c5c666..da2597e 100644 --- a/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.nuget.cache +++ b/Projekt_Calcan_Conze/Projekt_Calcan_Conze/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "eoIzlhHxBoI=", + "dgSpecHash": "3YDIWICGXm0=", "success": true, "projectFilePath": "C:\\Jan_bib_Module\\PMC\\Projekt\\Projekt_Calcan_Conze\\Projekt_Calcan_Conze\\Projekt_Calcan_Conze.csproj", "expectedPackageFiles": [