I am still developing stock management system with netbeans ide using java. In one interface I have three different jtables, one for current materials quantity in stock, one for required materials quantity for fulfill order, and other one for print is the quantity in stock is greater or lesser than the quantity in order. How can I compare this two quantity columns and print results?
/*** these are the codes tried till now ****/
//global variables
Vector v=new Vector();
Object listOrder=new Object();
Vector v1=new Vector();
Object listOrder1=new Object();
Vector v2=new Vector();
Object listOrder2=new Object();
int tranval[];
int stkval[];
//button action for import database values to tables
private void RequiredActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tranval =new int[20];
stkval =new int[20];
try{
ResultSet rs = new getMatierialDataM().searchItems("SELECT icode,qty from transactiono where oid ='"+jComboBox2_oid.getSelectedItem()+"'");
//define tables
DefaultTableModel dtm = (DefaultTableModel)jTable2_required.getModel(); //required materials
dtm.setRowCount(0);
Vector v = null;
DefaultTableModel dtm1 = (DefaultTableModel)jTable1_availability.getModel();
dtm1.setRowCount(0); //available materials in stock
Vector v1 =null;
while(rs.next()){
String ico=rs.getString("icode");
String q1=rs.getString("qty");
int q11=Integer.parseInt(q1);
ResultSet rs1 = new getMatierialDataM().searchItems("SELECT transactionbom.mid,transactionbom.qty,component.comid,matierial.stockqty from transactionbom,component,matierial where transactionbom.icode ='"+ico+"' AND transactionbom.icode=component.icode AND transactionbom.mid=matierial.mid");
int len=0;
while(rs1.next()){
String q2=rs1.getString("qty");
int q22=Integer.parseInt(q2);
int qty =q11*q22; //calculation
String cid,mid,stq;
cid=rs1.getString("comid");
mid=rs1.getString("mid");
stq=rs1.getString("stockqty");
tranval[len]=qty;
stkval[len]=q22;
len++;
v = new Vector();
v.add(cid);
v.add(mid);
v.add(qty);
dtm.addRow(v);
v1 = new Vector();
v1.add(cid);
v1.add(mid);
v1.add(stq);
dtm1.addRow(v1);
}
}
}
catch (Exception e) {
e.printStackTrace();
//Logger.getLogger(ItemCosting.class.getName()).log(Level.SEVERE, null, e);
}
}
//button action for compare above two tables and get stock status in third table
private void jButton1_checkActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
DefaultTableModel dtm1 = (DefaultTableModel)jTable1_status.getModel();
dtm1.setRowCount(0);
Vector v2 =null;
int x=0;
int y=3;
int len=jTable1_availability.getRowCount();
v2 = new Vector();
while(x<len){
if(tranval[x]>stkval[x]){
v2.add("mid");
v2.add("OK");
}else{
v2.add("mid");
v2.add("NO");
}
dtm1.addRow(v2);
tranval[x]++;
stkval[x]++;
x++;
}
}
That above codes print only one same result in all rows in third table. I expected some NO status in few rows but is prints OK in all of the rows.