private void btn_ok_Click(object sender, EventArgs e) { try { using (var barangdao = new BarangDAO()) { foreach (var item in list) { Barang before = barangdao.GetDataBarangByKode(item.Kode); Barang brng = new Barang { Kode = item.Kode, Nama = item.Nama, Stok = (item.Jumlah + Int32.Parse(before.Stok)).ToString(), Harga = item.Harga }; barangdao.UpdateStok(brng); } } MessageBox.Show("Success", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void txtKode_Leave(object sender, EventArgs e) { using (var dao = new BarangDAO(sqlString)) { if ((brg = dao.GetDataBarangByKode(this.txtKode.Text)) != null) { this.txtNama.Text = brg.Nama; this.txtHarga.Text = brg.Harga.ToString(); this.txtStock.Text = brg.Jumlah.ToString(); this.txtPajak.Text = brg.Pajak.ToString(); } else { this.txtKode.Text = ""; this.txtHarga.Text = ""; this.txtJumlah.Text = ""; this.txtNama.Text = ""; this.txtPajak.Text = ""; this.txtStock.Text = ""; this.txtKode.Focus(); this.label3.Visible = true; } } }