Esempio n. 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);
        }
Esempio n. 2
0
        private async void AddPurchase()
        {
            // prepare and show dialog
            IngredientPurchase purchase = new IngredientPurchase();

            purchase.Ingredient   = this.ingredient;
            purchase.IngredientID = this.ingredient.ID;
            purchase.Date         = DateTime.Today;
            var dialog = new ContentDialogIngredientPurchase("Add Ingredient Purchase", purchase);
            var result = await dialog.ShowAsync();

            // while Add New Category button is pressed
            while (dialog.Tag is string && (string)(dialog.Tag) == "Add New Provider")
            {
                await AddProvier();                    // show add category dialog

                dialog.Tag = null;                     // remember to reset Tag property
                result     = await dialog.ShowAsync(); // show ingredient dialog again
            }

            // if ok button is pressed
            if (result == ContentDialogResult.Primary)
            {
                purchases.Add(purchase);

                MainModelView.Current.AddIngredientPurchase(purchase);

                await UpdateAverageCosts();
            }
        }
        // constructor
        public ContentDialogIngredientPurchase(string title, IngredientPurchase purchase)
        {
            this.InitializeComponent();

            // initialize customized title
            this.Title = title ?? throw new ArgumentException();

            // initialize data source
            this.purchase    = purchase;
            this.DataContext = purchase;
            this.ComboBoxProvider.ItemsSource = MainModelView.Current.IngredientProviders;
        }
Esempio n. 4
0
 public void DeleteIngredientPurchase(IngredientPurchase item)
 {
     DBHelper.Delete(item);
 }
Esempio n. 5
0
 public void UpdateIngredientPurchase(IngredientPurchase item)
 {
     DBHelper.Update(item);
 }
Esempio n. 6
0
 public void AddIngredientPurchase(IngredientPurchase item)
 {
     DBHelper.Insert(item);
 }