コード例 #1
0
        /* TODO DEBUG
         * public PageShoppingAdd()
         * {
         *  InitializeComponent();
         * }
         */

        public PageShoppingAdd(MVVM.ObservableItem itemPass)
        {
            InitializeComponent();

            item = itemPass; // see if best way

            entryFood.Text             = item.Title;
            entryDescription.Text      = item.Description;
            entryQuantity.Text         = item.Quantity.ToString();
            pickerAmount.SelectedIndex = 1;

            buttunSave.Clicked += async(sender, e) =>
            {
                if (entryFood.Text == "" || entryDescription.Text == "" || entryQuantity.Text == "" || pickerAmount.SelectedIndex == -1)
                {
                    await DisplayAlert("Invalid Input", "Input is missing in a required field", "OK");

                    return;
                }

                item.Title       = entryFood.Text;
                item.Description = entryDescription.Text;
                item.Quantity    = convert2oz(int.Parse(entryQuantity.Text), (string)pickerAmount.ItemsSource[pickerAmount.SelectedIndex]); // TODO clean up

                await App.Database.UpdateItemAsync(item);

                Saved = true;
            };
        }
コード例 #2
0
        public PageShoppingList()
        {
            InitializeComponent();

            updateList();
            MVVM.ObservableItem item;

            buttonAdd.Clicked += async(sender, e) =>
            {
                item = new MVVM.ObservableItem {
                    Title = "Food", Description = "A test Food", Quantity = 1, Got = false
                };
                await App.Database.InsertItemAsync(item); // creates a new row in the database

                await Navigation.PushAsync(new PageShoppingAdd(item));

                updateList(); // updates list
            };

            listShopping.ItemTapped += async(sender, e) => // TODO find way to move to button
            {
                item     = (MVVM.ObservableItem)e.Item;    // sets item to the tapped item
                item.Got = !item.Got;                      // toggles if the item is gotten

                await App.Database.UpdateItemAsync(item);  // update table with changed item

                updateList();                              // update list
            };
        }
コード例 #3
0
        public async void OnAdd(object sender, EventArgs e)
        {
            var mi     = ((MenuItem)sender);
            var recipe = (Recipe)mi.CommandParameter;

            // add ing to list
            var ingdeblob = recipe.ingredientsBlobbed.Split('\n'); // array of foods ( FOOD\n )

            foreach (var item in ingdeblob)
            {
                if (item != "")
                {
                    var temp    = item.Split('@'); // array of item vars ( Title@Quantity )
                    var tempIng = new MVVM.ObservableItem {
                        Title = temp[0], Description = "", Quantity = int.Parse(temp[1]), Got = false
                    };
                    await App.Database.InsertItemAsync(tempIng);
                }
            }

            await DisplayAlert("Added To List", "The Ingredients for this recipe have been added to the shopping list.", "OK");
        }
コード例 #4
0
        /* TODO DEBUG
         * public PageRecipeView()
         * {
         *  InitializeComponent();
         * }
         */
        public PageRecipeView(Recipe recipePass)
        {
            InitializeComponent();

            recipe = recipePass;

            // deserialize data
            var ingdeblob = recipe.ingredientsBlobbed.Split('\n'); // array of foods ( FOOD\n )

            foreach (var item in ingdeblob)
            {
                if (item != "")
                {
                    var temp    = item.Split('@'); // array of item vars ( ID@Title@Quantity )
                    var tempIng = new MVVM.ObservableItem {
                        Title = temp[0], Description = "", Quantity = int.Parse(temp[1])
                    };
                    ingredients.Add(tempIng);
                }
            }
            var insdeblob = recipe.instructionsBlobbed.Split('\n'); // array of instructions ( INSTRUCTION\n )

            foreach (var item in insdeblob)
            {
                if (item != "") // if item exists change to remove maybe
                {
                    instructions.Add(item);
                }
            }
            tags = recipe.tagsBlobbed; // can be a string with commas

            entryTitle.Text     = recipe.title;
            entryYield.Text     = recipe.yield;
            entryTags.Text      = tags;
            listIng.ItemsSource = ingredients;
            listIns.ItemsSource = instructions;

            buttonSave.Clicked += async(sender, e) =>
            {
                if (entryTitle.Text != "" && entryTags.Text != "" && entryYield.Text != "")
                {
                    recipe.title = entryTitle.Text;
                    recipe.yield = entryYield.Text;
                    var tags = entryTags.Text.Split(','); // splits tags and puts in array
                    // do ing
                    // do ins

                    // serialize data \n shows new entry and @ shows new section
                    recipe.ingredientsBlobbed = "";
                    foreach (var food in ingredients)
                    {
                        recipe.ingredientsBlobbed += food.Title + '@' + food.Quantity + '\n';
                    }
                    recipe.instructionsBlobbed = "";
                    foreach (var step in instructions)
                    {
                        recipe.instructionsBlobbed += step + '\n';
                    }
                    recipe.tagsBlobbed = entryTags.Text; // user can split using comma

                    await App.Recipedb.UpdateItemAsync(recipe);

                    Saved = true;
                    await DisplayAlert("Recipe Saved", "The recipe changes have been saved.", "OK");
                }
                else
                {
                    await DisplayAlert("Recipe Not Saved", "Please fill in all the fields to save.", "OK");
                }
            };

            buttonAddIng.Clicked += async(sender, e) =>
            {
                if (entryIng.Text != null && entryAmount.Text != null && pickerAmount.SelectedIndex != -1)
                {
                    var ing = new MVVM.ObservableItem {
                        Title = entryIng.Text, Description = "", Quantity = int.Parse(entryAmount.Text)
                    };                                                                                                                     // TODO maybe Food : ObservableItem
                    ingredients.Add(ing);

                    entryIng.Text              = "";
                    entryAmount.Text           = "";
                    pickerAmount.SelectedIndex = -1;
                }
            };

            buttonAddIns.Clicked += async(sender, e) =>
            {
                if (entryIns.Text != null || entryIns.Text != "")
                {
                    instructions.Add(entryIns.Text);

                    entryIns.Text = "";
                }
            };
        }
コード例 #5
0
 public Task <int> InsertItemAsync(MVVM.ObservableItem item)
 {
     return(Database.InsertAsync(item));
 }
コード例 #6
0
 public Task <int> UpdateItemAsync(MVVM.ObservableItem item)
 {
     return(Database.UpdateAsync(item));
 }