Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Update information about a course
- public void setCourseInfo(String iD, JTextField newCourseName, String newCourseStart, String newCourseEnd, JComboBox newTeacher, JComboBox newSubject) {
- try {
- //Name of the new course
- String course = newCourseName.getText();
- //Dates
- DateFormat format = new SimpleDateFormat("yyyy-MM-d", Locale.GERMAN);
- Date startDate = format.parse(newCourseStart);
- DateFormat format2 = new SimpleDateFormat("yyyy-MM-d", Locale.GERMAN);
- Date endDate = format2.parse(newCourseEnd);
- //New id
- String tempTeacher = newTeacher.getSelectedItem().toString();
- String[] splitStr = tempTeacher.split("\\s+");
- String teacherId = getIdTeacher(splitStr[0], splitStr[1]);
- //get subject Id for course
- String courseSubject = newSubject.getSelectedItem().toString();
- String subjectId = getSubjectId(courseSubject);
- //The accual command to insert new course
- String command = "UPDATE kurs SET kursnamn= '" + course + "', kursstart= '" + startDate + "', kursslut= '" + endDate + "', kurslarare= " + teacherId + ", amnestillhorighet= " + subjectId +
- "WHERE kurs_id=" + iD;
- hwdb.insert(command);
- } catch (InfException e) {
- System.out.println(e.getMessage());
- } catch (ParseException er) {
- System.out.println(er.getMessage());
- }
- }
- //Remove a course from the system
- public void deleteCourse(JComboBox courseName) {
- try {
- //Get courseId from a coursename in a combobox
- String course = courseName.getSelectedItem().toString();
- String command = "SELECT kurs_id FROM kurs WHERE kursnamn= '" + course + "'";
- String courseId = hwdb.fetchSingle(command);
- //Delete course from various places
- String command1 = "DELETE FROM har_betyg_i WHERE kurs_id=" + courseId;
- hwdb.delete(command1);
- String command2 = "DELETE FROM registrerad_pa WHERE kurs_id=" + courseId;
- hwdb.delete(command2);
- String command3 = "DELETE FROM kurs WHERE kurs_id=" + courseId;
- hwdb.delete(command3);
- } catch (InfException e) {
- System.out.println(e.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement