Ejemplo n.º 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtID.Text == "")
            {
                MetroMessageBox.Show(this, "Data Tidak Ditemukan", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DataClassDataContext dbCtx = new DataClassDataContext();
                var getData = (
                    from x in dbCtx.Bukus
                    where x.Id == Convert.ToInt32(txtID.Text)
                    select x
                    ).ToList().First();

                getData.nama_buku  = txtJudul.Text;
                getData.harga      = Convert.ToInt32(txtHarga.Text);
                getData.thn_terbit = Convert.ToInt32(txtTahun.Text);
                getData.pengarang  = txtPengarang.Text;

                try
                {
                    dbCtx.SubmitChanges();
                    MetroMessageBox.Show(this, "Data Telah Di Update", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtID.Clear();
                    txtHarga.Clear();
                    txtJudul.Clear();
                    txtPengarang.Clear();
                    txtTahun.Clear();
                }catch (Exception ex) {
                    MetroMessageBox.Show(this, "Gagal Update Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtHarga.Text == "" || txtJudul.Text == "" || txtKode.Text == "" || txtPengarang.Text == "" || txtTahun.Text == "")
            {
                MetroMessageBox.Show(this, "Semua Form Harus Diisi", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Buku newBuku = new Buku();
                newBuku.kode_buku  = txtKode.Text;
                newBuku.nama_buku  = txtJudul.Text;
                newBuku.harga      = Convert.ToInt32(txtHarga.Text);
                newBuku.thn_terbit = Convert.ToInt32(txtTahun.Text);
                newBuku.pengarang  = txtPengarang.Text;

                DataClassDataContext dbCtx = new DataClassDataContext();
                dbCtx.Bukus.InsertOnSubmit(newBuku);

                try
                {
                    dbCtx.SubmitChanges();

                    MetroMessageBox.Show(this, "Data Berhasil Ditambahkan", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtKode.Clear();
                    txtJudul.Clear();
                    txtHarga.Clear();
                    txtPengarang.Clear();
                    txtTahun.Clear();
                }
                catch (Exception ex)
                {
                    MetroMessageBox.Show(this, "Gagal", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnGetData_Click(object sender, EventArgs e)
        {
            if (txtKodeBuku.Text == "")
            {
                MetroMessageBox.Show(this, "Kode Buku Harus Terisi", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                float kodeTransaksi;
                var   bytes = new byte[4];
                var   rng   = RandomNumberGenerator.Create();
                rng.GetBytes(bytes);
                kodeTransaksi       = (BitConverter.ToInt32(bytes, 0) % 99999);
                txtIDtransaksi.Text = txtKodeBuku.Text + (kodeTransaksi).ToString();

                DataClassDataContext dbCtx = new DataClassDataContext();

                var getData = (
                    from x in  dbCtx.Bukus
                    where x.kode_buku == txtKodeBuku.Text
                    select x
                    ).ToList().First();

                try
                {
                    txtjudul.Text = getData.nama_buku;
                    txtharga.Text = getData.harga.ToString();
                }
                catch (Exception ex)
                {
                }
            }
        }
Ejemplo n.º 4
0
        private void btnHapus_Click(object sender, EventArgs e)
        {
            if (txtIDhps.Text == "")
            {
                MetroMessageBox.Show(this, "ID Harus Di Isi", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DataClassDataContext dbCtx = new DataClassDataContext();
                var getData = (
                    from x in dbCtx.Bukus
                    where x.Id == Convert.ToInt32(txtIDhps.Text)
                    select x
                    ).ToList().Last();

                dbCtx.Bukus.DeleteOnSubmit(getData);

                try
                {
                    dbCtx.SubmitChanges();
                    MetroMessageBox.Show(this, "Data Berhasil", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MetroMessageBox.Show(this, "Gagal Hapus Data", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            DataClassDataContext dbCtx = new DataClassDataContext();

            var getData = (
                from x in dbCtx.Bukus
                select x
                );

            metroGrid1.DataSource = getData;
        }
Ejemplo n.º 6
0
        private void metroTabControl1_Selected(object sender, TabControlEventArgs e)
        {
            DataClassDataContext dbCtx = new DataClassDataContext();

            var getData = (
                from x in dbCtx.Bukus
                select x
                );

            metroGrid2.DataSource = getData;
        }
Ejemplo n.º 7
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtID.Text == "")
            {
                MetroMessageBox.Show(this, "Kolom ID Harus di Isi", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                DataClassDataContext dbCtx = new DataClassDataContext();
                var getData = (
                    from x in dbCtx.Bukus
                    where x.Id == Convert.ToInt32(txtID.Text)
                    select x
                    ).ToList().First();

                txtJudul.Text     = getData.nama_buku.ToString();
                txtHarga.Text     = getData.harga.ToString();
                txtTahun.Text     = getData.thn_terbit.ToString();
                txtPengarang.Text = getData.pengarang.ToString();
            }
        }