Exemplo n.º 1
0
        //private async void SaveButton_Click(object sender, RoutedEventArgs e)
        //{
        //    MealLog logger = null;
        //    try
        //    {
        //        logger = new MealLog();

        //        string dietType = DietComboBox.SelectedValue.ToString();
        //        DietBase dietMeal = DietFactory.GetDietBase(dietType);
        //        IDrink dietDrink = DietFactory.GetIDrink(dietType);
        //        string meal = dietMeal.GetNextMeal();
        //        string drink = dietDrink.GetNextDrink();

        //        await logger.Log(DateTime.Now + " : " + meal + " : " + drink);
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show("Problem logging: " + ex.Message, "Error");
        //    }
        //    finally
        //    {
        //        if (logger != null)
        //            logger.Dispose();
        //    }
        //}

        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            using (var logger = new MealLog())
            {
                string   dietType  = DietComboBox.SelectedValue.ToString();
                DietBase dietMeal  = DietFactory.GetDietBase(dietType);
                IDrink   dietDrink = DietFactory.GetIDrink(dietType);
                string   meal      = dietMeal.GetNextMeal();
                string   drink     = dietDrink.GetNextDrink();

                await logger.Log(DateTime.Now + " : " + meal + " : " + drink);
            }
        }
Exemplo n.º 2
0
        private void DrinkButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string dietType = DietComboBox.SelectedValue.ToString();
                IDrink diet     = DietFactory.GetIDrink(dietType);
                string drink    = diet.GetNextDrink();

                MessageBox.Show("Next Drink: " + drink, "Drink");
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("Please select a diet.", "Error");
            }
        }
Exemplo n.º 3
0
        private void MealButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string   dietType = DietComboBox.SelectedValue.ToString();
                DietBase diet     = DietFactory.GetDietBase(dietType);
                string   meal     = diet.GetNextMeal();

                MessageBox.Show("Next Meal: " + meal, "Meal");
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("Please select a diet.", "Error");
            }
        }