Quote:
/*
* HotelGUI.java
*
* Created on 07 January 2008, 10:43
*/
package System;
import DB.DBRoutines;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author andrpors
*/
public class HotelGUI extends javax.swing.JFrame {
/** Creates new form HotelGUI */
public HotelGUI() {
initComponents();
choClientType.add("");
choClientType.add("Business");
choClientType.add("Couple");
choClientType.add("Family");
choClientType.add("VIP");
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
HotelPanes = new javax.swing.JTabbedPane();
ClientTab = new javax.swing.JPanel();
txtClientId = new javax.swing.JTextField();
lblClientId = new javax.swing.JLabel();
txtClientName = new javax.swing.JTextField();
lblClientName = new javax.swing.JLabel();
txtClientSurname = new javax.swing.JTextField();
lblClientSurname = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtClientAddress = new javax.swing.JEditorPane();
lblClientAddress = new javax.swing.JLabel();
txtClientTel = new javax.swing.JTextField();
lblClientTelephone = new javax.swing.JLabel();
lblClientMobile = new javax.swing.JLabel();
txtClientMobile = new javax.swing.JTextField();
choClientType = new java.awt.Choice();
lblClientType = new javax.swing.JLabel();
btnClientAdd = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
setResizable(false);
lblClientId.setText("Client ID");
lblClientName.setText("Name");
lblClientSurname.setText("Surname");
jScrollPane1.setViewportView(txtClientAddress);
lblClientAddress.setText("Address");
lblClientTelephone.setText("Telephone");
lblClientMobile.setText("Mobile");
lblClientType.setText("Client Type");
btnClientAdd.setText("Add");
btnClientAdd.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnClientAddMouseClicked(evt);
}
});
org.jdesktop.layout.GroupLayout ClientTabLayout = new org.jdesktop.layout.GroupLayout(ClientTab);
ClientTab.setLayout(ClientTabLayout);
ClientTabLayout.setHorizontalGroup(
ClientTabLayout.createParallelGroup(org.jdesktop.l ayout.GroupLayout.LEADING)
.add(ClientTabLayout.createSequentialGroup()
.add(38, 38, 38)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
.add(ClientTabLayout.createSequentialGroup()
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.TRAILING)
.add(lblClientSurname)
.add(lblClientName)
.add(lblClientTelephone)
.add(lblClientAddress)
.add(lblClientMobile)
.add(lblClientType))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, txtClientMobile)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
.add(txtClientName)
.add(txtClientSurname, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
.add(txtClientTel)
.add(org.jdesktop.layout.GroupLayout.LEADING, choClientType, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(18, 18, 18)
.add(btnClientAdd))
.add(ClientTabLayout.createSequentialGroup()
.add(lblClientId)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(txtClientId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)))
.addContainerGap(15, Short.MAX_VALUE))
);
ClientTabLayout.setVerticalGroup(
ClientTabLayout.createParallelGroup(org.jdesktop.l ayout.GroupLayout.LEADING)
.add(ClientTabLayout.createSequentialGroup()
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
.add(ClientTabLayout.createSequentialGroup()
.addContainerGap()
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
.add(lblClientId)
.add(txtClientId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED, 82, Short.MAX_VALUE)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, ClientTabLayout.createSequentialGroup()
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
.add(lblClientTelephone)
.add(txtClientTel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
.add(txtClientMobile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(lblClientMobile)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, ClientTabLayout.createSequentialGroup()
.add(lblClientAddress)
.add(118, 118, 118))))
.add(ClientTabLayout.createSequentialGroup()
.add(56, 56, 56)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
.add(lblClientName)
.add(txtClientName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.BASELINE)
.add(lblClientSurname)
.add(txtClientSurname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(btnClientAdd))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.R ELATED)
.add(ClientTabLayout.createParallelGroup(org.jdesk top.layout.GroupLayout.LEADING)
.add(lblClientType)
.add(choClientType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(21, 21, 21))
);
HotelPanes.addTab("tab1", ClientTab);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
.add(HotelPanes, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.Gro upLayout.LEADING)
.add(HotelPanes, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void btnClientAddMouseClicked(java.awt.event.MouseEvent evt) {
DBRoutines db = new DBRoutines("ftp.mcast.edu.mt", "gerards", "gerards", "***");
db.connect();
String clientInsert = "INSERT INTO apfclients (ClientID,Name,Surname,Address,Telephone,Mobile,Ty pe,Treatment) VALUE (?,?,?,?,?,?,?,?)";
PreparedStatement sqlStatement = null;
try {
sqlStatement = db.dbConnection.prepareStatement(clientInsert);
sqlStatement.setString(1, txtClientId.getText());
sqlStatement.setString(2, txtClientName.getText());
sqlStatement.setString(3, txtClientSurname.getText());
sqlStatement.setString(4, txtClientAddress.getText());
sqlStatement.setString(5, txtClientTel.getText());
sqlStatement.setString(6, txtClientMobile.getText());
sqlStatement.setString(7, choClientType.getSelectedItem());
if (choClientType.getSelectedItem().equals("VIP")) {
sqlStatement.setString(8,"Wifi, Sweets, Champagne");
} else if (choClientType.getSelectedItem().equals("Family")) {
sqlStatement.setString(8,"Sweets");
} else if (choClientType.getSelectedItem().equals("Couple")) {
sqlStatement.setString(8,"Champagne");
} else if (choClientType.getSelectedItem().equals("Business" )) {
sqlStatement.setString(8,"Wifi");
} else {
sqlStatement.setString(8,"null");
}
sqlStatement.executeUpdate();
JOptionPane.showMessageDialog(null, "Client has been successfully added!");
} catch (SQLException ex) {
ex.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new HotelGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel ClientTab;
private javax.swing.JTabbedPane HotelPanes;
private javax.swing.JButton btnClientAdd;
private java.awt.Choice choClientType;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblClientAddress;
private javax.swing.JLabel lblClientId;
private javax.swing.JLabel lblClientMobile;
private javax.swing.JLabel lblClientName;
private javax.swing.JLabel lblClientSurname;
private javax.swing.JLabel lblClientTelephone;
private javax.swing.JLabel lblClientType;
private javax.swing.JEditorPane txtClientAddress;
private javax.swing.JTextField txtClientId;
private javax.swing.JTextField txtClientMobile;
private javax.swing.JTextField txtClientName;
private javax.swing.JTextField txtClientSurname;
private javax.swing.JTextField txtClientTel;
// End of variables declaration
}