Exemplo n.º 1
0
        public void UpdateProductNameByName(string product, string change)
        {
            int             prodid = reader.GetProductID(product);
            MySqlConnection conn   = new MySqlConnection(ConnStr);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "UPDATE products SET name = @change WHERE name = @product";
                cmd.Parameters.AddWithValue("product", product);
                cmd.Parameters.AddWithValue("change", change);
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 2
0
        public void DeleteProductByName(string product)
        {
            int prodid = reader.GetProductID(product);

            DeleteSalesByProductId(prodid);
            MySqlConnection conn = new MySqlConnection(ConnStr);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "DELETE FROM products WHERE name = @product";
                cmd.Parameters.AddWithValue("product", product);
                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 3
0
        public void AddSale(string product, int quantity, DateTime date)
        {
            MySqlConnection conn      = new MySqlConnection(ConnStr);
            decimal         price     = reader.GetProductPrice(product);
            int             productID = reader.GetProductID(product);

            using (conn)
            {
                conn.Open();

                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = "INSERT INTO sales (ProductID, Quantity, Price, Date) VALUES(@productID, @quantity, @price, @date);";
                cmd.Parameters.AddWithValue("productId", productID);
                cmd.Parameters.AddWithValue("quantity", quantity);
                cmd.Parameters.AddWithValue("price", price);
                cmd.Parameters.AddWithValue("date", date);
                cmd.ExecuteNonQuery();
            }
        }