Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
0
  public void tuiPiao(String flightNum, String day, int seats) {
    try {
      long index = cacuIndex(day);
      long address = cacuAddr(flightNum);
      long absoluteAddress = index + address;

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

      if (bookedSeats < seats)
        JOptionPane.showMessageDialog(null, "退票数大于已定票数!", "错误信息", JOptionPane.ERROR_MESSAGE);
      else {
        raf.seek(absoluteAddress);
        raf.writeInt(bookedSeats - seats);
      }
    } catch (Exception e) {
    }
  }
Ejemplo 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;
    }
  }