예제 #1
0
 public ArrayList<Event> queryEvents(User user) {
   ArrayList<Event> events = new ArrayList<Event>();
   String query =
       String.format(
           SELECT_FROM_WHERE,
           "event." + FIELDS_EVENT,
           TABLE_EVENT + " JOIN " + TABLE_IS_OWNER + " ON event.eventID=isOwner.eventID ",
           "username='******'");
   ArrayList<Properties> pl = dbComm.query(query);
   for (Properties p : pl) {
     events.add(makeEvent(p, true));
   }
   return events;
 }
예제 #2
0
 private Alarm queryAlarm(User user, int eventID) {
   ArrayList<Properties> pl =
       dbComm.query(
           String.format(
               SELECT_FROM_WHERE,
               FIELDS_ALARM,
               TABLE_ALARM,
               "username='******' and eventID=" + eventID));
   if (pl.size() > 0) {
     Properties p = pl.get(0);
     return makeAlarm(p, false);
   } else {
     return null;
   }
 }
  private void jButton1ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton1ActionPerformed

    try {
      String status = null;
      if (jRadioButton1.isSelected()) status = "Student";
      else if (jRadioButton2.isSelected()) status = "Teacher";

      User u = new User();
      u.setUsername(jTextField8.getText());
      u.setPassword(jPasswordField1.getText());
      u.setFirstname(jTextField1.getText());
      u.setLastname(jTextField2.getText());
      u.setStudentID(jTextField3.getText());
      u.setBirthDay(jTextField4.getText());
      u.setTelephone(jTextField5.getText());
      u.setEmail(jTextField6.getText());
      u.setFacebook(jTextField7.getText());
      u.setStatus(status);

      SQLConnection MyCon = new SQLConnection();
      Connection c = MyCon.getConnection("journal");
      Statement stmt = c.createStatement();
      // String name = MyCon.getUsername();
      String checkname, checkid;
      int foundname = 0, foundid = 0;
      String SQL = "select * from profile ;";
      ResultSet rs = stmt.executeQuery(SQL);
      while (rs.next()) {
        checkname = rs.getString("username");
        if (checkname.toUpperCase().equals(jTextField8.getText().toUpperCase())) {
          foundname = 1;
          break;
        }
        checkid = rs.getString("studentID");
        if (checkid.toUpperCase().equals(jTextField3.getText().toUpperCase())) {
          foundid = 1;
          break;
        }
      }

      if (u.getUsername().equalsIgnoreCase("")) {
        jLabel12.setVisible(true);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (foundname == 1) {
        JOptionPane.showMessageDialog(null, "Username " + jTextField8.getText() + " is already");
        jLabel12.setVisible(true);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getPassword().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(true);
      } else if (u.getFirstname().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(true);
        jLabel16.setVisible(false);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getLastname().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(true);
        jLabel17.setVisible(false);
        jLabel18.setVisible(false);
      } else if (u.getStudentID().equalsIgnoreCase("")) {
        jLabel12.setVisible(false);
        jLabel15.setVisible(false);
        jLabel16.setVisible(false);
        jLabel17.setVisible(true);
        jLabel18.setVisible(false);
      } else if (foundid == 1) {
        JOptionPane.showMessageDialog(null, "StudentID " + jTextField3.getText() + " is already");
      } else {
        SQLConnection mycon = new SQLConnection();
        mycon.SQLInsertProfile(u);
        mycon.SQLcreateTableForUser(jTextField8.getText());
        mycon.useUsername(jTextField8.getText());
        new ShowProfile().show();
        this.dispose();
      }
    } catch (SQLException ex) {
      Logger.getLogger(CreateProfile.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // GEN-LAST:event_jButton1ActionPerformed
  private void saveAppointment() {
    String title = titleField.getText();
    String descr = descriptionField.getText();

    // construct starttime
    int syear = startTime.getDate().getYear();
    int smonth = startTime.getDate().getMonth();
    int sddate = startTime.getDate().getDate();
    int sh = (Integer) startHourSpinner.getValue();
    int sm = (Integer) startMinuteSpinner.getValue();
    Date sDate = new Date(syear, smonth, sddate, sh, sm);

    // set startTime
    Calendar start = new GregorianCalendar();
    start.setTime(sDate);

    // construct endTime
    int eyear = endTime.getDate().getYear();
    int emonth = endTime.getDate().getMonth();
    int eddate = endTime.getDate().getDate();
    int eh = (Integer) endHourSpinner.getValue();
    int em = (Integer) endMinuteSpinner.getValue();
    Date eDate = new Date(eyear, emonth, eddate, eh, em);

    // set endTime
    Calendar finish = new GregorianCalendar();
    finish.setTime(eDate);

    User owner = main.getUser();
    Room r = (Room) roomList.getSelectedValue();
    Appointment saveApp;

    if (isNull) {
      saveApp = new Appointment(0, title, start, finish, owner);
    } else {
      saveApp = new Appointment(model.getAppointmentId(), title, start, finish, owner);
    }

    // legg til participants
    ArrayList<Participant> deletablePart = new ArrayList<Participant>();

    Map<String, User> userMap = new HashMap<String, User>();
    userMap.put(owner.getUsername(), owner);
    for (int i = 0; i < personListModel.getSize(); i++) {
      userMap.put(((User) personListModel.get(i)).getUsername(), ((User) personListModel.get(i)));
    }

    // fra gruppe
    for (int i = 0; i < groupListModel.getSize(); i++) {
      ArrayList<Member> members = ((Group) groupListModel.get(i)).getMembers();
      for (int j = 0; j < members.size(); j++) {
        userMap.put(members.get(j).getUser().getUserName(), members.get(j).getUser());
      }
    }

    ArrayList<User> allPart = new ArrayList<User>(userMap.values());

    for (int i = 0; i < allPart.size(); i++) {
      deletablePart.add(new Participant(saveApp, allPart.get(i)));
    }

    saveApp.setRoom(r);
    saveApp.setDescription(descr);

    if (isNull) {
      main.getServer().insertAppointment(saveApp);
    } else {
      main.getServer().updateAppointment(saveApp, model);
    }

    // delete participants
    for (int i = 0; i < deletablePart.size(); i++) {
      deletablePart.get(i).remove();
    }
    saveApp.remove();
  }