protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { Utilities.SetNoCache(Response); } HideErrorMessage(); if (!IsPostBack) { PagePermissions.EnforcePermissions_RequireAny(Session, Response, true, true, true, false, false, false); string displayData = SmsAndEmailBirthdayMessages.Run(true, false, DateTime.Now.Date); htmlOutput.Text = displayData; } } catch (CustomMessageException ex) { if (IsPostBack) { SetErrorMessage(ex.Message); } else { HideTableAndSetErrorMessage(ex.Message); } } catch (Exception ex) { if (IsPostBack) { SetErrorMessage("", ex.ToString()); } else { HideTableAndSetErrorMessage("", ex.ToString()); } } }
// http://localhost:2524/SMS/RunBirthdayReminders.aspx?pwd=mah_sms_reminder // http://localhost:2524/SMS/RunBirthdayReminders.aspx?pwd=mah_sms_reminder&inc_sending=false // http://portal.mediclinic.com.au:803/SMS/RunBirthdayReminders.aspx?pwd=mah_sms_reminder // http://portal.mediclinic.com.au:803/SMS/RunBirthdayReminders.aspx?pwd=mah_sms_reminder&inc_sending=false // can upload and let marcus add booking, view, mobile nbr, view, then try send to his nbr in aus... #region Page_Load protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Utilities.SetNoCache(Response); } try { string pwd = Request.Form["pwd"]; if (pwd != null) // sent by http post { if (pwd == null || pwd != System.Configuration.ConfigurationManager.AppSettings["SMSRunRemindersPwd"]) { throw new CustomMessageException("Incorrect password"); } string exceptionOutput = string.Empty; if (Session != null && Session["DB"] != null) { SmsAndEmailBirthdayMessages.Run(false, true, DateTime.Now.Date); } else { if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseConfigDB"])) { Session["DB"] = System.Configuration.ConfigurationManager.AppSettings["Database"]; Session["SystemVariables"] = SystemVariableDB.GetAll(); SmsAndEmailBirthdayMessages.Run(false, true, DateTime.Now.Date); Session.Remove("DB"); Session.Remove("SystemVariables"); } else // Get all DB's and run it on all of them { System.Data.DataTable tbl = DBBase.ExecuteQuery("EXEC sp_databases;", "master").Tables[0]; for (int i = 0; i < tbl.Rows.Count; i++) { string databaseName = tbl.Rows[i][0].ToString(); if (!Regex.IsMatch(databaseName, @"Mediclinic_\d{4}")) { continue; } try { Session["DB"] = databaseName; Session["SystemVariables"] = SystemVariableDB.GetAll(); SmsAndEmailBirthdayMessages.Run(false, true, DateTime.Now.Date); } catch (Exception ex) { exceptionOutput += Environment.NewLine + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + " " + "DB: " + databaseName; exceptionOutput += Environment.NewLine + ex.ToString(); } finally { Session.Remove("DB"); Session.Remove("SystemVariables"); } } } } if (exceptionOutput.Length > 0) { Response.Write("Run Completed But With Errors!"); Response.Write(Environment.NewLine + exceptionOutput); } else { Response.Write("Run Completed!"); } } else // send in url by http get { pwd = Request.QueryString["pwd"]; if (pwd == null || pwd != System.Configuration.ConfigurationManager.AppSettings["SMSRunRemindersPwd"]) { throw new CustomMessageException("Incorrect password"); } string inc_sending = Request.QueryString["inc_sending"]; if (inc_sending != null && inc_sending != "true" && inc_sending != "false") { throw new CustomMessageException("Incorrect inc_sending value"); } bool incSending = inc_sending != null && inc_sending == "true"; if (Session != null && Session["DB"] != null) { string displayData = SmsAndEmailBirthdayMessages.Run(true, incSending, DateTime.Now.Date); Response.Write(displayData); } else { if (!Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UseConfigDB"])) { throw new CustomMessageException("Can not run for logged out user where UseConfigDB = false"); } else { Session["DB"] = System.Configuration.ConfigurationManager.AppSettings["Database"]; Session["SystemVariables"] = SystemVariableDB.GetAll(); string displayData = SmsAndEmailBirthdayMessages.Run(true, incSending, DateTime.Now.Date); Response.Write(displayData); Session.Remove("DB"); Session.Remove("SystemVariables"); } } } } catch (CustomMessageException ex) { Response.Write(ex.Message); } catch (Exception ex) { Response.Write("Exception: " + (ex.ToString())); } }
protected void btnTest_Click(object sender, EventArgs e) { try { bool enableEmails = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendEmail").Value) == 1; string emailAddress = SystemVariableDB.GetByDescr("BirthdayNotificationEmail_EmailAddress").Value; bool incPatientsWithMobile = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_IncPatientsWithMobile").Value) == 1; bool incPatientsWithEmail = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_IncPatientsWithEmail").Value) == 1; bool sendMondays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendMondays").Value) == 1; bool sendTuesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendTuesdays").Value) == 1; bool sendWednesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendWednesdays").Value) == 1; bool sendThursdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendThursdays").Value) == 1; bool sendFridays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFridays").Value) == 1; bool sendSaturdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendSaturdays").Value) == 1; bool sendSundays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendSundays").Value) == 1; int fromDaysAheadMondays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Mondays").Value); int untilDaysAheadMondays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Mondays").Value); int fromDaysAheadTuesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Tuesdays").Value); int untilDaysAheadTuesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Tuesdays").Value); int fromDaysAheadWednesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Wednesdays").Value); int untilDaysAheadWednesdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Wednesdays").Value); int fromDaysAheadThursdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Thursdays").Value); int untilDaysAheadThursdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Thursdays").Value); int fromDaysAheadFridays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Fridays").Value); int untilDaysAheadFridays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Fridays").Value); int fromDaysAheadSaturdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Saturdays").Value); int untilDaysAheadSaturdays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Saturdays").Value); int fromDaysAheadSundays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendFromDaysAhead_Sundays").Value); int untilDaysAheadSundays = Convert.ToInt32(SystemVariableDB.GetByDescr("BirthdayNotificationEmail_SendUntilDaysAhead_Sundays").Value); int fromDaysAhead = 0, untilDaysAhead = 0; if (DateTime.Today.DayOfWeek == DayOfWeek.Monday) { fromDaysAhead = fromDaysAheadMondays; untilDaysAhead = untilDaysAheadMondays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Tuesday) { fromDaysAhead = fromDaysAheadTuesdays; untilDaysAhead = untilDaysAheadTuesdays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Wednesday) { fromDaysAhead = fromDaysAheadWednesdays; untilDaysAhead = untilDaysAheadWednesdays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Thursday) { fromDaysAhead = fromDaysAheadThursdays; untilDaysAhead = untilDaysAheadThursdays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Friday) { fromDaysAhead = fromDaysAheadFridays; untilDaysAhead = untilDaysAheadFridays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Saturday) { fromDaysAhead = fromDaysAheadSaturdays; untilDaysAhead = untilDaysAheadSaturdays; } if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday) { fromDaysAhead = fromDaysAheadSundays; untilDaysAhead = untilDaysAheadSundays; } DateTime start = DateTime.Now.AddDays(fromDaysAhead); DateTime end = DateTime.Now.AddDays(untilDaysAhead); if (!Utilities.IsValidEmailAddresses(emailAddress, false)) { throw new CustomMessageException("No emails will be sent in the test if you have not set an email address."); } SmsAndEmailBirthdayMessages.RunBirthdaysWithoutSMSorEmail(false); SetErrorMessage("Test Run Completed."); } catch (CustomMessageException ex) { SetErrorMessage(ex.Message); } }