Rabu, 08 Februari 2012

MEMBUAT PROGRAM PENJUALAN SEDERHANA


MEMBUAT PROGRAM PENJUALAN SEDERHANA
TABEL KARYAWAN

KARIAWAN.JPG
TABEL MENU


TABEL LOGIN


LANGKAH2NYA
1.buat acses seperti gambar

Db1.jpg
2.setting odbc.saat setting odbc database accses harus di close dulu agar tidak ada error path
Saat memilih setting odbc Pilih ini

Gambar odbc

Jangan pilih yang ini  

Gambar odbc salah
3.coding tombol simpan

String nik = txtnik.getText();
String nama = txtnama.getText();
String jabatan = txtjabatan.getText();
String gapok = txtgapok.getText();
String tunjangan = txttunjangan.getText();
String totalgaji = txttotalgaji.getText();
try
{
String dbname="jdbc:odbc:utsb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbname,"","");
Statement statement = con.createStatement();
String sql="insert into datakaryawan values('"+nik+"','"+nama+"','"+jabatan+"','"+gapok+"','"+tunjangan+"','"+totalgaji+"')";
statement.executeUpdate(sql);
statement.close();
JOptionPane.showMessageDialog(null, "Data berhasil dimasukkan..","Insert Data",JOptionPane.INFORMATION_MESSAGE);
txtnik.setText("");
txtnama.setText("");
txtjabatan.setText("");
txtgapok.setText("");
txttunjangan.setText("");
txttotalgaji.setText("");

//txtnpm.setFocusable(rootPaneCheckingEnabled);
con.close();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Eror: "+e,"Gagal",JOptionPane.WARNING_MESSAGE);
//System.err.println("Exception: "+e.getMessage());
}
//pasti banyak yang merah yach//tambahin penawar ni
//letakkan di bawah package //missal// package uas;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import java.sql.ResultSet;

//Coding tombol ubah

String nik = txtnik.getText();
String nama = txtnama.getText();
String jabatan = txtjabatan.getText();
String gapok = txtgapok.getText();
String tunjangan = txttunjangan.getText();
String totalgaji = txttotalgaji.getText();
        try
{
    String dbname="jdbc:odbc:utsb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbname,"","");
Statement statement = con.createStatement();
String sql="UPDATE datakaryawan SET nik='"+nik+"',nama='"+nama+"',jabatan='"+jabatan+"',gapok='"+gapok+"',tunjangan='"+tunjangan+"',totalgaji='"+totalgaji+"' WHERE nik LIKE '"+nik+"'";
statement.executeUpdate(sql);
   statement.close();
JOptionPane.showMessageDialog(null, "Data berhasil di edit..","Insert Data",JOptionPane.INFORMATION_MESSAGE);
con.close();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Eror: "+e,"Gagal",JOptionPane.WARNING_MESSAGE);
//System.err.println("Exception: "+e.getMessage());
}

//Coding tombol hapus

String nik = txtnik.getText();
try {
String dbname="jdbc:odbc:utsb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbname,"","");
Statement statement = con.createStatement();
String sql="DELETE FROM datakaryawan WHERE nik LIKE '"+nik+"'";
statement.executeUpdate(sql);
statement.close();


JOptionPane.showMessageDialog(null, "Data berhasil dihapus..","Insert Data",JOptionPane.INFORMATION_MESSAGE);
con.close();
} catch (Exception e) { JOptionPane.showMessageDialog(null, "Eror: "+e,"Gagal",JOptionPane.WARNING_MESSAGE);
txtnik.setText("");
txtnama.setText("");
txtjabatan.setText("");
txtgapok.setText("");
txttunjangan.setText("");
txttotalgaji.setText("");
//System.err.println("Exception: "+e.getMessage());
}
//Coding tombol batal

  txtnik.setText("");
txtnama.setText("");
txtjabatan.setText("");
txtgapok.setText("");
txttunjangan.setText("");
txttotalgaji.setText("");
//Coding tombol keluar
dispose();
//Coding tombol cari
String nik =txtnik.getText();
         try
        {
        String dbname="jdbc:odbc:utsb";
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection(dbname,"","");
        Statement statement = (Statement) con.createStatement();
        String sql="SELECT * FROM datakaryawan WHERE nik like '"+nik+"'";
        ResultSet rs = (ResultSet) statement.executeQuery(sql);
        if (rs.next())
        {
        txtnik.setText(rs.getString(1));
        txtnama.setText(rs.getString(2));
        txtjabatan.setText(rs.getString(3));
        txtgapok.setText(rs.getString(4));
        txttunjangan.setText(rs.getString(5));
         txttotalgaji.setText(rs.getString(6));


        JOptionPane.showMessageDialog(null, "Data ditemukan","Insert Data",JOptionPane.INFORMATION_MESSAGE);
        }
        else
        {
        JOptionPane.showMessageDialog(null, "Data tidak ditemukan ","Insert Data",JOptionPane.INFORMATION_MESSAGE);
        }
        statement.close();
        con.close();
        }
        catch (Exception e)
       {
       JOptionPane.showMessageDialog(null, "Eror:"+e,"Gagal",JOptionPane.WARNING_MESSAGE);
//System.err.println("Exception: "+e.getMessage());
       }

//Coding tombol total gaji

int gapok = Integer.parseInt(txtgapok.getText());
         int tunjangan = Integer.parseInt(txttunjangan.getText());
         totalgaji=gapok+tunjangan;
         //total=harga*jumlah;
        txttotalgaji.setText(String.valueOf(totalgaji));

//public class nya jgn lupa//letakkan setelah scrip ini //public class kariawan extends javax.swing.JFrame//

int gapok,tunjangan,totalgaji;




alhamdulilah yach sesuatu........

Tidak ada komentar:

Posting Komentar