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;
  }
  public SeatInfo() {
    File file = new File(".", "data");
    file.mkdir();
    File f = new File(file, "SeatInfo.txt");

    try {
      raf = new RandomAccessFile(f, "rw");

      if (raf.length() == 0) {
        raf.setLength(31 * 4 * FLIGHT_PER_DAY);
        for (int i = 0; i < 31 * FLIGHT_PER_DAY; i++) raf.writeInt(0);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  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;
  }