public void UpdateDairy(DairyData dairyData, DairyBarcode dairyBarData, 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.DairyDatas where s.Article == productArticle select s; var query1 = from s in context.DairyBarcodes where s.Article == productArticle select s; var dairyProducts = query.FirstOrDefault(); var dairyProductsWithBarcode = query1.FirstOrDefault(); dairyProducts.Article = dairyData.Article; dairyProducts.Article_Description = dairyData.Article_Description; dairyProductsWithBarcode.Article = dairyBarData.Article; dairyProductsWithBarcode.Barcode = dairyBarData.Barcode; dairyProducts.Storage_Bin = dairyData.Storage_Bin; dairyProducts.Department = dairyData.Department; dairyProducts.Sub_Department = dairyData.Sub_Department; context.SaveChanges(); } }
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(); } }
public IEnumerable GetDepartment() { // Allows the user to choose a department from the DB which will then populate into the cbxdepartment to be selected from there using (var context = new GroceryTestDBEntities()) { var Department = context.AllDeptsAllProductsAllDatas.Select(a => a.Department).Distinct().ToList(); return(Department); } }
public void SelectDepartment() // Select a department from the myDepartment class { using (var context = new GroceryTestDBEntities()) { var c = from a in context.AllDeptsAllProductsAllDatas where a.Department == cbxDepartment.Text select a; // Populate results to the DGV dgvProducts.DataSource = c.ToList(); } }
public void LoadAllProducts() //Loads all products from the AllDeptsAllProductsAllDatas view into the gridview { using (var context = new GroceryTestDBEntities()) { var c = from a in context.AllDeptsAllProductsAllDatas select a; // Populate results to the DGV dgvProducts.DataSource = c.ToList(); SelectDepartment(); // Reset and select the current selected department } }
private void AllBarcodesSearch() // Search for all barcodes in DB and return the result { using (var context = new GroceryTestDBEntities()) { // Sets a variable to the barcode text box double barcode = Convert.ToDouble(txtBarcode.Text); //LINQ query to the database for where the barcode inputted matches the one in the DB then return a display var c = from a in context.AllDeptsAllProductsAllDatas where a.Barcode == barcode select a; //Populate results to the DGV dgvProducts.DataSource = c.ToList(); } }
private void SearchGMProduct() { using (var context = new GroceryTestDBEntities()) { //Sets a variable to the description text box string description = txtDescription.Text; //LINQ query to the database where the description inputted matches the one in the DB then display var c = from a in context.GMAllProductsAllDatas where a.Article_Description.Contains(description) orderby a.Article_Description ascending select a; //Populate results to the DGV dgvProducts.DataSource = c.ToList(); } }
private void DeleteGMProduct() { //Deletes products from the DB based off the article number in the update article textbox using (var context = new GroceryTestDBEntities()) { double article = Convert.ToDouble(txtUpdateArticle.Text); var products = (from p in context.GMDatas where p.Article == article select p).SingleOrDefault(); MessageBox.Show("This will delete " + article + " from the database."); context.GMDatas.Remove(products); context.SaveChanges(); 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(); } }