private void FormTambahNotaBeli_Load(object sender, EventArgs e) { DaftarNotaBeli daftar = new DaftarNotaBeli(); string hasil = daftar.GenerateNoNota(); if (hasil == "sukses") { textBoxNoNota.Text = daftar.NoNotaTerbaru; textBoxNoNota.Enabled = false; } else { MessageBox.Show("Generate Kode gagal dilakukan. Pesan Kesalahan= " + hasil); } dateTimePickerTanggal.Value = DateTime.Now; dateTimePickerTanggal.Enabled = false; comboBoxSupplier.DropDownStyle = ComboBoxStyle.DropDownList; DaftarSupplier daftarSp = new DaftarSupplier(); hasil = daftarSp.BacaSemuaData(); if (hasil == "sukses") { comboBoxSupplier.Items.Clear(); for (int i = 0; i < daftarSp.JumlahSupplier; i++) { comboBoxSupplier.Items.Add(daftarSp.ListSupplier[i].KodeSupplier + " - " + daftarSp.ListSupplier[i].NamaSupplier); textBoxAlamat.Text = daftarSp.ListSupplier[i].AlamatSupplier; } comboBoxSupplier.SelectedIndex = 0; } else { MessageBox.Show("Data Pelanggan gagal ditampilkan di combobox. Pesan kesalahan " + hasil); } FormUtama frmUtama = (FormUtama)this.Owner.MdiParent; labelKodePegawai.Text = frmUtama.labelKodePegawai.Text; labelNamaPegawai.Text = frmUtama.labelNamaPegawai.Text; FormatDataGrid(); textBoxKodeBarang.MaxLength = 5; textBoxKodeBarang.CharacterCasing = CharacterCasing.Upper; }
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"); } }