/** 查询选中市内所有的县,优先从数据库查询,如果没有查询到再去服务器上查询。 */
 private void queryCounties() {
   countyList = coolWeatherDB.loadCounties(selectedCity.getId());
   if (countyList.size() > 0) {
     dataList.clear();
     for (County county : countyList) {
       dataList.add(county.getCountyName());
     }
     adapter.notifyDataSetChanged();
     listView.setSelection(0);
     titleText.setText(selectedCity.getCityName());
     currentLevel = LEVEL_COUNTY;
   } else {
     queryFromServer(selectedCity.getCityCode(), "county");
   }
 }
 /** 查询所有的市,优先从数据库查询,如果没有就从服务器查询 */
 private void queryCities() {
   cityList = coolWeatherDB.loadCities(selectedProvince.getId());
   if (cityList.size() > 0) {
     dataList.clear();
     for (City c : cityList) {
       dataList.add(c.getCityName());
     }
     adapter.notifyDataSetChanged();
     list_view.setSelection(0);
     title_text.setText(selectedProvince.getProvinceName());
     currentLevel = LEVEL_CITY;
   } else {
     queryFromServer(selectedProvince.getProvinceCode(), "city");
   }
 }
 @Override
 public int getDistance(City other) {
   if (distances.containsKey(other)) {
     return distances.get(other);
   }
   throw new RuntimeException("Don't know distance to " + other.getName());
 }
示例#4
0
 /** 解析和处理服务器返回的市级数据 */
 public static synchronized boolean handleCitiesResponse(
     CoolWeatherDB coolWeatherDB, String response, int provinceId) {
   if (!TextUtils.isEmpty(response)) {
     String[] allCities = response.split(",");
     if (allCities != null && allCities.length > 0) {
       for (String c : allCities) {
         String[] array = c.split("\\|");
         City city = new City();
         city.setCityCode(array[0]);
         city.setCityName(array[1]);
         city.setProvinceId(provinceId);
         // 将解析出来的数据存储到City表
         coolWeatherDB.saveCity(city);
       }
       return true;
     }
   }
   return false;
 }
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (request.getSession().getAttribute("current_user") != null) {
      model.pojo.Gup gup = (model.pojo.Gup) request.getSession().getAttribute("current_user");

      String hotel_name = request.getParameter("hotel_name");
      String hotel_overview = request.getParameter("hotel_overview");
      String lat = request.getParameter("lat");
      String lng = request.getParameter("lng");
      String addr_no = request.getParameter("addr_no");
      String addr_street = request.getParameter("addr_street");
      int city_id = Integer.parseInt(request.getParameter("city"));
      model.pojo.City city = model.City.getInstance().getCityById(city_id);
      int hotel_type_id = Integer.parseInt(request.getParameter("hotel_type"));
      model.pojo.HotelType hotelType =
          model.HotelType.getInstance().getHotelTypeById(hotel_type_id);
      int hotel_rating_id = Integer.parseInt(request.getParameter("hotel_rating"));

      HotelInfo hotel_info =
          model.HotelInfo.getInstance()
              .saveHotel(
                  hotel_name,
                  hotel_overview,
                  lat,
                  lng,
                  hotel_rating_id,
                  addr_no,
                  addr_street,
                  gup,
                  hotelType,
                  city);
      response.sendRedirect(
          "hotel_bo.jsp?hbo_action=manage_hotel&hotel=" + hotel_info.getIdhotelInfo());
    }
  }