private void btnSimpan_Click(object sender, EventArgs e) { Spd s = new Spd(); List <Pengikut> p = new List <Pengikut>(); Biaya b = new Biaya(); s.kode = txtKode.Text; s.pegawai_id = ((KeyValuePair <int, string>)cmbPegawai.SelectedItem).Key; s.tb = cmbTb.SelectedItem.ToString(); s.maksud = txtMaksud.Text; s.trasport_id = ((KeyValuePair <int, string>)cmbTrasportasi.SelectedItem).Key; s.t_berangkat_id = ((KeyValuePair <int, string>)cmbBerangkat.SelectedItem).Key; s.t_tujuan_id = ((KeyValuePair <int, string>)cmbTujuan.SelectedItem).Key; s.penjabat = txtPenjabat.Text; s.t_jabatan = txtTJabatan.Text; s.lama = Int32.Parse(txtLama.Text); s.tgl_berangkat = dtTglBerangkat.Value.ToString("yyyy-MM-dd"); s.tgl_kembali = dtTglKembali.Value.ToString("yyyy-MM-dd"); s.no_surat = txtNoSuratTuga.Text; s.tgl_tugas = dtTglSurat.Value.ToString("yyyy-MM-dd"); s.akun = txtAkun.Text; if (cbPengikut1.Checked) { Pengikut p1 = new Pengikut(); if (aksi == "update") { p1.id = pengikut.ElementAtOrDefault(0) == null ? -1 : pengikut[0].id; } p1.pegawai = ((KeyValuePair <int, string>)cmbPengikut1.SelectedItem).Key; p1.ket = txtKetPengikut1.Text; p1.t_lahir = tgl_lahir.Text; p.Add(p1); } if (cbPengikut2.Checked) { Pengikut p2 = new Pengikut(); if (aksi == "update") { p2.id = pengikut.ElementAtOrDefault(1) == null ? -1 : pengikut[1].id; } p2.pegawai = ((KeyValuePair <int, string>)cmbPengikut2.SelectedItem).Key; p2.ket = txtKetPengikut2.Text; p2.t_lahir = tgl_lahir1.Text; p.Add(p2); } if (cbPengikut3.Checked) { Pengikut p3 = new Pengikut(); if (aksi == "update") { p3.id = pengikut.ElementAtOrDefault(2) == null ? -1 : pengikut[2].id; } p3.pegawai = ((KeyValuePair <int, string>)cmbPengikut3.SelectedItem).Key; p3.ket = txtKetPengikut3.Text; p3.t_lahir = tgl_lahir2.Text; p.Add(p3); } b.harian = string.IsNullOrEmpty(txtHarian.Text) ? 0 : int.Parse(txtHarian.Text); b.h_lama = string.IsNullOrEmpty(txtHLama.Text) ? 0 : int.Parse(txtHLama.Text); b.h_total = Int32.Parse(txtHLama.Text) * Int32.Parse(txtHarian.Text); b.penginapan = string.IsNullOrEmpty(txtPenginapan.Text) ? 0 : int.Parse(txtPenginapan.Text); b.p_lama = string.IsNullOrEmpty(txtP_lama.Text) ? 0 : int.Parse(txtP_lama.Text); b.p_total = Int32.Parse(txtP_lama.Text) * Int32.Parse(txtPenginapan.Text); b.transport_pp = string.IsNullOrEmpty(txtTransport.Text) ? 0 : int.Parse(txtTransport.Text); b.transport_loak = string.IsNullOrEmpty(txtLTransport.Text) ? 0 : int.Parse(txtLTransport.Text); b.damri = string.IsNullOrEmpty(txtLTransport.Text) ? 0 : int.Parse(txtDamri.Text); b.lain_lain = string.IsNullOrEmpty(txtLain_lain.Text) ? 0 : int.Parse(txtLain_lain.Text); int result = -1; if (aksi == "insert") { result = DbQuery.InsertSPD(s, p, b); } else if (aksi == "update") { foreach (var ss in spd) { s.id = ss.id; } foreach (var bi in biaya) { b.id = bi.id; } result = DbQuery.UpdateSPD(s, p, b); } string msg = "Terjadi Kesalahan Pada Saat Menyimpan Data"; if (result > 0) { msg = "Berhasil! Data Telah Tersimpan"; } MessageBox.Show(msg); if (Application.OpenForms["Form1"] != null) { (Application.OpenForms["Form1"] as Form1).RefSpd(); } this.Close(); }