void OnGUI() { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Title:"); title = GUILayout.TextField(title); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Content:"); content = GUILayout.TextField(content); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Notification ID:"); notificationID = int.Parse(GUILayout.TextField(notificationID.ToString())); notificationID = (notificationID < 0) ? 0 : notificationID; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Days:"); days = int.Parse(GUILayout.TextField(days.ToString())); days = (days < 0) ? 0 : days; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Hours:"); hours = int.Parse(GUILayout.TextField(hours.ToString())); hours = (hours < 0) ? 0 : hours; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Minutes:"); minutes = int.Parse(GUILayout.TextField(minutes.ToString())); minutes = (minutes < 0) ? 0 : minutes; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Seconds:"); seconds = int.Parse(GUILayout.TextField(seconds.ToString())); seconds = (seconds < 0) ? 0 : seconds; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Count:"); count = int.Parse(GUILayout.TextField(count.ToString())); count = (count < 0) ? 0 : count; GUILayout.EndHorizontal(); if (GUILayout.Button("Start")) { NotificationSetup scrpt = notification.GetComponent <NotificationSetup>(); scrpt.Title = title; scrpt.Content = content; scrpt.notificationID = notificationID; scrpt.Days = days; scrpt.Hours = hours; scrpt.Minutes = minutes; scrpt.Seconds = seconds; scrpt.Count = count; notification.SetActive(true); notification.SetActive(false); } GUILayout.EndVertical(); }
private static void Send(AppointmentEntry graphAppointmentEntry, PXCache sourceCache, Guid setupID, int?branchID, IDictionary <string, string> reportParams, IList <Guid?> attachments = null) { string emailToAccounts, emailBCCAccounts; emailToAccounts = string.Empty; emailBCCAccounts = string.Empty; FSAppointment fsAppointmentRow = graphAppointmentEntry.AppointmentRecords.Current; Guid?refNoteId = fsAppointmentRow.NoteID; Guid?parentNoteId = null; string srvOrdType = fsAppointmentRow.SrvOrdType; NotificationSetup notificationSetup = PXSelect <NotificationSetup, Where <NotificationSetup.setupID, Equal <Required <NotificationSetup.setupID> > > > . Select(graphAppointmentEntry, setupID); string notificationCD = notificationSetup?.NotificationCD; NotificationSource source = GetSource(graphAppointmentEntry, srvOrdType, setupID, branchID); if (source == null) { //The current Notification Type (MailingID) is not configured for this Service Order Type return; } var accountId = source.EMailAccountID ?? DefaultEMailAccountId; if (accountId == null) { throw new PXException(TX.Warning.EMAIL_ACCOUNT_NOT_CONFIGURED_FOR_MAILING, notificationCD, srvOrdType, PX.Data.ActionsMessages.PreferencesEmailMaint); } RecipientList recipients = GetRecipients(graphAppointmentEntry, source.SourceID, accountId); if (recipients == null || recipients.Count() == 0) { return; } GetsRecipientsFields(recipients, ref emailToAccounts, ref emailBCCAccounts); var sent = false; if (source.ReportID != null) { var sender = new ReportNotificationGenerator(source.ReportID) { MailAccountId = accountId, Format = source.Format, AdditionalRecipents = recipients, Parameters = reportParams, NotificationID = source.NotificationID }; sent |= sender.Send().Any(); } else if (source.NotificationID != null) { var sender = TemplateNotificationGenerator.Create(fsAppointmentRow, (int)source.NotificationID); if (source.EMailAccountID != null) { sender.MailAccountId = accountId; } string notificationBody = sender.Body; FSAppointment.ReplaceWildCards(graphAppointmentEntry, ref notificationBody, fsAppointmentRow); sender.Body = notificationBody; sender.BodyFormat = source.Format; sender.RefNoteID = refNoteId; sender.ParentNoteID = parentNoteId; sender.To = emailToAccounts; sender.Bcc = emailBCCAccounts; if (attachments != null) { foreach (var attachment in attachments) { if (attachment != null) { sender.AddAttachmentLink(attachment.Value); } } } sent |= sender.Send().Any(); } if (!sent) { throw new PXException(CR.Messages.EmailNotificationError); } }
// // // Start Custom Functions // // public void SetNotifications() { int ids = 0; DateTime todaysDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); DateTime tomorrowsDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1); //DateTime timeGap = DateTime.Today.AddHours(notifHours); TimeSpan dueTime = DateTime.Today.AddHours(22) - DateTime.Now; foreach (Homework x in homeworkTasks) { if (!x.isComplete) { if (x.dateSet == todaysDate) { print("correct date"); GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Homework Reminder"; notifHolder.Content = "Incomplete " + x.subject + " homework " + x.heading + "due today."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } if (x.dateSet == tomorrowsDate) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Homework Reminder"; notifHolder.Content = "Incomplete " + x.subject + " homework " + x.heading + "due tomorrow."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } if (x.dateSet == tomorrowsDate.AddDays(1)) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Homework Reminder"; notifHolder.Content = "Incomplete " + x.subject + " homework " + x.heading + "due in two days."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } } } foreach (Assignment x in assignmentTasks) { if (x.completion < 100) { if (x.dateSet == todaysDate) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Assignment Reminder"; notifHolder.Content = x.completion + "% completed " + x.subject + " assignment " + x.heading + "due today."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } if (x.dateSet == tomorrowsDate) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Assignment Reminder"; notifHolder.Content = x.completion + "% completed " + x.subject + " assignment " + x.heading + "due tomorrow."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } if (x.dateSet == tomorrowsDate.AddDays(1)) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Assignment Reminder"; notifHolder.Content = x.completion + "% completed " + x.subject + " homework " + x.heading + "due in two days."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } if (x.dateSet == tomorrowsDate.AddDays(2)) { GameObject insNotif = Instantiate(notifObj); NotificationSetup notifHolder = insNotif.GetComponent <NotificationSetup>(); notifHolder.Title = "Assignment Reminder"; notifHolder.Content = x.completion + "% completed " + x.subject + " homework " + x.heading + "due in three days."; notifHolder.notificationID = ids; notifHolder.Hours = dueTime.Hours; notifHolder.Minutes = dueTime.Minutes; notifHolder.Seconds = dueTime.Seconds; ids++; } } } // // Problem is notifs will fail if user does not open app every day, so instead give an infinite reminder for every day for a week to get the user to check up manually to startup the notif system. // }