Skip to content

Commit

Permalink
Fixed a bug in Import
Browse files Browse the repository at this point in the history
  • Loading branch information
BornIncompetence committed Dec 11, 2018
2 parents 94f68b3 + fac2c54 commit ebd82da
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .idea/libraries/activation_1_1_1.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/commons_email_1_4.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/javax_mail_1_5_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cecs343.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="javax.mail-1.5.2" level="project" />
<orderEntry type="library" name="commons-email-1.4" level="project" />
<orderEntry type="library" name="activation-1.1.1" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion src/ChangeCancelAppointment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ object ChangeCancelAppointment {
hBox.children.addAll(modify, back,cancel )
gridPane.add(hBox, 0, 2)

return Scene(gridPane, 350.0, 325.0)
return Scene(gridPane, 350.0, 375.0)
}

// Window shown verifying changes to Appointment
Expand Down
5 changes: 4 additions & 1 deletion src/FileExplorer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ object FileExplorer {
val idResult = idStatement.executeQuery(checkForExistingAppt(it.id))

// Modify if the ID already exists, else create a new one
if (idResult.next()) {
idResult.next()
val count = idResult.getInt(1)
if (count > 0) {
val titleStatement = connection.createStatement()
val startStatement = connection.createStatement()
val endStatement = connection.createStatement()
Expand All @@ -60,6 +62,7 @@ object FileExplorer {
creationStatement.executeUpdate(createAppointment(it.title, it.startDate, it.endDate, account.id, aptID, null))
}
}
ChangeCancelAppointment.updateComboBox()
}

// Appointment reminders aren't saved
Expand Down
2 changes: 1 addition & 1 deletion src/MakeAppointment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ object MakeAppointment {
hBox.children.addAll(register, back)
gridPane.add(hBox, 0, 2)

return Scene(gridPane, 350.0, 250.0)
return Scene(gridPane, 350.0, 300.0)
}

// Window shown when changing Appointment Creation has failed
Expand Down
1 change: 1 addition & 0 deletions src/Registrar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ object Registrar {
status = RegistrationStatus.SUCCESS
try {
successStatement.executeUpdate(createAccount(maxID + 1, pendingUser))
pendingUser.id = maxID + 1
account = pendingUser
Welcome.welcomeBanner.text = "Logged in as " + pendingUser.username
} catch (e: Exception) {
Expand Down
35 changes: 26 additions & 9 deletions src/Squeal.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import java.time.LocalDateTime


import org.apache.commons.mail.DefaultAuthenticator
import org.apache.commons.mail.HtmlEmail

// We will be using the user's locally installed database for the purposes
// of this assignment. The user should already have a MYSQL database
// created with the name "scheduler"
Expand Down Expand Up @@ -103,16 +107,29 @@ fun removeAppointment(appID: Int): String {
//Returns true for email sent
//Returns false for email not sent
fun sendEmail(emailAddress: String, appointmentName: String, startDate: LocalDateTime, username: String): Boolean{

val emailSent = emailAddress == ""//Set to true if email is sent
val emailMSG = " Hello, $username \nYou have a/an $appointmentName @ ${startDate.toLocalDate()} ${startDate.toLocalTime()} "//Message String
val emailMSG = " Hello, $username ($emailAddress). \nYou have an appointment: '$appointmentName' @ ${startDate.toLocalDate()} ${startDate.toLocalTime()} "//Message String
println(emailMSG)

//TODO actually send message emailMSG and update emailSent



return emailSent
return true

val senderEmail = "[email protected]"
val password = "#passsword"
return try {
val email = HtmlEmail()
email.hostName = "smtp.googlemail.com"
email.setSmtpPort(465)
email.setAuthenticator(DefaultAuthenticator(senderEmail, password))
email.isSSLOnConnect = true
email.setFrom(senderEmail)
email.addTo(emailAddress)
email.subject = "You have an Appointment coming up"
email.setHtmlMsg("<html><h1>$emailMSG</h1></html>")
email.send()

true
} catch (ex: Exception) {
ex.printStackTrace()
false
}
}

// Change the reminder for this appointment
Expand Down
14 changes: 10 additions & 4 deletions src/Welcome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import kotlin.concurrent.schedule
import kotlin.math.absoluteValue

// Main menu
object Welcome {
var welcomeBanner = Text()
var appointmentList = mutableListOf<Int>()
// Stage for many of the menu bar options available
val stage = Stage()

Expand Down Expand Up @@ -157,16 +159,20 @@ object Welcome {
timer.schedule(1000, 60000) {
val emailStatement = connection.createStatement()
val emailResult = emailStatement.executeQuery(getAppointments(account.username))
var remindersSet = false
while (emailResult.next()) {
val name = emailResult.getString("title")
val start = emailResult.getString("start_date")
val reminder = emailResult.getInt("reminder")
val aptID = emailResult.getInt("appointment_id")

val startDate = LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
val now = LocalDateTime.now()
val minutes = Duration.between(startDate, now).toMinutes()
if (minutes < reminder && startDate > now) {
remindersSet = sendEmail(account.email, name, startDate, account.username)
val minutes = Duration.between(startDate, now).toMinutes().absoluteValue

if (minutes < reminder && startDate > now && !appointmentList.contains(aptID)) {
if (sendEmail(account.email, name, startDate, account.username)) {
appointmentList.add(aptID)
}
}
}
}
Expand Down

0 comments on commit ebd82da

Please sign in to comment.