public int Update(Pembelian pbl) { int result = 0; // Validavsi kode pembelian tidak boleh NULL if (string.IsNullOrEmpty(pbl.KdPembelian)) { MessageBox.Show("Kode pembelian harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi nama barang tidak boleh NULL if (string.IsNullOrEmpty(pbl.NamaBarang)) { MessageBox.Show("Nama harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Tanggal pembelian tidak boleh NULL if (string.IsNullOrEmpty(pbl.TglPembelian)) { MessageBox.Show("Tanggal Pembelian harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Harga pembelian tidak boleh NULL if (string.IsNullOrEmpty(Convert.ToString(pbl.HargaBeli.ToString()))) { MessageBox.Show("Harga harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi jumlah tidak boleh NULL if (string.IsNullOrEmpty(Convert.ToString(pbl.Jumlah.ToString()))) { MessageBox.Show("Kuantitas harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Kode pesanan tidak boleh NULL if (string.IsNullOrEmpty(pbl.KdPesanan)) { MessageBox.Show("Kode pesanan harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Kode barang tidak boleh NULL if (string.IsNullOrEmpty(pbl.KdBarang)) { MessageBox.Show("Kode Barang harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Kode produsen tidak boleh NULL if (string.IsNullOrEmpty(pbl.KdProdusen)) { MessageBox.Show("Kode produsen harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Kode admin tidak boleh NULL if (string.IsNullOrEmpty(pbl.KdAdmin)) { MessageBox.Show("Kode admin harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // membuat objek context menggunakan blok using using (DbContext context = new DbContext()) { // membuat objek class repository _repository = new PembelianRepository(context); // panggil method Create class repository untuk menambahkan data result = _repository.Update(pbl); } if (result > 0) { MessageBox.Show("Data pembelian berhasil diperbaiki !", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data pembelian gagal diperbaiki !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }
public int Update(Pembelian pbl) { int result = 0; // cek npm yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(pbl.KdPembelian)) { MessageBox.Show("Kode pembelian harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // cek nama yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(pbl.NamaBarang)) { MessageBox.Show("Nama harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // cek angkatan yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(Convert.ToString(pbl.HargaBeli))) { MessageBox.Show("Harga harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(Convert.ToString(pbl.Jumlah))) { MessageBox.Show("Harga harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(pbl.Jumlah)) { MessageBox.Show("Jumlah harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(pbl.KdBarang)) { MessageBox.Show("Kode Barang harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // membuat objek context menggunakan blok using using (DbContext context = new DbContext()) { // membuat objek class repository _repository = new PembelianRepository(context); // panggil method Create class repository untuk menambahkan data result = _repository.Update(pbl); } if (result > 0) { MessageBox.Show("Data pembelian disimpan !", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data pembelian gagal disimpan !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }