Пример #1
0
        public static void ReadManuFromDB(List <Coffee_Type> manu)
        {
            string connectionstring =
                ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                string command = "select * from Coffee_Manu";

                connection.Open();

                SqlCommand com = new SqlCommand(command, connection);

                SqlDataReader reader = com.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Coffee_Type data = new Coffee_Type(
                            (int)reader["ID"],
                            (string)reader["coffee_name"],
                            (double)reader["coffee_dose"],
                            (double)reader["water_dose"],
                            (double)reader["sugar_dose"],
                            (int)reader["price"]);

                        manu.Add(data);
                    }
                }
                reader.Close();
            }
        }
        public void MakeCoffee(Coffee_Type selectCoffee)
        {
            string connectionstring = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString;

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                string selectQuerry = "select * from Ingredients";

                connection.Open();
                SqlCommand    command = new SqlCommand(selectQuerry, connection);
                SqlDataReader reader  = command.ExecuteReader();
                Storage       storage = null;

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        storage = new Storage(
                            (double)reader["coffee"],
                            (double)reader["water"],
                            (double)reader["sugar"]);
                    }
                }
                else
                {
                    throw new Exception();
                }

                reader.Close();

                if (selectCoffee.coffee_dose <= storage.coffee &&
                    selectCoffee.water_dose <= storage.water &&
                    selectCoffee.sugar_dose <= storage.sugar)
                {
                    storage.coffee -= selectCoffee.coffee_dose;
                    storage.water  -= selectCoffee.water_dose;
                    storage.sugar  -= selectCoffee.sugar_dose;

                    string updateQuerry =
                        $"update Ingredients set water = {storage.water}," +
                        $"sugar = {storage.sugar}," +
                        $"coffee = {storage.coffee}";

                    SqlCommand com = new SqlCommand(updateQuerry, connection);

                    com.ExecuteNonQuery();
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("Your coffee is complet!\n" +
                                          "Press 1 to take the change\n" +
                                          "Press 2 to go to the MAIN MANU");
                        string PressKey = Console.ReadKey().KeyChar.ToString().ToLower();
                        switch (PressKey)
                        {
                        case ("1"):
                            Console.Clear();
                            BusinessLogic.RemovePriceFromMoney(selectCoffee, buyer);
                            BusinessLogic.ReturningChange(buyer);
                            return;

                        case ("2"):
                            Console.Clear();
                            BusinessLogic.RemovePriceFromMoney(selectCoffee, buyer);
                            return;

                        default:
                            Console.Clear();
                            Console.WriteLine("Invalid entry try again");
                            break;
                        }
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Coffee machine is out of ingredients");
                    Thread.Sleep(1500);
                    Console.Clear();
                }
            }
        }
Пример #3
0
 public static void RemovePriceFromMoney(Coffee_Type selectCoffee, Buyer buyer)
 {
     buyer.Money -= selectCoffee.price;
 }