Advertisement
Guest User

Untitled

a guest
May 21st, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. //Update information about a course
  2.     public void setCourseInfo(String iD, JTextField newCourseName, String newCourseStart, String newCourseEnd, JComboBox newTeacher, JComboBox newSubject) {
  3.     try {
  4.             //Name of the new course
  5.             String course = newCourseName.getText();
  6.             //Dates
  7.             DateFormat format = new SimpleDateFormat("yyyy-MM-d", Locale.GERMAN);
  8.             Date startDate = format.parse(newCourseStart);
  9.             DateFormat format2 = new SimpleDateFormat("yyyy-MM-d", Locale.GERMAN);
  10.             Date endDate = format2.parse(newCourseEnd);
  11.             //New id
  12.             String tempTeacher = newTeacher.getSelectedItem().toString();
  13.             String[] splitStr = tempTeacher.split("\\s+");
  14.             String teacherId = getIdTeacher(splitStr[0], splitStr[1]);
  15.             //get subject Id for course
  16.             String courseSubject = newSubject.getSelectedItem().toString();
  17.             String subjectId = getSubjectId(courseSubject);
  18.             //The accual command to insert new course
  19.             String command = "UPDATE kurs SET kursnamn= '" + course + "', kursstart= '" + startDate + "', kursslut= '" + endDate + "', kurslarare= " + teacherId + ", amnestillhorighet= " + subjectId +
  20.                     "WHERE kurs_id=" + iD;
  21.             hwdb.insert(command);
  22.         } catch (InfException e) {
  23.             System.out.println(e.getMessage());
  24.         } catch (ParseException er) {
  25.             System.out.println(er.getMessage());
  26.         }
  27.     }
  28.    
  29.     //Remove a course from the system
  30.     public void deleteCourse(JComboBox courseName) {
  31.         try {
  32.             //Get courseId from a coursename in a combobox
  33.             String course = courseName.getSelectedItem().toString();
  34.             String command = "SELECT kurs_id FROM kurs WHERE kursnamn= '" + course + "'";
  35.             String courseId = hwdb.fetchSingle(command);
  36.             //Delete course from various places
  37.             String command1 = "DELETE FROM har_betyg_i WHERE kurs_id=" + courseId;
  38.             hwdb.delete(command1);
  39.             String command2 = "DELETE FROM registrerad_pa WHERE kurs_id=" + courseId;
  40.             hwdb.delete(command2);
  41.             String command3 = "DELETE FROM kurs WHERE kurs_id=" + courseId;
  42.             hwdb.delete(command3);
  43.         } catch (InfException e) {
  44.             System.out.println(e.getMessage());
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement