forked from v98/ClassroomBookingsSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewCourses.java
227 lines (189 loc) · 8.12 KB
/
ViewCourses.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
import javafx.scene.control.TextArea;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
public class ViewCourses{
static List ls;
static ListView<String> list = new ListView<String>();
static HashMap<String, ArrayList<String>> hm;
static ObservableList<String> items;
private static TextArea t2;
// @Override
// public void start(Stage arg0) {
// Scene sc=new Scene(compiler(addTop(),addVBox(),addCenter()));
// Stage s=new Stage();
// s.setScene(sc);
// s.setTitle("My Courses");
// s.show();
// }
// private static BorderPane addTop(){
// BorderPane bp=new BorderPane();
// Button lo=new Button("Log Out");
// Text txt=new Text("MOCCHI");
// txt.maxWidth(Double.MAX_VALUE);
// bp.setLeft(txt);
// bp.setRight(lo);
// bp.setAlignment(lo, Pos.TOP_LEFT);
// bp.setPadding(new Insets(0,10,0,10));
// return bp;
// }
// private static VBox addVBox() {
// Button b1=new Button("Time Table");
// Button b2=new Button("Search Courses");
// Button b3=new Button("Room Availability");
// Button b4=new Button("My Requests");
// Button b5=new Button("My Profile");
//
// VBox v=new VBox();
// b1.setMaxWidth(Double.MAX_VALUE);
// b2.setMaxWidth(Double.MAX_VALUE);
// b3.setMaxWidth(Double.MAX_VALUE);
// b4.setMaxWidth(Double.MAX_VALUE);
// b5.setMaxWidth(Double.MAX_VALUE);
// v.getChildren().addAll(b1,b2,b3,b4,b5);
// v.setPadding(new Insets(10, 20, 10, 10));
// v.setAlignment(Pos.CENTER);
//
// return v;
// }
public static void addCenter() {
GridPane gp=new GridPane();
VBox bp=new VBox(10);
Text head=new Text("MY COURSES");
head.setStyle("-fx-font-weight:bold;-fx-font-size:125%;");
bp.getChildren().add(head);
Button rem=new Button("Remove Course");
Button done=new Button("Done");
//GridPane bp1=new GridPane();
Text crs=new Text("Courses");
Text det=new Text("Course Details");
//ListView<String> list = new ListView<String>();
t2=new TextArea();
t2.setEditable(false);
t2.setPrefHeight(150);
t2.setPrefWidth(280);
list.setPrefWidth(100);
list.setPrefHeight(70);
//ObservableList<String> items =FXCollections.observableArrayList ("Course 1", "Course 2", "Course 3", "Course 4");
//list.setItems(items);\
connect();
list.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
//System.out.println(list.getSelectionModel().getSelectedItem());
ArrayList<String> result=hm.get(list.getSelectionModel().getSelectedItem());
//System.out.println(result.get(0).isEmpty());
String s = result.get(0) + " " + result.get(1) + "\nType: " + result.get(2) + "\nInstructor: " + result.get(3)+ "\nCredits: " + result.get(4) + "\nPre-Conditions: " + result.get(5) + "\nPost-Conditions: "+ result.get(6);
t2.setText(s);
}
});
rem.setOnAction(e-> {
remove();
t2.setText("");
});
gp.setHgap(5);
gp.setVgap(5);
gp.add(crs, 1, 1);
gp.add(det, 2, 1);
gp.add(list, 1, 2);
gp.add(t2, 2, 2);
gp.add(rem, 2, 3);
bp.getChildren().add(gp);
HBox lower=new HBox(10);
lower.getChildren().addAll(rem,done);
lower.setAlignment(Pos.CENTER);
bp.getChildren().add(lower);
bp.setAlignment(Pos.CENTER);
bp.setPadding(new Insets(10,10,10,10));
Scene scene1=new Scene(bp,300,300);
Stage courses=new Stage();
courses.setTitle("Classroom Booking System: My Courses");
courses.setScene(scene1);
done.setOnAction(e ->courses.close());
courses.show();
}
public static void connect() {
try {
Class.forName("ViewCourses");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useSSL=false", "root","vrinda@16186");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select courses from user where email='"+LoginPage.emailid+"';");
rs.next();
String[] courseslol=rs.getString(1).split(",");
int n=courseslol.length;
hm = new HashMap<String, ArrayList<String>>();
ls=new ArrayList<String>();
for(int i=0;i<n;i++){
Statement stmt1 = con.createStatement();
//System.out.println(courseslol[i]);
ResultSet rs1 = stmt1.executeQuery("select cid,name,type,teacher,credits,precond,postcond from courses where cid='"+courseslol[i]+"';");
//System.out.println("select cid,name,type,teacher,credits,precond,postcond from courses where cid='"+courseslol[i]+"';");
while(rs1.next()){
ArrayList<String> temp=new ArrayList<String>();
temp.add(rs1.getString(1));//cid
temp.add(rs1.getString(2));//name
temp.add(rs1.getString(3));//type
temp.add(rs1.getString(4));//teacher
temp.add(rs1.getString(5));//credits
temp.add(rs1.getString(6));//precond
temp.add(rs1.getString(7));//postcond
ls.add(rs1.getString(2));
hm.put(rs1.getString(2),temp);
}
stmt1.close();
}
items=FXCollections.observableArrayList(ls);
list.setItems(items);
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void remove(){
try{
Class.forName("ViewCourses");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project?useSSL=false", "root","vrinda@16186");
Statement stmt1 = con.createStatement();
String q=list.getSelectionModel().getSelectedItem();
ResultSet rs1=stmt1.executeQuery("select courses from user where email='"+LoginPage.emailid+"';");
rs1.next();
Statement stmt2 = con.createStatement();
ResultSet rs2=stmt2.executeQuery("select cid from courses where name='"+q+"';");
rs2.next();
String t=rs1.getString(1).replace(rs2.getString(1)+",","");
Statement stmt3=con.createStatement();
stmt3.executeUpdate("update user set courses='"+t+"' where email='"+LoginPage.emailid+"';");
connect();
stmt1.close();
stmt2.close();
stmt3.close();
con.close();
}
catch(Exception t){
t.printStackTrace();
}
}
}