private void loadTablePerangkat() { c = new ConnectionUtils(); using (SQLiteConnection cc = new SQLiteConnection(c.getConnection())) { try { cc.Open(); cmd = cc.CreateCommand(); cmd.CommandText = @"SELECT nama_perangkat,nip,jabatan FROM perangkat ORDER BY nama_perangkat"; using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd.CommandText, cc)) { DataTable ddt = new DataTable(); da.Fill(ddt); dataGrid.ItemsSource = ddt.AsDataView(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Bosku!", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void loadTableSPPD() { c = new ConnectionUtils(); using (SQLiteConnection cc = new SQLiteConnection(c.getConnection())) { try { cc.Open(); cmd = cc.CreateCommand(); cmd.CommandText = @"SELECT no_agenda, dasar_surat, tanggal_surat, nama_perangkat, nip, jabatan, maksud_sppd, alat_transportasi, tempat_berangkat, tempat_tujuan, tanggal_berangkat, tanggal_kembali, lama_keberangkatan, pengikut1, jabatan_pengikut1, pengikut2, jabatan_pengikut2, sumber_anggaran, keterangan FROM sppd ORDER BY no_agenda"; using (SQLiteDataAdapter da = new SQLiteDataAdapter(cmd.CommandText, cc)) { DataTable ddta = new DataTable(); da.Fill(ddta); dataGridSppd.ItemsSource = ddta.AsDataView(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Bosku!", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void btn_baru_Click(object sender, RoutedEventArgs e) { c = new ConnectionUtils(); pd = new PerangkatDAO(); string a = "- Pilih Jabatan -"; if (txt_namaPerangkat.Text != string.Empty && cmb_jabatan.Text.ToString() != a) { if (!pd.CheckJabatan(cmb_jabatan.Text.ToString())) { if (pd.insertData(txt_namaPerangkat.Text.ToString(), IntegerExtensions.ParseInt(txt_Nip.Text), cmb_jabatan.Text.ToString())) { MessageBox.Show("Data Perangkat Berhasil ditambahkan Bosku!", "Sukses", MessageBoxButton.OK, MessageBoxImage.Information); emptyFields(); loadTablePerangkat(); } } } else { MessageBox.Show("Nama Perangkat dan Jabatan Wajib di isi Bosku!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btn_new_Click(object sender, RoutedEventArgs e) { edit = false; c = new ConnectionUtils(); sd = new sppdDAO(); var na = new StringBuilder(); try { na.Append(agenda.Text); na.Append(txt_separator1.Text); na.Append(txt_autoNumber.Text); na.Append(txt_separator2.Text); na.Append(txt_currentMonth.Text); na.Append(txt_separator3.Text); na.Append(txt_currentYear.Text); string no_agenda = na.ToString(); try { if (txt_autoNumber.Text != string.Empty && txt_ds.Text != string.Empty && dp_ts.Text.ToString() != string.Empty && cmb_namaPerangkat.Text.ToString() != string.Empty && txt_maksud.Text != string.Empty && cmb_alat.Text.ToString() != string.Empty && txt_tempatBerangkat.Text != string.Empty && txt_tempatTujuan.Text != string.Empty && dp_tb.Text != string.Empty && dp_tk.Text != string.Empty && txt_sumberAnggaran.Text != string.Empty ) { sppdModel sm = new sppdModel(); try { sm.no_agenda = no_agenda.ToString(); sm.dasar_surat = txt_ds.Text.ToString(); sm.tanggal_surat = dp_ts.Text.ToString(); sm.nama_perangkat = cmb_namaPerangkat.Text.ToString(); sm.nip = IntegerExtensions.ParseInt(txt_nip.Text); sm.jabatan = txt_jabatan.Text.ToString(); sm.maksud_sppd = txt_maksud.Text.ToString(); sm.alat_transportasi = cmb_alat.Text.ToString(); sm.tempat_berangkat = txt_tempatBerangkat.Text.ToString(); sm.tempat_tujuan = txt_tempatTujuan.Text.ToString(); sm.tanggal_berangkat = dp_tb.Text.ToString(); sm.tanggal_kembali = dp_tk.Text.ToString(); sm.lama_keberangkatan = txt_lk.Text.ToString(); sm.pengikut1 = cmb_pengikut1.Text.ToString(); sm.jabatan_pengikut1 = txt_jabatan_pengikut1.Text.ToString(); sm.pengikut2 = cmb_pengikut2.Text.ToString(); sm.jabatan_pengikut2 = txt_jabatan_pengikut2.Text.ToString(); sm.sumber_anggaran = txt_sumberAnggaran.Text.ToString(); sm.keterangan = txt_ket.Text.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { try { using (SQLiteConnection con = new SQLiteConnection(c.getConnection())) { try { con.Open(); } catch (Exception ex) { throw ex; } using (SQLiteTransaction trn = con.BeginTransaction(IsolationLevel.ReadCommitted)) { try { sd.insertDataSPPD(sm, trn); } catch (Exception ex) { trn.Rollback(); MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { emptyFields(); loadTableSPPD(); } } } else { MessageBox.Show("Semua yang terdapat tanda (*) wajib diisi Bosku!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }