private void btnBeli_Click(object sender, EventArgs e) { try { string sjml = txtJml.Text; int jml = Convert.ToInt16(sjml); long har = Convert.ToInt16(c); int stk = Convert.ToInt16(d); har = jml * har; stk -= jml; tot += har; if (stk >= 0) { string shar = Convert.ToString(har); string stot = Convert.ToString(tot); d = Convert.ToString(stk); txtHarga.Text = shar; txtTotHarga.Text = stot; Barang std = new Barang(a, b, c, d); CRUDBarang.UpdateBarang(std, a); } else { txtID.Text = txtJml.Text = txtHarga.Text = txtTotHarga.Text = string.Empty; MessageBox.Show("Stok tidak mencukupi!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Error!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnTambah_Click(object sender, EventArgs e) { if (txtID.Text.Trim().Length <= 0) { MessageBox.Show("ID Kosong!"); return; } if (txtNama.Text.Trim().Length <= 0) { MessageBox.Show("Nama Kosong!"); return; } if (txtHarga.Text.Trim().Length <= 0) { MessageBox.Show("Harga Kosong!"); return; } if (txtStok.Text.Trim().Length <= 0) { MessageBox.Show("Stok Kosong!"); return; } if (btnTambah.Text == "Tambah") { Barang std = new Barang(txtID.Text.Trim(), txtNama.Text.Trim(), txtHarga.Text.Trim(), txtStok.Text.Trim()); CRUDBarang.TmbhBarang(std); clrscr(); } if (btnTambah.Text == "Edit") { Barang std = new Barang(txtID.Text.Trim(), txtNama.Text.Trim(), txtHarga.Text.Trim(), txtStok.Text.Trim()); CRUDBarang.UpdateBarang(std, ID); clrscr(); } _parent.Display(); }