private void dataGridViewBarang_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex == dataGridViewBarang.Columns.Count - 2) { //pilih FormIsiKoleksi formKoleksi = new FormIsiKoleksi(); formKoleksi.UpdateTabel(dataGridViewBarang.Rows[e.RowIndex].Cells[0].Value.ToString()); form.mainForm.Add(formKoleksi); } else if (e.RowIndex >= 0 && e.ColumnIndex == dataGridViewBarang.Columns.Count - 1) { //hapus Connection con = new Connection(); string nama_koleksi = dataGridViewBarang.Rows[e.RowIndex].Cells[0].Value.ToString(); if (!con.IsKoleksiExist(nama_koleksi)) { CustomMessageBox.Show("Koleksi tersebut tidak ada"); return; } void Yes() { con.DeleteKoleksi(nama_koleksi); dataGridViewBarang.Rows.RemoveAt(e.RowIndex); } CustomYesNoBox.Show("Apakah anda yakin ingin menghapus koleksi : " + nama_koleksi + "? \n Semua barang pada koleksi tersebut akan ikut terhapus", Yes); } } catch (Exception ex) { CustomMessageBox.Show("Error : " + ex.Message); } }
private void dataGridViewTabelBarang_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex >= 0 && e.ColumnIndex == dataGridViewTabelBarang.Columns.Count - 1) { //pilih FormIsiKoleksi formKoleksi = new FormIsiKoleksi(); formKoleksi.UpdateTabel(dataGridViewTabelBarang.Rows[e.RowIndex].Cells[dataGridViewTabelBarang.Columns.Count - 2].Value.ToString()); form.mainForm.Add(formKoleksi); } } catch (Exception ex) { CustomMessageBox.Show("Error : " + ex.Message); } }
private void buttonSelesai_Click(object sender, EventArgs e) { //try { //Error cek dimulai if (CustomErrorMessage(textBoxNoBarangDaftar, "No Barang tidak boleh kosong", textBoxNamaBarang, "Nama barang tidak boleh kosong", textBoxHargaBeli, "Haraga beli tidak boleh kosong", textBoxHargaJual, "Harga jual tidak boleh kosong")) { return; } for (int i = 0; i < dataGridHargaJualData.Rows.Count; i++) { for (int j = 0; j < dataGridHargaJualData.Rows[i].Cells.Count; j++) { if (dataGridHargaJualData.Rows[i].Cells[j].ColumnIndex < 2) { if (j == 0) { if ((int)dataGridHargaJualData.Rows[i].Cells[j].Value <= 0) { CustomMessageBox.Show("Kolom jumlah pada tabel harga jual tidak boleh 0 ke bawah"); return; } } else { if ((ulong)dataGridHargaJualData.Rows[i].Cells[j].Value <= 0) { CustomMessageBox.Show("Kolom jumlah pada tabel harga jual tidak boleh 0 ke bawah"); return; } } if (dataGridHargaJualData.Rows[i].Cells[j].Value.ToString() == "" || dataGridHargaJualData.Rows[i].Cells[j].Value == null) { CustomMessageBox.Show("Tabel harga jual tidak boleh ada yang kosong"); return; } } } } List <string> jumlahList = new List <string>(); for (int i = 0; i < dataGridHargaJualData.Rows.Count; i++) { for (int j = 0; j < dataGridHargaJualData.Rows[i].Cells.Count; j++) { if (dataGridHargaJualData.Rows[i].Cells[j].ColumnIndex == 0) { jumlahList.Add(dataGridHargaJualData.Rows[i].Cells[j].Value.ToString()); break; } } } for (int i = 0; i < jumlahList.Count; i++) { for (int j = i + 1; j < jumlahList.Count; j++) { if (jumlahList[i] == jumlahList[j]) { CustomMessageBox.Show("Jumlah tidak boleh ada yang sama"); return; } } } string no_barang = textBoxNoBarangDaftar.Text; string nama_barang = textBoxNamaBarang.Text; string satuan_tipe = labelTipeSatuan.Text; string nama_satuan = comboBoxSatuan.Text; string nama_koleksi = koleksi.NamaKoleksi; int GetSatuanID(string satuan) { for (int i = 0; i < satuanList.Count; i++) { if (satuanList[i].SatuanName == satuan) { return(satuanList[i].Id); } } return(-1); } int satuan_id = GetSatuanID(nama_satuan); UInt64 harga_beli = UInt64.Parse(textBoxHargaBeli.Text); UInt64 harga_jual = UInt64.Parse(textBoxHargaJual.Text); if (harga_jual < harga_beli) { CustomMessageBox.Show("Harga jual tidak boleh di bawah harga beli"); return; } //error cek selesai, mulai proses data Connection con = new Connection(); //cek validasi data dan insert if (tambahBarang) { if (con.IsBarangExist(no_barang)) { CustomMessageBox.Show("Barang dengan nomor barang : " + no_barang + " telah ada, nomor barang tidak boleh sama"); return; } if (!con.IsKoleksiExist(nama_koleksi)) { CustomMessageBox.Show("KOLEKSI TIDAK DITEMUKAN. PASTIKAN NAMA KOLEKSI BENAR ATAU BUAT KOLEKSI BARU"); return; } if (con.IsSatuanExisInKoleksi(nama_koleksi, satuan_id)) { CustomMessageBox.Show("Satuan -" + nama_satuan + "- telah ada pada koleksi tersebut, gunakan satuan yang lain"); return; } object[] dataBarang = new object[] { no_barang, nama_barang, satuan_id, harga_beli, harga_jual, nama_koleksi }; con.InsertBarang(dataBarang); for (int i = 0; i < dataGridHargaJualData.Rows.Count; i++) { var dataRes = dataGridHargaJualData.Rows[i].Cells; object[] dataPotongan = new object[] { no_barang, dataRes[0].Value, dataRes[1].Value }; con.InsertBarangPotongan(dataPotongan); } CustomMessageBox.Show("Barang telah di tambah"); } //cek validasi data dan edit else { if (!con.IsBarangExist(no_barang)) { CustomMessageBox.Show("Barang dengan nomor barang : " + no_barang + " tidak ada, ada masalah BESAR, tolong hubungi Elton"); return; } if (!con.IsKoleksiExist(nama_koleksi)) { CustomMessageBox.Show("KOLEKSI TIDAK DITEMUKAN. PASTIKAN NAMA KOLEKSI BENAR ATAU BUAT KOLEKSI BARU"); return; } Barang data = new Barang(no_barang, nama_barang, harga_beli, harga_jual, satuan_id, "", satuan_tipe, nama_koleksi); con.UpdateBarang(data); AturanBarang barangBaru = new AturanBarang(data); List <AturanHargaJual> aturanHargaJual = new List <AturanHargaJual>(); for (int i = 0; i < dataGridHargaJualData.Rows.Count; i++) { aturanHargaJual.Add(new AturanHargaJual((int)dataGridHargaJualData.Rows[i].Cells[0].Value, (ulong)dataGridHargaJualData.Rows[i].Cells[1].Value)); } barangBaru.AturanHarga = aturanHargaJual; con.SimpanJumlahPotongan(barangBaru); CustomMessageBox.Show("Barang telah di edit"); } this.Close(); formIsiKoleksi.UpdateTabel(koleksi.NamaKoleksi); /* } catch(Exception ex) { * CustomMessageBox.Show("Error : " + ex.Message); * }*/ }