Esempio n. 1
0
        public void DeleteCountry(ManufacturerCountry country, Proxy proxy)
        {
            string sqlExpression = string.Format(@"DELETE FROM manufacturercountry WHERE Id = {0} AND CountryName = ""{1}""", country.Id, country.CountryName);

            using (var connection = Connection.GetInstance().GetConnection())
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(sqlExpression, connection);
                var          number  = command.ExecuteNonQuery();
                Console.WriteLine($"Deleted {number} rows");
            }
            NotifyAllObservers();
        }
Esempio n. 2
0
        public void UpdateCountry(ManufacturerCountry manufacturerCountry, string newName, Proxy proxy)
        {
            string sqlexpression = string.Format(@"UPDATE manufacturercountry SET CountryName = ""{0}"" WHERE Id = {1}", newName, manufacturerCountry.Id);

            using (var connection = Connection.GetInstance().GetConnection())
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(sqlexpression, connection);
                var          number  = command.ExecuteNonQuery();
                Console.WriteLine($"{number} rows was updated");
            }
            NotifyAllObservers();
        }
Esempio n. 3
0
        public ManufacturerCountry CreateCountry(string name, Proxy proxy)
        {
            ManufacturerCountry country = null;
            string sqlexpression        = string.Format(@"INSERT INTO manufacturercountry (CountryName) VALUES (""{0}"")", name);

            using (var connection = Connection.GetInstance().GetConnection())
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(sqlexpression, connection);
                int          number  = command.ExecuteNonQuery();
                Console.WriteLine($"Added {number} elements");
            }
            country = GetByName(name);
            NotifyAllObservers();
            return(country);
        }
Esempio n. 4
0
        public ManufacturerCountry GetById(int id)
        {
            ManufacturerCountry country = null;
            string sqlexpression        = String.Format("SELECT * FROM manufacturercountry WHERE ID = {0}", id);

            using (var connection = Connection.GetInstance().GetConnection())
            {
                connection.Open();
                MySqlCommand command = new MySqlCommand(sqlexpression, connection);
                var          reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    Console.WriteLine($"{reader.GetName(0)}\t{reader.GetName(1)}");
                    while (reader.Read())
                    {
                        country = new ManufacturerCountry((int)reader.GetValue(0), (string)reader.GetValue(1));
                    }
                }
                reader.Close();
            }
            return(country);
        }