Exemplo n.º 1
0
  public long cacuAddr(String flightNum) {
    long remark = 0;
    try {
      String sqlString = "select remark from flight where flight='" + flightNum + "'";
      ResultSet rs = sqlConnection.executeQuery(sqlString);

      while (rs.next()) remark = rs.getInt(1);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return (remark - 1) * 4;
  }
Exemplo n.º 2
0
  public int dingPiao(String flightNum, String day, int seats) {
    int leftSeats = 0;
    try {
      long index = cacuIndex(day);
      long address = cacuAddr(flightNum);
      long absoluteAddress = index + address;

      raf.seek(absoluteAddress);
      int bookedSeats = raf.readInt();

      String sqlString = "select seat,week from flight where flight='" + flightNum + "' ";
      ResultSet rs = sqlConnection.executeQuery(sqlString);

      int totalSeats = 0;
      String week = "";
      while (rs.next()) {
        totalSeats = rs.getInt(1);
        week = rs.getString(2);
      }

      String c = isAbsence(day);
      int flag = 0;
      for (int i = 0; i < week.length(); i++) {
        String w = week.substring(i, i + 1);
        if (c.equals(w)) {
          flag = 1;
          break;
        }
      }

      if (flag == 1) {
        leftSeats = totalSeats - bookedSeats;

        if (leftSeats >= seats) {
          raf.seek(absoluteAddress);
          raf.writeInt(bookedSeats + seats);
          return -1;
        } else return leftSeats;
      } else return -2;

    } catch (Exception e) {
      e.printStackTrace();
    }

    return leftSeats;
  }
Exemplo n.º 3
0
  public boolean isFull(String flightNum, String day) {
    try {
      long index = cacuIndex(day);
      long address = cacuAddr(flightNum);
      long absoluteAddress = index + address;

      raf.seek(absoluteAddress);
      int bookedSeats = raf.readInt();
      String sqlString = "select seat from flight where flight='" + flightNum + "'";
      ResultSet rs = sqlConnection.executeQuery(sqlString);

      int totalSeats = 0;

      while (rs.next()) totalSeats = rs.getInt(1);
      if (totalSeats == bookedSeats) return true;
      else return false;

    } catch (Exception e) {
      return false;
    }
  }