void UpdateDetails(object sender, RoutedEventArgs e) { for (var vis = sender as Visual; vis != null; vis = VisualTreeHelper.GetParent(vis) as Visual) { if (vis is DataGridRow) { var row = (DataGridRow)vis; var data = dataGrid1.Items[row.GetIndex()]; try { int iMapel = row.GetIndex(); Pelajaran mp = pelajaran[row.GetIndex()]; InsertPelajaranDetail inputDialog = new InsertPelajaranDetail("Update Mata Kuliah:", mp.NamaPelajaran); if (inputDialog.ShowDialog() == true) { if (dbConnection.SelectMataKuliah(inputDialog.Answer)[0].Count == 0) { dbConnection.UpdateMataKuliah(int.Parse(mp.IDPelajaran), inputDialog.Answer); } else { MessageBox.Show("Data Mata Kuliah sudah ada"); } } dataGrid1.ItemsSource = LoadCollectionData(); } catch (Exception all) { } } } }
private void Insert_Click(object sender, RoutedEventArgs e) { InsertPelajaranDetail inputDialog = new InsertPelajaranDetail("Masukan Mata Kuliah:", "Elektro"); if (inputDialog.ShowDialog() == true) { if (!String.IsNullOrWhiteSpace(inputDialog.Answer)) { if (dbConnection.SelectMataKuliah(inputDialog.Answer)[0].Count == 0) { dbConnection.InsertMataKuliah(inputDialog.Answer); dataGrid1.ItemsSource = LoadCollectionData(); } else { MessageBox.Show("Data Mata Kuliah sudah ada"); } } else { MessageBox.Show("Tidak Boleh Kosong"); } } }