Skip to content

Commit

Permalink
update teacher function 6 and sql file
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenquan123vn committed May 11, 2019
1 parent 326d739 commit 21d6071
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 246 deletions.
19 changes: 19 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

385 changes: 224 additions & 161 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions UETConnect.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
Binary file not shown.
Binary file modified out/production/UETConnect/home/controllers/Timetable.class
Binary file not shown.
16 changes: 0 additions & 16 deletions out/production/UETConnect/home/fxml/subject1.fxml

This file was deleted.

Binary file modified out/production/UETConnect/home/util/StudentModel.class
Binary file not shown.
4 changes: 0 additions & 4 deletions src/home/controllers/Subject1.java

This file was deleted.

3 changes: 0 additions & 3 deletions src/home/controllers/Timetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ public void run() {
}
};




updateTimeThread.setPriority(Thread.MIN_PRIORITY);
updateTimeThread.setDaemon(true);
updateTimeThread.start();
Expand Down
4 changes: 2 additions & 2 deletions src/home/controllers/coursesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public void initialize(URL location, ResourceBundle resources){
} catch (SQLException e) {
e.printStackTrace();
}
week.setCellValueFactory(new PropertyValueFactory<>("Week"));
week.setCellValueFactory(new PropertyValueFactory<>("week"));
week.setMinWidth(50);
date.setCellValueFactory(new PropertyValueFactory<>("Date"));
date.setCellValueFactory(new PropertyValueFactory<>("date"));
date.setMinWidth(200);
fileName.setCellValueFactory(new PropertyValueFactory<>("fileName"));
fileName.setMinWidth(300);
Expand Down
14 changes: 6 additions & 8 deletions src/home/controllers/myCourseTeacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ public void handleFunctions(ActionEvent actionEvent) throws IOException, SQLExce
list1.getItems().remove(index);
delete(substr);
} else if (actionEvent.getSource() == viewStudentbtn) {
buildData(substr);
StackPane root = new StackPane();
Parent root = FXMLLoader.load(getClass().getResource("/home/fxml/studentListView.fxml"));
Stage stage = new Stage();
root.setPadding(new Insets(10));
root.getChildren().add(tableView);
Scene scene = new Scene(root, 370, 300);
stage.setScene(scene);
stage.setScene(new Scene(root));
stage.initModality(Modality.WINDOW_MODAL);
stage.setTitle("Student List" + str);
stage.show();
}
} else if (actionEvent.getSource() == newCoursebtn) {
Expand Down Expand Up @@ -222,7 +220,7 @@ public ListView<String> getList() {
return list1;
}

public void buildData(String string) throws SQLException{
/*public void buildData(String string) throws SQLException{
String sql = "SELECT s1.studentId, s1.studentName, s.grade FROM uetcourse.students_subjects as s inner join uetcourse.studentsInfo as s1 where s.studentsId = s1.studentId and s.classId = ?;";
ResultSet rs = null;
try{
Expand Down Expand Up @@ -268,7 +266,7 @@ private ArrayList dataBaseArrayList(ResultSet resultSet) throws SQLException{
data.add(new StudentModel(resultSet.getString(1),resultSet.getString(2), resultSet.getString(3)));
}
return data;
}
} */
/*
private void handleUpdate(TableColumn column){
tableView.setEditable(true);
Expand Down
147 changes: 147 additions & 0 deletions src/home/controllers/studentListView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package home.controllers;

import home.util.ConnectionUtil;
import home.util.StudentModel;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;

import java.net.URL;
import java.sql.*;
import java.util.ResourceBundle;

public class studentListView implements Initializable {

@FXML
private TableView<StudentModel> table;
@FXML
private TableColumn<StudentModel,String> studId;
@FXML
private TableColumn<StudentModel,String> studName;
@FXML
private TableColumn<StudentModel, String> midTerm;
@FXML
private TableColumn<StudentModel, String> finalEx;
@FXML
private TableColumn<StudentModel, String> attendance;

private ObservableList<StudentModel> listStudent = FXCollections.observableArrayList();

@Override
public void initialize(URL location, ResourceBundle resources) {
buildData();
studId.setCellValueFactory(new PropertyValueFactory<>("studId"));
studName.setCellValueFactory(new PropertyValueFactory<>("studName"));
midTerm.setCellValueFactory(new PropertyValueFactory<>("midterm"));
midTerm.setCellFactory(TextFieldTableCell.forTableColumn());
finalEx.setCellValueFactory(new PropertyValueFactory<>("finalEx"));
finalEx.setCellFactory(TextFieldTableCell.forTableColumn());
attendance.setCellValueFactory(new PropertyValueFactory<>("attendance"));
attendance.setCellFactory(TextFieldTableCell.forTableColumn());
handleEdit();
}

public void buildData(){
Connection conn = ConnectionUtil.connectdb();
String sql = "SELECT distinct ss.studentsId, s1.studentName, ss.midterm, ss.final, ss.attendance FROM uetcourse.students_subjects as ss\n" +
"inner join uetcourse.studentsInfo as s1 inner join uetcourse.classes as c\n" +
"where ss.studentsId = s1.studentId and ss.classId = ?";
try{
PreparedStatement pre = conn.prepareStatement(sql);
pre.setString(1,myCourseTeacher.getClassID());
ResultSet rs = pre.executeQuery();
while (rs.next()){
listStudent.add(new StudentModel(rs.getString(1), rs.getString(2), setupGrade(rs.getString(3)), setupGrade(rs.getString(4)), setupAttendance(rs.getString(5))));
}
table.setItems(listStudent);
} catch (SQLException e){
e.printStackTrace();
}
}

public void refresh(){
listStudent.clear();
table.getItems().clear();
buildData();
}

public void updateDb(String sql, String str, String id){
Connection con = ConnectionUtil.connectdb();
try {
PreparedStatement preparedStatement = con.prepareStatement(sql);
preparedStatement.setString(1, str);
preparedStatement.setString(2,id);
preparedStatement.setString(3,myCourseTeacher.getClassID());
preparedStatement.executeUpdate();
} catch (SQLException e){
e.printStackTrace();
}
}

public void handleEdit(){
table.setEditable(true);
table.getSelectionModel().cellSelectionEnabledProperty().set(true);

midTerm.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<StudentModel, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<StudentModel, String> event) {
String id = event.getTableView().getItems().get(event.getTablePosition().getRow()).getStudId();
System.out.println(id);
((StudentModel) event.getTableView().getItems().get(event.getTablePosition().getRow())).setMidterm(event.getNewValue());
String str = event.getTableView().getItems().get(event.getTablePosition().getRow()).getMidterm();
System.out.println(str);
String sql = "UPDATE uetcourse.students_subjects SET midterm = ? WHERE studentsId = ? && classId = ?";
updateDb(sql, str, id);
refresh();
}
});
finalEx.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<StudentModel, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<StudentModel, String> event) {
String id = event.getTableView().getItems().get(event.getTablePosition().getRow()).getStudId();
System.out.println(id);
((StudentModel) event.getTableView().getItems().get(event.getTablePosition().getRow())).setFinalEx(event.getNewValue());
String str = event.getTableView().getItems().get(event.getTablePosition().getRow()).getFinalEx();
System.out.println(str);
String sql = "UPDATE uetcourse.students_subjects SET final = ? WHERE studentsId = ? && classId = ?";
updateDb(sql, str, id);
refresh();
}
});
attendance.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<StudentModel, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<StudentModel, String> event) {
String id = event.getTableView().getItems().get(event.getTablePosition().getRow()).getStudId();
System.out.println(id);
((StudentModel) event.getTableView().getItems().get(event.getTablePosition().getRow())).setAttendance(event.getNewValue());
String str = event.getTableView().getItems().get(event.getTablePosition().getRow()).getAttendance();
System.out.println(str);
String sql = "UPDATE uetcourse.students_subjects SET attendance = ? WHERE studentsId = ? && classId = ?";
updateDb(sql, str, id);
refresh();
}
});
}

private String setupGrade(String grade){
if(Double.parseDouble(grade) >= 0){
} else {
grade = "Not yet grade";
}
return grade;
}

private String setupAttendance(String attendance){
if(attendance == null){
attendance = "0";
}
return attendance;
}
}
19 changes: 19 additions & 0 deletions src/home/fxml/studentListView.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="home.controllers.studentListView">
<children>
<TableView fx:id="table" fixedCellSize="0.0" prefHeight="400.0" prefWidth="600.0">
<columns>
<TableColumn fx:id="studId" prefWidth="75.0" text="MSSV" />
<TableColumn fx:id="studName" prefWidth="188.0" text="Ho va ten" />
<TableColumn fx:id="midTerm" onEditCommit="#handleEdit" prefWidth="102.0" text="Giua Ki" />
<TableColumn fx:id="finalEx" onEditCommit="#handleEdit" prefWidth="115.0" text="Cuoi Ky" />
<TableColumn fx:id="attendance" onEditCommit="#handleEdit" prefWidth="119.0" text="Diem Danh" />
</columns>
</TableView>
</children>
</AnchorPane>
16 changes: 0 additions & 16 deletions src/home/fxml/subject1.fxml

This file was deleted.

63 changes: 27 additions & 36 deletions src/home/util/StudentModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,55 @@

public class StudentModel {

public SimpleStringProperty studentId = new SimpleStringProperty();
public SimpleStringProperty studentName = new SimpleStringProperty();
public SimpleStringProperty grade = new SimpleStringProperty();
public SimpleStringProperty classId = new SimpleStringProperty();
private String studId, studName, midterm, finalEx, attendance;

public StudentModel(){}

public StudentModel(String studId, String studName, String grade){
this.studentId = new SimpleStringProperty(studId);
this.studentName = new SimpleStringProperty(studName);
this.grade = new SimpleStringProperty(grade);
public StudentModel(String studId, String studName, String midterm, String finalEx, String attendance){
this.studId = studId;
this.studName = studName;
this.midterm = midterm;
this.finalEx = finalEx;
this.attendance = attendance;
}

public void setClassId(String classId) {
this.classId.set(classId);
public String getAttendance() {
return attendance;
}

public void setGrade(String grade) {
this.grade.set(grade);
public void setAttendance(String attendance) {
this.attendance = attendance;
}

public void setStudentId(String studentId) {
this.studentId.set(studentId);
public String getFinalEx() {
return finalEx;
}

public void setStudentName(String studentName) {
this.studentName.set(studentName);
public void setFinalEx(String finalEx) {
this.finalEx = finalEx;
}

public String getStudentId() {
return studentId.get();
public String getMidterm() {
return midterm;
}

public SimpleStringProperty studentIdProperty() {
return studentId;
public void setMidterm(String midterm) {
this.midterm = midterm;
}

public String getStudentName() {
return studentName.get();
public String getStudId() {
return studId;
}

public SimpleStringProperty studentNameProperty() {
return studentName;
public void setStudId(String studId) {
this.studId = studId;
}

public String getGrade() {
return grade.get();
public String getStudName() {
return studName;
}

public SimpleStringProperty gradeProperty() {
return grade;
}

public String getClassId() {
return classId.get();
}

public SimpleStringProperty classIdProperty() {
return classId;
public void setStudName(String studName) {
this.studName = studName;
}
}
Loading

0 comments on commit 21d6071

Please sign in to comment.