package inventorysystem.gui;
import com.sun.glass.events.KeyEvent;
import interfaces.Switchable;
import inventorysystem.data.NumberFormater;
import inventorysystem.data.Product;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
*
* @author Epic
*/
public class Products
extends javax.
swing.
JPanel implements Switchable
{
/**
* Creates new form Products
*/
public Products() {
initComponents();
this.setName("Product");
this.fillSupplierList();
}
/**
* 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() {
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();
cbmSupplier = new javax.swing.JComboBox<>();
btnSave
= new javax.
swing.
JButton();
btnCancel
= new javax.
swing.
JButton();
jLabel7
= new javax.
swing.
JLabel();
cbmManufactureDate = new datechooser.beans.DateChooserCombo();
cbmExpiryDate = new datechooser.beans.DateChooserCombo();
jLabel8
= new javax.
swing.
JLabel();
jLabel9
= new javax.
swing.
JLabel();
txtCost = new javax.swing.JFormattedTextField();
txtSales = new javax.swing.JFormattedTextField();
costError
= new javax.
swing.
JLabel();
salesError
= new javax.
swing.
JLabel();
jLabel1.setText("Name:");
jLabel2.setText("Description:");
taDescription.setColumns(20);
taDescription.setRows(5);
jScrollPane1.setViewportView(taDescription);
jLabel3.setText("Cost Price:");
jLabel4.setText("Sale Price:");
jLabel5.setText("Quantity:");
jLabel6.setText("Supplier:");
jLayeredPane1.
setLayout(new java.
awt.
GridLayout(1,
0));
btnSave.setText("Save");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
btnSaveActionPerformed(evt);
}
});
jLayeredPane1.add(btnSave);
btnCancel.setText("Cancel");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
btnCancelActionPerformed(evt);
}
});
jLayeredPane1.add(btnCancel);
jLabel7.setText("Manufacture Date:");
cbmManufactureDate.setCurrentView(new datechooser.view.appearance.AppearancesList("Swing",
new datechooser.view.appearance.ViewAppearance("custom",
new datechooser.
view.
appearance.
swing.
SwingCellAppearance(new java.
awt.
Font("Dialog", java.
awt.
Font.
PLAIN,
11),
new java.
awt.
Color(222,
222,
222),
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("Dialog", java.
awt.
Font.
PLAIN,
11),
new java.
awt.
Color(222,
222,
222),
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("Dialog", 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("Dialog", 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("Dialog", java.
awt.
Font.
PLAIN,
11),
new java.
awt.
Color(222,
222,
222),
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("Dialog", java.
awt.
Font.
PLAIN,
11),
new java.
awt.
Color(222,
222,
222),
new java.
awt.
Color(255,
0,
0),
false,
false,
new datechooser.view.appearance.swing.ButtonPainter()),
(datechooser.view.BackRenderer)null,
false,
true)));
jLabel8.setText("Expiry Date:");
jLabel9.setText("Batch Number:"// </editor-fold>
private void btnSaveActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
// TODO add your handling code here:
Product product = new Product(0, txtName.getText(),
Integer.
parseInt(txtQuantity.
getText()),
Float.
valueOf(txtSales.
getText()),
"", taDescription.getText(),
cbmManufactureDate.getText(),
cbmExpiryDate.getText(),
txtBatchNo.getText(),
Float.
valueOf(txtCost.
getText()));
try {
// since the login class has access to the currently logged in employee
if(product.addProduct(
((String)cbmSupplier.
getSelectedItem()),
//supplier from the combo selection
login.getCurrentEmployee().getEmployeeId() //currently logged in employee in the system
)){
JOptionPane.
showMessageDialog(null,
"New Product saved..");
}
Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void btnCancelActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
// TODO add your handling code here:
}
private void txtCostActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
// TODO add your handling code here:
}
private void txtCostKeyTyped
(java.
awt.
event.
KeyEvent evt
) {
// TODO add your handling code here:
NumberFormater.integerOnlyField(evt, costError);
}
private void txtSalesKeyTyped
(java.
awt.
event.
KeyEvent evt
) {
// TODO add your handling code here:
NumberFormater.integerOnlyField(evt, salesError);
}
// Variables declaration - do not modify
private javax.
swing.
JButton btnCancel
;
private javax.
swing.
JButton btnSave
;
private datechooser.beans.DateChooserCombo cbmExpiryDate;
private datechooser.beans.DateChooserCombo cbmManufactureDate;
private javax.swing.JComboBox<String> cbmSupplier;
private javax.
swing.
JLabel costError
;
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.
JLabel jLabel9
;
private javax.
swing.
JLabel salesError
;
private javax.swing.JFormattedTextField txtCost;
private javax.swing.JFormattedTextField txtSales;
// End of variables declaration
@Override
public void OnPanelSwitched
(JPanel panelToSwitch
) {
}
/**
* Get a list of suppliers and fill the suppler comboList
*/
private void fillSupplierList(){
inventorysystem.data.Suppler s = new inventorysystem.data.Suppler();
Vector supplierList
= new Vector(); // since a DefaultComboBoxModel takes a vector for initialization
supplierList.add(0,"Select Suppler");
try {
ArrayList<inventorysystem.data.Suppler> suppliers = s.getSupplier("", true);
for (int i = 0; i < suppliers.size(); i++) {
supplierList.add(suppliers.get(i).getSupplerBusinessName());
cbmSupplier.setModel(new DefaultComboBoxModel<>(supplierList));
}
Logger.getLogger(Products.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I tried to do this earlier by creating an instance of the login class but the variable (employee) returned null every time, but making it static solved the problem.
Question: was i right to have done this, and is there a better way? thanks sir