Kamis, 20 Januari 2011

Program tugas akhirqu part 2

Entry data penduduk pindahdatang
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
    jButton6.setVisible(true);
    jButton7.setVisible(false);
   
    jPanel2.setVisible(true);
        no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");
        no_srt.setEditable(true);
}                                       

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
     no_srt.setEditable(true);
     no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");
          jPanel2.setVisible(false);
}                                       

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
      jButton7.setVisible(true);
      jButton6.setVisible(false);
     
    try{
   
    dapat_dari_table();
    jPanel2.setVisible(true);
    no_srt.setEditable(false);
    no_ktp.setEditable(false);
    }catch(Exception e)
    {
    JOptionPane.showMessageDialog(null, "Klik Record yang mau di edit","Pesan",JOptionPane.ERROR_MESSAGE);
    }
}                                       

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
    try{
     int table = jTable1.getSelectedRow();
    //mengambil data dari table
    String a = jTable1.getValueAt(table, 0).toString();
    String b = jTable1.getValueAt(table, 1).toString();
    String c = jTable1.getValueAt(table, 2).toString();
    try {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:penduduk");
           Statement stmt = con.createStatement();
           String SQL ="Delete From siswa  where no_ktp = '"+a+"' ";
                                                   
           stmt.executeUpdate(SQL);
           stmt.close();
           JOptionPane.showMessageDialog(null,"Data Berhasil DiHapus !!");
           tampil();
          
         
          
   }
   catch (Exception e)
   {
       System.out.println(e.getMessage());
       JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
       
   }
    }catch(Exception se)
    {
    JOptionPane.showMessageDialog(null, "Klik Record yang mau di Hapus ","ERROR",JOptionPane.ERROR_MESSAGE);
    }
}                                       

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:penduduk");
        Statement stmt = con.createStatement();
        String SQL ="insert into dbpndhdatang values ('"+no_srt.getText()+"' , '"+tglpindah.getText()+"' , '"+no_ktp.getText()+"', '"+nama.getText()+"'  ,'"+tglahir.getText()+"' , '"+jekel.getText()+"','"+lurah.getText()+"' , '"+camat.getText()+"','"+kab.getText()+"','"+prov.getText()+"','"+alasan.getText()+"' ,'"+almt_asl.getText()+"','"+almt_skg.getText()+"' )";

        stmt.executeUpdate(SQL);
        stmt.close();
        JOptionPane.showMessageDialog(null,"data Di simpan !!");
        tampil();

        no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");
        jPanel2.setVisible(false);

    } catch (Exception e) {
        System.out.println(e.getMessage());
        JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
        no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");
    }
    String a = null;
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbc");
        Connection con = DriverManager.getConnection("jdbc:odbc:penduduk");
        Statement stmt = (Statement) con.createStatement();
        String SQL ="Delete From dbpenduduk  where no_kk = '"+a+"' ";

        stmt.executeUpdate(SQL);
        stmt.close();
        JOptionPane.showMessageDialog(null,"Data Berhasil DiHapus !!");
    }catch(Exception e) {
        System.out.println(e.getMessage());
        JOptionPane.showMessageDialog(null,"Error"+e.getMessage());

    }
}                                       

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    jButton6.setVisible(false);
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:penduduk");
        Statement stmt = con.createStatement();
        String SQL ="update  dbpndhdatang set tglpindah = '"+tglpindah.getText()+"', no_ktp = '"+no_ktp.getText()+"' ,nama = '"+nama.getText()+"'  ,tglahir = '"+tglahir.getText()+"' , jekel = '"+jekel.getText()+"',lurah='"+lurah.getText()+"' ,camat= '"+camat.getText()+"',kab='"+kab.getText()+"',prov='"+prov.getText()+"',alasan='"+alasan.getText()+"' ,almt_asl='"+almt_asl.getText()+"',almt_skg'"+almt_skg.getText()+"' where no_srt = '"+no_srt.getText()+"' ";

        stmt.executeUpdate(SQL);
        stmt.close();
        JOptionPane.showMessageDialog(null,"Data Berhasil Di Edit !!");
        tampil();
        jPanel2.setVisible(false);
        no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");

    } catch (Exception e) {
        System.out.println(e.getMessage());
        JOptionPane.showMessageDialog(null,"Error"+e.getMessage());
       no_srt.setText("");
        tglpindah.setText("");
        no_ktp.setText("");
        nama.setText("");
        tglahir.setText("");
        jekel.setText("");
        lurah.setText("");
        camat.setText("");
        kab.setText("");
        prov.setText("");
        alasan.setText("");
        almt_asl.setText("");
        almt_skg.setText("");
    }
}                                       

public void tampil(){
     DefaultTableModel tbl = new DefaultTableModel();
        tbl.addColumn("No Surat");
        tbl.addColumn("Tgl Pindah");
        tbl.addColumn("no_ktp");
        tbl.addColumn("Nama");
        tbl.addColumn("tgl Lahir");
        tbl.addColumn("Jenis Kelamin");
        tbl.addColumn("Kelurahan");
        tbl.addColumn("Kecamatan");
        tbl.addColumn("Kabupaten");
        tbl.addColumn("Provinsi");
        tbl.addColumn("Alasan");
        tbl.addColumn("Alamat Asal");
        tbl.addColumn("Alamat Sekarang");
        try
        {
            int nomor= 0 ;
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con =DriverManager.getConnection("jdbc:odbc:penduduk");
            Statement stmt = con.createStatement();
            ResultSet RS = stmt.executeQuery("select *from dbpndhdatang");
            while (RS.next())
            {
               tbl.addRow(new Object []{RS.getString(1),RS.getString(2),RS.getString(3),RS.getString(4),RS.getString(5),RS.getString(6),RS.getString(7),RS.getString(8),RS.getString(9),RS.getString(10),RS.getString(11),RS.getString(12),RS.getString(13)});
            }
            jTable1.setModel(tbl);
            RS.close();
            stmt.close();
            con.close();
         
        }catch (Exception e)
        { System.err.println(e.getMessage());}
}

 public  void dapat_dari_table(){
      int table = jTable1.getSelectedRow();    String a = jTable1.getValueAt(table, 0).toString();
    String b = jTable1.getValueAt(table, 1).toString();
    String c = jTable1.getValueAt(table, 2).toString();
    String d = jTable1.getValueAt(table,3).toString();
    String e = jTable1.getValueAt(table,4).toString();
    String f = jTable1.getValueAt(table,5).toString();
    String g = jTable1.getValueAt(table, 6).toString();
    String h = jTable1.getValueAt(table, 7).toString();
    String i = jTable1.getValueAt(table,8).toString();
    String j = jTable1.getValueAt(table,9).toString();
    String k = jTable1.getValueAt(table,10).toString();
    String l = jTable1.getValueAt(table,11).toString();
    String m = jTable1.getValueAt(table,12).toString();
        no_srt.setText(a);
        tglpindah.setText(b);
        no_ktp.setText(c);
        nama.setText(d);
        tglahir.setText(e);
        jekel.setText(f);
        lurah.setText(g);
        camat.setText(h);
        kab.setText(i);
        prov.setText(j);
        alasan.setText(k);
        almt_asl.setText(l);
        almt_skg.setText(m);
    }   
   

Tidak ada komentar:

Posting Komentar