Example #1
0
        public void UpdateGrocery(GroceryData groceryData, GroceryBarcode groceryBarData, double productArticle) //Info passed back to Form1 where it is linked to the textboxes
        {
            //LINQ query to the database where the products in the update textboxes are populated back to the DB
            using (var context = new GroceryTestDBEntities())
            {
                var query = from s in context.GroceryDatas
                            where s.Article == productArticle
                            select s;
                var query1 = from s in context.GroceryBarcodes
                             where s.Article == productArticle
                             select s;
                var groceryProducts            = query.FirstOrDefault();
                var groceryProductsWithBarcode = query1.FirstOrDefault();

                groceryProducts.Article             = groceryData.Article;
                groceryProducts.Article_Description = groceryData.Article_Description;
                groceryProductsWithBarcode.Article  = groceryBarData.Article;
                groceryProductsWithBarcode.Barcode  = groceryBarData.Barcode;
                groceryProducts.Storage_Bin         = groceryData.Storage_Bin;
                groceryProducts.Department          = groceryData.Department;
                groceryProducts.Sub_Department      = groceryData.Sub_Department;

                context.SaveChanges();
            }
        }
        private void UpdateGroceryProduct()
        {
            // Update the products in the DB based off what is entered into the update textboxes
            GroceryData    groceryProducts            = new GroceryData();
            GroceryBarcode groceryProductsWithBarcode = new GroceryBarcode();
            double         article = Convert.ToDouble(txtUpdateArticle.Text);

            groceryProducts.Article             = Convert.ToDouble(txtUpdateArticle.Text);
            groceryProducts.Article_Description = txtUpdateDesc.Text;
            groceryProductsWithBarcode.Article  = Convert.ToDouble(txtUpdateArticle.Text);
            groceryProductsWithBarcode.Barcode  = Convert.ToDouble(txtUpdateBarcode.Text);
            groceryProducts.Storage_Bin         = txtUpdateStorage.Text;
            groceryProducts.Department          = txtUpdateDept.Text;
            groceryProducts.Sub_Department      = txtUpdateSubDept.Text;

            myLinqUpdateCalls.UpdateGrocery(groceryProducts, groceryProductsWithBarcode, article);
            ClearAddTextBoxes();
            ClearUpdateTextBoxes();
            RefreshDGV();
        }
        private void AddGroceryProduct()
        {
            // Adds products to the DB based off what is entered into the text boxes
            using (var context = new GroceryTestDBEntities())
            {
                var products       = new GroceryData();
                var productbarcode = new GroceryBarcode();
                products.Article             = Convert.ToDouble(txtAddArticle.Text);
                products.Article_Description = txtAddDesc.Text;
                productbarcode.Article       = Convert.ToDouble(txtAddArticle.Text);
                productbarcode.Barcode       = Convert.ToDouble(txtAddBarcode.Text);
                products.Storage_Bin         = txtAddStorage.Text;
                products.Department          = txtAddDept.Text;
                products.Sub_Department      = txtAddSubDept.Text;
                MessageBox.Show(products.Article_Description + " was added to the Database.");

                context.GroceryDatas.Add(products);
                context.GroceryBarcodes.Add(productbarcode);
                context.SaveChanges();

                ClearAddTextBoxes();
            }
        }