private void buttonSimpan_Click(object sender, EventArgs e) { if (dataGridViewBarang.Rows != null && dataGridViewBarang.Rows.Count != 0) { //buat objek bertipe pelanggan Supplier supplier = new Supplier(); //format comboboxpelanggan : x - yyyyyy (kode pelanggan karakter 0 sebanyak 1, nama kategori mulai karakter ke-4 s/d akhir) supplier.KodeSupplier = int.Parse(comboBoxSupplier.Text.Substring(0, 1)); //kode pelanggan diambil dari combobox supplier.NamaSupplier = comboBoxSupplier.Text.Substring(4, comboBoxSupplier.Text.Length - 4); //nama pelanggan diambil dari combobox supplier.Alamat = labelAlamat.Text; //buat objek bertipe pegawai Pegawai pegawai = new Pegawai(); pegawai.KodePegawai = int.Parse(labelKodePeg.Text); pegawai.Nama = labelNamaPeg.Text; //buat objek bertipe notajual NotaBeli nota = new NotaBeli(textBoxNoNota.Text, dateTimePickerTanggal.Value, supplier, pegawai); //data barang diperoleh dari datagridview for (int i = 0; i < dataGridViewBarang.Rows.Count; i++) { Barang brg = new Barang(); brg.KodeBarang = dataGridViewBarang.Rows[i].Cells["KodeBarang"].Value.ToString(); brg.Nama = dataGridViewBarang.Rows[i].Cells["Nama"].Value.ToString(); int harga = int.Parse(dataGridViewBarang.Rows[i].Cells["HargaJual"].Value.ToString()); int jumlah = int.Parse(dataGridViewBarang.Rows[i].Cells["Jumlah"].Value.ToString()); NotaBeliDetil notaDetil = new NotaBeliDetil(brg, harga, jumlah); //simpan detil barang ke nota nota.TambahDetilBarang(brg, harga, jumlah); } string hasilTambah = NotaBeli.TambahData(nota); if (hasilTambah == "1") { MessageBox.Show("Data nota Beli telah tersimpan dan tercetak", "Info"); cetak(); FormTambahNotaBeli_Load(sender, e); //buttonCetak_Click(sender, e); } else { MessageBox.Show("Data nota beli gagal tersimpan. Pesan kesalahan : " + hasilTambah, "Kesalahan"); } } else { MessageBox.Show("Isi nota beli terlebih dahulu"); } }
private void buttonSimpan_Click(object sender, EventArgs e) { string kdSupplier = comboBoxSupplier.Text.Substring(0, 1); string nmSupplier = comboBoxSupplier.Text.Substring(4, comboBoxSupplier.Text.Length - 4); Supplier s = new Supplier(); s.KodeSupplier = kdSupplier; s.NamaSupplier = nmSupplier; Pegawai pegawai = new Pegawai(); pegawai.KodePegawai = labelKodePegawai.Text; pegawai.NamaPegawai = labelNamaPegawai.Text; List <NotaBeliDetil> listNotaDetil = new List <NotaBeliDetil>(); for (int i = 0; i < dataGridViewBarang.Rows.Count; i++) { Barang br = new Barang(); br.KodeBarang = dataGridViewBarang.Rows[i].Cells["KodeBarang"].Value.ToString(); br.NamaBarang = dataGridViewBarang.Rows[i].Cells["Namabarang"].Value.ToString(); int harga = int.Parse(dataGridViewBarang.Rows[i].Cells["HargaBeli"].Value.ToString()); int jumlah = int.Parse(dataGridViewBarang.Rows[i].Cells["Jumlah"].Value.ToString()); NotaBeliDetil notaDetil = new NotaBeliDetil(br, harga, jumlah); listNotaDetil.Add(notaDetil); } NotaBeli nota = new NotaBeli(textBoxNoNota.Text, dateTimePickerTanggal.Value, s, pegawai, listNotaDetil); DaftarNotaBeli daftar = new DaftarNotaBeli(); string hasilTambah = daftar.TambahData(nota); if (hasilTambah == "sukses") { MessageBox.Show("data nota jual telah tersimpan"); } else { MessageBox.Show("data nota jual gagal tersimpan. Pesan kesalahan : " + hasilTambah, "Kesalahan"); } }