kasir
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nmMaster;
import Class.classkoneksi;
import javax.swing.JOptionPane;
import Class.classkoneksi;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
/**
*
* @author RPL
*/
public class Kasir extends javax.swing.JFrame {
private String IdKasir;
private String namaKasir;
private String alamatKasir;
private String teleponKasir;
private String statusKasir;
private String userKasir;
private String passwordKasir;
private String aksesKasir;
private boolean update = false;
/**
* Creates new form Kasir
*/
public Kasir() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
}
public void bersih(){
tNama.setText("");
tAlamat.setText("");
tTelepon.setText("");
tStatus.setText("");
tUser.setText("");
tPassword.setText("");
cmbAkses.setSelectedItem("");
}
private void pushData(){
txtIdKasir.setText(this.getIdKasir());
tNama.setText(this.getNamaKasir());
tAlamat.setText(this.getAlamatKasir());
tTelepon.setText(this.getTeleponKasir());
tStatus.setText(this.getStatusKasir());
tUser.setText(this.getStatusKasir());
tPassword.setText(this.getPasswordKasir());
cmbAkses.setSelectedItem(this.getAksesKasir());
}
private void IdKasir() {
try{
String query = "select substring(id_Kasir,4,6) as id from tbl_kasir order by id_Kasir desc limit 0,1";
ResultSet rs = classkoneksi.executeQuery(query);
SimpleDateFormat df = new SimpleDateFormat("yyMM");
Date date = new Date();
String hasil = "KSR";
if(rs.first()) {
String str = "000";
String Id = rs.getString("id");
int no = Integer.valueOf(Id)+1;
String str_no = String.valueOf(no);
String idKasir = hasil +str.substring(0,3-str_no.length())+Integer.toString(no);
txtIdKasir.setText(idKasir);
} else {
String idKasir = hasil+"001";
txtIdKasir.setText(idKasir);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
System.out.println(e);
}
}
private void updateData() {
String idkasir = txtIdKasir.getText();
String nama = tNama.getText();
String alamat = tAlamat.getText();
String telepon = tTelepon.getText();
String status = tStatus.getText();
String user = tUser.getText();
String password = tPassword.getText();
String akses = (String) cmbAkses.getSelectedItem();
String SQL = "UPDATE tbl_kasir set id_kasir = '"+idkasir+"',nama = '"+nama+"',alamat = '"+alamat+"',telepon = '"+telepon+"',status = '"+status+"',username = '"+user+"',password = '"+password+"',akses = '"+akses+"' where nama='"+
this.getNamaKasir()+"'";
int i = classkoneksi.execute(SQL);
if(i>0){
JOptionPane.showMessageDialog(this, "data berhasil diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}else{
JOptionPane.showMessageDialog(this, "data gagal diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
private void simpan(){
if ("".equals(txtIdKasir.getText()) ||"".equals(tNama.getText()) || "".equals(tAlamat.getText()) || "".equals(tTelepon.getText()) || "".equals(tStatus.getText()) || "".equals(tUser.getText()) || "".equals(tPassword.getText()) || "".equals(cmbAkses.getSelectedItem())) {
JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "Eror", JOptionPane.WARNING_MESSAGE);
} else {
String SQL = "INSERT INTO tbl_kasir (id_kasir,nama,alamat,telepon,status,username,password,akses)"
+ "VALUES('"+txtIdKasir.getText()+"','"+tNama.getText()+"','"+tAlamat.getText()+"','"+tTelepon.getText()+"','"+tStatus.getText()+"','"+tUser.getText()+"',md5('"+tPassword.getText()+"'),"
+ "'"+cmbAkses.getSelectedItem()+"')";
int status = classkoneksi.execute(SQL);
if(status == 1) {
JOptionPane.showMessageDialog(this, "data berhasil ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
} else {
JOptionPane.showMessageDialog(this, "data gagal ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
txtIdKasir = new javax.swing.JTextField();
tNama = new javax.swing.JTextField();
tAlamat = new javax.swing.JTextField();
tTelepon = new javax.swing.JTextField();
tStatus = new javax.swing.JTextField();
tUser = new javax.swing.JTextField();
tPassword = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
btnSimpan = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
cmbAkses = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 102)), "Kasir"));
tNama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tNamaActionPerformed(evt);
}
});
tTelepon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tTeleponActionPerformed(evt);
}
});
jLabel1.setText("Id Kasir");
jLabel2.setText("Nama");
jLabel3.setText("Alamat");
jLabel4.setText("Telepon");
jLabel5.setText("Status");
jLabel6.setText("Username");
jLabel7.setText("Password");
jLabel8.setText("Akses");
btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900179_floppy_disk_save.png"))); // NOI18N
btnSimpan.setText("SIMPAN");
btnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSimpanActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900274_ic_cancel_48px.png"))); // NOI18N
jButton2.setText("BATAL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton3.setText("KELUAR");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
cmbAkses.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "User", " " }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addGap(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtIdKasir, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(33, 33, 33)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel5)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
.addComponent(tUser)
.addComponent(tPassword)
.addComponent(cmbAkses, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(27, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtIdKasir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel8)
.addComponent(cmbAkses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSimpan)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap(16, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void tTeleponActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if(this.isUpdate()==true){
pushData();
btnSimpan.setText("Ubah");
}else{
btnSimpan.setText("Simpan");
}
IdKasir();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void tNamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bersih();
}
private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(btnSimpan.getText().equals("Ubah")){
updateData();
}else{
simpan();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Kasir().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnSimpan;
private javax.swing.JComboBox cmbAkses;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField tAlamat;
private javax.swing.JTextField tNama;
private javax.swing.JTextField tPassword;
private javax.swing.JTextField tStatus;
private javax.swing.JTextField tTelepon;
private javax.swing.JTextField tUser;
private javax.swing.JTextField txtIdKasir;
// End of variables declaration
/**
* @return the IdKasir
*/
public String getIdKasir() {
return IdKasir;
}
/**
* @param IdKasir the IdKasir to set
*/
public void setIdKasir(String IdKasir) {
this.IdKasir = IdKasir;
}
/**
* @return the namaKasir
*/
public String getNamaKasir() {
return namaKasir;
}
/**
* @param namaKasir the namaKasir to set
*/
public void setNamaKasir(String namaKasir) {
this.namaKasir = namaKasir;
}
/**
* @return the alamatKasir
*/
public String getAlamatKasir() {
return alamatKasir;
}
/**
* @param alamatKasir the alamatKasir to set
*/
public void setAlamatKasir(String alamatKasir) {
this.alamatKasir = alamatKasir;
}
/**
* @return the teleponKasir
*/
public String getTeleponKasir() {
return teleponKasir;
}
/**
* @param teleponKasir the teleponKasir to set
*/
public void setTeleponKasir(String teleponKasir) {
this.teleponKasir = teleponKasir;
}
/**
* @return the statusKasir
*/
public String getStatusKasir() {
return statusKasir;
}
/**
* @param statusKasir the statusKasir to set
*/
public void setStatusKasir(String statusKasir) {
this.statusKasir = statusKasir;
}
/**
* @return the userKasir
*/
public String getUserKasir() {
return userKasir;
}
/**
* @param userKasir the userKasir to set
*/
public void setUserKasir(String userKasir) {
this.userKasir = userKasir;
}
/**
* @return the passwordKasir
*/
public String getPasswordKasir() {
return passwordKasir;
}
/**
* @param passwordKasir the passwordKasir to set
*/
public void setPasswordKasir(String passwordKasir) {
this.passwordKasir = passwordKasir;
}
/**
* @return the aksesKasir
*/
public String getAksesKasir() {
return aksesKasir;
}
/**
* @param aksesKasir the aksesKasir to set
*/
public void setAksesKasir(String aksesKasir) {
this.aksesKasir = aksesKasir;
}
/**
* @return the update
*/
public boolean isUpdate() {
return update;
}
/**
* @param update the update to set
*/
public void setUpdate(boolean update) {
this.update = update;
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package nmMaster;
import Class.classkoneksi;
import javax.swing.JOptionPane;
import Class.classkoneksi;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
/**
*
* @author RPL
*/
public class Kasir extends javax.swing.JFrame {
private String IdKasir;
private String namaKasir;
private String alamatKasir;
private String teleponKasir;
private String statusKasir;
private String userKasir;
private String passwordKasir;
private String aksesKasir;
private boolean update = false;
/**
* Creates new form Kasir
*/
public Kasir() {
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);
initComponents();
this.setLocationRelativeTo(this);
}
public void bersih(){
tNama.setText("");
tAlamat.setText("");
tTelepon.setText("");
tStatus.setText("");
tUser.setText("");
tPassword.setText("");
cmbAkses.setSelectedItem("");
}
private void pushData(){
txtIdKasir.setText(this.getIdKasir());
tNama.setText(this.getNamaKasir());
tAlamat.setText(this.getAlamatKasir());
tTelepon.setText(this.getTeleponKasir());
tStatus.setText(this.getStatusKasir());
tUser.setText(this.getStatusKasir());
tPassword.setText(this.getPasswordKasir());
cmbAkses.setSelectedItem(this.getAksesKasir());
}
private void IdKasir() {
try{
String query = "select substring(id_Kasir,4,6) as id from tbl_kasir order by id_Kasir desc limit 0,1";
ResultSet rs = classkoneksi.executeQuery(query);
SimpleDateFormat df = new SimpleDateFormat("yyMM");
Date date = new Date();
String hasil = "KSR";
if(rs.first()) {
String str = "000";
String Id = rs.getString("id");
int no = Integer.valueOf(Id)+1;
String str_no = String.valueOf(no);
String idKasir = hasil +str.substring(0,3-str_no.length())+Integer.toString(no);
txtIdKasir.setText(idKasir);
} else {
String idKasir = hasil+"001";
txtIdKasir.setText(idKasir);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, e);
System.out.println(e);
}
}
private void updateData() {
String idkasir = txtIdKasir.getText();
String nama = tNama.getText();
String alamat = tAlamat.getText();
String telepon = tTelepon.getText();
String status = tStatus.getText();
String user = tUser.getText();
String password = tPassword.getText();
String akses = (String) cmbAkses.getSelectedItem();
String SQL = "UPDATE tbl_kasir set id_kasir = '"+idkasir+"',nama = '"+nama+"',alamat = '"+alamat+"',telepon = '"+telepon+"',status = '"+status+"',username = '"+user+"',password = '"+password+"',akses = '"+akses+"' where nama='"+
this.getNamaKasir()+"'";
int i = classkoneksi.execute(SQL);
if(i>0){
JOptionPane.showMessageDialog(this, "data berhasil diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}else{
JOptionPane.showMessageDialog(this, "data gagal diubah", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
private void simpan(){
if ("".equals(txtIdKasir.getText()) ||"".equals(tNama.getText()) || "".equals(tAlamat.getText()) || "".equals(tTelepon.getText()) || "".equals(tStatus.getText()) || "".equals(tUser.getText()) || "".equals(tPassword.getText()) || "".equals(cmbAkses.getSelectedItem())) {
JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "Eror", JOptionPane.WARNING_MESSAGE);
} else {
String SQL = "INSERT INTO tbl_kasir (id_kasir,nama,alamat,telepon,status,username,password,akses)"
+ "VALUES('"+txtIdKasir.getText()+"','"+tNama.getText()+"','"+tAlamat.getText()+"','"+tTelepon.getText()+"','"+tStatus.getText()+"','"+tUser.getText()+"',md5('"+tPassword.getText()+"'),"
+ "'"+cmbAkses.getSelectedItem()+"')";
int status = classkoneksi.execute(SQL);
if(status == 1) {
JOptionPane.showMessageDialog(this, "data berhasil ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
} else {
JOptionPane.showMessageDialog(this, "data gagal ditambahkan", "sukses", JOptionPane.INFORMATION_MESSAGE );
}
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
txtIdKasir = new javax.swing.JTextField();
tNama = new javax.swing.JTextField();
tAlamat = new javax.swing.JTextField();
tTelepon = new javax.swing.JTextField();
tStatus = new javax.swing.JTextField();
tUser = new javax.swing.JTextField();
tPassword = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
btnSimpan = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
cmbAkses = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 102)), "Kasir"));
tNama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tNamaActionPerformed(evt);
}
});
tTelepon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tTeleponActionPerformed(evt);
}
});
jLabel1.setText("Id Kasir");
jLabel2.setText("Nama");
jLabel3.setText("Alamat");
jLabel4.setText("Telepon");
jLabel5.setText("Status");
jLabel6.setText("Username");
jLabel7.setText("Password");
jLabel8.setText("Akses");
btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900179_floppy_disk_save.png"))); // NOI18N
btnSimpan.setText("SIMPAN");
btnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSimpanActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900274_ic_cancel_48px.png"))); // NOI18N
jButton2.setText("BATAL");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gambar/1484900317_common-logout-signout-exit-glyph.png"))); // NOI18N
jButton3.setText("KELUAR");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
cmbAkses.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Admin", "User", " " }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addGap(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtIdKasir, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(30, 30, 30)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(33, 33, 33)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel6)
.addComponent(jLabel5)
.addComponent(jLabel8))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tStatus, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
.addComponent(tUser)
.addComponent(tPassword)
.addComponent(cmbAkses, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addContainerGap(27, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtIdKasir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)
.addComponent(jLabel8)
.addComponent(cmbAkses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSimpan)
.addComponent(jButton2)
.addComponent(jButton3))
.addContainerGap(16, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void tTeleponActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if(this.isUpdate()==true){
pushData();
btnSimpan.setText("Ubah");
}else{
btnSimpan.setText("Simpan");
}
IdKasir();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.dispose();
}
private void tNamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
bersih();
}
private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(btnSimpan.getText().equals("Ubah")){
updateData();
}else{
simpan();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Kasir.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Kasir().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnSimpan;
private javax.swing.JComboBox cmbAkses;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField tAlamat;
private javax.swing.JTextField tNama;
private javax.swing.JTextField tPassword;
private javax.swing.JTextField tStatus;
private javax.swing.JTextField tTelepon;
private javax.swing.JTextField tUser;
private javax.swing.JTextField txtIdKasir;
// End of variables declaration
/**
* @return the IdKasir
*/
public String getIdKasir() {
return IdKasir;
}
/**
* @param IdKasir the IdKasir to set
*/
public void setIdKasir(String IdKasir) {
this.IdKasir = IdKasir;
}
/**
* @return the namaKasir
*/
public String getNamaKasir() {
return namaKasir;
}
/**
* @param namaKasir the namaKasir to set
*/
public void setNamaKasir(String namaKasir) {
this.namaKasir = namaKasir;
}
/**
* @return the alamatKasir
*/
public String getAlamatKasir() {
return alamatKasir;
}
/**
* @param alamatKasir the alamatKasir to set
*/
public void setAlamatKasir(String alamatKasir) {
this.alamatKasir = alamatKasir;
}
/**
* @return the teleponKasir
*/
public String getTeleponKasir() {
return teleponKasir;
}
/**
* @param teleponKasir the teleponKasir to set
*/
public void setTeleponKasir(String teleponKasir) {
this.teleponKasir = teleponKasir;
}
/**
* @return the statusKasir
*/
public String getStatusKasir() {
return statusKasir;
}
/**
* @param statusKasir the statusKasir to set
*/
public void setStatusKasir(String statusKasir) {
this.statusKasir = statusKasir;
}
/**
* @return the userKasir
*/
public String getUserKasir() {
return userKasir;
}
/**
* @param userKasir the userKasir to set
*/
public void setUserKasir(String userKasir) {
this.userKasir = userKasir;
}
/**
* @return the passwordKasir
*/
public String getPasswordKasir() {
return passwordKasir;
}
/**
* @param passwordKasir the passwordKasir to set
*/
public void setPasswordKasir(String passwordKasir) {
this.passwordKasir = passwordKasir;
}
/**
* @return the aksesKasir
*/
public String getAksesKasir() {
return aksesKasir;
}
/**
* @param aksesKasir the aksesKasir to set
*/
public void setAksesKasir(String aksesKasir) {
this.aksesKasir = aksesKasir;
}
/**
* @return the update
*/
public boolean isUpdate() {
return update;
}
/**
* @param update the update to set
*/
public void setUpdate(boolean update) {
this.update = update;
}
}
Comments
Post a Comment