/// <summary> /// Handles the title if there is more than one receipe /// </summary> /// <param name="receipeTime">The receipe time.</param> public void HandleTitle(ReceipeTime receipeTime) { this.nbCountReceipe = 0; if (receipeTime is ReceipeTimeOfDay) { nbCountReceipe = ((ReceipeTimeOfDay)receipeTime).Receipes.Count; } else if (receipeTime is ReceipeDate) { ReceipeDate receipeDate = (ReceipeDate)receipeTime; day = true; foreach (ReceipeTimeOfDay receipeTimeOfDay in receipeDate.ReceipeTimeOfDay.Values) { nbCountReceipe += receipeTimeOfDay.Receipes.Count; } } if (nbCountReceipe > 1) { this.pageTitle.Text = "Liste de recettes"; } else { this.pageTitle.Text = "Liste de recettes"; } }
/// <summary> /// Fills the page with the previous elements while the navigation. Any state loaded is given when the page /// is recreated from a previous session. /// </summary> /// <param name="sender">The event source ; generaly <see cref="NavigationHelper" /></param> /// <param name="e">Event data that give the parameter of the navigation transmitted /// <see cref="Frame.Navigate(Type, Object)" /> during the initial request of this page and /// a state dictionnary preserved by this page during a previous session /// The state will not take the value Null when the first visit of this page.</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { GoToReceipeListEvent evnt = e.NavigationParameter as GoToReceipeListEvent; this.Model = evnt.AppModel; this.time = evnt.Time; List <ItemReceipe> receipes = new List <ItemReceipe>(); if (evnt.ReceipeTime is ReceipeTimeOfDay) { ReceipeTimeOfDay receipeTimeOfDay = (ReceipeTimeOfDay)evnt.ReceipeTime; foreach (Receipe receipe in receipeTimeOfDay.Receipes.Values) { receipes.Add(ToolItem.CreateItemReceipe(receipe)); } HandleTitle(receipeTimeOfDay); } else if (evnt.ReceipeTime is ReceipeDate) { ReceipeDate receipeDate = (ReceipeDate)evnt.ReceipeTime; foreach (ReceipeTimeOfDay receipeTimeOfDay in receipeDate.ReceipeTimeOfDay.Values) { foreach (Receipe receipe in receipeTimeOfDay.Receipes.Values) { receipes.Add(ToolItem.CreateItemReceipe(receipe)); } } HandleTitle(receipeDate); } listReceipeViewSource.Source = receipes; }
/// <summary> /// Handle the button to go to the receipe list /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ItemClickEventArgs"/> instance containing the event data.</param> private void ItemReceipeListSelected_Click(object sender, ItemClickEventArgs e) { if (e.ClickedItem is ItemReceipeListSelected) { ItemReceipeListSelected item = (ItemReceipeListSelected)e.ClickedItem; Time time = new Time(); time.Date = item.Title; if (this.appModel.ReceipeList.ContainsKey(time.Date)) { ReceipeDate receipeDate = this.appModel.ReceipeList[time.Date]; this.Frame.Navigate(typeof(ReceipeList), new GoToReceipeListEvent(this.appModel, time, receipeDate)); } } }
/// <summary> /// Listener that allow to go to the ReceipeList page. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void GoToReceipeListAll_CLick(object sender, RoutedEventArgs e) { var group = (sender as FrameworkElement).DataContext; SampleDataGroup data = (SampleDataGroup)group; string date = (string)data.Title; Time time = new Time(); time.Date = date; if (this.appModel.ReceipeList.ContainsKey(date)) { ReceipeDate receipeDate = this.appModel.ReceipeList[date]; this.Frame.Navigate(typeof(ReceipeList), new GoToReceipeListEvent(this.appModel, time, receipeDate)); } }
/// Fills the page with the previous elements while the navigation. Any state loaded is given when the page /// is recreated from a previous session. /// </summary> /// <param name="sender"> /// The event source ; generaly <see cref="NavigationHelper"/> /// </param> /// <param name="e"> Event data that give the parameter of the navigation transmitted /// <see cref="Frame.Navigate(Type, Object)"/> during the initial request of this page and /// a state dictionnary preserved by this page during a previous session /// The state will not take the value Null when the first visit of this page.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { if (this.appModel == null) { this.appModel = e.NavigationParameter as AppModel; this.appModel.AddView(this); } StorageFolder folder = KnownFolders.PicturesLibrary; List <SampleDataGroup> sampleDataGroups = new List <SampleDataGroup>(); try { StorageFile receipesFile = await folder.GetFileAsync("receipes.json"); String jsonString = await FileIO.ReadTextAsync(receipesFile); JsonObject jsonObject = JsonObject.Parse(jsonString); JsonArray jsonArray = jsonObject.GetNamedArray("Receipes"); foreach (var jsonDate in jsonArray) { JsonObject receipeDateJson = JsonObject.Parse(jsonDate.Stringify()); ReceipeDate receipeDate = new ReceipeDate(receipeDateJson); SampleDataGroup sampleDataGroup = new SampleDataGroup(receipeDate.Time.Date); foreach (ReceipeTimeOfDay receipeTimeOfDay in receipeDate.ReceipeTimeOfDay.Values) { List <string> imgs = new List <string>(); foreach (Receipe receipe in receipeTimeOfDay.Receipes.Values) { imgs.Add(receipe.Image); } sampleDataGroup.Items.Add(new ItemReceipeTimeOfDay(receipeDate.Time.Date, imgs, receipeTimeOfDay.Time.TimeOfDay)); } sampleDataGroups.Add(sampleDataGroup); } } catch (FileNotFoundException ex) { var messageDialog = new Windows.UI.Popups.MessageDialog("Error: " + ex.Message + " \nLocation: PlanningReceipe class."); } BubbleSort(sampleDataGroups); this.DefaultViewModel["Groups"] = sampleDataGroups; }
/// <summary> /// Fills the page with the previous elements while the navigation. Any state loaded is given when the page /// is recreated from a previous session. /// </summary> /// <param name="sender"> /// The event source ; generaly <see cref="NavigationHelper"/> /// </param> /// <param name="e"> Event data that give the parameter of the navigation transmitted /// <see cref="Frame.Navigate(Type, Object)"/> during the initial request of this page and /// a state dictionnary preserved by this page during a previous session /// The state will not take the value Null when the first visit of this page.</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { GoToModifyReceipeListEvent evnt = e.NavigationParameter as GoToModifyReceipeListEvent; if (evnt != null) { this.Model = evnt.AppModel; if (this.addedView == false) { this.Model.AddView(this); this.addedView = true; } Time time = evnt.Time; this.pageTitle.Text = "Liste de recette du " + time.Date; if (this.Model.ReceipeList.ContainsKey(time.Date)) { ReceipeDate receipeDate = this.Model.ReceipeList[time.Date]; this.date = receipeDate.Time.Date; List <ItemReceipe> itemsMorning = new List <ItemReceipe>(); foreach (Receipe receipe in receipeDate.ReceipeTimeOfDay["Matin"].Receipes.Values) { itemsMorning.Add(ToolItem.CreateItemReceipe(receipe)); } morningReceipeViewSource.Source = itemsMorning; List <ItemReceipe> itemsNoon = new List <ItemReceipe>(); foreach (Receipe receipe in receipeDate.ReceipeTimeOfDay["Midi"].Receipes.Values) { itemsNoon.Add(ToolItem.CreateItemReceipe(receipe)); } noonReceipeViewSource.Source = itemsNoon; List <ItemReceipe> itemsEvenning = new List <ItemReceipe>(); foreach (Receipe receipe in receipeDate.ReceipeTimeOfDay["Soir"].Receipes.Values) { itemsEvenning.Add(ToolItem.CreateItemReceipe(receipe)); } evenningReceipeViewSource.Source = itemsEvenning; } } }
/// <summary> /// Add the ingredients of the receipe in the receipeList, in the shoppingList /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void AddAllIngredients_Click(object sender, RoutedEventArgs e) { foreach (SampleDataGroup data in this.receipeListSelectedModel.GetReceipeListSelected()) { string date = data.Title; ReceipeDate receipeDate = this.appModel.ReceipeList[date]; foreach (ReceipeTimeOfDay receipetod in receipeDate.ReceipeTimeOfDay.Values) { foreach (Receipe rec in receipetod.Receipes.Values) { this.appModel.CreateShoppingList(rec); } } } StorageFolder folder = KnownFolders.PicturesLibrary; StorageFile shoppingListFile = await folder.CreateFileAsync("shoppingList.json", CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteTextAsync(shoppingListFile, this.appModel.StringifyShoppingList()); }
/// <summary> /// Fills the page with the content passed during navigation. Any registered state is also /// provided when a page is recreated from a previous session. /// </summary> /// <param name="sender">The source of the event; in general <see cref="NavigationHelper" /></param> /// <param name="e">Event data that provide the navigation parameter passed to /// <see cref="Frame.Navigate(Type, Object)" /> during the initial request of this page and /// a dictionary stored by this page during a previous session /// The state will not have the Null value at the first visit to the page.</param> private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { this.Model.FavouriteReceipes.Clear(); this.Model.FavouriteReceipes = new Dictionary <string, Receipe>(); StorageFolder folder = KnownFolders.PicturesLibrary; try { StorageFile receipesFile = await folder.GetFileAsync("receipesFavorite.json"); String jsonString = await FileIO.ReadTextAsync(receipesFile); JsonObject jsonObject = JsonObject.Parse(jsonString); JsonArray jsonArray = jsonObject.GetNamedArray("Receipes"); foreach (var jsonReceipe in jsonArray) { Receipe receipe = new Receipe(jsonReceipe.Stringify()); this.Model.AddFavoriteReceipe(receipe); } } catch (FileNotFoundException ex) { } this.favoriteViewSource.Source = this.Model.FavouriteReceipes.Values; if (this.Model.ReceipeList.Count == 0) { try { StorageFile receipesFile = await folder.GetFileAsync("receipes.json"); String jsonString = await FileIO.ReadTextAsync(receipesFile); JsonObject jsonObject = JsonObject.Parse(jsonString); JsonArray jsonArray = jsonObject.GetNamedArray("Receipes"); foreach (var jsonDate in jsonArray) { JsonObject receipeDateJson = JsonObject.Parse(jsonDate.Stringify()); ReceipeDate receipeDate = new ReceipeDate(receipeDateJson); this.Model.ReceipeList.Add(receipeDate.Time.Date, receipeDate); } } catch (Exception ex) { } } if (this.Model.ShoppingList.Count == 0) { try { StorageFile shoppingListFile = await folder.GetFileAsync("shoppingList.json"); String jsonString = await FileIO.ReadTextAsync(shoppingListFile); JsonObject jsonObject = JsonObject.Parse(jsonString); JsonArray jsonArray = jsonObject.GetNamedArray("ShoppingList"); foreach (var jsonShoppingListGroup in jsonArray) { JsonObject groupObject = JsonObject.Parse(jsonShoppingListGroup.Stringify()); String groupName = groupObject.GetNamedString("Name"); this.Model.AddShoppingListGroup(groupName); JsonArray ingredientsArray = groupObject.GetNamedArray("Ingredients"); foreach (var ingredientJson in ingredientsArray) { Ingredient ingredient = new Ingredient(ingredientJson.GetObject()); this.Model.AddIngredientToShoppingList(ingredient, groupName); } } } catch (Exception ex) { } } }