示例#1
0
 private void BBatal_Click(object sender, EventArgs e)
 {
     if (Dg.Enabled)
     {
         Close();
     }
     else
     {
         Dg.Enabled = !Dg.Enabled;
         TbJenisNilai.Clear();
         TbKeterangan.Clear();
     }
 }
 private void BSimpan_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(TbKelas.Text))
     {
         MessageBox.Show("Nama kelas kosong!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else if (string.IsNullOrEmpty(TbUrutan.Text))
     {
         MessageBox.Show("Urutan kosong!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         if (Dg.Enabled)
         {
             if (MessageBox.Show("Simpan kelas baru?", "Pertanyaan", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 A.SetInsert("INSERT INTO `r_kelas` (`kode_kelas`, `namakelas`, `urutan`, `keterangan`)");
                 A.SetValues("VALUES('" + A.GenerateKode("KL", "r_kelas", "kode_kelas") + "', '" + TbKelas.Text + "', '" + TbUrutan.Text + "', " +
                             "'" + TbKeterangan.StrEscape() + "')");
                 A.SetQueri(A.GetInsert() + A.GetValues() + ";");
                 if (A.GetQueri().ManipulasiData())
                 {
                     MessageBox.Show("Data telah ditambahkan!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     TbKelas.Clear();
                     TbUrutan.Clear();
                     TbKeterangan.Clear();
                     Loaddb();
                 }
             }
         }
         else
         {
             if (MessageBox.Show("Simpan perubahan kelas?", "Pertanyaan", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 A.SetUpdate("UPDATE `r_kelas` ");
                 A.SetSet("SET `namakelas` = '" + TbKelas.Text + "', `keterangan` = '" + TbKeterangan.StrEscape() + "', '" + TbUrutan.Text + "' ");
                 A.SetWhere("WHERE `kode_kelas` = '" + 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);
                     TbKelas.Clear();
                     TbUrutan.Clear();
                     TbKeterangan.Clear();
                     Dg.LoadIndex(Loaddb, 1);
                 }
             }
         }
     }
 }