Search in sources :

Example 6 with Question

use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.

the class LibraryImportTest method loadSubjective.

private boolean loadSubjective(File source, List<Question> questions) {
    Object[][] result = ExcelUtil.readExcelSheet(source.getAbsolutePath(), QuestionType.SUBJECTIVE.getSheetName(), 2);
    for (int i = 2; i < result.length; i++) {
        Object descObj = result[i][0];
        if (Util.isEmpty(descObj)) {
            String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.stem"));
            System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
            return false;
        }
        String title = String.valueOf(descObj).replaceAll("\\(", "(").replaceAll("\\)", ")").trim();
        if (title.length() > 250) {
            String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.stem"), 250);
            System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
            return false;
        }
        Object analysisObj = result[i][1];
        String analysis = String.valueOf(analysisObj).trim();
        if (analysis.length() > 250) {
            String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.analysis"), 250);
            System.out.println(MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
            return false;
        }
        Question question = new Question();
        question.setRelateId(rid);
        question.setTitle(title);
        question.setAnalysis(analysis);
        question.setType(3);
        question.setCreator(1);
        questions.add(question);
    }
    return true;
}
Also used : Question(com.cas.sim.tis.entity.Question)

Example 7 with Question

use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.

the class PreviewQuestionPaper method importExcel.

@FXML
private void importExcel() {
    FileChooser chooser = new FileChooser();
    chooser.setInitialDirectory(FileSystemView.getFileSystemView().getHomeDirectory());
    chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(MsgUtil.getMessage("resource.excel"), "*.xls"));
    File source = chooser.showOpenDialog(GUIState.getStage());
    if (source == null) {
        return;
    }
    List<Question> questions = new ArrayList<>();
    if (!loadChoice(source, questions) || !loadJudgment(source, questions) || !loadBlank(source, questions) || !loadSubjective(source, questions)) {
        return;
    }
    try {
        SpringUtil.getBean(QuestionAction.class).addQuestions(rid, questions);
        loadQuestions();
        this.options.getChildren().remove(importBtn);
        this.options.getChildren().add(exportBtn);
        AlertUtil.showAlert(AlertType.INFORMATION, MsgUtil.getMessage("excel.import.success"));
    } catch (Exception e) {
        e.printStackTrace();
        AlertUtil.showAlert(AlertType.ERROR, e.getMessage());
    }
}
Also used : QuestionAction(com.cas.sim.tis.action.QuestionAction) FileChooser(javafx.stage.FileChooser) ArrayList(java.util.ArrayList) Question(com.cas.sim.tis.entity.Question) File(java.io.File) IOException(java.io.IOException) FXML(javafx.fxml.FXML)

Example 8 with Question

use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.

the class PreviewQuestionPaper method loadBlank.

private boolean loadBlank(File source, List<Question> questions) {
    Object[][] result = ExcelUtil.readExcelSheet(source.getAbsolutePath(), QuestionType.BLANK.getSheetName(), 4);
    for (int i = 2; i < result.length; i++) {
        Object descObj = result[i][0];
        if (Util.isEmpty(descObj)) {
            String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.stem"));
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
            return false;
        }
        String title = String.valueOf(descObj).replaceAll("\\(", "(").replaceAll("\\)", ")").replaceAll("()", "(|)").trim();
        if (title.length() > 250) {
            String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.stem"), 250);
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 1, reason));
            return false;
        }
        Object referenceObj = result[i][1];
        if (Util.isEmpty(referenceObj)) {
            String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.reference"));
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
            return false;
        }
        String reference = String.valueOf(referenceObj).replace("\r\n", "|").replace("\n", "|").trim();
        if (reference.length() > 250) {
            String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.reference"), 250);
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
            return false;
        }
        Object pointObj = result[i][2];
        if (Util.isEmpty(pointObj)) {
            String reason = MsgUtil.getMessage("alert.warning.cant.null", MsgUtil.getMessage("question.point"));
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
            return false;
        }
        String point = String.valueOf(pointObj).replace("\r\n", "|").replace("\n", "|").trim();
        if (!Util.isNumeric(point)) {
            String reason = MsgUtil.getMessage("alert.warning.not.number", MsgUtil.getMessage("question.point"));
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 2, reason));
            return false;
        }
        Object analysisObj = result[i][3];
        String analysis = String.valueOf(analysisObj).trim();
        if (analysis.length() > 250) {
            String reason = MsgUtil.getMessage("alert.warning.over.length", MsgUtil.getMessage("question.analysis"), 250);
            AlertUtil.showAlert(AlertType.WARNING, MsgUtil.getMessage("excel.import.error", i + 1, 4, reason));
            return false;
        }
        Question question = new Question();
        question.setRelateId(rid);
        question.setTitle(title);
        question.setAnalysis(analysis);
        question.setPoint(Float.parseFloat(point));
        question.setReference(reference);
        question.setType(QuestionType.BLANK.getType());
        question.setCreator(Session.get(Session.KEY_LOGIN_ID));
        questions.add(question);
    }
    return true;
}
Also used : Question(com.cas.sim.tis.entity.Question)

Example 9 with Question

use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.

the class PreviewQuestionPaper method exportBlank.

private void exportBlank(Map<String, Object[][]> datas) {
    List<Question> questions = SpringUtil.getBean(QuestionAction.class).findQuestionsByLibraryAndQuestionType(rid, QuestionType.BLANK.getType());
    Object[][] data = new Object[questions.size() + 1][3];
    for (int i = 0; i < questions.size(); i++) {
        Question question = questions.get(i);
        data[i + 1][0] = question.getTitle().replaceAll("\\|", "");
        data[i + 1][1] = question.getReference().replaceAll("\\|", "\r\n");
        data[i + 1][2] = question.getAnalysis();
    }
    datas.put(QuestionType.BLANK.getSheetName(), data);
}
Also used : QuestionAction(com.cas.sim.tis.action.QuestionAction) Question(com.cas.sim.tis.entity.Question)

Example 10 with Question

use of com.cas.sim.tis.entity.Question in project TeachingInSimulation by ScOrPiOzzy.

the class PreviewQuestionPaper method loadQuestions.

private void loadQuestions() {
    this.paper.getChildren().clear();
    List<Question> choices = loadQuestionsByType(QuestionType.CHOICE);
    List<Question> judgments = loadQuestionsByType(QuestionType.JUDGMENT);
    List<Question> blanks = loadQuestionsByType(QuestionType.BLANK);
    List<Question> subjectives = loadQuestionsByType(QuestionType.SUBJECTIVE);
    List<Question> questions = new ArrayList<>();
    questions.addAll(choices);
    questions.addAll(judgments);
    questions.addAll(blanks);
    questions.addAll(subjectives);
    for (int i = 0; i < questions.size(); i++) {
        int index = i + 1;
        Question question = questions.get(i);
        PreviewQuestionItem item = new PreviewQuestionItem(index, QuestionType.getQuestionType(question.getType()), question, showReference);
        paper.getChildren().add(item);
    }
    ObservableList<Data> datas = // 
    FXCollections.observableArrayList(// 
    new PieChart.Data(MsgUtil.getMessage("question.choice"), choices.size()), // 
    new PieChart.Data(MsgUtil.getMessage("question.judgment"), judgments.size()), // 
    new PieChart.Data(MsgUtil.getMessage("question.blank"), blanks.size()), // 
    new PieChart.Data(MsgUtil.getMessage("question.subjective"), subjectives.size()));
    chart.setData(datas);
    for (final PieChart.Data data : chart.getData()) {
        Node node = data.getNode();
        node.setOnMouseEntered(e -> {
            tip.setText(data.getName() + ":" + (int) data.getPieValue());
            tip.setVisible(true);
        });
        node.setOnMouseExited(e -> {
            tip.setVisible(false);
        });
    }
}
Also used : Data(javafx.scene.chart.PieChart.Data) PieChart(javafx.scene.chart.PieChart) Node(javafx.scene.Node) ArrayList(java.util.ArrayList) Question(com.cas.sim.tis.entity.Question) Data(javafx.scene.chart.PieChart.Data)

Aggregations

Question (com.cas.sim.tis.entity.Question)20 QuestionAction (com.cas.sim.tis.action.QuestionAction)7 ArrayList (java.util.ArrayList)4 LibraryAnswer (com.cas.sim.tis.entity.LibraryAnswer)3 ToggleButton (javafx.scene.control.ToggleButton)2 LibraryAnswerAction (com.cas.sim.tis.action.LibraryAnswerAction)1 LibraryRecordAction (com.cas.sim.tis.action.LibraryRecordAction)1 Library (com.cas.sim.tis.entity.Library)1 LibraryRecord (com.cas.sim.tis.entity.LibraryRecord)1 LibraryService (com.cas.sim.tis.services.LibraryService)1 PageInfo (com.github.pagehelper.PageInfo)1 File (java.io.File)1 IOException (java.io.IOException)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 ActionEvent (javafx.event.ActionEvent)1 FXML (javafx.fxml.FXML)1 Node (javafx.scene.Node)1 PieChart (javafx.scene.chart.PieChart)1 Data (javafx.scene.chart.PieChart.Data)1