/* * 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 inventorysystem.gui; import interfaces.Switchable; import inventorysystem.data.Suppler; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.JPanel; /** * * @author Epic */ public class Supplier extends javax.swing.JPanel implements Switchable { private boolean businessNameExist = false; /** * Creates new form Supplier */ public Supplier() { initComponents(); this.setName("Suppler"); } /** * 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") // private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtName = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txtAddress = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtPhoneno = new javax.swing.JTextField(); jLayeredPane1 = new javax.swing.JLayeredPane(); btnSave = new javax.swing.JButton(); btnClear = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); txtBusinessName = new javax.swing.JTextField(); jLabel1.setText("Name:"); jLabel2.setText("Address:"); jLabel3.setText("Phone No:"); jLayeredPane1.setLayout(new java.awt.GridLayout()); btnSave.setText("Save"); btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); jLayeredPane1.add(btnSave); btnClear.setText("Clear"); btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); jLayeredPane1.add(btnClear); jLabel4.setText("Business Name"); txtBusinessName.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { txtBusinessNameFocusLost(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addGap(22, 22, 22) .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGap(23, 23, 23) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(txtAddress) .addComponent(jLabel3) .addComponent(txtPhoneno) .addComponent(jLabel4) .addComponent(jLabel2) .addComponent(txtBusinessName) .addComponent(txtName)))) .addGap(41, 41, 41)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(2, 2, 2) .addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtBusinessName, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(7, 7, 7) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtPhoneno, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(30, 30, 30) .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(109, Short.MAX_VALUE)) ); }// private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Suppler newSuppler = new Suppler(0, txtName.getText(), txtAddress.getText(), txtPhoneno.getText(), txtBusinessName.getText() ); if (!businessNameExist) { try { boolean saved = newSuppler.addSupplier(); if (!saved) { JOptionPane.showMessageDialog(null, "New suppler saved", "Information", JOptionPane.INFORMATION_MESSAGE); clearFields(); } else if (saved) { JOptionPane.showMessageDialog(null, "Error saving suppler", "Information", JOptionPane.ERROR_MESSAGE); } } catch (SQLException ex) { Logger.getLogger(Supplier.class.getName()).log(Level.SEVERE, null, ex); } }else{ JOptionPane.showMessageDialog(null, "Business Name must be unique", "Information", JOptionPane.INFORMATION_MESSAGE); } } private void btnClearActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clearFields(); } private void txtBusinessNameFocusLost(java.awt.event.FocusEvent evt) { // TODO add your handling code here: Suppler checkBusinessName = new Suppler(); try { if (checkBusinessName.checkIfExist("supplier_biz_name", txtBusinessName.getText())) { JOptionPane.showMessageDialog(null, "This Business name already exist"); businessNameExist = true; } } catch (SQLException ex) { Logger.getLogger(Supplier.class.getName()).log(Level.SEVERE, null, ex); } } // Variables declaration - do not modify private javax.swing.JButton btnClear; private javax.swing.JButton btnSave; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLayeredPane jLayeredPane1; private javax.swing.JTextField txtAddress; private javax.swing.JTextField txtBusinessName; private javax.swing.JTextField txtName; private javax.swing.JTextField txtPhoneno; // End of variables declaration @Override public void OnPanelSwitched(JPanel panelToSwitch) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } /** * Clear All fields in the form. */ private void clearFields() { txtName.setText(""); txtAddress.setText(""); txtPhoneno.setText(""); txtBusinessName.setText(""); } }