这是我的应用程序的数据库层。
public static void saledetails(int mem, String item2,String size2,int qty2)
{
try
{
Connection con = DriverManager.getConnection(GUIbuilding.con,GUIbuilding.usr,GUIbuilding.pass);
String sql = "INSERT INTO salesdetails VALUES(?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, mem);
ps.setString(2, item2);
ps.setString(3, size2);
ps.setInt(4, qty2);
ps.executeUpdate();
String sql2 = "update stock set qty = qty - ? where item= ? && size = ?";
PreparedStatement ps1 = con.prepareStatement(sql2);
ps1.setInt(1, qty2);
ps1.setString(2, item2);
ps1.setString(3, size2);
ps1.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//-------------- sales details------------------------
public static void saledetailsweb(int mem, String item2,String size2,int qty2)
{
try
{ // JOptionPane.showMessageDialog(null, GUIbuilding.conweb+"\n"+GUIbuilding.usrweb+"\n"+GUIbuilding.passweb);
Connection con = DriverManager.getConnection(GUIbuilding.conweb,GUIbuilding.usrweb,GUIbuilding.passweb);
String sql2 = "update stock set qty = qty - ? where item= ? && size = ?";
PreparedStatement ps1 = con.prepareStatement(sql2);
ps1.setInt(1, qty2);
ps1.setString(2, item2);
ps1.setString(3, size2);
ps1.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
//---------------------purchase details----------------------------------------------
public static void purdetails(int mem, String item2,String size2,int qty2)
{
try
{
Connection con = DriverManager.getConnection(GUIbuilding.con,GUIbuilding.usr,GUIbuilding.pass);
String sql = "INSERT INTO purdetails VALUES(?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, mem);
ps.setString(2, item2);
ps.setString(3, size2);
ps.setInt(4, qty2);
ps.executeUpdate();
String sql2 = "update stock set qty = qty + ? where item= ? && size = ?";
PreparedStatement ps1 = con.prepareStatement(sql2);
ps1.setInt(1, qty2);
ps1.setString(2, item2);
ps1.setString(3, size2);
ps1.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
这是整个动作监听器。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//sales confirm
boolean runt1= true;
boolean runt2= true;
String cust = jTextField1.getText();
String Is = jTextField2.getText();
//jTextField3.getText();
int sales_order_total_quantity =0;
if(cust.equalsIgnoreCase("") || Is.equalsIgnoreCase("") || jTable2.getRowCount()==0)
{
JOptionPane.showMessageDialog(null, "Please Enter all the required Feilds \n in order to update Sales memo");
}
else
{
jTextField1.setText("");
jTextField2.setText("");
try{
if(jTable2.getRowCount()==0)
{
JOptionPane.showMessageDialog(null,"Please Enter the Items in the sales memo");
}
else
{
for(int i=0;i<=jTable2.getRowCount();i++)
{
Object slno= jTable2.getValueAt(i, 1);
Object item2= jTable2.getValueAt(i, 2);
Object size2= jTable2.getValueAt(i, 3);
String it = slno.toString();
String si = item2.toString();
int qt = Integer.parseInt(size2.toString());
sales_order_total_quantity += qt;
// MSfuntion.saledetails(m,it, si, qt);
sc=0;
}
}
}
catch(Exception e)
{
//e.printStackTrace();
}
finally
{
MSfuntion.sales(cust, Is,sales_order_total_quantity);
final int m = MSfuntion.getmemomoc();
JOptionPane.showMessageDialog(null, m);
Thread t1 = new Thread(new Runnable(){
public void run()
{
try{ boolean runt1= true;
while(runt1){
try{
for(int i=0;i<=jTable2.getRowCount();i++)
{
Object slno= jTable2.getValueAt(i, 1);
Object item2= jTable2.getValueAt(i, 2);
Object size2= jTable2.getValueAt(i, 3);
String it = slno.toString();
String si = item2.toString();
int qt = Integer.parseInt(size2.toString());
// JOptionPane.showMessageDialog(null, "Thread is still alive bro");
MSfuntion.saledetails(m,it, si, qt);
//MSfuntion.saledetailsweb(m,it, si, qt);
sc=0;
}
}catch(Exception e)
{
e.printStackTrace();
}
runt1=false;
}
} catch(Exception e1){e1.printStackTrace();}}
});
Thread t2 = new Thread(new Runnable(){
public void run()
{ boolean runt2= true;
while(runt2){
try{
for(int i=0;i<=jTable2.getRowCount();i++)
{
Object slno= jTable2.getValueAt(i, 1);
Object item2= jTable2.getValueAt(i, 2);
Object size2= jTable2.getValueAt(i, 3);
String it = slno.toString();
String si = item2.toString();
int qt = Integer.parseInt(size2.toString());
// JOptionPane.showMessageDialog(null, "Thread is still alive bro");
//MSfuntion.saledetails(m,it, si, qt);
MSfuntion.saledetailsweb(m,it, si, qt);
sc=0;
}
}catch(Exception e)
{
e.printStackTrace();
}
runt2=false;
}
}
});
t1.start();
t2.start();
//---------------clear table sales memo---------------------
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][]
{
},
new String []
{
"Sl no", "Item", "Size", "Quantity"
}
)
{
Class[] types = new Class []
{
java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class
};
@Override
public Class getColumnClass(int columnIndex)
{
return types [columnIndex];
}
});
//-----------clear table low stock----------------------
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][]
{
},
new String []
{
"Item","Size","Quantity"
}
)
{
Class[] types = new Class []
{
java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class
};
@Override
public Class getColumnClass(int columnIndex)
{
return types [columnIndex];
}
});
//--------------------clear table recent sales----------------------------
jTable4.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Customer", "Issuer", "Date", "Memo No", "Quantity"
}
));
MSfuntion.tablepop_sr_recent(jTable4);
MSfuntion.tablepop_low(jTable1);
}}
//end of listener
}