Ejemplo n.º 1
0
        private void updateMealsList(DateFormatter dateFormatter)
        {
            DateTime start;
            DateTime end;

            if (dayRadioButton.Checked)
            {
                start = dateFormatter.DayBeginning();
                end   = dateFormatter.DayEnding();
            }
            else if (weekRadioButton.Checked)
            {
                start = dateFormatter.WeekBeginning();
                end   = dateFormatter.WeekEnding();
            }
            else
            {
                start = dateFormatter.MonthBeginning();
                end   = dateFormatter.MonthEnding();
            }
            MealsList.Clear();
            Globals.AllUsersMeals
            .Where(mealView => mealView.GetMeal().Date >= start && mealView.GetMeal().Date <= end).ToList()
            .ForEach(mealView => MealsList.Add(mealView));
        }
Ejemplo n.º 2
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            try
            {
                var text  = new StringBuilder();
                var start = new DateFormatter(startDateTimePicker.Value);
                var end   = new DateFormatter(endDateTimePicker.Value);
                if (start.DayBeginning() > end.DayEnding())
                {
                    throw new InputExemption("The start date cannot be after the end date.");
                }
                var mealsInDateRange = Globals.AllUsersMeals.Select(mealView => mealView.GetMeal())
                                       .Where(meal => meal.Date > start.DayBeginning() && meal.Date < end.DayEnding()).ToList();

                if (shoppingListRadioButton.Checked)
                {
                    text.AppendLine("Shopping List");
                    text.AppendLine($"For dates {start} to {end}");
                    text.AppendLine();

                    var mealIdArray = mealsInDateRange.Select(meal => meal.Id).ToHashSet <int>().ToArray();
                    Globals.GetListOfIngredientsForMeals(mealIdArray)
                    .ForEach(ingredient => text.AppendLine($"*\t{ingredient}"));

                    reportTextBox.Text = text.ToString();
                }

                if (topTenRadioButton.Checked)
                {
                    text.AppendLine($"Top Recipes for dates {start} to {end}");
                    text.AppendLine("(Max 10)");
                    text.AppendLine();
                    text.AppendLine("Recipe Title\t\t|  Times Recipe Used");
                    text.AppendLine("-----------------------------------------------------------------------------------");

                    var groupOfRecipes = Globals.GetMealsRecipes(mealsInDateRange).GroupBy(recipe => recipe.Title)
                                         .OrderByDescending(recipe => recipe.Count()).Take(10);

                    foreach (var group in groupOfRecipes)
                    {
                        if (group.Key.Length < 8)
                        {
                            text.AppendLine($"{group.Key}\t\t\t|    {group.Count()}");
                        }
                        else
                        {
                            text.AppendLine($"{group.Key}\t\t|    {group.Count()}");
                        }
                    }

                    reportTextBox.Text = text.ToString();
                }
            }
            catch (InputExemption error)
            {
                MessageBox.Show(error.Message, "Instructions", MessageBoxButtons.OK);
            }
        }