_dataSourceRevGeo = dataSourceRevGeo;
_outputLinux = outputLinux;
}
public DistrictInfo findDistrict(District district, ResultRange rr, int idLicenca) throws Exception {
DistrictInfo ri = new DistrictInfo();
try {
int iCount = 0;
Pagination pg;
Boolean hasState = (district.getCity().getState() != null && !district.getCity().getState().equals(""));
Boolean hasCity = (district.getCity().getName() != null && !district.getCity().getName().equals(""));
if (!hasCity || !hasState) {
throw (new Exception("Cidade e estado devem ser informados."));
}
if (district.getName() == null)
district.setName("");
if (district.getCity().getName() == null)
district.getCity().setName("");
if (district.getCity().getState() == null)
district.getCity().setState("");
if (Functions.IsNullOrEmpty(district.getCity().getCountry()))
district.getCity().setCountry("Brasil");
Connection con = dataBase.getConnection(Functions.getDataBase(idLicenca, "Brasil").getSource());
CallableStatement cst = con.prepareCall("{call CP_WS_DISTRICT(?,?,?)}");
cst.setString(1, district.getName());
cst.setString(2, district.getCity().getName());
cst.setString(3, district.getCity().getState());
cst.execute();
ResultSet rs1 = cst.getResultSet();
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs1);
int TotalRecords = crs.size();
if (TotalRecords > 0) {
try {
pg = Functions.definePage(TotalRecords, rr.getRecordsPerPage(), rr.getPageIndex());
DistrictLocation[] dl;
if (pg.getRecordsInitial() <= TotalRecords) {
dl = new DistrictLocation[(pg.getRecordsFinal() - pg.getRecordsInitial()) + 1];
for (int intI = pg.getRecordsInitial(); intI <= pg.getRecordsFinal(); intI++) {
// classe district
if (rs1.absolute(intI)) {
dl[iCount] = new DistrictLocation();
dl[iCount].setDistrict(new District());
dl[iCount].getDistrict().setName(rs1.getString("NOME"));
dl[iCount].getDistrict().setCity(new City());
dl[iCount].getDistrict().getCity().setName(rs1.getString("CIDADE"));
dl[iCount].getDistrict().getCity().setState(rs1.getString("UF"));
dl[iCount].setPoint(new Point());
dl[iCount].getPoint().setX(Double.parseDouble(rs1.getString("X")));
dl[iCount].getPoint().setY(Double.parseDouble(rs1.getString("Y")));
dl[iCount].getDistrict().setZone(rs1.getString("REGIAO"));
iCount++;
}
}
ri.setRecordCount((int) pg.getRecordCount());
ri.setPageCount(pg.getPageCount());
} else {
dl = new DistrictLocation[0];
}
ri.setDistrictLocation(dl);
} catch (Exception ex) {
throw (new Exception("Registro n�o encontrado."));
}
} else {
DistrictLocation[] rl = new DistrictLocation[0];
ri.setDistrictLocation(rl);
}
con.close();
rs1.close();
crs.close();