//---------------------------------------ADD OR GET LOCATION----------------------------------------------------------------------- public Location AddOrGetLocation(ContactBookLogic contactbooklogic, SQLConnection sql, long countLocations, string address, string cityName) { Location location = new Location() { Address = address, CityName = cityName, }; List <Location> locationslist = sql.OutputLocationTableToList(); var locIsDupe = false; var CommandText = ""; foreach (var loc1 in locationslist) { if ((location.Address == loc1.Address) && (location.CityName == loc1.CityName)) { locIsDupe = true; } } if (!locIsDupe) { CommandText = $"INSERT INTO locations(Address, CityName) VALUES ('{location.Address}', '{location.CityName}')"; sql.ExecuteNonQuery(CommandText); //TODOL: info ob location geaddet oder dupe war und nicht geaddet } return(location); }
public void ReadAndAddLocationFromCsvFile(string csvLine, SQLConnection sql) { string[] parts = csvLine.Split(','); parts = parts.Where(x => !string.IsNullOrEmpty(x)).ToArray(); string addressPart = InputChecker.CsvEmptyInputCheck(parts[0]); string cityNamePart = InputChecker.CsvEmptyInputCheck(parts[1]); if (addressPart != "wronginput" && cityNamePart != "wronginput") { Location location = new Location() { Address = addressPart, CityName = cityNamePart, }; List <Location> locationslist = sql.OutputLocationTableToList(); var locIsDupe = false; var CommandText = ""; foreach (var loc1 in locationslist) { if ((location.Address == loc1.Address) && (location.CityName == loc1.CityName)) { locIsDupe = true; } } if (!locIsDupe) { CommandText = $"INSERT INTO locations(Address, CityName) VALUES ('{location.Address}', '{location.CityName}')"; sql.ExecuteNonQuery(CommandText); } //TODOL: message INFO: Location is duplicate and will not be added } //TODOL: message WARNING: Wrong input on line: {csvLine} }
public void ReadAndAddContactFromCsvLine(string csvLine, SQLConnection sql) { string[] parts = csvLine.Split(','); string namePart = InputChecker.CsvEmptyInputCheck(parts[0]); string addressPart = InputChecker.CsvEmptyInputCheck(parts[1]); string cityNamePart = InputChecker.CsvEmptyInputCheck(parts[2]); long.TryParse(parts[3], out long a); long phoneNumberPart = a; string mailAddressPart = InputChecker.CsvMailFormatCheck(parts[4]); string genderPart = InputChecker.CsvGenderCheck(parts[5]); if (phoneNumberPart != 0 && genderPart != "wronginput" && namePart != "wronginput" && addressPart != "wronginput" && cityNamePart != "wronginput") { Location location = new Location() { Address = addressPart, CityName = cityNamePart, }; List <Location> locationslist = sql.OutputLocationTableToList(); var locIsDupe = false; var CommandText = ""; foreach (var loc1 in locationslist) { if ((location.Address == loc1.Address) && (location.CityName == loc1.CityName)) { locIsDupe = true; } } if (!locIsDupe) { CommandText = $"INSERT INTO locations(Address, CityName) VALUES ('{location.Address}', '{location.CityName}')"; sql.ExecuteNonQuery(CommandText); } // TODOL: Message INFO: Location is duplicate and will not be added long LocationID = sql.GetLocationID(location); var contact = new Contact { Name = namePart, LocationID = (int)LocationID, PhoneNumber = phoneNumberPart, MailAddress = mailAddressPart, Gender = genderPart }; List <Contact> contactslist = sql.OutputContactTableToList(); var conIsDupe = false; foreach (var con1 in contactslist) { if ((contact.Name == con1.Name) && (contact.LocationID == con1.LocationID) && (contact.PhoneNumber == con1.PhoneNumber) && (contact.MailAddress == con1.MailAddress) && (contact.Gender == con1.Gender)) { conIsDupe = true; } } if (!conIsDupe) { CommandText = $"INSERT INTO contacts(Name, LocationID, PhoneNumber, MailAddress, Gender) VALUES('{contact.Name}', '{contact.LocationID}', '{contact.PhoneNumber}', '{contact.MailAddress}', '{contact.Gender}');"; sql.ExecuteNonQuery(CommandText); } // TODOL: Message INFO: Contact on {csvLine} is duplicate and will not be added } // TODOL: message WARNING: Wrong input on line: {csvLine} }