diff options
Diffstat (limited to 'src/com.example.portfolio2/com/example/portfolio2/Model.java')
-rw-r--r-- | src/com.example.portfolio2/com/example/portfolio2/Model.java | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Model.java b/src/com.example.portfolio2/com/example/portfolio2/Model.java index 73f2f6b..bafa3fc 100644 --- a/src/com.example.portfolio2/com/example/portfolio2/Model.java +++ b/src/com.example.portfolio2/com/example/portfolio2/Model.java @@ -7,31 +7,47 @@ package com.example.portfolio2; import java.util.ArrayList; -class Model{ // The model handles all interactions with the database +// The model handles all interactions with the database +class Model{ MyDB db=new MyDB(); + Model(){} - void initialize() { // When running the program, it clears the participation database + + // When running the program, it clears the participation database + void initialize() { clearParticipation(); } - int getActivityIndeks(String name) { // Returns the integer value of the activity's index + + // Returns the integer value of the activity's index + int getActivityIndeks(String name) { if(name ==null) return -1; ArrayList<String> result = db.query("select indeks from activity a where name is '"+name+"';", "indeks"); return Integer.parseInt(result.getFirst()); } - void addParticipation(int activityIndex) { // Inserts the given activity into participation using the activity's index + + // Inserts the given activity into participation using the activity's index + void addParticipation(int activityIndex) { db.cmd("insert into participation values(123, "+activityIndex+");"); } - ArrayList<String> getParticipation(String program) { // Returns all activity names from activities currently in participation + + // Returns all activity names from activities currently in participation + ArrayList<String> getParticipation(String program) { return db.query("select name from participation p inner join activity a on p.indeks = a.indeks where program is '" + program + "';", "name"); } - void clearParticipation() { // Removes all entries in the participation database + + // Removes all entries in the participation database + void clearParticipation() { db.cmd("delete from participation"); } - ArrayList<String> selectProgram(String program) { // Returns an arraylist of activities within the given program + + // Returns an arraylist of activities within the given program + ArrayList<String> selectProgram(String program) { return db.query("select name from activity where program is '" + program + "';", "name"); } - String getSumEcts(String program){ // Returns the sum of ECTS points under the given category from the student as a string + + // Returns the sum of ECTS points under the given category from the student as a string + String getSumEcts(String program){ if(program==null)return "0"; ArrayList<String> result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '"+program+"' group by student.studid ;", "total_ects"); if (result.isEmpty()) return "0"; |