Пример #1
0
 /// <summary>
 /// Sets the steps of this recipe to the given list of recipe
 /// steps. This list cannot be null.
 /// </summary>
 /// <param name="newRecipeSteps">
 /// A non-null list of recipe steps
 /// </param>
 public void setSteps(ObservableCollection <RecipeStep> newRecipeSteps)
 {
     if (newRecipeSteps != null)
     {
         for (int i = 0; i < newRecipeSteps.Count; i++)
         {
             RecipeStep step = newRecipeSteps[i];
             if (step.RecipeID == -1)
             {
                 step.setRecipeId(this.id);
                 step.setOrder(i);
                 RecipeBookDataAccessor.addStep(step);
             }
             else
             {
                 if (step.Order != i)
                 {
                     step.setOrder(i);
                 }
                 RecipeBookDataAccessor.updateStep(step);
             }
         }
         this.recipeSteps = newRecipeSteps;
     }
 }
Пример #2
0
 public void updateJournalEntry(RecipeJournalEntry updatedEntry)
 {
     if (updatedEntry != null && updatedEntry.ID != -1)
     {
         int entryIndex = journalEntries.IndexOf(updatedEntry);
         journalEntries.set(entryIndex, updatedEntry);
         RecipeBookDataAccessor.updateJournalEntry(updatedEntry);
         journalEntries.sortJournal();
     }
 }
Пример #3
0
 public void addJournalEntry(RecipeJournalEntry newEntry)
 {
     if (newEntry != null)
     {
         journalEntries.Add(newEntry);
         RecipeBookDataAccessor.addJournalEntry(newEntry);
         journalEntries.sortJournal();
         RaisePropertyChanged("LastMadeString");
         RaisePropertyChanged("MadeToday");
     }
 }
Пример #4
0
 /// <summary>
 /// Empties this recipe list and deletes all related
 /// information
 /// </summary>
 public void empty()
 {
     recipes.Clear();
     RecipeBookDataAccessor.emptyRecipteList();
     selectedRecipeIndex = -1;
     recipeIdGenerator.reset();
     imageIdGenerator.reset();
     ingredientIdGenerator.reset();
     stepIdGenerator.reset();
     verifyImageFolder();
 }
Пример #5
0
        /// <summary>
        /// Sets the associated images of this recipe to the given new
        /// set of images.
        /// </summary>
        /// <param name="newImages">
        /// The new images to associate to this recipe.
        /// </param>
        public async void setImages(ObservableCollection <RecipeImage> newImages)
        {
            // TODO: clean up this code a bit, it's messy
            if (newImages != null)
            {
                recipeImages.Clear();
                for (int i = 0; i < newImages.Count; i++)
                {
                    RecipeImage newImage = newImages[i];
                    if (newImage.RecipeID == -1)
                    {
                        StorageFolder imageFolder = await RecipeList.imageFolder.CreateFolderAsync("" + this.id, CreationCollisionOption.OpenIfExists);

                        StorageFile imageFile = await StorageFile.GetFileFromPathAsync(newImage.ImagePath);

                        if (imageFile != null)
                        {
                            BitmapImage image       = null;
                            StorageFile savingImage = await imageFile.CopyAsync(imageFolder);

                            if (imageFile.IsAvailable)
                            {
                                using (IRandomAccessStream stream = await savingImage.OpenAsync(FileAccessMode.Read))
                                {
                                    image = new BitmapImage();
                                    await image.SetSourceAsync(stream);

                                    newImage.setInternalImage(image);
                                    stream.Dispose();
                                }
                            }
                            else
                            {
                                image           = new BitmapImage();
                                image.UriSource = new Uri(savingImage.Path);
                                newImage.setInternalImage(image);
                            }
                            newImage.ImagePath = savingImage.Path;
                        }

                        newImage.setRecipeId(this.id);
                        RecipeBookDataAccessor.addImage(newImage);
                    }
                    recipeImages.Add(newImage);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;
            recipes          = new RecipeList();

            recipes.verifyImageFolder();

            RecipeBookDataAccessor.InitializeDatabase();

            long recipeStartingId = RecipeBookDataAccessor.getMaxId(Recipe.TABLE_NAME) + 1;

            RecipeList.recipeIdGenerator = new IdentifierGenerator(Recipe.TABLE_NAME, recipeStartingId);

            long ingredientStartingId = RecipeBookDataAccessor.getMaxId(RecipeIngredient.TABLE_NAME) + 1;

            RecipeList.ingredientIdGenerator = new IdentifierGenerator(RecipeIngredient.TABLE_NAME, ingredientStartingId);

            long stepStartingId = RecipeBookDataAccessor.getMaxId(RecipeStep.TABLE_NAME) + 1;

            RecipeList.stepIdGenerator = new IdentifierGenerator(RecipeStep.TABLE_NAME, stepStartingId);

            long imageStartingId = RecipeBookDataAccessor.getMaxId(RecipeImage.TABLE_NAME) + 1;

            RecipeList.imageIdGenerator = new IdentifierGenerator(RecipeImage.TABLE_NAME, imageStartingId);

            long entryStartingId = RecipeBookDataAccessor.getMaxId(RecipeJournalEntry.TABLE_NAME) + 1;

            RecipeList.journalEntryIdGenerator = new IdentifierGenerator(RecipeJournalEntry.TABLE_NAME, entryStartingId);

            ObservableCollection <Recipe> savedRecipes = RecipeBookDataAccessor.getSavedRecipes();

            for (int i = 0; i < savedRecipes.Count; i++)
            {
                Recipe savedRecipe = savedRecipes[i];
                ObservableCollection <RecipeIngredient> savedIngredients = RecipeBookDataAccessor.getIngredients(savedRecipe.ID);
                ObservableCollection <RecipeStep>       savedSteps       = RecipeBookDataAccessor.getSteps(savedRecipe.ID);
                ObservableCollection <RecipeImage>      savedImages      = RecipeBookDataAccessor.getImages(savedRecipe.ID);
                RecipeJournal savedEntries = RecipeBookDataAccessor.getJournalEntries(savedRecipe.ID);
                savedRecipe.setIngredients(savedIngredients);
                savedRecipe.setSteps(savedSteps);
                savedRecipe.setImages(savedImages);
                savedRecipe.setJournalEntries(savedEntries);
            }
            recipes.setRecipeList(savedRecipes);
        }
Пример #7
0
        /*
         * Save the changes made to an existing recipe or add the new
         * recipe to the recipe list.
         */
        private async void saveRecipe(object sender, RoutedEventArgs e)
        {
            String newRecipeName = this.recipeName.Text;

            // double newRecipeRating = this.recipeRating.Value;

            recipe.Name = newRecipeName;
            // recipe.Rating = newRecipeRating;
            recipe.setImages(images);
            recipe.setIngredients(ingredients);
            recipe.setSteps(steps);

            if (!recipes.isEditing())
            {
                recipes.addRecipe(recipe);
                recipes.SelectedIndex = recipes.getRecipeList().Count - 1;
            }
            else
            {
                recipes.setEditing(false);
                RecipeBookDataAccessor.updateRecipe(recipe);
            }

            for (int i = 0; i < removedSteps.Count; i++)
            {
                RecipeBookDataAccessor.deleteStep(removedSteps[i]);
            }
            for (int i = 0; i < removedIngredients.Count; i++)
            {
                RecipeBookDataAccessor.deleteIngredient(removedIngredients[i]);
            }
            for (int i = 0; i < removedImages.Count; i++)
            {
                RecipeImage imageToRemove = removedImages[i];
                StorageFile imageFile     = await StorageFile.GetFileFromPathAsync(imageToRemove.getImagePath());

                await imageFile.DeleteAsync();

                RecipeBookDataAccessor.deleteImage(imageToRemove);
            }
            Frame.GoBack();
        }
Пример #8
0
 /// <summary>
 /// Sets the ingredients of this recipe to the given list of
 /// ingredients.
 /// </summary>
 /// <param name="newIngredients">
 /// the list of ingredients to change the current list of
 /// ingredients to
 /// </param>
 public void setIngredients(ObservableCollection <RecipeIngredient> newIngredients)
 {
     if (newIngredients != null)
     {
         for (int i = 0; i < newIngredients.Count; i++)
         {
             RecipeIngredient ingredient = newIngredients[i];
             if (ingredient.getRecipeId() == -1)
             {
                 ingredient.setRecipeId(this.id);
                 RecipeBookDataAccessor.addIngredient(ingredient);
             }
             else
             {
                 RecipeBookDataAccessor.updateIngredient(ingredient);
             }
         }
         this.recipeIngredients = newIngredients;
     }
 }
Пример #9
0
 public void emptyJournalEntries()
 {
     journalEntries.Clear();
     RecipeBookDataAccessor.emptyJournal(this.id);
 }
Пример #10
0
 public void removeJournalEntry(RecipeJournalEntry entryToRemove)
 {
     journalEntries.Remove(entryToRemove);
     RecipeBookDataAccessor.deleteJournalEntry(entryToRemove);
     journalEntries.sortJournal();
 }
Пример #11
0
 /// <summary>
 /// Removes the given recipe from the recipe list and deletes
 /// it from teh app database
 /// </summary>
 /// <param name="recipeToRemove">
 /// the recipe to delete from the list
 /// </param>
 public void removeRecipe(Recipe recipeToRemove)
 {
     this.recipes.Remove(recipeToRemove);
     RecipeBookDataAccessor.deleteRecipe(recipeToRemove);
 }
Пример #12
0
 /// <summary>
 /// Adds the given recipe to the recipe list. Also saves the
 /// new recipe to the app database.
 /// </summary>
 /// <param name="newRecipe">
 /// the new recipe to add
 /// </param>
 public void addRecipe(Recipe newRecipe)
 {
     this.recipes.Add(newRecipe);
     RecipeBookDataAccessor.addRecipe(newRecipe);
 }