Fakultas Ilmu Komputer UI

Commit 1018935a authored by hazlazuardi's avatar hazlazuardi
Browse files

Merge with Altaaj and Bagus2

parents a83b6d2a 8e201394
Pipeline #81523 failed with stages
in 18 seconds
......@@ -44,10 +44,8 @@ public class Timetable {
return courses;
}
public void addCourse(Course course) {
courses.add(course);
}
public void addCourse(Course course) { courses.add(course); }
public void deleteCourse(Course course){ courses.remove(course); }
}
......@@ -38,22 +38,45 @@ public class CSVTimetable {
}
}
public static void updateUser(String Uname, String newType){
public static void addCourseTimetable(String name, String table, List<Course> newCourse){
try{
BufferedReader check = new BufferedReader(new FileReader("Timetable.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] usersWritten = row.split(",");
if(usersWritten[0].equalsIgnoreCase(Uname)){
usersWritten[1] = newType;
String[] tableWritten = row.split(",");
int counter = 0;
if(tableWritten[0].equalsIgnoreCase(name) && tableWritten[1].equalsIgnoreCase(table)){
for(int i = 2; i < tableWritten.length; i++, counter++){
tableWritten[i] = newCourse.get(i-2).getCourseName();
}if(counter <= newCourse.size()-1){
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}for(int i = counter; i < newCourse.size(); i++){
newList.add(",");
newList.add(newCourse.get(i).getCourseName());
}
newList.add("\n");
}else{
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}
newList.add("\n");
}
}else{
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}
newList.add("\n");
}
newList.add(usersWritten[0]);
newList.add(",");
newList.add(usersWritten[1]);
newList.add("\n");
} check.close();
FileWriter reader = new FileWriter("Users.csv");
FileWriter reader = new FileWriter("Timetable.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
......@@ -92,4 +115,32 @@ public class CSVTimetable {
e.printStackTrace();
}
}
public static void deleteUserTimetable(String name){
try{
BufferedReader check = new BufferedReader(new FileReader("Timetable.csv"));
String row;
List<String> newList = new ArrayList<>();
while((row = check.readLine()) != null){
String[] tableWritten = row.split(",");
if(!tableWritten[0].equalsIgnoreCase(name)){
newList.add(tableWritten[0]);
for(int i = 1; i < tableWritten.length; i++) {
newList.add(",");
newList.add(tableWritten[i]);
}
newList.add("\n");
}
} check.close();
FileWriter reader = new FileWriter("Timetable.csv");
for (String s : newList) {
reader.append(s);
}reader.flush();
reader.close();
}
catch (IOException e) {
System.out.println("File not found.");
e.printStackTrace();
}
}
}
package Softeng.Group3.SiJadwal.repository;
import Softeng.Group3.SiJadwal.actor.User;
import Softeng.Group3.SiJadwal.model.Course;
import java.sql.Time;
......
......@@ -34,6 +34,9 @@ public class UserList {
public void updateRole(String username, RoleType role){
User newUser = getUser(username);
if((newUser.getRole().getRoleName() == RoleType.STUDENT) && (role != RoleType.STUDENT)){
CSVTimetable.deleteUserTimetable(newUser.getUsername());
}
int index = userList.indexOf(newUser);
User updated = new User();
updated.setRole(role);
......@@ -44,6 +47,9 @@ public class UserList {
public void deleteUser(String Uname){
User delUser = getUser(Uname);
if(delUser.getRole().getRoleName() == RoleType.STUDENT){
CSVTimetable.deleteUserTimetable(delUser.getUsername());
}
userList.remove(delUser);
CSVUser.deleteUser(Uname);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment