private void btnTambah_Click(object sender, EventArgs e) { try { String pesan = ""; if (va.doValidation() == false) { return; } ob = db.tbl_Obats.FirstOrDefault(x => x.id_obat == int.Parse(tbIdobat.Text)); if (ob == null) { aksi("insert"); pesan = "menambah"; } else { aksi("update"); pesan = "memperbaharui"; } MessageBox.Show("Berhasil " + pesan + " data", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); loadGrid(); va.clear(""); } catch (Exception err) { MessageBox.Show("Terjadi kesalahan", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmbIdobat_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(cmbIdobat.Text)) { setTextbox(); tbl_Obat ob = db.tbl_Obats.FirstOrDefault(x => x.id_obat == int.Parse(cmbIdobat.Text)); tbNamaobat.Text = ob.nama_obat; tbHargaobat.Text = ob.harga.ToString(); tbStokobat.Text = ob.stok.ToString(); } }
private void aksi(String aksinya) { ob = aksinya == "insert" ? new tbl_Obat() : db.tbl_Obats.FirstOrDefault(x => x.id_obat == int.Parse(tbIdobat.Text)); ob.nama_obat = tbNama.Text; ob.harga = float.Parse(tbHarga.Text); ob.stok = (int)nudStok.Value; if (aksinya == "insert") { ob.id_obat = int.Parse(tbIdobat.Text); db.tbl_Obats.InsertOnSubmit(ob); } db.SubmitChanges(); }
private void setTextBox() { if (!String.IsNullOrEmpty(tbIdobat.Text)) { ob = db.tbl_Obats.FirstOrDefault(x => x.id_obat == int.Parse(tbIdobat.Text)); if (ob != null) { tbIdobat.Text = ob.id_obat.ToString(); tbNama.Text = ob.nama_obat; tbHarga.Text = ob.harga.ToString(); nudStok.Value = ob.stok; } else { va.clear("tbIdobat"); } } }
private void btnHapus_Click(object sender, EventArgs e) { if (klik == 1) { foreach (DataGridViewRow rw in this.dgvObat.SelectedRows) { primary = rw.Cells[0].Value.ToString(); } ob = db.tbl_Obats.Where(x => x.id_obat == int.Parse(primary)).Single(); db.tbl_Obats.DeleteOnSubmit(ob); db.SubmitChanges(); loadGrid(); } else { MessageBox.Show("Silahkan pilih baris yang ingin dihapus", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }