Esempio n. 1
0
        public string getNextMeal(ref int nextMealTime)
        {
            nextMeal = "";
            Eat eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Dinner").First() as Eat;

            if (user.DinnerTime > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                nextMeal     = "Dinner";
                nextMealTime = user.DinnerTime;
            }

            eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Lunch").First() as Eat;
            if (user.LunchTime > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                nextMeal     = "Lunch";
                nextMealTime = user.LunchTime;
            }

            eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Breakfest").First() as Eat;
            if (user.BreakfestTime > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                nextMeal     = "Breakfest";
                nextMealTime = user.BreakfestTime;
            }

            return(nextMeal);
        }
Esempio n. 2
0
        public void checkAndNotify()
        {
            //check if it is time
            string current = getCurrentMeal();

            if (!current.Equals(""))
            {
                Eat eat = null;
                eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == current).First() as Eat;

                if (!eat.Notified)
                {
                    eat.Notified = true;
                    EatDB edb = new EatDB(eat);
                    edb.save();
                    //notify:
                    string toast = "<toast>"
                                   + "<visual>"
                                   + "<binding template = \"ToastGeneric\" >"
                                   + "<text> Time to eat! </text>"
                                   + "</binding>"
                                   + "</visual>"
                                   + "<audio src=\"ms - winsoundevent:Notification.Reminder\"/>"
                                   + "</toast>";


                    Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
                    toastDOM.LoadXml(toast);

                    ToastNotification toastNotification = new ToastNotification(toastDOM);

                    var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();
                    toastNotifier.Show(toastNotification);
                }
                this.tbNextMeal.Text  = "It is time for your";
                this.countdown.Text   = current + " now!";
                rectTime.Visibility   = Visibility.Collapsed;
                rectTimeBG.Visibility = Visibility.Collapsed;
                //countdown.Visibility = Visibility.Collapsed;
            }
            else
            {
                rectTime.Visibility   = Visibility.Visible;
                rectTimeBG.Visibility = Visibility.Visible;
                countdown.Visibility  = Visibility.Visible;
                updateCountdown();
            }
        }
Esempio n. 3
0
        public void updateText()
        {
            List <Eat> eats = new List <Eat> {
            };
            string text     = "";

            Day d = DayDB.getDatByDate(dtPicker.Date);

            if (d == null)
            {
                text            = "There is no records for this day";
                tbDays.MaxLines = 100;
                tbDays.Text     = text;

                return;
            }
            eats = EatDB.getByDayID(d.DayID);
            int energy = 0, fat = 0, saturates = 0, sugar = 0, salt = 0;

            if (eats != null)
            {
                foreach (Eat e in eats)
                {
                    Meal meal = MealDB.getAll().Where(m => m.MealID == e.MealID).FirstOrDefault();
                    if (e != null && e.Done && meal != null)
                    {
                        text      += meal.Name + "\n";
                        energy    += meal.Energy;
                        fat       += meal.Fat;
                        saturates += meal.Saturates;
                        sugar     += meal.Sugar;
                        salt      += meal.Salt;
                    }
                }
            }



            text += "\n Energy: " + energy;
            text += "\n Fat: " + fat;
            text += "\n Saturates: " + saturates;
            text += "\n Sugar: " + sugar;
            text += "\n Salt: " + salt;

            tbDays.MaxLines = 100;
            tbDays.Text     = text;
        }
Esempio n. 4
0
        public void updateCountdown()
        {
            if (EatDB.getByDayID(_day.DayID).Where(d => d.Done == false).ToList().Count == 0 ||
                DateTime.Now.TimeOfDay.TotalMinutes > user.DinnerTime)
            {
                this.tbNextMeal.Text = "no more food today...";
                this.rectTime.Width  = 0;
            }
            else
            {
                int      nextMealTime = 0;
                string   nextMeal     = getNextMeal(ref nextMealTime);
                TimeSpan until        = untilNext(nextMeal);

                this.tbNextMeal.Text = nextMeal + " in";
                this.countdown.Text  = until.Hours.ToString() + " hours and " + until.Minutes.ToString() + " minutes";


                double ratio = (DateTime.Now.TimeOfDay.TotalMinutes - (double)_day.LastMeal) / (double)nextMealTime;
                this.rectTime.Width = ratio < 1 ? 200 * ratio : 1;
            }
        }
Esempio n. 5
0
        private void btnHave_Click(object sender, RoutedEventArgs e)
        {
            //get eat from day by kind
            Meal meal = (Meal)cbMeal.SelectedItem;

            if (!_kind.Equals("Snack"))
            {
                Eat eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == _kind).First() as Eat;
                eat.Time   = DateTime.Now;
                eat.Done   = true;
                eat.MealID = meal.MealID;
                EatDB edb = new EatDB(eat);
                edb.save();
            }
            else
            {
                Eat eat = new Eat();
                eat.Time   = DateTime.Now;
                eat.Done   = true;
                eat.MealID = meal.MealID;
                eat.Kind   = "Snack";
                EatDB edb = new EatDB(eat);
                edb.save();
            }

            _day.Energy    += meal.Energy;
            _day.Fat       += meal.Fat;
            _day.Saturates += meal.Saturates;
            _day.Sugars    += meal.Sugar;
            _day.Salt      += meal.Salt;

            DayDB ddb = new DayDB(_day);

            ddb.save();



            Frame.Navigate(typeof(MainPage));
        }
Esempio n. 6
0
        public string getCurrentMeal()
        {
            string currentMeal = "";
            Eat    eat         = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Dinner").First() as Eat;

            if (user.DinnerTime < DateTime.Now.TimeOfDay.TotalMinutes && user.DinnerTime + 60 > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                currentMeal = "Dinner";
            }

            eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Lunch").First() as Eat;
            if (user.LunchTime < DateTime.Now.TimeOfDay.TotalMinutes && user.LunchTime + 60 > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                currentMeal = "Lunch";
            }

            eat = EatDB.getByDayID(_day.DayID).Where(et => et.Kind == "Breakfest").First() as Eat;
            if (user.BreakfestTime < DateTime.Now.TimeOfDay.TotalMinutes && user.BreakfestTime + 60 > DateTime.Now.TimeOfDay.TotalMinutes && !eat.Done && !eat.Skipped)
            {
                currentMeal = "Breakfest";
            }
            nextMeal = currentMeal;
            return(currentMeal);
        }