コード例 #1
0
ファイル: DBEdit.cs プロジェクト: Alex-Klyuchnik/UBB_Test_app
 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;
     }
 }
コード例 #2
0
ファイル: DBEdit.cs プロジェクト: Alex-Klyuchnik/UBB_Test_app
 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;
     }
 }
コード例 #3
0
 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;
 }