我想计算表格模型中单位代码的总工资

时间:2014-01-05 20:37:43

标签: java mysql netbeans

我想计算表格型号单位代码栏中单位代码的工资总额,但我用一个单位代码计算总薪水:

private void total(){
  try{
      int row =  tbl_sale.getRowCount();

      TableModel tabelModel1;
      tabelModel1 = tbl_sale.getModel();
      for (int j=0; j<row; j++){
     String sql = "Select qty from unit Where   cd_unit='"+tbl_sale.getValueAt(j,4).toString()+"'";
     r=s.executeQuery(sql); 
      r.next();
      }

int unit = Integer.parseInt(r.getString("jumlah")); 
int rows = tbl_sale.getRowCount();
int paytotal = 0;
int qtys, price;
TableModel tabelModel;
tabelModel = tbl_sale.getModel();
for (int i=0; i<rows; i++){

    qtys = Integer.parseInt(tabelModel.getValueAt(i, 3).toString());
    price = Integer.parseInt(tabelModel.getValueAt(i, 2).toString());
    paytotal = paytotal + ((qtys*unit) *price);
}
ttot_price.setText(String.valueOf(paytotal));
  } catch (SQLException ex) {
}}   

0 个答案:

没有答案