Exemple #1
0
        private void tambahBidang()
        {
            BidangBagian bdg = new BidangBagian();

            bdg.setBidang(textBoxBidangTambah.Text);
            string bidang = bdg.getBidang();

            Database        db      = new Database();
            string          strconn = db.getString();
            MySqlConnection conn    = new MySqlConnection(strconn);

            conn.Open();
            string       query = "INSERT INTO bagian_bidang VALUES(NULL, @nama_bagian_bidang)";
            MySqlCommand cmd   = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@nama_bagian_bidang", bidang);
            int hasil = cmd.ExecuteNonQuery();

            if (hasil > 0)
            {
                MessageBox.Show("Data berhasil ditambah", "Sukses");
                frm1.getAllBidang();
            }
            else
            {
                MessageBox.Show("Data gagal ditambah", "Gagal");
            }

            conn.Close();
        }
        private void buttonEditBidang_Click(object sender, EventArgs e)
        {
            Database        db      = new Database();
            string          strconn = db.getString();
            MySqlConnection conn    = new MySqlConnection(strconn);

            conn.Open();
            string       query = "UPDATE bagian_bidang SET nama_bagian_bidang = @nama_bagian_bidang WHERE id_bagian_bidang = @id_bagian_bidang";
            MySqlCommand cmd   = new MySqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@id_bagian_bidang", id_bagian_bidang);
            cmd.Parameters.AddWithValue("@nama_bagian_bidang", textBoxEditBidang.Text);
            //MessageBox.Show(query);
            int sukses = cmd.ExecuteNonQuery();

            if (sukses > 0)
            {
                MessageBox.Show("Data berhasil diupdate", "Sukses");
                frm1.getAllBidang();
            }
            else
            {
                MessageBox.Show("Data gagal diupdate", "Gagal");
            }
            conn.Close();
        }