private void btnAdd_Click(object sender, EventArgs e) { correct = true; Product_Type prodT = new Product_Type(); if (rtxtDescription.Text == "") { MessageBox.Show("Please Enter Product type details"); correct = false; } if (correct == true) { prodT.Product_Type_Name = rtxtDescription.Text; } db.Product_Type.Add(prodT); db.SaveChanges(); int Product_Type_ID = prodT.Product_Type_ID; string ProdT_value = Convert.ToString(prodT); var r = db.Product_Type.ToList(); dgvProductType.DataSource = r.Select(col => new { col.Product_Type_ID, col.Product_Type_Name }).ToList(); dgvProductType.Columns[0].HeaderText = "Product_Type_ID"; dgvProductType.Columns[1].HeaderText = "Product_Type"; }
private void btnDeletePT_Click_1(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Would you like to delete this Product Type?", "Delete Product Type", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { try { Product_Type prodT2 = new Product_Type(); prodT2 = db.Product_Type.Find(tempID); db.Product_Type.Remove(prodT2); db.SaveChanges(); int prodType = prodT2.Product_Type_ID; string prodType_Value = Convert.ToString(prodT2); MessageBox.Show("Product Type Successfully Deleted"); this.Close(); } catch (Exception) { MessageBox.Show("Error: Product Type was not deleted"); } } }