@Test public void testFindID() throws Exception { StudentManager db = new StudentManager(CONN); try { Student e = db.findStudent(1); assertEquals("ANNA", e.getFirstName().toUpperCase()); assertEquals("TRESS", e.getLastName().toUpperCase()); e = db.findStudent(2); assertEquals("DIANA", e.getFirstName().toUpperCase()); assertEquals("DOS", e.getLastName().toUpperCase()); } catch (Throwable var3) { fail(); } }
public static boolean checkIfAlreadyBegun(Student student) { String studentFilenameBegining = student.getLastName() + student.getFirstName().substring(0, 1); File[] studentResults = Folders.getFilesBeginningWith( "Results" + File.separator + studentFilenameBegining, studentFilenameBegining, "csv"); if (studentResults.length > 0) return true; else return false; }
/** Test of findStudents method, of class SimpleStudentRepository. */ @Test public void testFindStudents() { System.out.println("findStudents"); Student getS = instance.find(3); try { System.out.println(getS.getFirstName()); } catch (NullPointerException e) { Assert.fail("Wrong execute"); } }
public void insertStudent(Student student) throws SQLException { PreparedStatement stmt = null; try { stmt = con.prepareStatement( "INSERT INTO students " + "(firstName, patronymic, surName, sex, dateOfBirth, group_id, educationYear) " + "VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, student.getFirstName()); stmt.setString(2, student.getPatronymic()); stmt.setString(3, student.getSurName()); stmt.setString(4, new String(new char[] {student.getSex()})); stmt.setDate(5, new Date(student.getDateOfBirth().getTime())); stmt.setInt(6, student.getGroupId()); stmt.setInt(7, student.getEducationYear()); stmt.execute(); } finally { if (stmt != null) { stmt.close(); } } }
/** * Renders the JTable of the students being avoided given a student. * * @param student Student to render the avoiding list of * @return JTable of the students being avoided. */ public JTable makeTable(Student student) { String[] columns = {"Student ID", "First Name", "Last Name"}; ArrayList<Student> avoidingList = student.getAvoiding(); String[][] names = new String[avoidingList.size()][]; for (int i = 0; i < avoidingList.size(); i++) { Student avoiding = avoidingList.get(i); for (Student j : window.currentClass.getStudents()) { if (j.getStudentID() == avoiding.getStudentID()) { avoiding = j; } } names[i] = new String[] { Integer.toString(avoiding.getStudentID()), avoiding.getFirstName(), avoiding.getLastName() }; } JTable avoidingTable = new JTable(new CustomTableModel(names, columns)); /* * Shrinking size of table */ avoidingTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); for (int i = 0; i < 3; i++) { avoidingTable.getColumnModel().getColumn(i).setMaxWidth(250); } /* * Appearance Options */ avoidingTable.setDefaultRenderer(Object.class, new CustomTableRenderer()); avoidingTable.setShowGrid(false); return avoidingTable; }
@Override public Object getValueAt(int rowIndex, int columnIndex) { if ((rowIndex < 0) || (rowIndex >= students.size())) return null; else { Student s = this.activeCourse.getStudents().get(rowIndex); if (columnIndex == IDX_FIRST_NAME) { return s.getFirstName(); } else if (columnIndex == IDX_LAST_NAME) { return s.getLastName(); } else if (columnIndex == IDX_STUDENT_NUM) { return s.getNumber(); } else if (columnIndex == IDX_WEIGHTED_AVG) { return this.activeCourse.getWeightedAverage(s); } else if (columnIndex > IDX_WEIGHTED_AVG) { try { Double d = s.getGrade(columnIndex - 4); return d.toString(); } catch (NullPointerException e) { return " "; } } else return " "; } }
public void updateStudent(Student student) throws SQLException { PreparedStatement stmt = null; try { stmt = con.prepareStatement( "UPDATE students SET " + "firstName=?, patronymic=?, surName=?, " + "sex=?, dateOfBirth=?, group_id=?, educationYear=?" + "WHERE student_id=?"); stmt.setString(1, student.getFirstName()); stmt.setString(2, student.getPatronymic()); stmt.setString(3, student.getSurName()); stmt.setString(4, new String(new char[] {student.getSex()})); stmt.setDate(5, new Date(student.getDateOfBirth().getTime())); stmt.setInt(6, student.getGroupId()); stmt.setInt(7, student.getEducationYear()); stmt.setInt(8, student.getStudentId()); stmt.execute(); } finally { if (stmt != null) { stmt.close(); } } }
/** * Creates a small window for editing student information * * @param window Parent window * @param student Student to edit. */ public StudentInfoEditor(StudentsListTab window, Student student) { this.window = window; this.student = student; this.setTitle(student.getFirstName() + " " + student.getLastName()); this.tabs = new JTabbedPane(); this.avoidingTable = makeTable(student); this.scrollbar = new JScrollPane(this.avoidingTable); /* * Separation Tab */ JPanel buttonsPane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton newStudentButton = new JButton("New"); newStudentButton.setActionCommand("New Student"); newStudentButton.addActionListener(this); buttonsPane.add(newStudentButton); JButton delStudentButton = new JButton("Delete"); delStudentButton.setActionCommand("Delete Student"); delStudentButton.addActionListener(this); buttonsPane.add(delStudentButton); JPanel separationPanel = new JPanel(new BorderLayout()); separationPanel.add(scrollbar, BorderLayout.CENTER); separationPanel.add(buttonsPane, BorderLayout.PAGE_END); /* * Information Editing Tab contents */ /* * Name and student ID text fields for setting those of a student. */ JPanel studentIDSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel studentIDLabel = new JLabel("Student ID: "); this.studentIDField = new JTextField(Integer.toString(student.getStudentID())); this.studentIDField.setColumns(5); studentIDSetter.add(studentIDLabel); studentIDSetter.add(studentIDField); JPanel firstNameSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel firstNameLabel = new JLabel("First: "); this.firstNameField = new JTextField(student.getFirstName()); this.firstNameField.setColumns(8); firstNameSetter.add(firstNameLabel); firstNameSetter.add(firstNameField); JPanel lastNameSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel lastNameLabel = new JLabel("Last: "); this.lastNameField = new JTextField(student.getLastName()); this.lastNameField.setColumns(8); lastNameSetter.add(lastNameLabel); lastNameSetter.add(lastNameField); /* * Box to force assigned seating */ JPanel assignedSeatSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel assignedSeatLabel = new JLabel("Assigned Seat"); this.assignedSeatField = new JTextField(); for (int i = 0; i < 3; i++) { for (int j = 0; j < this.window.currentClass.getQuadrants().get(i).getSize(); j++) { Desk desk = this.window.currentClass.getQuadrants().get(i).getDesk(j); if (desk.isEditable() == false && desk.getOccupyingStudent().equals(student)) { switch (i) { case 0: this.assignedSeatField = new JTextField(Integer.toString(j + 1)); break; case 1: this.assignedSeatField = new JTextField(Integer.toString(j + 11)); break; case 2: this.assignedSeatField = new JTextField(Integer.toString(j + 23)); break; } } } } this.assignedSeatField.setColumns(2); assignedSeatSetter.add(assignedSeatLabel); assignedSeatSetter.add(assignedSeatField); /* * Box to set the race of a student. */ JPanel raceSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel raceNameLabel = new JLabel("Race: "); this.raceSelection = new JComboBox<String>( new String[] { "White", "Asian", "AfricanAmerican", "Latino", "PacificIslander", "Other" }); this.raceSelection.setSelectedItem(student.getRace().toString()); raceSetter.add(raceNameLabel); raceSetter.add(raceSelection); /* * Box to set the Gender of a student */ JPanel genderSetter = new JPanel(new FlowLayout(FlowLayout.LEFT)); JLabel genderLabel = new JLabel("Gender: "); this.genderSelection = new JComboBox<String>(new String[] {"Male", "Female", "Other"}); this.genderSelection.setSelectedItem(student.getGender().toString()); genderSetter.add(genderLabel); genderSetter.add(genderSelection); /* * Bottom button pane with save/cancel buttons */ JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); JButton saveChanges = new JButton("Save"); saveChanges.addActionListener(this); saveChanges.setActionCommand("Save"); JButton cancelChanges = new JButton("Cancel"); cancelChanges.addActionListener(this); cancelChanges.setActionCommand("Cancel"); buttonPane.add(saveChanges); buttonPane.add(cancelChanges); JPanel comboboxPane = new JPanel(new FlowLayout(FlowLayout.LEFT)); comboboxPane.add(genderSetter); JPanel informationPanel = new JPanel(); informationPanel.setLayout(new GridLayout(5, 2)); informationPanel.add(studentIDSetter); informationPanel.add(assignedSeatSetter); informationPanel.add(firstNameSetter); informationPanel.add(lastNameSetter); informationPanel.add(genderSetter); informationPanel.add(raceSetter); informationPanel.add(new JPanel()); informationPanel.add(buttonPane); tabs.addTab("Information", null, informationPanel); ; tabs.addTab("Separation", null, separationPanel); this.add(tabs, BorderLayout.CENTER); this.setResizable(false); this.setSize(400, 320); this.setLocationRelativeTo(null); this.setVisible(true); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); }
private void build(ReportXml report, Student student) { putDefaultValues(report.getValuesMap()); report.addValue("FACULTY_FULLNAME", student.getSpeciality().getFaculty().getFullName()); report.addValue("FACULTY_SHORTNAME", student.getSpeciality().getFaculty().getShortName()); report.addValue( "FACULTY_DEAN", student.getSpeciality().getFaculty().getDean().generateShortName(true)); report.addValue( "RECTOR", student .getSpeciality() .getFaculty() .getAdministration() .getRector() .generateShortName(true)); report.addValue( "RECTOR_DEGREE", student.getSpeciality().getFaculty().getAdministration().getRector().getDegree()); report.addValue( "Student.fullName", student.getLastName() + " " + student.getFirstName() + " " + student.getMiddleName()); report.addValue("Student.lastName", student.getLastName()); report.addValue("Student.firstName", student.getFirstName()); report.addValue("Student.middleName", student.getMiddleName()); report.addValue("Student.courseNumber", student.getGroup().getCourse().toString()); report.addValue("Student.speciality", student.getSpeciality().getShortName()); report.addValue("Student.specialityCode", student.getSpeciality().getCode()); EnrollmentOrder order = student.getEnrollmentOrder(); String division = "неизвестного"; switch (student.getDivision()) { case INTRAMURAL: division = "очного"; break; case EXTRAMURAL: division = "заочного"; break; case EVENINGSTUDY: division = "вечернего"; break; } report.addValue("Student.division_rad", division); SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); SimpleDateFormat dateFormatYear = new SimpleDateFormat("yyyy"); Date date = order.getEnrollmentDate(); // Борьба с ленивой загрузкой // http://forum.vingrad.ru/forum/topic-258355.html // http://www.javalobby.org/java/forums/t62077.html // .initialize(student.getAdditionalData()); // Hibernate.initialize(student.getAdditionalData().getPhoto()); report.addValue("Student.birthday", dateFormat.format(student.getBirthday())); report.addValue("Student.birthPlace", student.getAdditionalData().getBirthPlace()); report.addValue("Student.photoData", student.getAdditionalData().getPhoto().getData()); report.addValue("Student.startDate", dateFormat.format(date)); // "01.09.2007" report.addValue("Student.startYear", dateFormatYear.format(date)); report.addValue("Student.endDate", dateFormat.format(student.getReleaseDate())); // "01.07.2012" report.addValue("Student.order.number", order.getNumber()); // "22-0107" report.addValue("Student.order.date", dateFormat.format(order.getSignedDate())); // "12.08.2007" String studyForm = "неизвестная"; switch (student.getStudyForm()) { case BUDGET: studyForm = "бюджетная"; break; case COMMERCIAL: studyForm = "коммерческая"; break; } report.addValue("Student.studyForm", studyForm); String str = ""; switch (student.getSex()) { case MALE: str = "М"; break; case FEMALE: str = "Ж"; break; } report.addValue("Student.sex", str); report.addValue("Student.education", student.getAdditionalData().getEducation()); report.addValue("Student.workInfo", student.getAdditionalData().getWorkInfo()); str = student.getAdditionalData().getMaritalStatus(); report.addValue("Student.maritalStatus", str == null ? "\n" : str); str = student.getAdditionalData().getChildrenInfo(); report.addValue("Student.childrenInfo", str == null ? "\n" : str); Passport firstPassport = student.getAdditionalData().getPassports().get(0); Passport lastPassport; /*Passport actualPasport = null; for (Passport currentPassport : student.getAdditionalData().getPassports()) { if (currentPassport.isActual()) { actualPasport = currentPassport; break; } } report.addValue("Student.citizenship", actualPasport.getCitizenship()); */ if (student.getAdditionalData().getPassports().size() > 1) { lastPassport = student .getAdditionalData() .getPassports() .get(student.getAdditionalData().getPassports().size() - 1); report.addValue("Student.citizenship", lastPassport.getCitizenship()); } else { lastPassport = new Passport(); new PassportServiceImpl().fillAllFields(lastPassport, ""); report.addValue("Student.citizenship", firstPassport.getCitizenship()); } report.addValue( "Student.firstPassport.fullName", firstPassport.getLastName() + " " + firstPassport.getFirstName() + " " + firstPassport.getMiddleName()); report.addValue("Student.firstPassport.citizenship", firstPassport.getCitizenship()); report.addValue("Student.firstPassport.number", firstPassport.getNumber()); report.addValue("Student.firstPassport.series", firstPassport.getSeries()); report.addValue( "Student.firstPassport.issuedDate", dateFormat.format(firstPassport.getIssuedDate())); report.addValue( "Student.firstPassport.issuingOrganization", firstPassport.getIssuingOrganization()); report.addValue( "Student.lastPassport.fullName", lastPassport.getLastName() + " " + lastPassport.getFirstName() + " " + lastPassport.getMiddleName()); report.addValue("Student.lastPassport.citizenship", lastPassport.getCitizenship()); report.addValue("Student.lastPassport.number", lastPassport.getNumber()); report.addValue("Student.lastPassport.series", lastPassport.getSeries()); report.addValue( "Student.lastPassport.issuedDate", lastPassport.getIssuedDate() == null ? "" : dateFormat.format(lastPassport.getIssuedDate())); report.addValue( "Student.lastPassport.issuingOrganization", lastPassport.getIssuingOrganization()); Parent father = student.getAdditionalData().getFather(); Parent mother = student.getAdditionalData().getMother(); report.addValue( "Student.father.fullName", father.getLastName() + " " + father.getFirstName() + " " + father.getMiddleName()); report.addValue("Student.father.birthday", dateFormat.format(father.getBirthday())); report.addValue("Student.father.address", father.getAddress()); report.addValue("Student.father.workInfo", father.getWorkInfo()); report.addValue("Student.father.phoneNumbers", father.getPhoneNumbers()); report.addValue( "Student.mother.fullName", mother.getLastName() + " " + mother.getFirstName() + " " + mother.getMiddleName()); report.addValue("Student.mother.birthday", dateFormat.format(mother.getBirthday())); report.addValue("Student.mother.address", mother.getAddress()); report.addValue("Student.mother.workInfo", mother.getWorkInfo()); report.addValue("Student.mother.phoneNumbers", mother.getPhoneNumbers()); report.addValue("Student.oldAddress", student.getAdditionalData().getOldAddress()); report.addValue("Student.actualAddress", student.getAdditionalData().getActualAddress()); report.addValue( "Student.passportAddress", student.getAdditionalData().getPassports().size() > 1 ? lastPassport.getAddress() : firstPassport.getAddress()); }