public int Create(Barang barang) { int result = 0; if (string.IsNullOrEmpty(barang.Kode_Barang)) { MessageBox.Show("Kode Barang Harus Diisi !", "Peringatan ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(barang.Nama_Barang)) { MessageBox.Show("Nama Barang Harus Diisi !", "Peringatan ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(barang.Harga)) { MessageBox.Show("Harga Barang Harus Diisi !", "Peringatan ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } using (DbContext context = new DbContext()) { _repository = new BarangRepository(context); result = _repository.Create(barang); } if (result > 0) { MessageBox.Show("Data Barang disimpan !", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data Barang gagal disimpan !", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }
public int Create(Barang brg) { int result = 0; // cek npm yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(brg.KdBarang)) { MessageBox.Show("Kode barang harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // cek nama yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(brg.Nama)) { MessageBox.Show("Nama harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // cek angkatan yang diinputkan tidak boleh kosong if (string.IsNullOrEmpty(Convert.ToString(brg.Harga))) { MessageBox.Show("Harga harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(brg.Warna)) { MessageBox.Show("Warna harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } if (string.IsNullOrEmpty(brg.Ukuran)) { MessageBox.Show("Ukuran 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 BarangRepository(context); // panggil method Create class repository untuk menambahkan data result = _repository.Create(brg); } if (result > 0) { MessageBox.Show("Data Barang berhasil disimpan !", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data Barang gagal disimpan !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }
public int Create(Barang brg) { int result = 0; // Validasi kode barang tdak boleh NULL if (string.IsNullOrEmpty(brg.KdBarang)) { MessageBox.Show("Kode barang harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi Nama barang tdak boleh NULL if (string.IsNullOrEmpty(brg.Nama)) { MessageBox.Show("Nama barang harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi kuantitas tdak boleh NULL if (string.IsNullOrEmpty(Convert.ToString(brg.Qty))) { MessageBox.Show("Kuantitas harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi harga tdak boleh NULL if (string.IsNullOrEmpty(Convert.ToString(brg.Harga))) { MessageBox.Show("Harga harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi warna tdak boleh NULL if (string.IsNullOrEmpty(brg.Warna)) { MessageBox.Show("Warna harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // Validasi ukurn tdak boleh NULL if (string.IsNullOrEmpty(brg.Ukuran)) { MessageBox.Show("Ukuran harus diisi !!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(0); } // membuat objek context menggunakan blok using using (DbContext context = new DbContext()) { // membuat objek class barang repository _repository = new BarangRepository(context); // panggil method Create pada repository barang untuk menambahkan data result = _repository.Create(brg); } if (result > 0) { MessageBox.Show("Data Barang berhasil disimpan!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Data Barang gagal disimpan!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(result); }