Monday, September 22, 2014

FORM BARANG

 pack();
    }// </editor-fold>                       

    private void v_namabarangActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
       
    }                                           

    private void jButton1_simpanActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here

        try {
            koneksidatabase();
            sql="insert into barang values('"+v_kodebarang.getText()+"','"+v_namabarang.getText()+"','"+v_satuan.getText()+"','"+v_harga.getText()+"')";
            stat.execute(sql);
            bersih_form();      
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }   
    }                                              

    private void jButton5_batalActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        bersih_form();
    }                                             

    private void jButton6_keluarActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        this.dispose();
    }                                              

    private void jButton3_editActionPerformed(java.awt.event.ActionEvent evt) {                                             
        // TODO add your handling code here:
        try {
            koneksidatabase();
            sql ="update barang set nama_barang ='"+v_namabarang.getText()+"', satuan ='"+v_satuan.getText()+"', harga ='"+v_harga.getText()+"' where kode_barang ='"+v_kodebarang.getText()+"'";
            stat.execute(sql);
            bersih_form();
        } catch (Exception e) {
        }
    }                                            

    private void jButton4_hapusActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // TODO add your handling code here:
        try {
            koneksidatabase();
            sql="delete from barang where kode_barang = '"+v_kodebarang.getText()+"'";
            stat.execute(sql);
            bersih_form();
        } catch (Exception e) {
        }
    }                                             

    private void v_kodebarangActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
        try {
            koneksidatabase();
            sql = "select * from barang where kode_barang = '"+ v_kodebarang.getText()+"' ";
            //(*->TAMPILKAN SMUA DARI DATA TABEL KODE_BARANG=TABEL KODE_BARANG DI FORM
            rs = stat.executeQuery(sql);
            while(rs.next())
            {
                v_namabarang.setText(rs.getString("nama_barang"));
                v_satuan.setText(rs.getString("satuan"));
                v_harga.setText(rs.getString("harga"));
            }
        } catch (Exception e) {
        }
    }                                           
private void koneksidatabase()
{
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbc");
        con = DriverManager.getConnection("Jdbc:Odbc:dsprogram");
        stat = con.createStatement();
        } catch (Exception e) {
    JOptionPane.showMessageDialog(null,"Kesalahan"+e);
        }
}
private void bersih_form()
{
     v_kodebarang.setText("");
     v_namabarang.setText("");
     v_satuan.setText("");
     v_harga.setText("");
     v_kodebarang.requestFocus();

    

No comments:

Post a Comment