private void DataGridView7_CellContentClick(object sender, DataGridViewCellEventArgs e) { Product_Types_View product_Types_View = new Product_Types_View(); switch (e.ColumnIndex) { case 2: Product_Types_View.edit = false; product_Types_View.Show(); break; case 3: Product_Types_View.edit = true; product_Types_View.Show(); break; case 4: DialogResult delete = MessageBox.Show("Do you really want to delete this entry?", "Delete", MessageBoxButtons.YesNo); if (delete == DialogResult.Yes) { //do shit } else { //dont do shit } break; default: break; } }
private void DataGridView7_CellContentClick(object sender, DataGridViewCellEventArgs e) { Product_Types_View product_Types_View = new Product_Types_View(); string productTypeID = ""; switch (e.ColumnIndex) { case 3: Product_Types_View.edit = false; productTypeID = dataGridView7.Rows[e.RowIndex].Cells[0].Value.ToString(); product_Types_View.GetProductTypeRow = productTypeID; product_Types_View.ShowDialog(); break; case 4: Product_Types_View.edit = true; productTypeID = dataGridView7.Rows[e.RowIndex].Cells[0].Value.ToString(); product_Types_View.GetProductTypeRow = productTypeID; product_Types_View.ShowDialog(); break; case 5: productTypeID = dataGridView7.Rows[e.RowIndex].Cells[0].Value.ToString(); DialogResult delete = MessageBox.Show("Do you really want to delete this entry?", "Delete", MessageBoxButtons.YesNo); if (delete == DialogResult.Yes) { try { DBConnection dBConnection = DBConnection.Instance(); if (dBConnection.IsConnect()) { string query = "DELETE FROM `product_type` WHERE product_type_id = '" + productTypeID + "'"; var command = new MySqlCommand(query, dBConnection.Connection); command.ExecuteNonQuery(); } } catch (Exception) { System.Windows.Forms.MessageBox.Show("This product type contains services. It can not be deleted."); } dataGridView7.Rows.Clear(); try { DBConnection dBConnection = DBConnection.Instance(); if (dBConnection.IsConnect()) { string productTypesID = " "; string productTypeName = " "; string prpductTypeDescription = " "; DataTable ProductTypes = new DataTable(); string query = "SELECT product_type_id, product_type_name, product_type_description FROM product_type"; var command = new MySqlCommand(query, dBConnection.Connection); var reader = command.ExecuteReader(); ProductTypes.Load(reader); for (int i = 0; i < ProductTypes.Rows.Count; i++) { productTypesID = ProductTypes.Rows[i].ItemArray[0].ToString(); productTypeName = ProductTypes.Rows[i].ItemArray[1].ToString(); prpductTypeDescription = ProductTypes.Rows[i].ItemArray[2].ToString(); dataGridView7.Rows.Add(productTypesID, productTypeName, prpductTypeDescription, "View", "Edit", "Delete"); } reader.Close(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } } else { //dont do shit } break; default: break; } }