Esempio n. 1
0
        public static bool CheckStoreIsEnough(Coffees coffee, out string message)
        {
            message       = "";
            Coffees.Store = Store.LoadStoreData();

            if (coffee.Coffee > Coffees.Store.Coffee)
            {
                message = "Sorry, there is no enough coffee for your order.";
                return(false);
            }

            if (coffee.Sugar > Coffees.Store.Sugar)
            {
                message = "Sorry, there is no enough sugar for your order.";
                return(false);
            }

            if (coffee.Water > Coffees.Store.Water)
            {
                message = "Sorry, there is no enough water for your order.";
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        public static Coffees GetCoffeeByNumber(int coffeeNumber)
        {
            Coffees coffee = new Coffees();

            using (SqlConnection connection = new SqlConnection(Program.ConnectionString))
            {
                string     sqlCommand = "Select * From Coffees Where CoffeeNumber=@CoffeeNumber";
                SqlCommand cmd        = new SqlCommand(sqlCommand, connection);
                cmd.Parameters.AddWithValue("@CoffeeNumber", coffeeNumber);
                connection.Open();

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        coffee.CoffeeName   = reader["CoffeeName"].ToString();
                        coffee.Water        = Double.Parse(reader["Water"].ToString());
                        coffee.Sugar        = Double.Parse(reader["Sugar"].ToString());
                        coffee.Coffee       = Double.Parse(reader["Coffee"].ToString());
                        coffee.Price        = Int32.Parse(reader["Price"].ToString());
                        coffee.CoffeeNumber = Int32.Parse(reader["CoffeeNumber"].ToString());
                    }

                    connection.Close();
                }
            }

            return(coffee);
        }
Esempio n. 3
0
        public static List <Coffees> GetAllCoffees()
        {
            List <Coffees> coffees = new List <Coffees>();

            using (SqlConnection connection = new SqlConnection(Program.ConnectionString))
            {
                string     sqlCommand = "Select * From Coffees";
                SqlCommand cmd        = new SqlCommand(sqlCommand, connection);
                connection.Open();

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Coffees coffee = new Coffees();
                        coffee.CoffeeName   = reader["CoffeeName"].ToString();
                        coffee.Water        = Double.Parse(reader["Water"].ToString());
                        coffee.Sugar        = Double.Parse(reader["Sugar"].ToString());
                        coffee.Coffee       = Double.Parse(reader["Coffee"].ToString());
                        coffee.Price        = Int32.Parse(reader["Price"].ToString());
                        coffee.CoffeeNumber = Int32.Parse(reader["CoffeeNumber"].ToString());

                        coffees.Add(coffee);
                    }

                    connection.Close();
                }
            }

            return(coffees);
        }
Esempio n. 4
0
        public bool UpdateStoreData(Coffees coffee)
        {
            using (SqlConnection connection = new SqlConnection(Program.ConnectionString))
            {
                string     sqlCommand = "Update Store SET Water=@Water, Coffee=@Coffee, Sugar=@Sugar";
                SqlCommand cmd        = new SqlCommand(sqlCommand, connection);
                cmd.Parameters.AddWithValue("@Water", this.Water - coffee.Water);
                cmd.Parameters.AddWithValue("@Coffee", this.Coffee - coffee.Coffee);
                cmd.Parameters.AddWithValue("@Sugar", this.Sugar - coffee.Sugar);
                connection.Open();

                return(cmd.ExecuteNonQuery() > 0);
            }
        }
Esempio n. 5
0
 public static bool UpdateStore(Coffees coffee)
 {
     return(Store.UpdateStoreData(coffee));
 }