コード例 #1
0
        private void btnHapus_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                var konfirmasi = MessageBox.Show("Apakah data Paket ingin dihapus?", "Konfirmasi",
                                                 MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                if (konfirmasi == DialogResult.Yes)
                {
                    tbl_paketsewa paketsewa = listOfPaketsewa[listView1.SelectedIndices[0]];


                    var result = controller.Delete(paketsewa);
                    if (result > 0)
                    {
                        LoadDataPaketSewa();
                    }
                }
            }
            else
            {
                MessageBox.Show("Data PaketSewa belum dipilih !!!", "Peringatan",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #2
0
        public List <tbl_paketsewa> ReadAll()
        {
            var list = new List <tbl_paketsewa>();

            try
            {
                string sql = @"select kd_paket, kd_mobil, paketsewa, harga from tbl_paketsewa";

                using (OleDbCommand cmd = new OleDbCommand(sql, _conn))
                {
                    using (OleDbDataReader dtr = cmd.ExecuteReader())
                    {
                        while (dtr.Read())
                        {
                            var paket = new tbl_paketsewa();

                            paket.kd_paket  = dtr["kd_paket"].ToString();
                            paket.kd_mobil  = dtr["kd_mobil"].ToString();
                            paket.paketsewa = dtr["paketsewa"].ToString();
                            paket.harga     = dtr["harga"].ToString();
                            list.Add(paket);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Print("ReadByD error: {0}", ex.Message);
            }
            return(list);
        }
コード例 #3
0
        private void OnUpdateEventHandler(tbl_paketsewa paketsewa)
        {
            int index = listView1.SelectedIndices[0];

            ListViewItem itemRow = listView1.Items[index];

            itemRow.SubItems[1].Text = paketsewa.kd_paket;
            itemRow.SubItems[2].Text = paketsewa.kd_mobil;
            itemRow.SubItems[3].Text = paketsewa.paketsewa;
            itemRow.SubItems[2].Text = paketsewa.harga;
        }
コード例 #4
0
        private void OnCreateEventHandler(tbl_paketsewa paketsewa)
        {
            listOfPaketsewa.Add(paketsewa);

            int noUrut = listView1.Items.Count + 1;

            ListViewItem item = new ListViewItem(noUrut.ToString());

            item.SubItems.Add(paketsewa.kd_paket);
            item.SubItems.Add(paketsewa.kd_mobil);
            item.SubItems.Add(paketsewa.paketsewa);
            item.SubItems.Add(paketsewa.harga);
            listView1.Items.Add(item);
        }
コード例 #5
0
        // constructor untuk inisialisasi data ketika mengedit data
        public FrmEntryPakaetsewa(string title, tbl_paketsewa obj, tbl_paketsewaController controller)
            : this()
        {
            this.Text       = title;
            this.controller = controller;

            isNewData = false; // set status edit data
            paket     = obj;   // set objek mhs yang akan diedit

            // untuk edit data, tampilkan data lama
            txtKdPaket.Text   = paket.kd_paket;
            txtKdMobil.Text   = paket.kd_mobil;
            txtPaketSewa.Text = paket.paketsewa;
            txtHarga.Text     = paket.harga;
        }
コード例 #6
0
        public int Delete(tbl_paketsewa paket)
        {
            int result = 0;

            using (DbContext context = new DbContext())
            {
                _repo  = new tbl_paketsewaRepo(context);
                result = _repo.Delete(paket);
            }

            if (result == 0)
            {
                MessageBox.Show("Delete Data Gagal!", "Gagal", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(result);
        }
コード例 #7
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                tbl_paketsewa paket = listOfPaketsewa[listView1.SelectedIndices[0]];

                FrmEntryPakaetsewa frmEntry = new FrmEntryPakaetsewa("Edit Data Paket", paket, controller);

                frmEntry.OnUpdate += OnUpdateEventHandler;

                frmEntry.ShowDialog();
            }
            else
            {
                MessageBox.Show("Data belum dipilih", "Peringatan", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
        }
コード例 #8
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            if (isNewData)
            {
                paket = new tbl_paketsewa();
            }

            // set nilai property objek mahasiswa yg diambil dari TextBox
            paket.kd_paket  = txtKdPaket.Text;
            paket.kd_mobil  = txtKdMobil.Text;
            paket.paketsewa = txtPaketSewa.Text;
            paket.harga     = txtHarga.Text;
            int result = 0;

            if (isNewData) // tambah data baru, panggil method Create
            {
                // panggil operasi CRUD
                result = controller.Create(paket);

                if (result > 0)      // tambah data berhasil
                {
                    OnCreate(paket); // panggil event OnCreate

                    // reset form input, utk persiapan input data berikutnya
                    txtKdPaket.Clear();
                    txtKdMobil.Clear();
                    txtPaketSewa.Clear();
                    txtHarga.Clear();
                    txtKdPaket.Focus();
                }
            }
            else // edit data, panggil method Update
            {
                result = controller.Update(paket);

                if (result > 0)
                {
                    OnUpdate(paket);
                    this.Close();
                }
            }
        }
コード例 #9
0
        public int Delete(tbl_paketsewa paket)
        {
            int    result = 0;
            string sql    = @"delete from tbl_paketsewa where kd_paket = @kd_paket";

            using (OleDbCommand cmd = new OleDbCommand(sql, _conn))
            {
                cmd.Parameters.AddWithValue("@kd_paket", paket.kd_paket);
                cmd.Parameters.AddWithValue("@kd_mobil", paket.kd_mobil);
                cmd.Parameters.AddWithValue("@paketsewa", paket.paketsewa);
                cmd.Parameters.AddWithValue("@harga", paket.harga);
                try
                {
                    result = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("Create error: {0}", ex.Message);
                }
            }
            return(result);
        }
コード例 #10
0
        public int Create(tbl_paketsewa paket)
        {
            int result = 0;

            if (string.IsNullOrEmpty(paket.kd_paket))
            {
                MessageBox.Show("kd_paket harus diisi!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(0);
            }

            using (DbContext context = new DbContext())
            {
                _repo  = new tbl_paketsewaRepo(context);
                result = _repo.Create(paket);
            }

            if (result == 0)
            {
                MessageBox.Show("Input Data Gagal!", "Gagal", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(result);
        }
コード例 #11
0
        public int Create(tbl_paketsewa paketsewa)
        {
            int    result = 0;
            string sql    = @"insert into tbl_paketsewa (kd_paket, kd_mobil, paketsewa, harga)
                        values (@kd_paket, kd_mobil, paketsewa, harga)";

            using (OleDbCommand cmd = new OleDbCommand(sql, _conn))
            {
                cmd.Parameters.AddWithValue("@kd_paket", paketsewa.kd_paket);
                cmd.Parameters.AddWithValue("@kd_mobil", paketsewa.kd_mobil);
                cmd.Parameters.AddWithValue("@paketsewa", paketsewa.paketsewa);
                cmd.Parameters.AddWithValue("@harga", paketsewa.harga);

                try
                {
                    result = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Print("Create Error: {0}", ex.Message);
                }
            }
            return(result);
        }