private void button3_Click(object sender, EventArgs e) { formProduct frm = new formProduct(this); frm.btnSave.Enabled = true; frm.btnUpdate.Enabled = false; frm.loadBrand(); frm.loadCategory(); frm.ShowDialog(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = dataGridView1.Columns[e.ColumnIndex].Name; if (colName == "Edit") { try { formProduct frm = new formProduct(this); frm.btnSave.Enabled = false; frm.btnUpdate.Enabled = true; frm.txtProd.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); frm.txtBarCode.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); frm.txtDesc.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); frm.brandCombo.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); frm.catCombo.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); frm.txtPrice.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString(); frm.loadBrand(); frm.loadCategory(); frm.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (colName == "Delete") { try { if (MessageBox.Show("Are you sure you want to delete this product?", "Delete Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("delete from tblProduct where pcode like '" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'", cn); cm.ExecuteNonQuery(); cn.Close(); LoadRecords(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }