Java tutorial
import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfStamper; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Desktop; import java.awt.HeadlessException; import java.awt.Toolkit; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; /* * 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. */ /** * * @author Mark Herbert Cabuang */ public class Registration_Transient extends javax.swing.JFrame { private DefaultTableModel modelTop; private String id = ""; private String tName = ""; private String[] guestNames; private String lastPage = ""; private String separator = ":"; private String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); private double perHead = 0.0; private double bedCharge = 0.0; private double securityCharge = 0.0; private int iterate = 0; private final MessageDialog md = new MessageDialog(); private final DecimalFormat df = new DecimalFormat("0.00"); private Connection connection; /** * Creates new form TransientTemp * */ public Registration_Transient() { this.setIconImage( Toolkit.getDefaultToolkit().getImage(getClass().getResource("icons/Backup and Recovery.png"))); initComponents(); try { Calendar cal = Calendar.getInstance(); cal.setTime(dateArrivalChooserCombo.getDateFormat().parse(dateArrivalChooserCombo.getText())); cal.add(Calendar.DATE, 1); dateDepartureChooserCombo.setSelectedDate(cal); Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection("jdbc:mysql://localhost/181nprdb", "root", ""); } catch (ClassNotFoundException | ParseException | SQLException ex) { // Logger.getLogger(Registration_Tenant.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } } /** * 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">//GEN-BEGIN:initComponents private void initComponents() { areaPanel = new javax.swing.JPanel(); amountPanel = new javax.swing.JPanel(); jLabel18 = new javax.swing.JLabel(); totalAmountTextField = new javax.swing.JTextField(); jLabel19 = new javax.swing.JLabel(); balanceTextField = new javax.swing.JTextField(); jLabel20 = new javax.swing.JLabel(); amountPaidTextField = new javax.swing.JTextField(); jSeparator2 = new javax.swing.JSeparator(); infoPanel = new javax.swing.JPanel(); lastNameTextField = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); firstNameTextField = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); mobileNoTextField = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); addressTextField = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); emailTextField = new javax.swing.JTextField(); residentNameCheckBox = new javax.swing.JCheckBox(); relationComboBox = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); residentComboBox = new javax.swing.JComboBox(); parentCheckBox = new javax.swing.JCheckBox(); stayPanel = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); daysTextField = new javax.swing.JTextField(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); PersonTextField = new javax.swing.JTextField(); jLabel17 = new javax.swing.JLabel(); bedChargeTextField = new javax.swing.JTextField(); jLabel23 = new javax.swing.JLabel(); jLabel24 = new javax.swing.JLabel(); roomInventoryButton = new javax.swing.JButton(); jSeparator1 = new javax.swing.JSeparator(); guestSpinner = new javax.swing.JSpinner(); bedSpinner = new javax.swing.JSpinner(); dateArrivalChooserCombo = new datechooser.beans.DateChooserCombo(); dateDepartureChooserCombo = new datechooser.beans.DateChooserCombo(); jScrollPane2 = new javax.swing.JScrollPane(); guestTable = new javax.swing.JTable(); reservedRoomTextField = new javax.swing.JSpinner(); roomReservedTextField = new javax.swing.JTextField(); jLabel21 = new javax.swing.JLabel(); saveButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); clearButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setUndecorated(true); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); areaPanel.setBackground(new java.awt.Color(255, 255, 255)); areaPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); areaPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); amountPanel.setBackground(new java.awt.Color(255, 255, 255)); amountPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total Amount", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 18))); // NOI18N amountPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel18.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel18.setText("Total Amount"); amountPanel.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 70, -1, -1)); totalAmountTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); totalAmountTextField.setText("0.00"); totalAmountTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { totalAmountTextFieldCaretUpdate(evt); } }); totalAmountTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { totalAmountTextFieldFocusGained(evt); } public void focusLost(java.awt.event.FocusEvent evt) { totalAmountTextFieldFocusLost(evt); } }); amountPanel.add(totalAmountTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 70, 110, -1)); jLabel19.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel19.setText("Amount Paid"); amountPanel.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 100, -1, -1)); balanceTextField.setEditable(false); balanceTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); balanceTextField.setText("0.00"); amountPanel.add(balanceTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 140, 110, -1)); jLabel20.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel20.setText("Balance"); amountPanel.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 140, -1, -1)); amountPaidTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); amountPaidTextField.setText("0.00"); amountPaidTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { amountPaidTextFieldFocusGained(evt); } public void focusLost(java.awt.event.FocusEvent evt) { amountPaidTextFieldFocusLost(evt); } }); amountPanel.add(amountPaidTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 100, 110, -1)); amountPanel.add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 130, 210, 10)); areaPanel.add(amountPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 350, 400, 200)); infoPanel.setBackground(new java.awt.Color(255, 255, 255)); infoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Transient's Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 18))); // NOI18N infoPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); lastNameTextField.setBackground(new java.awt.Color(255, 255, 204)); lastNameTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { lastNameTextFieldCaretUpdate(evt); } }); infoPanel.add(lastNameTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, 286, -1)); jLabel1.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel1.setText("Last Name"); infoPanel.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, -1, -1)); jLabel3.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel3.setText("First Name"); infoPanel.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, -1, -1)); firstNameTextField.setBackground(new java.awt.Color(255, 255, 204)); firstNameTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { firstNameTextFieldCaretUpdate(evt); } }); infoPanel.add(firstNameTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 60, 286, -1)); jLabel4.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel4.setText("Mobile Number"); infoPanel.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 90, -1, -1)); mobileNoTextField.setBackground(new java.awt.Color(255, 255, 204)); mobileNoTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { mobileNoTextFieldCaretUpdate(evt); } }); infoPanel.add(mobileNoTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 90, 286, -1)); jLabel5.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel5.setText("Home Address"); infoPanel.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 120, -1, 20)); addressTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { addressTextFieldCaretUpdate(evt); } }); addressTextField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { addressTextFieldKeyTyped(evt); } }); infoPanel.add(addressTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 120, 286, -1)); jLabel6.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel6.setText("E-mail "); infoPanel.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 150, 70, 20)); emailTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { emailTextFieldCaretUpdate(evt); } }); infoPanel.add(emailTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 150, 286, -1)); residentNameCheckBox.setBackground(new java.awt.Color(255, 255, 255)); residentNameCheckBox.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N residentNameCheckBox.setText("Resident's Name"); residentNameCheckBox.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); residentNameCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { residentNameCheckBoxActionPerformed(evt); } }); infoPanel.add(residentNameCheckBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 200, 125, -1)); relationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Other", "Mother", "Father", "Brother", "Sister", "Grandmother", "Grandfather", "Aunt", "Uncle" })); relationComboBox.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); relationComboBox.setEnabled(false); infoPanel.add(relationComboBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 240, 237, -1)); jLabel7.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel7.setText("Relation to Resident"); jLabel7.setEnabled(false); infoPanel.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 240, -1, -1)); residentComboBox.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); residentComboBox.setEnabled(false); residentComboBox.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { residentComboBoxItemStateChanged(evt); } }); infoPanel.add(residentComboBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 200, 241, -1)); parentCheckBox.setBackground(new java.awt.Color(255, 255, 255)); parentCheckBox.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N parentCheckBox.setText("Same room with resident"); parentCheckBox.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); parentCheckBox.setEnabled(false); parentCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { parentCheckBoxActionPerformed(evt); } }); infoPanel.add(parentCheckBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 270, 150, -1)); areaPanel.add(infoPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 400, 320)); stayPanel.setBackground(new java.awt.Color(255, 255, 255)); stayPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Stay Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 18))); // NOI18N stayPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel8.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel8.setText("Date of Arrival"); stayPanel.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, 120, 20)); jLabel9.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel9.setText("Date of Checkout"); stayPanel.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, 120, 20)); jLabel10.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel10.setText("Total Number of Days"); stayPanel.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(19, 179, -1, -1)); daysTextField.setEditable(false); daysTextField.setBackground(new java.awt.Color(255, 255, 255)); daysTextField.setText("1"); daysTextField.setEnabled(false); daysTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { daysTextFieldCaretUpdate(evt); } }); stayPanel.add(daysTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(151, 176, 64, -1)); jLabel11.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel11.setText("Number of Reserved Rooms"); stayPanel.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, 130, 20)); jLabel12.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel12.setText("Reserved Room Number/s"); stayPanel.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 70, -1, -1)); jLabel13.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel13.setText("No. of Additional Guest/s"); stayPanel.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 210, -1, -1)); jLabel14.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel14.setText("Names of Additional Guest/s : "); stayPanel.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, -1, -1)); jLabel15.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel15.setText("No. of Extra Bed/s"); stayPanel.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 450, -1, -1)); jLabel16.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel16.setText("Charge per Person"); stayPanel.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 410, -1, -1)); PersonTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); PersonTextField.setText("0.00"); PersonTextField.setEnabled(false); PersonTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { PersonTextFieldCaretUpdate(evt); } }); PersonTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { PersonTextFieldFocusGained(evt); } public void focusLost(java.awt.event.FocusEvent evt) { PersonTextFieldFocusLost(evt); } }); stayPanel.add(PersonTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 410, 80, -1)); jLabel17.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N jLabel17.setText("Bed Charge"); stayPanel.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 480, -1, -1)); bedChargeTextField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); bedChargeTextField.setText("0.00"); bedChargeTextField.setEnabled(false); bedChargeTextField.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { bedChargeTextFieldCaretUpdate(evt); } }); bedChargeTextField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { bedChargeTextFieldFocusGained(evt); } public void focusLost(java.awt.event.FocusEvent evt) { bedChargeTextFieldFocusLost(evt); } }); stayPanel.add(bedChargeTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 480, 80, -1)); jLabel23.setFont(new java.awt.Font("Rondalo", 0, 11)); // NOI18N jLabel23.setText("day/s"); stayPanel.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(225, 180, -1, -1)); jLabel24.setFont(new java.awt.Font("Rondalo", 0, 11)); // NOI18N jLabel24.setText("guest/s"); stayPanel.add(jLabel24, new org.netbeans.lib.awtextra.AbsoluteConstraints(225, 209, -1, -1)); roomInventoryButton.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N roomInventoryButton.setText("Room Inventory"); roomInventoryButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); roomInventoryButton.setEnabled(false); roomInventoryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { roomInventoryButtonActionPerformed(evt); } }); stayPanel.add(roomInventoryButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(439, 175, -1, -1)); stayPanel.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 440, 201, 10)); guestSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 100, 1)); guestSpinner.setEditor(new javax.swing.JSpinner.NumberEditor(guestSpinner, "")); guestSpinner.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { guestSpinnerStateChanged(evt); } }); stayPanel.add(guestSpinner, new org.netbeans.lib.awtextra.AbsoluteConstraints(151, 209, 64, -1)); bedSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 50, 1)); bedSpinner.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { bedSpinnerStateChanged(evt); } }); stayPanel.add(bedSpinner, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 450, 80, -1)); dateArrivalChooserCombo.setCurrentView(new datechooser.view.appearance.AppearancesList("Light", new datechooser.view.appearance.ViewAppearance("custom", new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), true, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(255, 0, 0), false, false, new datechooser.view.appearance.swing.ButtonPainter()), (datechooser.view.BackRenderer) null, false, true))); dateArrivalChooserCombo.setNothingAllowed(false); dateArrivalChooserCombo.setFieldFont(new java.awt.Font("Rondalo", java.awt.Font.PLAIN, 11)); dateArrivalChooserCombo.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE); dateArrivalChooserCombo.addCommitListener(new datechooser.events.CommitListener() { public void onCommit(datechooser.events.CommitEvent evt) { dateArrivalChooserComboOnCommit(evt); } }); stayPanel.add(dateArrivalChooserCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 100, 248, -1)); dateDepartureChooserCombo.setCurrentView(new datechooser.view.appearance.AppearancesList("Light", new datechooser.view.appearance.ViewAppearance("custom", new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), true, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.ButtonPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 255), false, true, new datechooser.view.appearance.swing.LabelPainter()), new datechooser.view.appearance.swing.SwingCellAppearance( new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0), new java.awt.Color(255, 0, 0), false, false, new datechooser.view.appearance.swing.ButtonPainter()), (datechooser.view.BackRenderer) null, false, true))); dateDepartureChooserCombo.setFieldFont(new java.awt.Font("Rondalo", java.awt.Font.PLAIN, 11)); dateDepartureChooserCombo.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE); dateDepartureChooserCombo.addCommitListener(new datechooser.events.CommitListener() { public void onCommit(datechooser.events.CommitEvent evt) { dateDepartureChooserComboOnCommit(evt); } }); stayPanel.add(dateDepartureChooserCombo, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 130, 248, -1)); guestTable.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { "Guest Name" })); jScrollPane2.setViewportView(guestTable); stayPanel.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 260, 530, 140)); reservedRoomTextField.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N reservedRoomTextField.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1))); stayPanel.add(reservedRoomTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 30, 70, -1)); roomReservedTextField.setBackground(new java.awt.Color(255, 255, 204)); roomReservedTextField.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N stayPanel.add(roomReservedTextField, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 70, 230, -1)); jLabel21.setFont(new java.awt.Font("Rondalo", 0, 14)); // NOI18N jLabel21.setForeground(new java.awt.Color(255, 0, 0)); jLabel21.setText("*Separated by Comma"); stayPanel.add(jLabel21, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 70, -1, -1)); areaPanel.add(stayPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 30, 560, 520)); saveButton.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N saveButton.setText("Save"); saveButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); saveButton.setEnabled(false); saveButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveButtonActionPerformed(evt); } }); areaPanel.add(saveButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(850, 560, 70, -1)); cancelButton.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N cancelButton.setText("Cancel"); cancelButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); areaPanel.add(cancelButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 560, 70, -1)); clearButton.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N clearButton.setText("Clear"); clearButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); clearButton.setEnabled(false); clearButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearButtonActionPerformed(evt); } }); areaPanel.add(clearButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(770, 560, 70, -1)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(areaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 1024, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( areaPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 615, javax.swing.GroupLayout.PREFERRED_SIZE)); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private boolean insertIntoDatabase() { boolean tester = true; try { if (isSaved(firstNameTextField.getText().trim(), lastNameTextField.getText().trim())) { ArrayList<String> transientInfo = new ArrayList<>(); tName = lastNameTextField.getText() + ", " + firstNameTextField.getText(); transientInfo.add(lastNameTextField.getText()); transientInfo.add(firstNameTextField.getText()); transientInfo.add(mobileNoTextField.getText()); transientInfo.add(addressTextField.getText()); transientInfo.add(emailTextField.getText()); transientInfo.add(timeStamp); transientInfo.add(relationComboBox.getSelectedItem().toString()); transientInfo.add(totalAmountTextField.getText()); transientInfo.add(amountPaidTextField.getText()); String bal = balanceTextField.getText(); if (balanceTextField.getText().contains("(") && balanceTextField.getText().contains(")")) { bal = "-" + balanceTextField.getText().substring(1, balanceTextField.getText().length() - 1) .trim(); } transientInfo.add(bal); transientInfo.add(reservedRoomTextField.getValue().toString()); transientInfo.add(roomReservedTextField.getText()); DateFormat originalFormat1 = dateArrivalChooserCombo.getDateFormat(); DateFormat targetFormat1 = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date utilDate1 = originalFormat1.parse(dateArrivalChooserCombo.getText()); String formattedDateArrival = targetFormat1.format(utilDate1); transientInfo.add(formattedDateArrival); DateFormat originalFormat2 = dateDepartureChooserCombo.getDateFormat(); DateFormat targetFormat2 = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date utilDate2 = originalFormat2.parse(dateDepartureChooserCombo.getText()); String formattedDateDeparture = targetFormat2.format(utilDate2); transientInfo.add(formattedDateDeparture); transientInfo.add(daysTextField.getText()); transientInfo.add(guestSpinner.getValue().toString()); String names = ""; modelTop = (DefaultTableModel) guestTable.getModel(); if (modelTop.getRowCount() != 0) { names = modelTop.getValueAt(0, 0).toString().trim() + separator; for (int count = 1; count < modelTop.getRowCount() - 1; count++) { names = names + modelTop.getValueAt(count, 0).toString().trim() + separator; } names = names + modelTop.getValueAt(modelTop.getRowCount() - 1, 0).toString().trim(); } transientInfo.add(names); transientInfo.add(bedSpinner.getValue().toString()); transientInfo.add(bedChargeTextField.getText()); transientInfo.add(PersonTextField.getText()); if (residentComboBox.isEnabled()) { transientInfo.add(getResidentId(residentComboBox.getSelectedItem().toString())); } else { transientInfo.add(""); } if (insertTransient(transientInfo)) { String[] rooms = roomReservedTextField.getText().split(","); for (String room : rooms) { if (updateRoomStatusFromTransient(room, "fully occupied")) { md.unsuccessful(this, "Room(s) update failed!"); tester = false; break; } for (int c = 0; c < getFurnitureRowCount(room); c++) { if (updateFurnitureFromTransient(getTransientId(tName))) { md.unsuccessful(this, "Furniture(s) update failed!"); tester = false; break; } } } clearAll(); } else { md.unsuccessful(this); tester = false; } } } catch (NumberFormatException | ParseException ex) { md.error(this, ex.getMessage()); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } return tester; } private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed // TODO add your handling code here: if (checker()) { if (md.confirmationSave(this) == md.YES) { saveToPdf(); if (insertIntoDatabase()) { md.successful(this); saveButton.setEnabled(false); } else { md.unsuccessful(this); } } } }//GEN-LAST:event_saveButtonActionPerformed private boolean checker() { boolean tester = false; // if (checkGuestTable() & mobileNumberChecker() & checkInDateChecker() & checkArrivalDate() & (emailAddressChecker() | totalAmountNumberChecker() & AmountPaidNumberChecker() & chargePerGuestChecker() & bedChecker() & guestsChecker())) { tester = true; } return tester; } private boolean guestsChecker() { for (int i = 0; i < guestTable.getRowCount(); i++) { if (guestTable.getValueAt(i, 0) == null || guestTable.getValueAt(i, 0).toString().isEmpty()) { md.error(this, "Names of the Guest(s) must be specified."); return false; } } return true; } private boolean checkInDateChecker() { boolean tester = true; Date arrivalDate = new Date(dateArrivalChooserCombo.getText()); Date departureDate = new Date(dateDepartureChooserCombo.getText()); if (arrivalDate.after(departureDate) || departureDate.before(arrivalDate)) { md.error(this, "Invalid check in date."); tester = false; } return tester; } private boolean checkArrivalDate() { boolean tester = true; Date arrivalDate = new Date(dateArrivalChooserCombo.getText()); Date dateToday = null; try { dateToday = new SimpleDateFormat("yyyy-MM-dd").parse(timeStamp); } catch (ParseException ex) { md.error(this, ex.getMessage()); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } if (arrivalDate.before(dateToday)) { md.error(this, "Date of arrival must be greater than date today."); tester = false; } return tester; } private boolean checkGuestTable() { boolean tester = true; for (int i = 0; i < guestTable.getRowCount(); i++) { if (guestTable.getValueAt(i, 0) == null) { md.error(this, "Names of the Guest(s) must be specified."); tester = false; break; } } return tester; } private boolean chargePerGuestChecker() { boolean tester = true; try { Double.parseDouble(PersonTextField.getText().trim()); } catch (NumberFormatException ex) { tester = false; md.error(this, "You've entered an alphanumeric, please try again."); totalAmountComputation(); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } // String str = PersonTextField.getText().trim(); // char[] chars = str.toCharArray(); // boolean tester = true; // //if it is null // if (!str.equals("")) { // //checks if the number is alphanumeric // for (int i = 0; i < chars.length; i++) { // try { // Integer.parseInt(String.valueOf(chars[i])); // } catch (NumberFormatException nfe) { // tester = false; // JOptionPane.showMessageDialog(null, "You've entered an alphanumeric, please try again.", "Error", JOptionPane.ERROR_MESSAGE); // PersonTextField.setText(""); // } // } // } return tester; } private boolean bedChecker() { boolean tester = true; try { Double.parseDouble(bedChargeTextField.getText().trim()); } catch (NumberFormatException ex) { tester = false; md.error(this, "You've entered an alphanumeric, please try again."); totalAmountComputation(); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } // String str = bedChargeTextField.getText().trim(); // char[] chars = str.toCharArray(); // boolean tester = true; // //if it is null // if (!str.equals("")) { // //checks if the number is alphanumeric // for (int i = 0; i < chars.length; i++) { // try { // Integer.parseInt(String.valueOf(chars[i])); // } catch (NumberFormatException nfe) { // tester = false; // JOptionPane.showMessageDialog(null, "You've entered an alphanumeric, please try again.", "Error", JOptionPane.ERROR_MESSAGE); // bedChargeTextField.setText(""); // } // } // } return tester; } private boolean mobileNumberChecker() { String str = mobileNoTextField.getText().trim(); char[] chars = str.toCharArray(); boolean tester = false; //if it is null if (!str.equals("")) { //checks if the number is alphanumeric for (int i = 0; i < chars.length; i++) { try { Integer.parseInt(String.valueOf(chars[i])); } catch (NumberFormatException nfe) { md.error(this, "You've entered an alphanumeric, please try again."); mobileNoTextField.setText(""); break; } } //checks if the number is 11 digits. if (str.length() == 11) { tester = true; } else { md.error(this, "The number you've enter is more than or less than 11 digits or\n an abroad number.."); mobileNoTextField.setText(""); } } return tester; } private boolean totalAmountNumberChecker() { boolean tester = true; try { Double.parseDouble(totalAmountTextField.getText().trim()); } catch (NumberFormatException ex) { tester = false; md.error(this, "You've entered an alphanumeric, please try again."); totalAmountComputation(); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } // String str = totalAmountTextField.getText().trim(); // char[] chars = str.toCharArray(); // boolean tester = true; // //if it is null // if (!str.equals("")) { // //checks if the number is alphanumeric // for (int i = 0; i < chars.length; i++) { // try { // Integer.parseInt(String.valueOf(chars[i])); // } catch (NumberFormatException nfe) { // tester = false; // JOptionPane.showMessageDialog(null, "You've entered an alphanumeric, please try again.", "Error", JOptionPane.ERROR_MESSAGE); // totalAmountTextField.setText(""); // } // } // } return tester; } private boolean AmountPaidNumberChecker() { boolean tester = true; try { Double.parseDouble(amountPaidTextField.getText().trim()); } catch (NumberFormatException ex) { tester = false; md.error(this, "You've entered an alphanumeric, please try again."); amountPaidTextField.setText("0"); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } // String str = amountPaidTextField.getText().trim(); // char[] chars = str.toCharArray(); // boolean tester = true; // //if it is null // if (!str.equals("")) { // //checks if the number is alphanumeric // for (int i = 0; i < chars.length; i++) { // try { // Integer.parseInt(String.valueOf(chars[i])); // } catch (NumberFormatException nfe) { // tester = false; // JOptionPane.showMessageDialog(null, "You've entered an alphanumeric, please try again.", "Error", JOptionPane.ERROR_MESSAGE); // amountPaidTextField.setText(""); // } // } // } return tester; } private boolean emailAddressChecker() { char atSymbol = '@'; String dotCom = ".com"; String emailAddress = emailTextField.getText().trim(); boolean tester = true; //find the @ symbol int atpos = emailAddress.indexOf(atSymbol); //find the .com int emadd = emailAddress.indexOf(dotCom, atpos); //if it is null if (!emailAddress.equals("")) { if (emadd == -1) { tester = false; md.error(this, "Invalid email address."); emailTextField.setText(""); } } return tester; } private void residentNameCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_residentNameCheckBoxActionPerformed residentComboBoxPreview(); if (residentNameCheckBox.isSelected()) { perHead = 350.0; bedCharge = 200.0; } totalAmountComputation(); }//GEN-LAST:event_residentNameCheckBoxActionPerformed private void residentComboBoxPreview() throws HeadlessException { residentComboBox.setEditable(false); ArrayList<String> names = getResidentNames(); for (String name : names) { residentComboBox.addItem(name); } if (residentNameCheckBox.isSelected()) { residentComboBox.setEnabled(true); relationComboBox.setEnabled(true); parentCheckBox.setEnabled(true); } else { residentComboBox.setEnabled(false); residentComboBox.removeAllItems(); relationComboBox.setEditable(false); relationComboBox.setEnabled(false); parentCheckBox.setEnabled(false); } } private void parentCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parentCheckBoxActionPerformed if (parentCheckBox.isSelected()) { roomInventoryButton.setEnabled(true); if (roomReservedTextField.getText().isEmpty()) { roomReservedTextField.setText(getRoomNumber(residentComboBox.getSelectedItem().toString())); } else { roomReservedTextField.setText(roomReservedTextField.getText() + ", " + getRoomNumber(residentComboBox.getSelectedItem().toString())); } if (reservedRoomTextField.getValue().equals("0")) { reservedRoomTextField.setValue("1"); } else { reservedRoomTextField.setValue(Integer.parseInt(reservedRoomTextField.getValue().toString()) + 1); } } else { roomInventoryButton.setEnabled(false); reservedRoomTextField.setValue("0"); roomReservedTextField.setText(""); } }//GEN-LAST:event_parentCheckBoxActionPerformed private void roomInventoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_roomInventoryButtonActionPerformed try { if (reservedRoomTextField.getValue().equals("0") | roomReservedTextField.getText().trim().equals("")) { md.error(this, "Please select a room in the iFloorPlan"); } else { String[] rooms = roomReservedTextField.getText().split(","); FurnitureList fl = new FurnitureList(rooms); fl.setVisible(true); } } catch (NullPointerException ex) { md.error(this, ex.getMessage()); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); // JOptionPane.showMessageDialog(null, "Please select a room in the iFloorPlan", "Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_roomInventoryButtonActionPerformed private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed // TODO add your handling code here: clearAll(); saveButton.setEnabled(false); clearButton.setEnabled(false); }//GEN-LAST:event_clearButtonActionPerformed private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed if (md.confirmationCancel(this) == md.YES) { if (lastPage.contains("registration")) { if (cancelButton.getText().contains("Cancel")) { String[] rooms = roomReservedTextField.getText().split(""); // for (String room : rooms) { // if (!updateRoomStatusFromTransient(room, "unoccupied")) { // md.error(this, "Room(s) update failed!"); // break; // } // } furnitureChecker(); this.dispose(); new Home().setVisible(true); } else { this.dispose(); new Home().setVisible(true); } } else { if (cancelButton.getText().contains("Cancel")) { String[] rooms = roomReservedTextField.getText().split(""); // for (String room : rooms) { // if (updateRoomStatusFromTransient(room, "unoccupied")) { // md.error(this, "Room(s) update failed!"); // break; // } // } furnitureChecker(); this.dispose(); new Home().setVisible(true); } else { this.dispose(); new Home().setVisible(true); } } } }//GEN-LAST:event_cancelButtonActionPerformed private void furnitureChecker() throws NullPointerException { if (!removeFurniture()) { md.error(this, "Furniture(s) update failed!"); } } private void addressTextFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addressTextFieldKeyTyped // TODO add your handling code here: enableClearButton(); enableButton(); }//GEN-LAST:event_addressTextFieldKeyTyped private void amountPaidTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_amountPaidTextFieldFocusLost // TODO add your handling code here: try { if (amountPaidTextField.getText().isEmpty()) { amountPaidTextField.setText("0.00"); } else { amountPaidTextField.setText(df.format(Double.parseDouble(amountPaidTextField.getText().trim()))); double totalAmount = Double.parseDouble(totalAmountTextField.getText().trim()); double amountPaid = Double.parseDouble(amountPaidTextField.getText().trim()); double balance = totalAmount - amountPaid; if (balance < 0) { balanceTextField.setText("( " + (balance * -1) + " )"); // md.error(this, "Negative number detected."); // balanceTextField.setText(""); } else { balanceTextField.setText(df.format(balance) + ""); } } } catch (NumberFormatException e) { md.error(this, e.getMessage()); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, e); //JOptionPane.showMessageDialog(null, "Not a number!", "Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_amountPaidTextFieldFocusLost private void guestSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_guestSpinnerStateChanged int row = Integer.parseInt("" + guestSpinner.getValue()); modelTop = (DefaultTableModel) guestTable.getModel(); modelTop.setNumRows(row); guestTable.setModel(modelTop); if (row == 0) { PersonTextField.setEnabled(false); PersonTextField.setText("0"); } else { PersonTextField.setEnabled(true); } totalAmountComputation(); }//GEN-LAST:event_guestSpinnerStateChanged private void residentComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_residentComboBoxItemStateChanged // TODO add your handling code here: if (!lastPage.equals("transient_form")) { if (parentCheckBox.isSelected()) { parentCheckBox.setSelected(false); reservedRoomTextField.setValue("0"); roomReservedTextField.setText(""); } else { parentCheckBox.setEnabled(true); } } }//GEN-LAST:event_residentComboBoxItemStateChanged private void totalAmountTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_totalAmountTextFieldFocusLost // TODO add your handling code here: if (totalAmountTextField.getText().isEmpty()) { totalAmountTextField.setText("0.00"); } else { totalAmountTextField.setText(df.format(Double.parseDouble(totalAmountTextField.getText().trim()))); } balanceTextField.setText(df.format(Double.parseDouble(totalAmountTextField.getText().trim()) - Double.parseDouble(amountPaidTextField.getText().trim())) + ""); }//GEN-LAST:event_totalAmountTextFieldFocusLost private void totalAmountTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_totalAmountTextFieldFocusGained // TODO add your handling code here: if (totalAmountTextField.getText().equals("0.00")) { totalAmountTextField.setText(""); } }//GEN-LAST:event_totalAmountTextFieldFocusGained private void amountPaidTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_amountPaidTextFieldFocusGained // TODO add your handling code here: if (amountPaidTextField.getText().equals("0.00")) { amountPaidTextField.setText(""); } }//GEN-LAST:event_amountPaidTextFieldFocusGained private void bedSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_bedSpinnerStateChanged // TODO add your handling code here: int value = Integer.parseInt(bedSpinner.getValue().toString()); // if (value > 0) { // bedChargeTextField.setEditable(true); // bedChargeTextField.setEnabled(true); // } else { // bedChargeTextField.setEditable(false); // bedChargeTextField.setEnabled(false); // bedChargeTextField.setText("0"); // } if (value == 0) { bedChargeTextField.setEnabled(false); bedChargeTextField.setText("0"); } else { bedChargeTextField.setEnabled(true); } totalAmountComputation(); }//GEN-LAST:event_bedSpinnerStateChanged private void dateArrivalChooserComboOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_dateArrivalChooserComboOnCommit days(); }//GEN-LAST:event_dateArrivalChooserComboOnCommit private void dateDepartureChooserComboOnCommit(datechooser.events.CommitEvent evt) {//GEN-FIRST:event_dateDepartureChooserComboOnCommit days(); }//GEN-LAST:event_dateDepartureChooserComboOnCommit private void lastNameTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_lastNameTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); enableButton(); }//GEN-LAST:event_lastNameTextFieldCaretUpdate private void firstNameTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_firstNameTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); enableButton(); }//GEN-LAST:event_firstNameTextFieldCaretUpdate private void mobileNoTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_mobileNoTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); enableButton(); }//GEN-LAST:event_mobileNoTextFieldCaretUpdate private void addressTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_addressTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); }//GEN-LAST:event_addressTextFieldCaretUpdate private void emailTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_emailTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); }//GEN-LAST:event_emailTextFieldCaretUpdate private void PersonTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_PersonTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); }//GEN-LAST:event_PersonTextFieldCaretUpdate private void bedChargeTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_bedChargeTextFieldCaretUpdate // TODO add your handling code here: enableClearButton(); }//GEN-LAST:event_bedChargeTextFieldCaretUpdate private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened // totalAmountTextField.setText((Double.parseDouble(totalAmountTextField.getText()) + securityCharge) + ""); totalAmountComputation(); }//GEN-LAST:event_formWindowOpened private void daysTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_daysTextFieldCaretUpdate // TODO add your handling code here: if (iterate != 0) { totalAmountComputation(); iterate = 0; } else { iterate = 1; } }//GEN-LAST:event_daysTextFieldCaretUpdate private void PersonTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PersonTextFieldFocusLost // TODO add your handling code here: try { if (PersonTextField.getText().trim().isEmpty()) { PersonTextField.setText("0.00"); } else { PersonTextField.setText(df.format(Double.parseDouble(PersonTextField.getText())) + ""); totalAmountComputationV2(); } } catch (NumberFormatException ex) { totalAmountComputation(); } }//GEN-LAST:event_PersonTextFieldFocusLost private void bedChargeTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_bedChargeTextFieldFocusLost // TODO add your handling code here: try { if (bedChargeTextField.getText().trim().isEmpty()) { bedChargeTextField.setText("0.00"); } else { bedChargeTextField.setText(df.format(Double.parseDouble(bedChargeTextField.getText())) + ""); totalAmountComputationV2(); } } catch (NumberFormatException ex) { totalAmountComputation(); } }//GEN-LAST:event_bedChargeTextFieldFocusLost private void PersonTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PersonTextFieldFocusGained // TODO add your handling code here: if (PersonTextField.getText().equals("0.00")) { PersonTextField.setText(""); } }//GEN-LAST:event_PersonTextFieldFocusGained private void bedChargeTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_bedChargeTextFieldFocusGained // TODO add your handling code here: if (bedChargeTextField.getText().equals("0.00")) { bedChargeTextField.setText(""); } }//GEN-LAST:event_bedChargeTextFieldFocusGained private void totalAmountTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_totalAmountTextFieldCaretUpdate // TODO add your handling code here: }//GEN-LAST:event_totalAmountTextFieldCaretUpdate private void days() { try { Calendar cal1 = new GregorianCalendar(); Calendar cal2 = new GregorianCalendar(); DateFormat originalFormat1 = dateArrivalChooserCombo.getDateFormat(); java.util.Date utilDate1 = originalFormat1.parse(dateArrivalChooserCombo.getText()); cal1.setTime(utilDate1); originalFormat1 = dateDepartureChooserCombo.getDateFormat(); utilDate1 = originalFormat1.parse(dateDepartureChooserCombo.getText()); cal2.setTime(utilDate1); int dayCount = daysBetween(cal1.getTime(), cal2.getTime()); if (dayCount <= 0) { md.warning(this, "Please check the dates."); daysTextField.setText("1"); cal1.setTime(Calendar.getInstance().getTime()); dateArrivalChooserCombo.setSelectedDate(cal1); cal2.setTime(Calendar.getInstance().getTime()); cal2.add(Calendar.DATE, 1); dateDepartureChooserCombo.setSelectedDate(cal2); } else { daysTextField.setText(dayCount + ""); } } catch (ParseException ex) { md.error(this, ex.getMessage()); // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); } } public int daysBetween(Date d1, Date d2) { return (int) ((d2.getTime() - d1.getTime()) / (1000 * 60 * 60 * 24)); } private void clearAll() { dateArrivalChooserCombo.setSelectedDate(Calendar.getInstance()); dateDepartureChooserCombo.setSelectedDate(Calendar.getInstance()); daysTextField.setText("1"); lastNameTextField.setText(""); firstNameTextField.setText(""); mobileNoTextField.setText(""); addressTextField.setText(""); emailTextField.setText(""); amountPaidTextField.setText(""); modelTop = (DefaultTableModel) guestTable.getModel(); modelTop.setRowCount(0); reservedRoomTextField.setValue(0); roomReservedTextField.setText(""); totalAmountTextField.setText((perHead + securityCharge) + ""); amountPaidTextField.setText("0.00"); guestSpinner.setValue(0); bedSpinner.setValue(0); residentNameCheckBox.setSelected(false); parentCheckBox.setSelected(false); residentComboBox.removeAllItems(); relationComboBox.setEditable(false); relationComboBox.setEnabled(false); parentCheckBox.setEnabled(false); relationComboBox.setSelectedItem("Other"); } private void enableClearButton() { // TODO add your handling code here: if (!lastNameTextField.getText().isEmpty() || !firstNameTextField.getText().isEmpty() || !mobileNoTextField.getText().isEmpty() || !addressTextField.getText().isEmpty() || !emailTextField.getText().isEmpty() //|| !additionalGuestTextArea.getText().isEmpty() || !PersonTextField.getText().equals("0") || !bedChargeTextField.getText().equals("0")) { clearButton.setEnabled(true); } else { clearButton.setEnabled(false); } } private void enableButton() { // TODO add your handling code here: if (!lastNameTextField.getText().isEmpty() & !firstNameTextField.getText().isEmpty() & !mobileNoTextField.getText().isEmpty() & !reservedRoomTextField.getValue().equals("0")) { saveButton.setEnabled(true); } else { saveButton.setEnabled(false); } } private void totalAmountComputation() { // double perHeadTotal = Integer.parseInt(daysTextField.getText().trim()) * perHead; // double perGuestTotal = ((int) guestSpinner.getValue() * perHead) * Integer.parseInt(daysTextField.getText().trim()); // PersonTextField.setText(((int) guestSpinner.getValue() * perHead) + ""); // double perBedTotal = ((int) bedSpinner.getValue() * bedCharge) * Integer.parseInt(daysTextField.getText().trim()); // bedChargeTextField.setText(((int) bedSpinner.getValue() * bedCharge) + ""); // // totalAmountTextField.setText((securityCharge + perHeadTotal + perGuestTotal + perBedTotal)+""); // // balanceTextField.setText(Double.parseDouble(totalAmountTextField.getText().trim()) - Double.parseDouble(amountPaidTextField.getText().trim()) + ""); } private void totalAmountComputationV2() { // double perHeadTotal = Integer.parseInt(daysTextField.getText().trim()) * perHead; // double perGuestTotal = Double.parseDouble(PersonTextField.getText().trim()); // double perBedTotal = Double.parseDouble(bedChargeTextField.getText().trim()); // // totalAmountTextField.setText((securityCharge + perHeadTotal + perGuestTotal + perBedTotal)+""); // // balanceTextField.setText(Double.parseDouble(totalAmountTextField.getText().trim()) - Double.parseDouble(amountPaidTextField.getText().trim()) + ""); double perHeadTotal = Double.parseDouble(PersonTextField.getText().trim()); double perBedTotal = Double.parseDouble(bedChargeTextField.getText().trim()); totalAmountTextField.setText(df.format(perHeadTotal + perBedTotal) + ""); balanceTextField.setText(df.format(Double.parseDouble(totalAmountTextField.getText().trim()) - Double.parseDouble(amountPaidTextField.getText().trim())) + ""); } private void saveToPdf() { try { com.itextpdf.text.Document doc = new com.itextpdf.text.Document(); BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } FileOutputStream fos = new FileOutputStream(path + "\\transient\\" + lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim() + "TransientForm.pdf"); PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("TransientForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); //doc.open(); //doc.add(new Paragraph(contents.getText().trim() + "-markram")); float varPosition = 0; for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); varPosition = 15; //last name content.showTextAligned(PdfContentByte.ALIGN_LEFT, lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim(), 100, 661 + varPosition, 0); //first name content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 400, 661 + varPosition, 0); if (residentNameCheckBox.isSelected()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentComboBox.getSelectedItem().toString(), 125, 633 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentComboBox.getSelectedItem().toString(), 470, 633 + varPosition, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 125, 633 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 470, 633 + varPosition, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, mobileNoTextField.getText(), 135, 590 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, emailTextField.getText(), 400, 590 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, addressTextField.getText(), 175, 577 + varPosition, 0); varPosition = 35; content.showTextAligned(PdfContentByte.ALIGN_LEFT, roomReservedTextField.getText(), 135, 507 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateArrivalChooserCombo.getText(), 135, 493 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateDepartureChooserCombo.getText(), 435, 493 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestSpinner.getValue().toString(), 180, 478 + varPosition, 0); for (int count = 0; count < guestTable.getRowCount(); count++) { float x = 50; if (count <= 3) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x, 435 + varPosition, 0); varPosition -= 13; if (count == 3) { varPosition = 35; } } else if (count >= 4 & count <= 7) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x + 200, 435 + varPosition, 0); varPosition -= 13; if (count == 7) { varPosition = 35; } } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x + 400, 435 + varPosition, 0); varPosition -= 13; } } content.endText(); } pdfStamper.close(); pdfReader.close(); } catch (DocumentException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (FileNotFoundException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (IOException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } } public boolean isSaved(String firstName, String lastName) { boolean status = true; try { String name = ""; PreparedStatement preparedStatement = connection .prepareStatement("SELECT transientIdnum FROM transient " + "WHERE transientStatus NOT LIKE '%Checkout%' AND transientLname LIKE ? " + "AND transientFname LIKE ?"); preparedStatement.setString(1, "%" + lastName.trim() + "%"); preparedStatement.setString(2, "%" + firstName.trim() + "%"); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { name = resultSet.getString("transientIdnum"); } if (name.length() != 0) { status = false; } else { status = true; } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return status; } public String getResidentId(String name) { String id = ""; try { String[] ResidentName = name.split(","); PreparedStatement preparedStatement = connection.prepareStatement( "SELECT residentIdnum FROM resident WHERE residentLname LIKE ? AND residentFname LIKE ?"); preparedStatement.setString(1, ResidentName[0].trim()); preparedStatement.setString(2, ResidentName[1].trim()); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { id = resultSet.getString("residentIdnum"); } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return id; } public boolean insertTransient(ArrayList<String> transientDetail) { boolean status = true; try { String lname = transientDetail.get(0).trim(); String fname = transientDetail.get(1).trim(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM transient"); ResultSet resultSet = preparedStatement.executeQuery(); int c1 = 0; while (resultSet.next()) { c1++; } preparedStatement = connection.prepareStatement("INSERT INTO transient (transientLname, transientFname," + " transientMobileNo, transientAddress, transientEmail, transientDateEntered, transientRelation," + " transientTotalAmount, transientAmountpaid, transientBalance, transientNoreservedRoom, " + " transientReservedRoomNo, transientArrival, transientDeparture, transientTotalNoDays, " + " transientNoAdditionalGuest, transientNamesAdditionalGuest, transientNoExtraBed, transientBedCharge," + " transientChargePerPerson, transientStatus, residentIdnum)" + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); preparedStatement.setString(1, lname); preparedStatement.setString(2, fname); preparedStatement.setString(3, transientDetail.get(2).trim()); if (transientDetail.get(3).length() != 0) { preparedStatement.setString(4, transientDetail.get(3).trim()); } else { preparedStatement.setNull(4, Types.VARCHAR); } if (transientDetail.get(4).length() != 0) { preparedStatement.setString(5, transientDetail.get(4).trim()); } else { preparedStatement.setNull(5, Types.VARCHAR); } if (transientDetail.get(5).length() != 0) { preparedStatement.setString(6, transientDetail.get(5).trim()); } else { preparedStatement.setNull(6, Types.VARCHAR); } if (transientDetail.get(6).length() != 0) { preparedStatement.setString(7, transientDetail.get(6).trim()); } else { preparedStatement.setNull(7, Types.VARCHAR); } if (transientDetail.get(7).length() != 0) { preparedStatement.setDouble(8, Double.parseDouble(transientDetail.get(7).trim())); } else { preparedStatement.setDouble(8, 0.0); } if (transientDetail.get(8).length() != 0) { preparedStatement.setDouble(9, Double.parseDouble(transientDetail.get(8).trim())); } else { preparedStatement.setDouble(9, 0.0); } if (transientDetail.get(9).length() != 0) { preparedStatement.setDouble(10, Double.parseDouble(transientDetail.get(9).trim())); } else { preparedStatement.setDouble(10, 0.0); } if (transientDetail.get(10).length() != 0) { preparedStatement.setInt(11, Integer.parseInt(transientDetail.get(10).trim())); } else { preparedStatement.setInt(11, 0); } if (transientDetail.get(11).length() != 0) { preparedStatement.setString(12, transientDetail.get(11).trim()); } else { preparedStatement.setNull(12, Types.VARCHAR); } if (transientDetail.get(12).length() != 0) { preparedStatement.setString(13, transientDetail.get(12).trim()); } else { preparedStatement.setNull(13, Types.VARCHAR); } if (transientDetail.get(13).length() != 0) { preparedStatement.setString(14, transientDetail.get(13).trim()); } else { preparedStatement.setNull(14, Types.VARCHAR); } if (transientDetail.get(14).length() != 0) { preparedStatement.setInt(15, Integer.parseInt(transientDetail.get(14).trim())); } else { preparedStatement.setInt(15, 0); } if (transientDetail.get(15).length() != 0) { preparedStatement.setInt(16, Integer.parseInt(transientDetail.get(15).trim())); } else { preparedStatement.setInt(16, 0); } if (transientDetail.get(16).length() != 0) { preparedStatement.setString(17, transientDetail.get(16).trim()); } else { preparedStatement.setNull(17, Types.VARCHAR); } if (transientDetail.get(17).length() != 0) { preparedStatement.setInt(18, Integer.parseInt(transientDetail.get(17).trim())); } else { preparedStatement.setInt(18, 0); } if (transientDetail.get(18).length() != 0) { preparedStatement.setDouble(19, Double.parseDouble(transientDetail.get(18).trim())); } else { preparedStatement.setDouble(19, 0.0); } if (transientDetail.get(19).length() != 0) { preparedStatement.setDouble(20, Double.parseDouble(transientDetail.get(19).trim())); } else { preparedStatement.setDouble(20, 0.0); } preparedStatement.setString(21, "Active"); if (transientDetail.get(20).length() != 0) { preparedStatement.setInt(22, Integer.parseInt(transientDetail.get(20).trim())); } else { preparedStatement.setInt(22, 0); } preparedStatement.execute(); preparedStatement = connection.prepareStatement( "SELECT transientIdnum FROM transient WHERE transientFname LIKE ? AND transientLname LIKE ?"); preparedStatement.setString(1, fname); preparedStatement.setString(2, lname); ResultSet rs = preparedStatement.executeQuery(); String transientIdnum = null; while (rs.next()) { transientIdnum = rs.getString("transientIdnum"); } preparedStatement = connection.prepareStatement( "UPDATE furniture SET transientIdnum = ?, furnitureStatus = 'Taken' WHERE transientIdnum LIKE '99999999'"); preparedStatement.setInt(1, Integer.parseInt(transientIdnum)); preparedStatement.execute(); } catch (SQLException ex) { status = false; // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return status; } public boolean updateRoomStatusFromTransient(String roomNum, String status) { boolean rStatus = true; try { String roomId = ""; PreparedStatement preparedStatement = connection .prepareStatement("SELECT `roomIdnum` " + "FROM `room` WHERE `roomNumber` = ?"); preparedStatement.setString(1, roomNum.trim()); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { roomId = resultSet.getString("roomIdnum"); } preparedStatement = connection.prepareStatement( "SELECT roomType, roomStatus, numberOfResident FROM room NATURAL JOIN personperroom WHERE roomNumber LIKE ?"); preparedStatement.setString(1, roomNum); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { switch (resultSet.getString("roomType")) { case "T": if (resultSet.getInt("numberOfResident") == 3) { status = "fully occupied"; } else if (resultSet.getInt("numberOfResident") < 3 && resultSet.getInt("numberOfResident") > 0) { status = "partially occupied"; } else { status = "unoccupied"; } break; case "D": if (resultSet.getInt("numberOfResident") == 2) { status = "fully occupied"; } else if (resultSet.getInt("numberOfResident") == 1) { status = "partially occupied"; } else { status = "unoccupied"; } break; case "S": if (resultSet.getInt("numberOfResident") == 1) { status = "fully occupied"; } else { status = "unoccupied"; } break; case "SU": status = "unoccupied"; break; } } PreparedStatement statement = connection .prepareStatement("UPDATE `room` set `roomStatus` = ? " + "WHERE `roomIdnum` = ?"); statement.setString(1, status.trim()); statement.setString(2, roomId.trim()); rStatus = statement.execute(); } catch (SQLException ex) { rStatus = false; // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return rStatus; } public int getFurnitureRowCount(String id) { int rows = 0; try { PreparedStatement preparedStatement = connection .prepareStatement("SELECT * FROM `furniture` WHERE `residentIdnum` = ?"); preparedStatement.setString(1, id.trim()); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { rows++; } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return rows; } public String getTransientId(String transientName) { String id = ""; try { String[] name = transientName.split(","); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `transient` " + "WHERE `transientLname` LIKE ? " + "AND `transientFname` LIKE ?"); preparedStatement.setString(1, name[0].trim()); preparedStatement.setString(2, name[1].trim()); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { id = resultSet.getString("transientIdnum") + " "; } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return id; } public boolean updateFurnitureFromTransient(String id) { boolean status = true; try { PreparedStatement preparedStatement = connection.prepareStatement( "UPDATE `furniture` SET `transientIdnum` = ? WHERE `transientIdnum` = '99999999'"); preparedStatement.setInt(1, Integer.parseInt(id.trim())); status = !preparedStatement.execute(); } catch (SQLException ex) { status = false; // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return status; } public ArrayList<String> getResidentNames() { ArrayList<String> names = new ArrayList<>(); try { PreparedStatement preparedStatement = connection.prepareStatement( "SELECT `residentLname`, `residentFname` FROM `resident` ORDER BY `residentLname` ASC"); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { names.add(resultSet.getString("residentLname") + ", " + resultSet.getString("residentFname")); } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return names; } public String getRoomNumber(String name) { String room = ""; try { String[] rName = name.split(","); String lastName = rName[0].trim(); String firstName = rName[1].trim(); PreparedStatement preparedStatement = connection .prepareStatement("SELECT `roomNumber` FROM `resident` NATURAL JOIN `room` " + "WHERE `residentLname` LIKE ? AND `residentFname` LIKE ?"); preparedStatement.setString(1, lastName); preparedStatement.setString(2, firstName); ResultSet resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { room = resultSet.getString("roomNumber"); } } catch (SQLException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return room; } public boolean removeFurniture() { boolean status = false; try { PreparedStatement preparedStatement = connection.prepareStatement( "UPDATE furniture SET residentIdnum = ?, transientIdnum = ?, furnitureStatus = 'Available' " + "WHERE residentIdnum = '99999999' OR transientIdnum = '99999999'"); preparedStatement.setNull(1, Types.INTEGER); preparedStatement.setNull(2, Types.INTEGER); status = !preparedStatement.execute(); } catch (SQLException ex) { status = false; // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } return status; } /** * @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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { JOptionPane.showMessageDialog(null, "Error!", "Error", JOptionPane.ERROR_MESSAGE); java.util.logging.Logger.getLogger(Registration_Transient.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new Registration_Transient().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField PersonTextField; private javax.swing.JTextField addressTextField; private javax.swing.JTextField amountPaidTextField; private javax.swing.JPanel amountPanel; private javax.swing.JPanel areaPanel; private javax.swing.JTextField balanceTextField; private javax.swing.JTextField bedChargeTextField; private javax.swing.JSpinner bedSpinner; private javax.swing.JButton cancelButton; private javax.swing.JButton clearButton; private datechooser.beans.DateChooserCombo dateArrivalChooserCombo; private datechooser.beans.DateChooserCombo dateDepartureChooserCombo; private javax.swing.JTextField daysTextField; private javax.swing.JTextField emailTextField; private javax.swing.JTextField firstNameTextField; private javax.swing.JSpinner guestSpinner; private javax.swing.JTable guestTable; private javax.swing.JPanel infoPanel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel24; 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.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JTextField lastNameTextField; private javax.swing.JTextField mobileNoTextField; private javax.swing.JCheckBox parentCheckBox; private javax.swing.JComboBox relationComboBox; private javax.swing.JSpinner reservedRoomTextField; private javax.swing.JComboBox residentComboBox; private javax.swing.JCheckBox residentNameCheckBox; private javax.swing.JButton roomInventoryButton; private javax.swing.JTextField roomReservedTextField; private javax.swing.JButton saveButton; private javax.swing.JPanel stayPanel; private javax.swing.JTextField totalAmountTextField; // End of variables declaration//GEN-END:variables }