Ejemplo n.º 1
0
 public boolean remove(String s) throws SQLException, Exception {
   return remove(JItemDB.findItem(s));
 }
Ejemplo n.º 2
0
 public boolean setPrice(String item, double b, double s)
     throws SQLException, IOException, Exception {
   return setPrice(JItemDB.findItem(item), b, s);
 }
Ejemplo n.º 3
0
 public double getBuyPrice(String s) throws SQLException, Exception {
   return getBuyPrice(JItemDB.findItem(s));
 }
Ejemplo n.º 4
0
 public double getSellPrice(ItemStack i) throws SQLException, Exception {
   return getSellPrice(JItemDB.findItem(i));
 }
Ejemplo n.º 5
0
 public boolean itemExists(ItemStack check) throws SQLException, Exception {
   return itemExists(JItemDB.findItem(check));
 }
Ejemplo n.º 6
0
  public boolean loadFile(File toload) throws IOException, Exception {
    if (toload != null) {
      databaseType = DBType.FLATFILE;
      flatFile = toload;
      priceList.clear();
      if (toload.exists()) {
        isLoaded = false;
        FileReader fstream = null;
        try {
          fstream = new FileReader(toload.getAbsolutePath());
          BufferedReader in = new BufferedReader(fstream);
          try {
            int n = 0;
            for (String line = null; (line = in.readLine()) != null && line.length() > 0; ++n) {
              // if was edited in openoffice, will instead have semicolins..
              String fields[] = line.replace(";", ",").replace(",,", ", ,").split(",");

              if (fields.length > 4) {
                if (n == 0 && fields[0].equals("id")) {
                  continue;
                }
                JItem plItem =
                    JItemDB.findItem(fields[0] + ":" + (fields[1].equals(" ") ? "0" : fields[1]));
                if (plItem != null) {
                  // priceList.add(new PriceListItem(plItem, fields[2].length() == 0 ? -1 :
                  // CheckInput.GetDouble(fields[2], -1), fields[3].length() == 0 ? -1 :
                  // CheckInput.GetDouble(fields[3], -1)));
                  priceList.add(
                      new PriceListItem(
                          plItem,
                          fields[2].equals(" ") ? -1 : CheckInput.GetDouble(fields[2], -1),
                          fields[3].equals(" ") ? -1 : CheckInput.GetDouble(fields[3], -1)));
                } else if (n > 0) { // first line is expected invalid: is title
                  logger.log(
                      Level.WARNING,
                      String.format(
                          "Invalid item on line %d in %s (%s)",
                          (n + 1),
                          toload.getName(),
                          fields[0]
                              + ":"
                              + (fields[1].equals(" ") ? "0" : fields[1])
                              + (fields.length <= 4 ? "" : " [" + fields[4] + "]")));
                }
              } else {
                logger.log(
                    Level.WARNING,
                    String.format(
                        "unexpected pricelist line at %d in %s", (n + 1), toload.getName()));
              }
            }
          } finally {
            in.close();
          }
        } catch (IOException ex) {
          if (!log_nothrow) {
            throw new IOException("Error opening " + toload.getName() + " for reading", ex);
          }
          logger.log(Level.SEVERE, "Error opening " + toload.getName() + " for reading", ex);
        } finally {
          if (fstream != null) {
            try {
              fstream.close();
            } catch (IOException ex) {
              if (!log_nothrow) {
                throw new IOException("Error closing " + toload.getName(), ex);
              }
              logger.log(Level.SEVERE, "Error closing " + toload.getName(), ex);
            }
          }
        }
        return isLoaded = true && save();
      } else { // !toload.exists()
        // still set as loaded
        isLoaded = true;
        return save();
      }
    }
    return false;
  }