public void UpdateWine(WineData wineData, WineBarcode wineBarData, 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.WineDatas where s.Article == productArticle select s; var query1 = from s in context.WineBarcodes where s.Article == productArticle select s; var wineProducts = query.FirstOrDefault(); var wineProductsWithBarcode = query1.FirstOrDefault(); wineProducts.Article = wineData.Article; wineProducts.Article_Description = wineData.Article_Description; wineProductsWithBarcode.Article = wineBarData.Article; wineProductsWithBarcode.Barcode = wineBarData.Barcode; wineProducts.Storage_Bin = wineData.Storage_Bin; wineProducts.Department = wineData.Department; wineProducts.Sub_Department = wineData.Sub_Department; context.SaveChanges(); } }
private void UpdateWineProduct() { // Update the products in the DB based off what is entered into the update textboxes WineData wineProducts = new WineData(); WineBarcode wineProductsWithBarcode = new WineBarcode(); double article = Convert.ToDouble(txtUpdateArticle.Text); wineProducts.Article = Convert.ToDouble(txtUpdateArticle.Text); wineProducts.Article_Description = txtUpdateDesc.Text; wineProductsWithBarcode.Article = Convert.ToDouble(txtUpdateArticle.Text); wineProductsWithBarcode.Barcode = Convert.ToDouble(txtUpdateBarcode.Text); wineProducts.Storage_Bin = txtUpdateStorage.Text; wineProducts.Department = txtUpdateDept.Text; wineProducts.Sub_Department = txtUpdateSubDept.Text; myLinqUpdateCalls.UpdateWine(wineProducts, wineProductsWithBarcode, article); ClearAddTextBoxes(); ClearUpdateTextBoxes(); RefreshDGV(); }
private void AddWineProduct() { // Adds products to the DB based off what is entered into the text boxes using (var context = new GroceryTestDBEntities()) { var products = new WineData(); var productbarcode = new WineBarcode(); 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.WineDatas.Add(products); context.WineBarcodes.Add(productbarcode); context.SaveChanges(); ClearAddTextBoxes(); } }