private void BSimpan_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(TbKodeMapel.Text)) { MessageBox.Show("Kode mapel kosong!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (string.IsNullOrEmpty(TbMataPelajaran.Text)) { MessageBox.Show("Mata Pelajaran kosong!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (CbStatus.SelectedIndex < 0) { MessageBox.Show("Status kosong!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (Dg.Enabled) { if (MessageBox.Show("Simpan pelajaran baru?", "Pertanyaan", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { A.SetInsert("INSERT INTO `r_matapelajaran` (`kodepelajaran`, `kodemapel`, `namapelajaran`, `status`)"); A.SetValues("VALUES('" + A.GenerateKode("MP", "r_matapelajaran", "kodepelajaran") + "', '" + TbKodeMapel.Text + "', " + "'" + TbMataPelajaran.StrEscape() + "', '" + CbStatus.ToYN() + "')"); A.SetQueri(A.GetInsert() + A.GetValues() + ";"); if (A.GetQueri().ManipulasiData()) { MessageBox.Show("Data telah ditambahkan!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); TbKodeMapel.Clear(); TbMataPelajaran.Clear(); CbStatus.SelectedIndex = -1; Loaddb(); } } } else { if (MessageBox.Show("Simpan perubahan pelajaran?", "Pertanyaan", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { A.SetUpdate("UPDATE `r_matapelajaran` "); A.SetSet("SET `kodemapel` = '" + TbKodeMapel.Text + "', `namapelajaran` = '" + TbMataPelajaran.StrEscape() + "', `status` = '" + CbStatus.ToYN() + "' "); A.SetWhere("WHERE `kodepelajaran` = '" + Dg.CurrentRow.Cells[0].Value.ToString() + "' "); A.SetQueri(A.GetUpdate() + A.GetSet() + A.GetWhere() + ";"); if (A.GetQueri().ManipulasiData()) { MessageBox.Show("Data telah diubah!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information); TbKodeMapel.Clear(); TbMataPelajaran.Clear(); CbStatus.SelectedIndex = -1; Dg.LoadIndex(Loaddb, 1); } } } } }
private void BBatal_Click(object sender, EventArgs e) { if (Dg.Enabled) { Close(); } else { Dg.Enabled = !Dg.Enabled; TbKodeMapel.Clear(); TbMataPelajaran.Clear(); CbStatus.SelectedIndex = -1; } }