private void BtnTambah_Click(object sender, EventArgs e) { tmbBarang frm = new tmbBarang(this); frm.btnUbah.Visible = false; frm.ShowDialog(); }
private void Dgv_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = dgv.Columns[e.ColumnIndex].Name; if (colName == "Ubah") { tmbBarang frm = new tmbBarang(this); frm.lblJudul.Text = "Ubah Data Barang"; frm.btnSimpan.Visible = false; frm.lblId.Text = dgv[0, e.RowIndex].Value.ToString(); frm.txtKode.Text = dgv[1, e.RowIndex].Value.ToString(); frm.txtNama.Text = dgv[2, e.RowIndex].Value.ToString(); frm.txtDeskripsi.Text = dgv[3, e.RowIndex].Value.ToString(); frm.txtStok.Text = dgv[4, e.RowIndex].Value.ToString(); frm.txtHrgBeli.Text = dgv[5, e.RowIndex].Value.ToString(); frm.txtHrgJual.Text = dgv[6, e.RowIndex].Value.ToString(); frm.cmbSuplier.SelectedItem = dgv[7, e.RowIndex].Value.ToString(); frm.ShowDialog(); } else if (colName == "Hapus") { if (MessageBox.Show("Apakah Anda yakin ingin menghapus data ini?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { cn.Open(); cm = new SqlCommand("delete from Barang where id ='" + dgv[0, e.RowIndex].Value.ToString() + "'", cn); cm.ExecuteNonQuery(); cn.Close(); load(); lblSukses.Visible = false; lblUbah.Visible = false; lblHapus.Visible = true; } } }