예제 #1
0
        public int Create(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 barang 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)))
            {
                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 menggunakan blok using
            using (DbContext context = new DbContext())
            {
                // buat clas repo
                _repository = new PembelianRepository(context);

                // manggil method repo biar nambah data
                result = _repository.Create(pbl);
            }

            if (result > 0)
            {
                MessageBox.Show("Data pembelian berhasil ditambah !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Data pembelian gagal ditambah !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(result);
        }
        public int Create(Pembelian pmb)
        {
            int result = 0;

            // kode pembelian wajib diisi
            if (string.IsNullOrEmpty(pmb.KdPembelian))
            {
                MessageBox.Show("Kode pembelian harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // nama barang wajib diisi
            if (string.IsNullOrEmpty(pmb.NamaBarang))
            {
                MessageBox.Show("Nama barang haru diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // Harga pembelian wajib diisi
            if (string.IsNullOrEmpty(Convert.ToString(pmb.HargaBeli)))
            {
                MessageBox.Show("Harga harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // produsen
            if (string.IsNullOrEmpty(pmb.KdProdusen))
            {
                MessageBox.Show("Kode produsen harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // Barang
            if (string.IsNullOrEmpty(pmb.KdBarang))
            {
                MessageBox.Show("Kode barang harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // Pesanan
            if (string.IsNullOrEmpty(pmb.KdPesanan))
            {
                MessageBox.Show("Kode pesanan harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // Admin
            if (string.IsNullOrEmpty(pmb.KdAdmin))
            {
                MessageBox.Show("Kode barang harus diisi !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            // membuat objek menggunakan blok using
            using (DbContext context = new DbContext())
            {
                // buat clas repo
                _repository = new PembelianRepository(context);

                // manggil method repo biar nambah data
                result = _repository.Create(pmb);
            }

            if (result > 0)
            {
                MessageBox.Show("Data pembelian berhasil disimpan !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Data pembelian gagal disimpan !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(result);
        }