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;
}
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());
}
}
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;
}
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);
}
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);
});
}
}
Aggregations