Вы находитесь на странице: 1из 6

/*

* 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 avonpos;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
/**
*
* @author junver
*/
public class add_stocks extends javax.swing.JDialog {
/**
* Creates new form add_stocks
*/
public add_stocks() {

initComponents();
}




private void stocks(){
String ids = code.getText();
String q = quan.getText();

try{
wifi.connect();
wifi.pst = wifi.con.prepareStatement("UPDATE `charliepos`.`inventory_stocks`
SET `Quantity` = '"+q+"' WHERE `prod_code` = '"+ids+"'; ");
wifi.pst.executeUpdate();
JOptionPane.showMessageDialog(this, "Add Stocks Successfuly");

wifi.con.close();

}
catch(Exception e){}


}

private void cleartxt(){
quan.setText("");

}


private void addNewStocks(){
try{
wifi.connect();
wifi.pst = wifi.con.prepareStatement("INSERT INTO `charliepos`.`inventory_
stocks` (prod_code,Quantity,userID,add_date,add_time,mod_by,mod_date,remarks)VAL
UES (?,?,?,?,?,?,?,?)");
wifi.pst.setString(1,code.getText());
wifi.pst.setString(2, quan.getText());
wifi.pst.setString(3, MainFrame.userID.getText());
wifi.pst.setString(4, MainFrame.getDate());
wifi.pst.setString(5, MainFrame.getTime());
wifi.pst.setString(6, MainFrame.userID.getText());
wifi.pst.setString(7, MainFrame.getDate()+" "+MainFrame.getTime());
wifi.pst.setString(8, remarks.getText());
wifi.pst.execute();
JOptionPane.showMessageDialog(this, "Stocks Added Successfuly");
clear();
wifi.con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(this, "error "+e);
}
}

public void clear(){
quan.setText("");
remarks.setText("");
}

/**
* 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:i
nitComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
remarks = new javax.swing.JTextArea();
quan = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
code = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
setModal(true);
setUndecorated(true);
jPanel1.setBackground(new java.awt.Color(255, 0, 153));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.aw
t.Color(255, 255, 255), 3));
jPanel1.setLayout(null);
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swin
g.border.BevelBorder.RAISED));
jPanel2.setOpaque(false);
jPanel2.setLayout(null);
jLabel3.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
jLabel3.setText("Remarks:");
jPanel2.add(jLabel3);
jLabel3.setBounds(10, 70, 110, 31);
remarks.setColumns(20);
remarks.setRows(5);
jScrollPane1.setViewportView(remarks);
jPanel2.add(jScrollPane1);
jScrollPane1.setBounds(120, 70, 250, 130);
quan.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
quan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quanActionPerformed(evt);
}
});
jPanel2.add(quan);
quan.setBounds(120, 40, 250, 30);
jLabel5.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
jLabel5.setText("Add Stocks:");
jPanel2.add(jLabel5);
jLabel5.setBounds(10, 40, 110, 31);
jLabel2.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
jLabel2.setText("Product Code:");
jPanel2.add(jLabel2);
jLabel2.setBounds(10, 10, 110, 31);
code.setEditable(false);
code.setFont(new java.awt.Font("Verdana", 0, 12)); // NOI18N
code.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
codeActionPerformed(evt);
}
});
jPanel2.add(code);
code.setBounds(120, 10, 250, 30);
jButton2.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
jButton2.setText("Save");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel2.add(jButton2);
jButton2.setBounds(10, 220, 100, 30);
jButton1.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
jButton1.setText("Clear");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1);
jButton1.setBounds(120, 220, 100, 30);
jButton3.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
jButton3.setText("Close");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel2.add(jButton3);
jButton3.setBounds(270, 220, 100, 30);
jPanel1.add(jPanel2);
jPanel2.setBounds(10, 10, 380, 260);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Sh
ort.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, j
avax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
);
setSize(new java.awt.Dimension(400, 279));
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jButton2ActionPerformed
int nn = JOptionPane.showConfirmDialog(this, "Are you sure you want to a
dd stocks for this product?","Confirmation", 0);
if(nn==0){
try{
int n = Integer.parseInt(quan.getText());
addNewStocks();
StocksDetails.getInventory();
StocksDetails.total.setText(StocksDetails.getTotalStocks(code.ge
tText()));
Inventory.itemlist();
}catch(Exception e){
JOptionPane.showMessageDialog(this, "invalid quantity!");
}
}
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
clear();
}//GEN-LAST:event_jButton1ActionPerformed
private void quanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
T:event_quanActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_quanActionPerformed
private void codeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
T:event_codeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_codeActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_jButton3ActionPerformed
/**
* @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 cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(add_stocks.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(add_stocks.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(add_stocks.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(add_stocks.class.getName()).log(j
ava.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new add_stocks ().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
public javax.swing.JTextField code;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
public javax.swing.JTextField quan;
public javax.swing.JTextArea remarks;
// End of variables declaration//GEN-END:variables
}