internal bool AddCity(City addedCity) { string cityAddSQL = @"insert into Cities (CityName, Region, Country, Attribute) values (?,?,?,?)"; try { using (SqlConnection connection = new SqlConnection(SQLConnStr)) { using (SqlCommand command = new SqlCommand(cityAddSQL,connection)) { connection.Open(); command.Parameters.AddWithValue("CityName", addedCity.Name); command.Parameters.AddWithValue("Region", addedCity.Region); command.Parameters.AddWithValue("Country", addedCity.Country); command.Parameters.AddWithValue("Attribute", addedCity.Attrib); command.ExecuteNonQuery(); } } return true; } catch (SqlException ex) { Console.WriteLine(ex.Message); return false; } }
internal bool EditCity(int id, City changedCity) { string cityEditSQL = string.Concat("update Cities set CityName=@CityName, Region=@Region, Country=@Country, Attribute=@Attribute where Id=",id.ToString()); try { using (SqlConnection connection = new SqlConnection(SQLConnStr)) { using (SqlCommand command = new SqlCommand(cityEditSQL,connection)) { connection.Open(); command.Parameters.AddWithValue("@CityName", changedCity.Name); command.Parameters.AddWithValue("@Region", changedCity.Region); command.Parameters.AddWithValue("@Country", changedCity.Country); command.Parameters.AddWithValue("@Attribute", changedCity.Attrib); command.ExecuteNonQuery(); } } return true; } catch (SqlException ex) { Console.WriteLine(ex.Message); return false; } }
public City DecodeCity(string cityInput) { City output = new City(); char delimiter = '#'; string[] cityInputSplit = cityInput.Split(delimiter); output.Name = cityInputSplit[2]; output.Region = cityInputSplit[3]; output.Country = cityInputSplit[4]; output.Attrib = Convert.ToBoolean(cityInputSplit[5]); return output; }