boolean result = true;
Iterator rowsIter = rows.iterator();
Vector rAndRis = new Vector();
while (rowsIter.hasNext()) {
Row row = (Row)rowsIter.next();
Cell cell1 = ObjectUtil.findNewCell(row, "TAXI", "R");
Cell cell2 = ObjectUtil.findNewCell(row, "TAXI", "RI");
if ( (cell1.getColumnValue() != null) && (cell2.getColumnValue() != null) ) {
boolean flag = true;//used by some bug
int r = 0;
if (cell1.getColumnValue() instanceof Number)
r = ((Number)cell1.getColumnValue()).intValue();
else if (cell1.getColumnValue() instanceof String) {
if (((String)cell1.getColumnValue()).trim().equals("")) {
flag = false;
} else {
r = Integer.parseInt((String)cell1.getColumnValue());
}
}
int ri = 0;
if (cell2.getColumnValue() instanceof Number)
ri = ((Number)cell2.getColumnValue()).intValue();
else if (cell2.getColumnValue() instanceof String) {
if (((String)cell2.getColumnValue()).trim().equals("")) {
flag = false;
} else {
ri = Integer.parseInt((String)cell2.getColumnValue());
}
}
if (flag) {
Vector data = new Vector();
data.add(r);
data.add(ri);
Iterator rAndRisIter = rAndRis.iterator();
while (rAndRisIter.hasNext()) {
Vector oldData = (Vector)rAndRisIter.next();
Integer oldR = (Integer)oldData.get(0);
Integer oldRi = (Integer)oldData.get(1);
if ( (r == oldR.intValue()) && (ri == oldRi.intValue()) ) {
result = false;
break;
}
}
if (result)
rAndRis.add(data);
}
}
}
if (result) {
int newR = 0;
int newRi = 1;
DAO dao = DAO.getInstance();
dao.query(Resources.SELECT_MAX_R_FROM_R_SQL);
ResultSet rs = dao.executeQuery();
try {
if (rs.next())
newR = rs.getInt(1) + 1;
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
boolean hasNewRow = false;
boolean firstNewRow = true;
rowsIter = rows.iterator();
while (rowsIter.hasNext()) {
Row row = (Row)rowsIter.next();
Cell cell1 = ObjectUtil.findNewCell(row, "TAXI", "R");
Cell cell2 = ObjectUtil.findNewCell(row, "TAXI", "RI");
boolean isAdd = false;
if ( (cell1.getColumnValue() != null) && (cell2.getColumnValue() != null) ) {
try {
if ( (cell1.getColumnValue() instanceof Number) && (cell2.getColumnValue() instanceof Number) ) {
isAdd = false;
} else if ( (cell1.getColumnValue() instanceof String) && (cell2.getColumnValue() instanceof String) ) {
Integer.parseInt((String)cell1.getColumnValue());
Integer.parseInt((String)cell2.getColumnValue());
isAdd = false;
}
} catch (Exception e) {
isAdd = true;
e.printStackTrace();
}
} else {
isAdd = true;
}
// System.err.println("isAdd = " + isAdd);
//LD
String ld = "";
String user = GlobalValueManager.getValue("SESSION.LOGINUSER");
Cell taxtCell = ObjectUtil.findNewCell(row, "TAXI", "TAXT");
dao.query(Resources.SELECT_LD_BY_TAXTYPE_SQL);
dao.setObject(1, taxtCell.getColumnValue());
dao.setObject(2, user);
rs = dao.executeQuery();
try {
if (rs.next()) {
ld = rs.getString(1);
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
//TC
String tc = "";
Cell tcCell = ObjectUtil.findNewCell(row, "TAXI", "TC");
tc = (String)tcCell.getColumnValue();
//TAMT
double tamt = 0.0;
Cell tamtCell = ObjectUtil.findNewCell(row, "TAXI", "TAMT");
tamt = getDouble(tamtCell.getColumnValue());
//R
int r = 0;
if (isAdd) {
r = newR;
} else {
if (cell1.getColumnValue() instanceof Number)
r = ((Number)cell1.getColumnValue()).intValue();
else
r = Integer.parseInt((String)cell1.getColumnValue());
}
//RI
int ri = 0;
if (isAdd) {
ri =newRi;
newRi++;
} else {
if (cell2.getColumnValue() instanceof Number)
ri = ((Number)cell2.getColumnValue()).intValue();
else
ri = Integer.parseInt((String)cell2.getColumnValue());
}
// System.err.println("R = " + r);
// System.err.println("RI = " + ri);
//LC
String lc = "";
dao.query(Resources.SELECT_LC_FROM_FAMILY_SQL);
rs = dao.executeQuery();
try {
if (rs.next()) {
lc = rs.getString("LC");
}
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
//TDATE
Cell tdateCell = ObjectUtil.findNewCell(row, "TAX", "TDATE");
//some bugs
String tdate;
tdate = tdateCell.getColumnValue().toString();
//XR
double xr = 1.0;
dao.query(Resources.SELECT_XR_SQL);
dao.setObject(1, lc);
dao.setObject(2, tc);
dao.setObject(3, lc);
dao.setObject(4, tc);
dao.setObject(5, tdate);
rs = dao.executeQuery();
try {
if (rs.next())
xr = rs.getDouble(1);
rs.close();
} catch (Exception e) {
e.printStackTrace();
}
//LAMT
double lamt = tamt * xr;
// System.err.println("r=" + r + " ri=" + ri + " ld=" + ld + " tc=" + tc + " tamt=" + tamt + " lc=" + lc + " lamt=" + lamt + " tdate=" + tdate + " xr=" + xr);
//set new taxes
if (isAdd) {
if (!row.isDelete()) {
hasNewRow = true;
//insert r table
if (firstNewRow) {
firstNewRow = false;