From 9f6c78d085311799c6bb3f09d6e9c45758db846d Mon Sep 17 00:00:00 2001 From: BornIncompetence Date: Sun, 9 Dec 2018 23:17:28 -0800 Subject: [PATCH] Added reminder times so we can start sending emails --- .gitignore | 6 +---- src/ChangeCancelAppointment.kt | 48 +++++++++++++++++++++++++++++++--- src/FileExplorer.kt | 9 ++++--- src/MakeAppointment.kt | 26 ++++++++++++++++-- src/Source.kt | 2 +- src/Squeal.kt | 18 ++++++++----- 6 files changed, 87 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index ecc07cf..c12d71e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,5 @@ # Compiled class file -*.class - # Kotlin -*.kotlin_module - # Log file *.log @@ -21,7 +17,7 @@ .idea/**/dynamic.xml .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml -.idea/workspace.xml +.idea/**/encodings.xml out/** # User-specific stuff diff --git a/src/ChangeCancelAppointment.kt b/src/ChangeCancelAppointment.kt index e537837..46f380c 100644 --- a/src/ChangeCancelAppointment.kt +++ b/src/ChangeCancelAppointment.kt @@ -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() + 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 { @@ -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 + } + } } } @@ -88,7 +107,9 @@ object ChangeCancelAppointment { startPrompt, startDate, endPrompt, - endDate + endDate, + remindPrompt, + remind ) gridPane.add(vBox, 0, 1) @@ -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) @@ -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" @@ -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" diff --git a/src/FileExplorer.kt b/src/FileExplorer.kt index 60c4c75..766b6bd 100644 --- a/src/FileExplorer.kt +++ b/src/FileExplorer.kt @@ -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 @@ -40,6 +39,7 @@ object FileExplorer { return Scene(gridPane, 250.0, 100.0) } + // Newly written appointments are given no reminder fun overwrite(appointments: MutableList) { appointments.forEach { val idStatement = connection.createStatement() @@ -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() @@ -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 diff --git a/src/MakeAppointment.kt b/src/MakeAppointment.kt index 6df211d..6f774b2 100644 --- a/src/MakeAppointment.kt +++ b/src/MakeAppointment.kt @@ -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 @@ -39,13 +40,20 @@ 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() + 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) @@ -53,6 +61,8 @@ object MakeAppointment { 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 @@ -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) { diff --git a/src/Source.kt b/src/Source.kt index b5b5edc..2eacaad 100644 --- a/src/Source.kt +++ b/src/Source.kt @@ -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 diff --git a/src/Squeal.kt b/src/Squeal.kt index d7ab359..2a50ee2 100644 --- a/src/Squeal.kt +++ b/src/Squeal.kt @@ -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';" @@ -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;" } \ No newline at end of file