Example #1
0
  public String[] getDineAvtaler(int d, int m, int a) {
    String dato = datoAsString(d, m, a);
    ArrayList<String> temp = new ArrayList<String>();
    ResultSet rs =
        db.readQuery(
            "SELECT avtaleid, dato, starttid, sluttid, beskrivelse, romid, sted, kommer "
                + "FROM avtale NATURAL JOIN erinviterttil "
                + "WHERE synlig = 1 AND dato = '"
                + dato
                + "' AND brukernavn = '"
                + bruker
                + "'");
    try {
      int count = 0;
      while (rs.next()) {
        String avtaleid = Integer.toString(rs.getInt(1));
        while (avtaleid.length() < 4) {
          avtaleid = "0" + avtaleid;
        }
        temp.add(
            avtaleid
                + ": "
                + rs.getString(2).substring(0, 2)
                + "."
                + rs.getString(2).substring(2, 4)
                + "."
                + rs.getString(2).substring(4)
                + " "
                + rs.getString(3)
                + " - "
                + rs.getString(4)
                + ": "
                + rs.getString(5)
                + " i ");
        if (rs.getString(6) == null) {
          temp.set(count, temp.get(count) + rs.getString(7) + ".");
        } else {
          temp.set(count, temp.get(count) + "Rom " + rs.getInt(6) + ".");
        }
        if (rs.getString(8) == null) {
          temp.set(count, temp.get(count) + " Du har ikke svart på invitasjonen.");
        } else if (rs.getBoolean(8)) {
          temp.set(count, temp.get(count) + " Du har svart ja.");
        } else {
          temp.set(count, temp.get(count) + " Du har svart nei.");
        }
        count++;
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }
    String[] dineavtaler = new String[temp.size()];
    temp.toArray(dineavtaler);
    return dineavtaler;
  }
Example #2
0
 public boolean harAnsattAvtale(int day, int maaned, int aar) {
   ResultSet rs =
       db.readQuery(
           "SELECT count(avtaleid) FROM avtale WHERE dato = '"
               + datoAsString(day, maaned, aar)
               + "'");
   int count = 0;
   try {
     rs.next();
     count = rs.getInt(1);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   if (count > 0) {
     return true;
   }
   return false;
 }
Example #3
0
 public boolean kommerTilAvtale(int day, int maaned, int aar) {
   ResultSet rs =
       db.readQuery(
           "SELECT count(avtaleid) FROM avtale NATURAL JOIN erinviterttil"
               + " WHERE dato = '"
               + datoAsString(day, maaned, aar)
               + "' AND brukernavn = '"
               + this.bruker
               + "' "
               + "AND kommer = 1");
   int count = 0;
   try {
     rs.next();
     count = rs.getInt(1);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   if (count > 0) {
     return true;
   }
   return false;
 }
Example #4
0
  public String[] getAlleAvtaler(int d, int m, int a) {
    String dato = datoAsString(d, m, a);
    ArrayList<String> temp = new ArrayList<String>();
    ArrayList<Integer> ja = new ArrayList<Integer>();
    ArrayList<Integer> nei = new ArrayList<Integer>();
    ArrayList<Integer> ikkesvart = new ArrayList<Integer>();
    ResultSet rs =
        db.readQuery(
            "SELECT avtaleid, dato, starttid, sluttid, beskrivelse, romid, sted, kommer "
                + "FROM avtale NATURAL JOIN erinviterttil "
                + "WHERE dato = '"
                + dato
                + "' ORDER BY avtaleid");
    try {
      int count = -1;
      while (rs.next()) {
        String avtaleid = Integer.toString(rs.getInt(1));
        while (avtaleid.length() < 4) {
          avtaleid = "0" + avtaleid;
        }
        if (temp.size() == 0 || !(avtaleid.equals(temp.get(count).substring(0, 4)))) {
          count++;
          temp.add(
              avtaleid
                  + ": "
                  + rs.getString(2).substring(0, 2)
                  + "."
                  + rs.getString(2).substring(2, 4)
                  + "."
                  + rs.getString(2).substring(4)
                  + " "
                  + rs.getString(3)
                  + " - "
                  + rs.getString(4)
                  + ": "
                  + rs.getString(5)
                  + " i ");
          ikkesvart.add(0);
          ja.add(0);
          nei.add(0);
          if (rs.getString(6) == null) {
            temp.set(count, temp.get(count) + rs.getString(7) + ". ");
          } else {
            temp.set(count, temp.get(count) + "Rom " + rs.getInt(6) + ". ");
          }
        }
        if (rs.getString(8) == null) {
          ikkesvart.set(count, ikkesvart.get(count) + 1);
        } else if (rs.getBoolean(8)) {
          ja.set(count, ja.get(count) + 1);
        } else {
          nei.set(count, nei.get(count) + 1);
        }
      }
      for (int i = 0; i < temp.size(); i++) {
        temp.set(
            i,
            temp.get(i)
                + ja.get(i)
                + " har svart ja, "
                + nei.get(i)
                + " har svart nei, "
                + ikkesvart.get(i)
                + " har ikke svart.");
      }

    } catch (SQLException e) {
      e.printStackTrace();
    }
    String[] alleavtaler = new String[temp.size()];
    temp.toArray(alleavtaler);
    return alleavtaler;
  }