Beispiel #1
0
 private void DeleteBtn_Click(object sender, EventArgs e)
 {
     using (var db = new AssignmentModel())
     {
         db.Tables.RemoveRange(db.Tables.Where(item => item.Nama_Tugas == lblNama.Text));
         db.SaveChanges();
         lblNama.Text          = "-";
         lblMatkul.Text        = "-";
         dateTimePicker1.Value = DateTime.Now;
         lblDeskripsi.Text     = "-";
         EditBtn.Enabled       = false;
         DeleteBtn.Enabled     = false;
     }
 }
 private void EditData()
 {
     using (var db = new AssignmentModel())
     {
         var result = db.Tables.SingleOrDefault(k => k.Nama_Tugas == Assignment.Nama_Tugas);
         if (result != null)
         {
             result.Nama_Tugas = NamaTb.Text;
             result.Matkul     = MatKulTb.Text;
             result.Deadline   = dateTimePicker1.Value;
             result.Deskripsi  = DeskripsiTb.Text;
             db.SaveChanges();
             MessageBox.Show("Assignment updated");
             Close();
         }
     }
 }
 private void TambahData()
 {
     if (NamaTb.Text != "" && MatKulTb.Text != "")
     {
         using (var db = new AssignmentModel())
         {
             var Assignment = new Table()
             {
                 Nama_Tugas = NamaTb.Text,
                 Matkul     = MatKulTb.Text,
                 Deskripsi  = DeskripsiTb.Text,
                 Deadline   = dateTimePicker1.Value,
             };
             db.Tables.Add(Assignment);
             db.SaveChanges();
             MessageBox.Show("Assignment added");
             Close();
         }
     }
 }