private void btnDaftar_Click(object sender, EventArgs e)
        {
            Barang barang = null;

            if (this.tbNamaBrgBaru.Text.Trim() == "")//jika isian nama kosong
            {
                MessageBox.Show("Sorry , nama barang wajib isi ...");
                this.tbNamaBrgBaru.Focus();
            }
            else if (this.tbHargaBrgBaru.Text.Trim() == "")
            {
                MessageBox.Show("Sorry , harga barang wajib isi ...");
                this.tbHargaBrgBaru.Focus();
            }
            else if (this.tbPajakBrg.Text.Trim() == "")
            {
                MessageBox.Show("Sorry , pajak barang wajib isi ...");
                this.tbPajakBrg.Focus();
            }
            else
            {
                barang             = new Barang();
                barang.KodeBarang  = dao.GetKodeBarangBerikutnya();
                barang.NamaBarang  = this.tbNamaBrgBaru.Text;
                barang.HargaBarang = Convert.ToDouble(this.tbHargaBrgBaru.Text);
                barang.PajakBarang = Convert.ToDouble(this.tbPajakBrg.Text);
                dao.Insert(barang);
                this.Close();
            }
        }
Beispiel #2
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            using (var barangdao = new BarangDAO())
            {
                list = barangdao.GetAllDataBarang();
            }



            if (txtKode.Text.Trim() == "" || txtNama.Text.Trim() == "" || txtHarga.Text.Trim() == "" || txtPajak.Text.Trim() == "")
            {
                MessageBox.Show("Tolong isi semua data yang diperlukan!", "Kosong", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtKode.Text.Length > 4)
            {
                MessageBox.Show("Kode Barang tidak boleh melebihi 4 karakter!", "Kode Barang", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtNama.Text.Length > 50)
            {
                MessageBox.Show("Nama tidak boleh melebihi 50 karakter !", "Nama Terlalu Panjang", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (Decimal.Parse(txtPajak.Text) > 100)
            {
                MessageBox.Show("Pajak tidak boleh melebihi 100%", "Pajak Melebihi Batas", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (list.Find(i => i.Kode.ToLower().ToString().Trim() == txtKode.Text.Trim().ToLower()) != null)
            {
                MessageBox.Show("Kode barang invalid ! Coba kode lain!", "Kode Invalid", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                try
                {
                    using (var barangdao = new BarangDAO())
                    {
                        barangdao.Insert(new Barang
                        {
                            Kode  = txtKode.Text,
                            Nama  = txtNama.Text,
                            Harga = Double.Parse(txtHarga.Text),
                            Pajak = Decimal.Parse(txtPajak.Text)
                        });
                    }
                    MessageBox.Show("Penambahan Barang Berhasil", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Beispiel #3
0
 private void btnSimpan_Click(object sender, EventArgs e)
 {
     try
     {
         using (var barangdao = new BarangDAO())
         {
             barangdao.Insert(new Barang {
                 Kode  = txtKode.Text,
                 Nama  = txtNama.Text,
                 Harga = Double.Parse(txtHarga.Text),
                 Pajak = Int32.Parse(txtPajak.Text)
             });
         }
         MessageBox.Show("Penambahan Barang Berhasil", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }