Exemple #1
0
        public void UpdateGM(GMData gmData, GMBarcode gmBarData, 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.GMDatas
                            where s.Article == productArticle
                            select s;
                var query1 = from s in context.GMBarcodes
                             where s.Article == productArticle
                             select s;
                var gmProducts            = query.FirstOrDefault();
                var gmProductsWithBarcode = query1.FirstOrDefault();

                gmProducts.Article             = gmData.Article;
                gmProducts.Article_Description = gmData.Article_Description;
                gmProductsWithBarcode.Article  = gmBarData.Article;
                gmProductsWithBarcode.EAN_UPC  = gmBarData.EAN_UPC;
                gmProducts.Storage_Bin         = gmData.Storage_Bin;
                gmProducts.Department          = gmData.Department;
                gmProducts.Sub_Department      = gmData.Sub_Department;

                context.SaveChanges();
            }
        }
        private void UpdateGMProduct()
        {
            // Update the products in the DB based off what is entered into the update textboxes
            GMData    gmProducts            = new GMData();
            GMBarcode gmProductsWithBarcode = new GMBarcode();
            double    article = Convert.ToDouble(txtUpdateArticle.Text);

            gmProducts.Article             = Convert.ToDouble(txtUpdateArticle.Text);
            gmProducts.Article_Description = txtUpdateDesc.Text;
            gmProductsWithBarcode.Article  = Convert.ToDouble(txtUpdateArticle.Text);
            gmProductsWithBarcode.EAN_UPC  = Convert.ToDouble(txtUpdateBarcode.Text);
            gmProducts.Storage_Bin         = txtUpdateStorage.Text;
            gmProducts.Department          = txtUpdateDept.Text;
            gmProducts.Sub_Department      = txtUpdateSubDept.Text;

            myLinqUpdateCalls.UpdateGM(gmProducts, gmProductsWithBarcode, article);
            ClearAddTextBoxes();
            ClearUpdateTextBoxes();
            RefreshDGV();
        }
        private void AddGMProduct()
        {
            // Adds products to the DB based off what is entered into the text boxes
            using (var context = new GroceryTestDBEntities())
            {
                var products       = new GMData();
                var productbarcode = new GMBarcode();
                products.Article             = Convert.ToDouble(txtAddArticle.Text);
                products.Article_Description = txtAddDesc.Text;
                productbarcode.Article       = Convert.ToDouble(txtAddArticle.Text);
                productbarcode.EAN_UPC       = 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.GMDatas.Add(products);
                context.GMBarcodes.Add(productbarcode);
                context.SaveChanges();

                ClearAddTextBoxes();
            }
        }