public NutritionPage() { InitializeComponent(); (App.Current as App).inverted = IsLightTheme; if ((App.Current as App).inverted) { gradStart.Color = Colors.White; gradStop.Color = Colors.Black; grad2start.Color = Colors.Black; grad2stop.Color = Colors.DarkGray; Glicious.Foreground = new SolidColorBrush(Colors.Black); PgTitle.Foreground = new SolidColorBrush(Colors.Black); dishName.Foreground = new SolidColorBrush(Colors.Black); } dish = (App.Current as App).nutrDish; dishName.Visibility = Visibility.Visible; dishName.Text = dish.name; if (dish.hasNutrition) { nutrTxt.Text = "Calories\nSaturated Fat\nTrans Fat\nCholesterol\nSodium\nDietary Fiber\nSugar\nProtein"; String temp = System.String.Format("{0}\n{1}g\n{2}g\n{3}mg\n{4}mg\n{5}g\n{6}g\n{7}g", dish.nutrition[0], dish.nutrition[4], dish.nutrition[14], dish.nutrition[7], dish.nutrition[11], dish.nutrition[8], dish.nutrition[19], dish.nutrition[3]); nutrVals.Text = temp; nutrVals.FontSize = nutrTxt.FontSize = 35; } else { nutrTxt.FontSize = 44; nutrTxt.Text = "No nutritional \ninformation is \ncurrently available \nfor this dish."; } }
public NutritionPage() { InitializeComponent(); (App.Current as App).inverted = IsLightTheme; if ((App.Current as App).inverted) { LayoutRoot.Background = new SolidColorBrush(Colors.White); Glicious.Foreground = new SolidColorBrush(Colors.Black); PgTitle.Foreground = new SolidColorBrush(Colors.Black); dishName.Foreground = new SolidColorBrush(Colors.Black); nutrTxt.Foreground = new SolidColorBrush(Colors.Black); } else { LayoutRoot.Background = new SolidColorBrush(Colors.Black); Glicious.Foreground = new SolidColorBrush(Colors.White); PgTitle.Foreground = new SolidColorBrush(Colors.White); dishName.Foreground = new SolidColorBrush(Colors.White); nutrTxt.Foreground = new SolidColorBrush(Colors.White); } dish = (App.Current as App).nutrDish; dishName.Visibility = Visibility.Visible; dishName.Text = dish.name; if (dish.hasNutrition) { String temp = System.String.Format("Calories {0}\nTotal Fat {1}g\n\tSaturated Fat {4}g\n\tTrans Fat {14}g\n\tPolyunsaturated Fat {5}g\n\tMonounsaturated Fat {6}g\nCholesterol {7}mg\nSodium {11}mg\nPotassium {15}g\nTotal Carbohydrate {2}g\n\tDietary Fiber {8}g\n\tSugars {19}g\nProtein {3}g\n\nVitamin A (IU): {17}\nVitamin C {9}mg\nVitamin B6 {18}mg\nVitamin B12 {10}mcg\nZinc {12}mg\nIron {13}mg\nCalcium {16}mg", dish.nutrition[0], dish.nutrition[1], dish.nutrition[2], dish.nutrition[3], dish.nutrition[4], dish.nutrition[5], dish.nutrition[6], dish.nutrition[7], dish.nutrition[8], dish.nutrition[9], dish.nutrition[10], dish.nutrition[11], dish.nutrition[12], dish.nutrition[13], dish.nutrition[14], dish.nutrition[15], dish.nutrition[16], dish.nutrition[17], dish.nutrition[18], dish.nutrition[19]); nutrTxt.Text = temp; } else { nutrTxt.FontSize = 44; nutrTxt.Text = "No nutritional \ninformation is \ncurrently available \nfor this dish."; } }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // ignore scenarios when we navigate back to this page and clear what was previously selected if (listBox.SelectedItem != null) { Menu.Venue.Dish dummy = new Menu.Venue.Dish("", false, false, false, false, false, false); Type type = listBox.SelectedItem.GetType(); Type type2 = dummy.GetType(); if (type.FullName.Equals(type2.FullName)) { Menu.Venue.Dish dummy2 = (Menu.Venue.Dish)listBox.SelectedItem; if (dummy2.hasNutrition) { (App.Current as App).nutrDish = (Menu.Venue.Dish)listBox.SelectedItem; datepickerBool = false; NavigationService.Navigate(new Uri("/NutritionPage.xaml", UriKind.Relative)); } } listBox.SelectedIndex = -1; } }
void loadCompleted(object sender, OpenReadCompletedEventArgs e) { try { using (var reader = new StreamReader(e.Result)) { String json = reader.ReadToEnd(); JObject o = JObject.Parse(json); Menu.Venue[] tempVens = new Menu.Venue[30]; int i = 0; String pass = (String)o["PASSOVER"]; if (pass.Equals("true")) { (App.Current as App).passover = true; } else { (App.Current as App).passover = false; } if (o[meal.Text.ToUpper()] != null && o[meal.Text.ToUpper()].HasValues) { foreach (JToken venue in o[meal.Text.ToUpper()].Children()) { //TODO allocate smarter Menu.Venue.Dish[] tempDishes = new Menu.Venue.Dish[60]; String temp = venue.ToString().Substring(1, 40); String venName = temp.Remove(temp.IndexOf("\"")); int j = 0; foreach (JToken dish in venue.Children().Children()) { bool ovolacto, vegan, halal, passover, hasNutrition, gf; String name = (String)dish["name"]; String ovo = (String)dish["ovolacto"]; if (ovo.Equals("true")) { ovolacto = true; } else { ovolacto = false; } String veg = (String)dish["vegan"]; if (veg.Equals("true")) { vegan = true; } else { vegan = false; } if ((App.Current as App).passover) { String passO = (String)dish["passover"]; if (passO.Equals("true")) { passover = true; } else { passover = false; } } else { passover = false; } String hal = (String)dish["halal"]; if (hal.Equals("true")) { halal = true; } else { halal = false; } String glutenF = (String)dish["gluten_free"]; if (glutenF.Equals("true")) { gf = true; } else { gf = false; } Newtonsoft.Json.Linq.JValue dummy = new Newtonsoft.Json.Linq.JValue(false); if (dummy.GetType().FullName.Equals(dish["nutrition"].GetType().FullName)) { hasNutrition = false; tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal, gf); } else { hasNutrition = true; float[] nutrition = new float[20]; int k = 0; foreach (JToken child in dish["nutrition"]) { nutrition[k++] = (float)child; } tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal, gf, nutrition); } } tempVens[i++] = new Menu.Venue(venName, tempDishes); } } else { listBox.Items.Add(new Menu.Venue("No menu available \nfor selected meal.", null)); return; } menu = new Menu(tempVens); } bool pFlag, oFlag, vFlag, gfFlag, compositeBool; if ((App.Current as App).passover && (App.Current as App).passoverFilter) { pFlag = true; } else { pFlag = false; } if ((App.Current as App).ovoFilter) { oFlag = true; } else { oFlag = false; } if ((App.Current as App).veganFilter) { vFlag = true; } else { vFlag = false; } if ((App.Current as App).gfFilter) { gfFlag = true; } else { gfFlag = false; } foreach (Menu.Venue ven in menu.venues) { if (ven != null) { bool added = false; listBox.Items.Add(ven); foreach (Menu.Venue.Dish dish in ven.dishes) { if (dish != null) { if (pFlag) { if (gfFlag && oFlag) { compositeBool = (dish.passover && (dish.vegan || dish.ovolacto) && dish.gf); } else if (gfFlag && vFlag) { compositeBool = (dish.passover && dish.vegan && dish.gf); } else if (oFlag) { compositeBool = (dish.passover && (dish.vegan || dish.ovolacto)); } else if (vFlag) { compositeBool = (dish.passover && dish.vegan); } else if (gfFlag) { compositeBool = (dish.passover && dish.gf); } else { compositeBool = dish.passover; } } else if (gfFlag && oFlag) { compositeBool = ((dish.vegan || dish.ovolacto) && dish.gf); } else if (gfFlag && vFlag) { compositeBool = (dish.vegan && dish.gf); } else if (oFlag) { compositeBool = (dish.vegan || dish.ovolacto); } else if (vFlag) { compositeBool = dish.vegan; } else if (gfFlag) { compositeBool = dish.gf; } else { compositeBool = true; } if (compositeBool) { listBox.Items.Add(dish); added = true; } } } if (!added) { listBox.Items.Remove(ven); } else { listBox.Items.Add(new Menu.Venue("\t", null)); } } } textBlock1.Visibility = Visibility.Collapsed; } catch (Exception except) { textBlock1.Visibility = Visibility.Collapsed; listBox.Items.Add(new Menu.Venue("No menu available \nfor selected meal", null)); Console.WriteLine("Parsing exception: {0}", except); } }
private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // ignore scenarios when we navigate back to this page and clear what was previously selected if (listBox.SelectedItem != null) { Menu.Venue.Dish dummy = new Menu.Venue.Dish("", false, false, false, false, false); Type type = listBox.SelectedItem.GetType(); Type type2 = dummy.GetType(); if (type.FullName.Equals(type2.FullName)) { //Menu.Venue.Dish dummy2 = (Menu.Venue.Dish)listBox.SelectedItem; //if (dummy2.hasNutrition) //{ (App.Current as App).nutrDish = (Menu.Venue.Dish)listBox.SelectedItem; NavigationService.Navigate(new Uri("/NutritionPage.xaml", UriKind.Relative)); //} } listBox.SelectedIndex = -1; } }
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { using (var reader = new StreamReader(e.Result)) { String json = reader.ReadToEnd(); JObject o = JObject.Parse(json); Menu.Venue[] tempVens = new Menu.Venue[30]; int i = 0; if (o[meal.Text.ToUpper()] != null && o[meal.Text.ToUpper()].HasValues) foreach (JToken venue in o[meal.Text.ToUpper()].Children()) { Menu.Venue.Dish[] tempDishes = new Menu.Venue.Dish[60]; String temp = venue.ToString().Substring(1, 40); String venName = temp.Remove(temp.IndexOf("\"")); int j = 0; foreach (JToken dish in venue.Children().Children()) { bool ovolacto, vegan, halal, passover, hasNutrition; String name = (String)dish["name"]; String ovo = (String)dish["ovolacto"]; if (ovo.Equals("true")) ovolacto = true; else ovolacto = false; String veg = (String)dish["vegan"]; if (veg.Equals("true")) vegan = true; else vegan = false; String passO = (String)dish["passover"]; if (passO.Equals("true")) passover = true; else passover = false; String hal = (String)dish["halal"]; if (hal.Equals("true")) halal = true; else halal = false; Newtonsoft.Json.Linq.JValue dummy = new Newtonsoft.Json.Linq.JValue(false); if (dummy.GetType().FullName.Equals(dish["nutrition"].GetType().FullName)) { hasNutrition = false; tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal); } else { hasNutrition = true; float[] nutrition = new float[20]; int k = 0; foreach (JToken child in dish["nutrition"]) nutrition[k++] = (float)child; tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal, nutrition); } } tempVens[i++] = new Menu.Venue(venName, tempDishes); ; } else listBox.Items.Add(new Menu.Venue("No menu available \nfor selected meal", null)); menu = new Menu(tempVens); } textBlock1.Visibility = Visibility.Collapsed; if ((App.Current as App).ovoFilter) { foreach (Menu.Venue ven in menu.venues) if (ven != null) { bool added = false; listBox.Items.Add(ven); foreach (Menu.Venue.Dish dish in ven.dishes) if (dish != null && (dish.ovolacto || dish.vegan)) { listBox.Items.Add(dish); added = true; } if (!added) listBox.Items.Remove(ven); else listBox.Items.Add(new Menu.Venue("\t", null)); } } else if ((App.Current as App).veganFilter) { foreach (Menu.Venue ven in menu.venues) if (ven != null) { bool added = false; listBox.Items.Add(ven); foreach (Menu.Venue.Dish dish in ven.dishes) if (dish != null && (dish.vegan)) { listBox.Items.Add(dish); added = true; } if (!added) listBox.Items.Remove(ven); else listBox.Items.Add(new Menu.Venue("\t", null)); } } else foreach (Menu.Venue ven in menu.venues) if (ven != null) { listBox.Items.Add(ven); foreach (Menu.Venue.Dish dish in ven.dishes) if (dish != null) listBox.Items.Add(dish); listBox.Items.Add(new Menu.Venue("\t", null)); } } catch (Exception execpt) { textBlock1.Visibility = Visibility.Collapsed; listBox.Items.Add(new Menu.Venue("No menu available \nfor selected meal", null)); } }