示例#1
0
        public List <IProduct> GetAllProducts()
        {
            try
            {
                string connectionString = "Server=remotemysql.com;Database=ZLVoYz8ysj;Uid=ZLVoYz8ysj;Pwd=7FkJ5gfEh0;";
                string query            = "select * from products";

                MySqlConnection con = new MySqlConnection(connectionString);
                MySqlCommand    cmd = new MySqlCommand(query, con);

                con.Open();

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ProductCreator pc = new CasualProductCreator();
                    products.Add(pc.Create(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), reader.GetFloat(3), reader.GetInt32(4)));
                }

                reader.Close();
                con.Close();


                return(products);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Błąd połączenia z bazą danych: " + ex.Message);
                return(null);
            }
        }
示例#2
0
        public IProduct GetProduct(int id)
        {
            IProduct product = null;

            try
            {
                string connectionString = "Server=remotemysql.com;Database=ZLVoYz8ysj;Uid=ZLVoYz8ysj;Pwd=7FkJ5gfEh0;";
                string query            = "select * from products where id='" + id + "';";

                MySqlConnection con = new MySqlConnection(connectionString);
                MySqlCommand    cmd = new MySqlCommand(query, con);

                con.Open();

                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    ProductCreator pc = new CasualProductCreator();
                    product = pc.Create(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), reader.GetFloat(3), reader.GetInt32(4));
                }

                con.Close();

                return(product);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wystąpił błąd: " + ex.Message);
                return(null);
            }
        }