Пример #1
0
        // private methods
        private void InitializeDatabase()
        {
            // specify SQLite library provider
            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_winsqlite3());

            // connect to database
            connectionString = "Filename=" + ApplicationData.Current.LocalFolder.Path + "\\" + "main.db";
            db = new SqliteConnection(connectionString);
            db.Open();
            DBHelper.Connection = db;

            // create category tables if not exist
            CategoryList[] categoryLists = { IngredientCategories, RecipeCategories, IngredientProviders };
            foreach (var list in categoryLists)
            {
                string tableName    = GetDBTableName(list);
                string tableCommand = "CREATE TABLE IF NOT EXISTS " +
                                      $"{tableName} (ID INTEGER PRIMARY KEY, Name TEXT NULL)";
                SqliteCommand createTable = new SqliteCommand(tableCommand, db);
                createTable.ExecuteReader();
            }

            // create main tables if not exist
            Ingredient.CreateDBTable(db);
            IngredientPurchase.CreateDBTable(db);
            Recipe.CreateDBTable(db);
            RecipeIngredientItem.CreateDBTable(db);
        }
Пример #2
0
        public ContentDialogIngredientQuantity(RecipeIngredientItem item)
        {
            this.InitializeComponent();

            // initialize data context
            this.ingredientItem = item;
            this.DataContext    = item;
        }
Пример #3
0
        private void AddIngrientItems(List <Ingredient> ingredients)
        {
            RecipeIngredientItem lastAddedItem = null;
            int NumOfAddedItem = 0;

            // add all selected ingredients
            foreach (var ingredient in ingredients)
            {
                // skip ingredient if already in the list
                if (this.ingredientItems.Any(x => x.Ingredient == ingredient))
                {
                    continue;
                }

                // create new RecipeIngredientItem instance
                RecipeIngredientItem item = new RecipeIngredientItem();
                item.Ingredient   = ingredient;
                item.IngredientID = ingredient.ID;
                item.RecipeID     = recipe.ID;

                // add to the list
                this.ingredientItems.Add(item);

                // add to db
                MainModelView.Current.AddIngredientItem(item);

                lastAddedItem = item;
                NumOfAddedItem++;
            }

            // if only one ingredient is added
            // show quantity dialog for subsequent input
            if (NumOfAddedItem == 1)
            {
                //this.ListViewIngredients.UpdateLayout();

                this.ListViewIngredients.SelectedItem = lastAddedItem;

                EditIngrientQuantity();
            }
        }
Пример #4
0
 public void DeleteIngredientItem(RecipeIngredientItem item)
 {
     DBHelper.Delete(item);
 }
Пример #5
0
 public void UpdateIngredientItem(RecipeIngredientItem item)
 {
     DBHelper.Update(item);
 }
Пример #6
0
 public void AddIngredientItem(RecipeIngredientItem item)
 {
     DBHelper.Insert(item);
 }