private static void SendDataDrivenEmail(MySqlConnection con) { Dictionary <string, string> dictFlareSystemConfigurationEntries = SystemConfigurationEntry.GetDictionary(con); if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerAddress)) { throw new Exception(@"Flare system configuration error: No SMTP server address is specified"); } if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerUserName)) { throw new Exception(@"Flare system configuration error: No SMTP server user name is specified"); } if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerPassword)) { throw new Exception(@"Flare system configuration error: No SMTP server password is specified"); } string strSMTPServerAddress = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerAddress]; string strSMTPServerUserName = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerUserName]; string strSMTPServerPassword = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerPassword]; const string strFrom = @"*****@*****.**"; const string strTo = @"*****@*****.**"; const string strSubject = @"Data-driven e-mail test"; string strBody = string.Format(@"Hello Tom; It is now {0} Universal Time.", MySqlUtils.DateTimeToString(DateTime.UtcNow)); Console.WriteLine(@"About to send data-driven e-mail to {0}...", strTo); MailUtils.SendMail(strSMTPServerAddress, strSMTPServerUserName, strSMTPServerPassword, strFrom, strTo, null, null, strSubject, strBody); Console.WriteLine(@"E-mail sent."); }
protected SystemConfigurationEntry GetSystemConfigurationEntryObjectBasedOnUI() // Do not get the SystemConfigurationEntry object from the database. { UInt32 unSelectedEntryID = 0; string strSelectedEntryName = lbEntryNames.SelectedValue; if (strSelectedEntryName != null && m_dict.ContainsKey(strSelectedEntryName)) { unSelectedEntryID = m_dict[strSelectedEntryName]; } SystemConfigurationEntry entry = new SystemConfigurationEntry(); entry.ID = unSelectedEntryID; entry.Name = tbName.Text; entry.Value = tbValue.Text; return(entry); }
protected void btnSave_Click(object sender, EventArgs e) { try { SystemConfigurationEntry entry = GetSystemConfigurationEntryObjectBasedOnUI(); // Ensure that the entry fields are valid; e.g. ensure that the strings contain no invalid characters such as the single quote. //if (!entry.Validate()) { } // Avoid entry name collisions if (m_dict.ContainsKey(entry.Name) && m_dict[entry.Name] != entry.ID) { throw new Exception(@"Cannot save: Another system configuration entry is using the specified name"); //return; } MySqlConnection con = GetMySqlConnection(); entry.SaveToDatabase(con); tbID.Text = entry.ID.ToString(); string strSelectedEntryName = lbEntryNames.SelectedValue; // The old entry name, if the name was changed. if (strSelectedEntryName != null && strSelectedEntryName != entry.Name) { lbEntryNames.Items.Remove(strSelectedEntryName); m_dict.Remove(strSelectedEntryName); } //if (!lbEntryNames.Items.Contains(ListItem item)) if (!m_dict.ContainsKey(entry.Name)) { lbEntryNames.Items.Add(entry.Name); m_dict.Add(entry.Name, entry.ID); } lbEntryNames.SelectedValue = entry.Name; } catch (Exception ex) { SetStatusMessageLabel(ex); } }
protected void lbEntryNames_SelectedIndexChanged(object sender, EventArgs e) { string strSelectedEntryName = lbEntryNames.SelectedValue; if (strSelectedEntryName == null || !m_dict.ContainsKey(strSelectedEntryName)) { ClearEntryUIFields(); return; } UInt32 unSelectedEntryID = m_dict[strSelectedEntryName]; MySqlConnection con = GetMySqlConnection(); SystemConfigurationEntry entry = new SystemConfigurationEntry(con, unSelectedEntryID); tbID.Text = entry.ID.ToString(); tbName.Text = entry.Name; tbValue.Text = entry.Value; }
protected void btnDelete_Click(object sender, EventArgs e) { SystemConfigurationEntry entry = GetSystemConfigurationEntryObjectBasedOnUI(); if (entry.ID != 0) { string strSelectedEntryName = lbEntryNames.SelectedValue; if (strSelectedEntryName != null) { lbEntryNames.Items.Remove(strSelectedEntryName); m_dict.Remove(strSelectedEntryName); } MySqlConnection con = GetMySqlConnection(); entry.DeleteFromDatabase(con); } ClearEntryUIFields(); }