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(); } }
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)); }
public void updateDay() { // _day = null; if (this._day == null || (this._day.Date.Date.Year != DateTime.Now.Date.Year || this._day.Date.Date.DayOfYear != DateTime.Now.Date.DayOfYear)) { //create day this._day = new Day(); this._day.User = this.user; this._day.Date = DateTime.Now; this._day.LastMeal = (int)DateTime.Now.TimeOfDay.TotalMinutes; DayDB ddb = new DayDB(this._day); ddb.save(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["dayID"] = _day.DayID; List <Eat> eats = new List <Eat> { }; eats.Add(new Eat(_day.DayID, "Breakfest")); eats.Add(new Eat(_day.DayID, "Lunch")); eats.Add(new Eat(_day.DayID, "Dinner")); foreach (Eat e in eats) { EatDB edb = new EatDB(e); edb.save(); } this.tbDate.Text = DateTime.Now.Day.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Year.ToString(); //Update meals from servers everyday NetworkService.updateMeals(); } }