private void Simpan(object sender, EventArgs e) { var service = new IadmClient(); var jadwal = new List <jadwal_umum>(); var idPeriode = service.viewPeriode().FirstOrDefault( q => q.awalSemester.ToString("yyyy") == comboBoxEdit2.SelectedItem.ToString().Substring(0, 4) && q.akhirSemester.ToString("yyyy") == comboBoxEdit2.SelectedItem.ToString().Substring(5, 4) && q.semester == comboBoxEdit1.SelectedItem.ToString()); if (idPeriode == null) { XtraMessageBox.Show( $"Semester {comboBoxEdit1.SelectedItem} Periode {comboBoxEdit2.SelectedItem} belum ada"); } else { //ambil data dari tabel for (var i = 0; i < gridView1.RowCount; i++) { DataRow row = gridView1.GetDataRow(i); if (row[3].ToString() == string.Empty || row[4].ToString() == string.Empty) { continue; } var idKelas = service.GetKelas().FirstOrDefault(q => q.Kelas == row[4].ToString()); var kdMk = service.GetMatKul().FirstOrDefault(q => q.mata_kuliah == row[3].ToString()); Debug.Assert(idKelas != null, "idKelas != null"); Debug.Assert(kdMk != null, "kdMk != null"); var listJadwal = new jadwal_umum() { hari = row[0].ToString(), id_kelas = idKelas.id_kelas, id_periode = idPeriode.id_periode, id_shift = row[1].ToString(), kode_mk = kdMk.kode_mk }; jadwal.Add(listJadwal); } //ubah List<jadwal_umum> ke jadwal_umum[] var jadd = new jadwal_umum[jadwal.Count]; for (var i = 0; i < jadwal.Count; i++) { var jadum = new jadwal_umum() { hari = jadwal[i].hari, id_kelas = jadwal[i].id_kelas, id_periode = jadwal[i].id_periode, id_shift = jadwal[i].id_shift, kode_mk = jadwal[i].kode_mk }; jadd[i] = jadum; } var errorMessage = false; try { service.InsertJadwal(jadd); } catch (Exception) { errorMessage = true; //XtraMessageBox.Show(error.ToString()); XtraMessageBox.Show("Tidak ada jadwal yg ditambahkan"); } if (errorMessage == false) { Close(); } } }