public void Remove(int id) { using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.DeleteCommand = new MySqlCommand("DELETE FROM mydb.cities WHERE (Id = " + id.ToString() + ");", connection); connection.Open(); StaticService.adapter.DeleteCommand.ExecuteNonQuery(); } StaticService.cities.Remove(StaticService.cities.Find(x => x.Id == id)); }
public void Remove(IDBEntity entity) { City cityIn = (City)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.DeleteCommand = new MySqlCommand("DELETE FROM mydb.cities WHERE (Id = " + cityIn.Id + ");", connection); connection.Open(); StaticService.adapter.DeleteCommand.ExecuteNonQuery(); } // StaticService.cities.Remove(cityIn); }
public void Remove(IDBEntity entity) { Customer customerIn = (Customer)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.DeleteCommand = new MySqlCommand("DELETE FROM mydb.customers WHERE (Name = '" + customerIn.Name + "') AND (FirstName = '" + customerIn.FirstName + "');", connection); connection.Open(); StaticService.adapter.DeleteCommand.ExecuteNonQuery(); } // StaticService.customers.Remove(customerIn); }
public IDBEntity Create(IDBEntity entity) { City city = (City)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.InsertCommand = new MySqlCommand( "INSERT INTO mydb.cities " + "VALUES(@Id,@City);", connection); StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value = city.Id; StaticService.adapter.InsertCommand.Parameters.Add("@City", MySqlDbType.VarChar).Value = city.Name; connection.Open(); StaticService.adapter.InsertCommand.ExecuteNonQuery(); } StaticService.cities.Add(city); return(city); }
public void Update(int id, IDBEntity entity) { City cityIn = (City)entity; using (MySqlConnection connection = StaticService.GetConnection()) { string query = @"UPDATE cities SET Id =" + cityIn.Id + " ,City = '" + cityIn.Name + @" WHERE (" + @"Id = " + cityIn.Id + @")"; MySqlDataAdapter localAadapter = new MySqlDataAdapter(); localAadapter.UpdateCommand = new MySqlCommand(query, connection); connection.Open(); localAadapter.UpdateCommand.ExecuteNonQuery(); } // StaticService.cities.Remove(StaticService.cities.Find(city => city.Id == id)); StaticService.cities.Add(cityIn); }
public IDBEntity Create(IDBEntity entity) { CustomerPlace customerPlace = (CustomerPlace)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.InsertCommand = new MySqlCommand( "INSERT INTO mydb.customersPlaces " + "VALUES(@Id,@UpdateTime,@CustomerId,@PlaceId);", connection); StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value = customerPlace.Id; StaticService.adapter.InsertCommand.Parameters.Add("@UpdateTime", MySqlDbType.Timestamp).Value = customerPlace.UpdateTime; // no ToString("FormatString") StaticService.adapter.InsertCommand.Parameters.Add("@CustomerId", MySqlDbType.Int32).Value = customerPlace.CustomerId; StaticService.adapter.InsertCommand.Parameters.Add("@PlaceId", MySqlDbType.Int32).Value = customerPlace.PlaceId; connection.Open(); StaticService.adapter.InsertCommand.ExecuteNonQuery(); } StaticService.customersPlaces.Add(customerPlace); return(customerPlace); }
public void Update(int id, IDBEntity entity) { CustomerPlace customerPlaceIn = (CustomerPlace)entity; using (MySqlConnection connection = StaticService.GetConnection()) { string query = @"UPDATE customersPlaces SET Id =" + customerPlaceIn.Id + " ,UpdateTime = '" + customerPlaceIn.UpdateTime.ToString("yyyy-MM-dd hh:mm:ss") + "' ,CustomerId = " + customerPlaceIn.CustomerId + " ,PlaceId = " + customerPlaceIn.PlaceId + @" WHERE (" + @"Id = " + customerPlaceIn.Id + @")"; MySqlDataAdapter localAadapter = new MySqlDataAdapter(); localAadapter.UpdateCommand = new MySqlCommand(query, connection); connection.Open(); localAadapter.UpdateCommand.ExecuteNonQuery(); } // StaticService.customersPlaces.Remove(StaticService.customersPlaces.Find(city => city.Id == id)); StaticService.customersPlaces.Add(customerPlaceIn); }
public IDBEntity Create(IDBEntity entity) { Place place = (Place)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.InsertCommand = new MySqlCommand( "INSERT INTO mydb.places " + "VALUES(@Id,@CityId,@Street);", connection); StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value = place.Id; StaticService.adapter.InsertCommand.Parameters.Add("@CityId", MySqlDbType.Int32).Value = place.City.Id; StaticService.adapter.InsertCommand.Parameters.Add("@Street", MySqlDbType.VarChar).Value = place.Street; connection.Open(); StaticService.adapter.InsertCommand.ExecuteNonQuery(); } StaticService.places.Add(place); return(place); }
public void Update(int id, IDBEntity entity) { Place placeIn = (Place)entity; using (MySqlConnection connection = StaticService.GetConnection()) { string query = @"UPDATE places SET Id =" + placeIn.Id + " ,CityId = '" + placeIn.City.Id + "' ,Street = '" + placeIn.Street + @"' WHERE (" + @"Id = " + placeIn.Id + @")"; MySqlDataAdapter localAadapter = new MySqlDataAdapter(); localAadapter.UpdateCommand = new MySqlCommand(query, connection); connection.Open(); localAadapter.UpdateCommand.ExecuteNonQuery(); } // StaticService.places.Remove(StaticService.places.Find(city => city.Id == id)); StaticService.places.Add(placeIn); }
public void Update(int id, IDBEntity entity) { Customer customerIn = (Customer)entity; using (MySqlConnection connection = StaticService.GetConnection()) { string query = @"UPDATE customers SET Id = " + customerIn.Id + " ,Name = '" + customerIn.Name + @"',FirstName = '" + customerIn.FirstName + @"',DateOfBirth = '" + customerIn.DateOfBirth.ToString("yyyy-MM-dd") + @"' WHERE (" + @"Id = " + id + @")"; MySqlDataAdapter localAadapter = new MySqlDataAdapter(); localAadapter.UpdateCommand = new MySqlCommand(query, connection); connection.Open(); localAadapter.UpdateCommand.ExecuteNonQuery(); } // StaticService.customers.Remove(StaticService.customers.Find(customer => customer.Id == id)); StaticService.customers.Add(customerIn); }
public IDBEntity Create(IDBEntity entity) { Customer customer = (Customer)entity; using (MySqlConnection connection = StaticService.GetConnection()) { StaticService.adapter.InsertCommand = new MySqlCommand( "INSERT INTO mydb.customers " + "VALUES(@Id,@Name,@FirstName,@DateOfBirth);", connection); StaticService.adapter.InsertCommand.Parameters.Add("@Id", MySqlDbType.Int32).Value = customer.Id; StaticService.adapter.InsertCommand.Parameters.Add("@Name", MySqlDbType.VarChar).Value = customer.Name; StaticService.adapter.InsertCommand.Parameters.Add("@FirstName", MySqlDbType.VarChar).Value = customer.Name; StaticService.adapter.InsertCommand.Parameters.Add("@DateOfBirth", MySqlDbType.Date).Value = customer.DateOfBirth.ToString("yyyy-MM-dd"); connection.Open(); StaticService.adapter.InsertCommand.ExecuteNonQuery(); } StaticService.customers.Add(customer); return(customer); }