Skip to content

Commit

Permalink
Added reminder times so we can start sending emails
Browse files Browse the repository at this point in the history
  • Loading branch information
BornIncompetence committed Dec 10, 2018
1 parent 93133e1 commit 9f6c78d
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 22 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Compiled class file
*.class

# Kotlin
*.kotlin_module

# Log file
*.log

Expand All @@ -21,7 +17,7 @@
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
.idea/workspace.xml
.idea/**/encodings.xml
out/**

# User-specific stuff
Expand Down
48 changes: 44 additions & 4 deletions src/ChangeCancelAppointment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ object ChangeCancelAppointment {
startDate.promptText = "YYYY-MM-DD HH:MM:SS"
startDate.font = GUIFont.regular

val endPrompt = Label("New End Date")
text.font = GUIFont.heavy
val endPrompt = Label("New End Date")
text.font = GUIFont.regular

//End Date
val endDate = TextField()
endDate.promptText = "YYYY-MM-DD HH:MM:SS"
endDate.font = GUIFont.regular

val remindPrompt = Label("Edit reminder")
remindPrompt.font = GUIFont.regular

val remind = ComboBox<String>()
remind.promptText = "Remind me in X minutes"
remind.items.setAll("Never", "15 minutes", "30 minutes", "1 hour", "2 hours", "4 hours", "1 day")

selectApp.selectionModel.selectedItemProperty().addListener {
_, _, newValue ->
val apt = appointments.find {
Expand All @@ -75,6 +82,18 @@ object ChangeCancelAppointment {
newName.text = apt.title
startDate.text = apt.startDate
endDate.text = apt.endDate
remind.value = when (apt.reminder) {
0 -> "Never"
15 -> "15 minutes"
30 -> "30 minutes"
60 -> "1 hour"
120 -> "2 hours"
240 -> "4 hours"
3600 -> "1 day"
else -> {
null
}
}
}
}

Expand All @@ -88,7 +107,9 @@ object ChangeCancelAppointment {
startPrompt,
startDate,
endPrompt,
endDate
endDate,
remindPrompt,
remind
)
gridPane.add(vBox, 0, 1)

Expand All @@ -107,6 +128,7 @@ object ChangeCancelAppointment {
val titleStatement = connection.createStatement()
val startStatement = connection.createStatement()
val endStatement = connection.createStatement()
val remindStatement = connection.createStatement()

println(newName.text)
println(startDate.text)
Expand All @@ -128,6 +150,23 @@ object ChangeCancelAppointment {
} catch(e: SQLException) {
success = false
}
try {
val remindInt = when (remind.value) {
"Never" -> null
"15 minutes" -> 15
"30 minutes" -> 30
"1 hour" -> 60
"2 hours" -> 120
"4 hours" -> 240
"1 day" -> 3600
else -> {
null
}
}
remindStatement.executeUpdate(changeReminder(remindInt, aptID))
} catch(e: SQLException) {
success = false
}

if (success) {
AppointmentModify.label.text = "Successfully updated all fields"
Expand Down Expand Up @@ -237,8 +276,9 @@ object ChangeCancelAppointment {
val start = aptResult.getString("start_date")
val end = aptResult.getString("end_date")
val id = aptResult.getInt("appointment_id")
val reminder = aptResult.getInt("reminder")

appointments.add(Appointment(title, start, end, id))
appointments.add(Appointment(title, start, end, id, reminder))

val listString = "NAME: $title DATES: ($start) - ($end) ID: $id"

Expand Down
9 changes: 5 additions & 4 deletions src/FileExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ object FileExplorer {

val gridPane = grid()

//TODO: Get the number of insertions and modifications to the database
//Align message to the left
val message = Label("99 entries inserted, 99 entries modified")
val message = Label("New appointments created.")
val leftPane = StackPane(message)
leftPane.alignment = Pos.CENTER_LEFT

Expand All @@ -40,6 +39,7 @@ object FileExplorer {
return Scene(gridPane, 250.0, 100.0)
}

// Newly written appointments are given no reminder
fun overwrite(appointments: MutableList<Appointment>) {
appointments.forEach {
val idStatement = connection.createStatement()
Expand All @@ -57,11 +57,12 @@ object FileExplorer {
} else {
val creationStatement = connection.createStatement()
val aptID = it.title.hashCode() + (account.id + Random().nextInt(100))
creationStatement.executeUpdate(createAppointment(it.title, it.startDate, it.endDate, account.id, aptID))
creationStatement.executeUpdate(createAppointment(it.title, it.startDate, it.endDate, account.id, aptID, null))
}
}
}

// Appointment reminders aren't saved
fun save(file: File) {
try {
val successGetAptStatement = connection.createStatement()
Expand All @@ -86,7 +87,7 @@ object FileExplorer {

file.forEachLine { line ->
val tokens = line.split(",")
appointments.add(Appointment(tokens[0], tokens[1], tokens[2], tokens[3].toInt()))
appointments.add(Appointment(tokens[0], tokens[1], tokens[2], tokens[3].toInt(), null))
}

return appointments
Expand Down
26 changes: 24 additions & 2 deletions src/MakeAppointment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import javafx.geometry.Pos
import javafx.scene.Scene
import javafx.scene.control.Button
import javafx.scene.control.ComboBox
import javafx.scene.control.Label
import javafx.scene.control.TextField
import javafx.scene.layout.HBox
Expand Down Expand Up @@ -39,20 +40,29 @@ object MakeAppointment {
startDate.font = GUIFont.regular

val endPrompt = Label("End Date")
text.font = GUIFont.heavy
text.font = GUIFont.regular

//End Date
val endDate = TextField()
endDate.promptText = "YYYY-MM-DD HH:MM:SS"
endDate.font = GUIFont.regular

val remindPrompt = Label("Remind me in")
remindPrompt.font = GUIFont.regular

val remind = ComboBox<String>()
remind.promptText = "Remind me in X minutes"
remind.items.setAll("Never", "15 minutes", "30 minutes", "1 hour", "2 hours", "4 hours", "1 day")

//Add to vBox
val vBox = VBox(10.0)
vBox.children.addAll(aptName)
vBox.children.addAll(startPrompt)
vBox.children.addAll(startDate)
vBox.children.addAll(endPrompt)
vBox.children.addAll(endDate)
vBox.children.addAll(remindPrompt)
vBox.children.addAll(remind)
gridPane.add(vBox, 0, 1)

//Update button
Expand All @@ -69,7 +79,19 @@ object MakeAppointment {

//Attempt to push new appointment to database. If error then that means this is a duplicate (very unlikely)
try {
createAppointmentStatement.executeUpdate(createAppointment(aptName.text, startDate.text, endDate.text, account.id, aptID))
val reminder = when (remind.value) {
"Never" -> null
"15 minutes" -> 15
"30 minutes" -> 30
"1 hour" -> 60
"2 hours" -> 120
"4 hours" -> 240
"1 day" -> 3600
else -> {
null
}
}
createAppointmentStatement.executeUpdate(createAppointment(aptName.text, startDate.text, endDate.text, account.id, aptID, reminder))
ChangeCancelAppointment.updateComboBox()
Welcome.stage.close()
} catch (ex:Exception) {
Expand Down
2 changes: 1 addition & 1 deletion src/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object GUIFont {
data class Account(var email: String, var username: String, var password: String, var phone: String?, var id: Int)

// Appointment data class used for storing one or more appointments
data class Appointment(var title: String, var startDate: String, var endDate: String, var id: Int)
data class Appointment(var title: String, var startDate: String, var endDate: String, var id: Int, var reminder: Int?)

// This is the main window used between Logger and Welcome objects
// By reassigning window.scene, we can switch windows
Expand Down
18 changes: 12 additions & 6 deletions src/Squeal.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ fun getMatchingRow(name: String, pass: String): String {
}

// Create Appointment
fun createAppointment(name: String, startDate: String, endDate: String, userID: Int, appID: Int): String {
return "INSERT INTO scheduler.appointments(appointment_id, user_id , title, start_date, end_date) VALUES( '$appID', '$userID', '$name' , '$startDate', '$endDate') "
fun createAppointment(name: String, startDate: String, endDate: String, userID: Int, appID: Int, reminder: Int?): String {
return "INSERT INTO scheduler.appointments(appointment_id, user_id , title, start_date, end_date, reminder) " +
"VALUES( '$appID', '$userID', '$name' , '$startDate', '$endDate', ${reminder ?: "NULL"});"
}

// Get all Appointments belonging to username
fun getAppointments(username: String): String {
return "SELECT a.title, a.start_date, a.end_date, a.appointment_id " +
return "SELECT a.title, a.start_date, a.end_date, a.appointment_id, a.reminder " +
"FROM Appointments a " +
"INNER JOIN Users u ON a.user_id = u.user_id " +
"WHERE username LIKE '$username';"
Expand Down Expand Up @@ -101,13 +102,18 @@ fun removeAppointment(appID: Int): String {
//Returns false for email not sent
fun sendEmail(emailAddress: String, appointmentName: String, startDate: String, username: String): Boolean{

val emailSent = false;//Set to true if email is sent
val emailSent = emailAddress == ""//Set to true if email is sent
val emailMSG = " Hello, $username \nYou have a/an $appointmentName @ $startDate "//Message String

println(emailMSG)

//TODO actually send message emailMSG and update emailSent



return emailSent;
return emailSent
}

// Change the reminder for this appointment
fun changeReminder(reminder: Int?, appID: Int) : String {
return "UPDATE Appointments SET reminder = ${reminder ?: "NULL"} WHERE appointment_id = $appID;"
}

0 comments on commit 9f6c78d

Please sign in to comment.