private void QueryData(Barang barang = null)
 {
     try
     {
         this.dataGridView1.DataSource = null;
         List <Barang> listData = null;
         using (var daoBarang = new BarangDAO())
         {
             if (barang == null)
             {
                 listData = daoBarang.GetAllDataBarang();
             }
             else
             {
                 listData = daoBarang.QueryData(barang);
             }
         }
         if (listData != null)
         {
             this.dataGridView1.DataSource = listData;
             this.dataGridView1.Columns[0].DataPropertyName = nameof(Barang.Kode);
             this.dataGridView1.Columns[1].DataPropertyName = nameof(Barang.Nama);
             this.dataGridView1.Columns[2].DataPropertyName = nameof(Barang.Quantity);
             this.dataGridView1.Columns[3].DataPropertyName = nameof(Barang.Harga);
             this.dataGridView1.Columns[4].DataPropertyName = nameof(Barang.Pajak);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        private void FrmEdit_Load(object sender, EventArgs e)
        {
            Barang barang = new BarangDAO().GetDataBarangByKode(_kode);

            if (barang != null)
            {
                this.txtkode.Text = barang.Kode;
                this.txtnama.Text = barang.Nama;
                //Convert.ToDecimal(this.txtharga.Text) = barang.Harga;
                this.txtpajak.Text = barang.Pajak;
            }
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            var daoBarang  = new BarangDAO();
            var ListBarang = daoBarang.GetAllDataBarang();

            foreach (var item in ListBarang)
            {
                if (item.Kode == txtkode.Text)
                {
                    temp = item;
                    break;
                }
            }
            txtnama.Text = temp.Nama;
        }
Exemple #4
0
        private void btnsimpan_Click(object sender, EventArgs e)
        {
            if (this.txtkode.Text.Trim() == "" || txtnama.Text.Trim() == "" || txtjumlah.Text.Trim() == "" || txtharga.Text.Trim() == "" || txtpajak.Text.Trim() == "")
            {
                MessageBox.Show("Sorry, isi semua terlebih dahulu ...", "Kosong", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtkode.Text.Length > 4)
            {
                MessageBox.Show("Sorry, Kode Barang tidak boleh melebihi 4 karakter ...", "Kode Barang", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (txtnama.Text.Length > 50)
            {
                MessageBox.Show("Sorry, Nama tidak boleh lewat 50 karakter ...", "Nama Terlalu Panjang", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else if (Decimal.Parse(txtpajak.Text) > 100)
            {
                MessageBox.Show("Sorry, Persen tidak boleh melebihi 100% ...", "Pajak Melebihan Batas!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                try
                {
                    using (var dao = new BarangDAO())
                    {
                        _result = dao.Insert(
                            new Barang
                        {
                            Kode     = this.txtkode.Text.Trim(),
                            Nama     = this.txtnama.Text.Trim(),
                            Harga    = Convert.ToDecimal(this.txtharga.Text.Trim()),
                            Quantity = Convert.ToInt32(this.txtjumlah.Text.Trim()),
                            Pajak    = (Convert.ToDouble(this.txtpajak.Text.Trim().Split('%')[0]) / 100).ToString()
                        }) > 0;
                    }
                    MessageBox.Show("Success Tambah Barang!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Hide();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
 private void FormEditBarang_Load(object sender, EventArgs e)
 {
     try
     {
         Barang barang = new BarangDAO().GetDataBarangByKode(_kode);
         if (barang != null)
         {
             this.txtkode.Text   = barang.Kode;
             this.txtnama.Text   = barang.Nama;
             this.txtjumlah.Text = Convert.ToInt32(barang.Quantity).ToString();
             this.txtharga.Text  = Convert.ToDecimal(barang.Harga).ToString();
             this.txtpajak.Text  = barang.Pajak;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Edit Form!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        private void FormMainMenu_Load(object sender, EventArgs e)
        {
            listBelanja = new List <Belanja>();

            try
            {
                using (var barangdao = new BarangDAO())
                {
                    listBrg = barangdao.GetAllDataBarang();
                }

                dataGridView1.DataSource = listBrg;
                dataGridView1.Columns[0].DataPropertyName = "Kode";
                dataGridView1.Columns[1].DataPropertyName = "Nama";
                dataGridView1.Columns[2].DataPropertyName = "Quantity";
                dataGridView1.Columns[3].DataPropertyName = "Harga";
                dataGridView1.Columns[4].DataPropertyName = "Pajak";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnhapus_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dr = MessageBox.Show("Apa Anda Yakin Ingin Menghapus Data Tersebut?", "Hapus Data", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                switch (dr)
                {
                case DialogResult.Yes:
                    using (var barangdao = new BarangDAO())
                    {
                        barangdao.Delete(dataGridView1.CurrentCell.Value.ToString());
                    }
                    MessageBox.Show("Barang berhasil dihapus!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;

                case DialogResult.No:
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }