Пример #1
0
        private void TombolTambah_Click(object sender, EventArgs e)
        {
            Model.Transaksi baru = new Model.Transaksi();

            //AMBIL NILAI HARGA
            MySqlConnection Server     = new MySqlConnection("server=localhost;database=geekrental;uid=root;pwd='';");
            string          KueriHarga = "SELECT harga FROM mobil WHERE id_mobil='" + MerekMobil.Text + "'";

            Server.Open();

            MySqlCommand    termux = new MySqlCommand(KueriHarga, Server);
            MySqlDataReader eja    = termux.ExecuteReader();

            while (eja.Read())
            {
                HargaMobil.Text = eja.GetString("harga");
            }
            Server.Close();

            //MASUK DB
            baru.Id_pelanggan = IDPelanggan.Text;
            baru.Mobil        = MerekMobil.Text;
            baru.Tgl_sewa     = TanggalSewa.Value.ToString("yyyy/MM/dd");
            baru.Tgl_kembali  = TanggalKembali.Value.ToString("yyyy/MM/dd");
            baru.Harga        = Convert.ToString((TanggalKembali.Value - TanggalSewa.Value).TotalDays * Double.Parse(HargaMobil.Text));
            baru.Status       = "Sewa";

            UD.InsertData(baru);
            IDPelanggan.Text = null;
            MerekMobil.Text  = null;
            HargaMobil.Text  = "";
            Status.Text      = "";
            TampilSemua();
        }
Пример #2
0
        public bool UpdateData(Model.Transaksi baru, string id_transaksi)
        {
            Boolean stat = false;

            try
            {
                terhubung.Open();
                cmd             = new MySqlCommand();
                cmd.Connection  = terhubung;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "UPDATE transaksi SET id_pelanggan='" + baru.Id_pelanggan + "'," + "id_mobil='" + baru.Mobil + "'," + "tgl_sewa='" + baru.Tgl_sewa + "'," + "tgl_kembali='" + baru.Tgl_kembali + "'," + "total_sewa='" + baru.Harga + "'," + "status_transaksi='" + baru.Status + "' WHERE id_transaksi='" + id_transaksi + "'";
                cmd.ExecuteNonQuery();
                stat = true;
                Notif("Data Berhasil Ditambahkan", Alert.alertTypeEnum.Success);
            }
            catch (MySqlException)
            {
                Notif("Data Gagal Ditambahkan", Alert.alertTypeEnum.Error);
            }
            return(stat);
        }
Пример #3
0
        public bool InsertData(Model.Transaksi baru)
        {
            Boolean stat = false;

            try
            {
                terhubung.Open();
                cmd             = new MySqlCommand();
                cmd.Connection  = terhubung;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "INSERT INTO transaksi (id_pelanggan, id_mobil, tgl_sewa, tgl_kembali, total_sewa, status_transaksi) VALUES ('" + baru.Id_pelanggan + "','" + baru.Mobil + "','" + baru.Tgl_sewa + "','" + baru.Tgl_kembali + "','" + baru.Harga + "','" + baru.Status + "')";
                cmd.ExecuteNonQuery();
                stat = true;
                Notif("Data Berhasil Ditambahkan", Alert.alertTypeEnum.Success);
            }
            catch (MySqlException)
            {
                Notif("Data Gagal Ditambahkan", Alert.alertTypeEnum.Error);
            }
            return(stat);
        }