public Notification GetNotification(ref string strError) { Notification notification = new Notification(); try { using (var conn = new SQLiteConnection(ConnectionString)) using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "SELECT * FROM Notification WHERE NotificationPK = 1"; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { Notification n = new Notification() { EmailAddress = reader.GetString(reader.GetOrdinal("EmailAddress")), PhoneNumber = reader.GetString(reader.GetOrdinal("PhoneNumber")), NotificationType = reader.GetString(reader.GetOrdinal("NotificationType")), CarrierGateway = reader.GetString(reader.GetOrdinal("CarrierGateway")), Carrier = reader.GetString(reader.GetOrdinal("Carrier")) }; notification = n; } } } } catch (Exception ex) { strError = ex.Message; } return notification; }
public void SendNotification(Notification notification, string message, ref string strError) { try { string email = string.Empty; string password = string.Empty; if (email == string.Empty || password == string.Empty) throw new Exception("The email and password are not set for notifications"); var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential(email, password), EnableSsl = true }; if (notification.NotificationType.ToUpper() == "EMAIL") client.Send(email, notification.EmailAddress, "CryptoCoinControl Price Notification", message); else if (notification.NotificationType.ToUpper() == "SMS") client.Send(email, notification.PhoneNumber + notification.CarrierGateway, string.Empty, message); } catch (Exception ex) { strError = ex.Message; } }
public void UpdateNotification(Notification notification, ref string strError) { try { using (var conn = new SQLiteConnection(ConnectionString)) using (var cmd = new SQLiteCommand("UPDATE Notification SET EmailAddress = @EmailAddress, PhoneNumber = @PhoneNumber, " + "NotificationType = @NotificationType, CarrierGateway = @CarrierGateway, Carrier = @Carrier WHERE NotificationPK = 1", conn)) { conn.Open(); cmd.Parameters.Add(new SQLiteParameter("@EmailAddress", notification.EmailAddress)); cmd.Parameters.Add(new SQLiteParameter("@PhoneNumber", notification.PhoneNumber)); cmd.Parameters.Add(new SQLiteParameter("@NotificationType", notification.NotificationType)); cmd.Parameters.Add(new SQLiteParameter("@CarrierGateway", notification.CarrierGateway)); cmd.Parameters.Add(new SQLiteParameter("@Carrier", notification.CarrierGateway)); cmd.ExecuteNonQuery(); } } catch (Exception ex) { strError = ex.Message; } }
public void UpdatePublicAddress(Notification notification, ref string strError) { NotificationData data = new NotificationData(); data.UpdateNotification(notification, ref strError); }
private void Buttons_Click(object sender, EventArgs e) { string strError = string.Empty; if (sender == btnOK) this.Close(); else if (sender == btnAddPublicAddress) { frmAddPublicAddress add = new frmAddPublicAddress(); add.ShowDialog(); } else if (sender == btnDeleteAddress) { if (lvAddresses.SelectedItems.Count > 0) { PublicAddress address = SettingsManager.PublicAddresses.Single(x => x.Address == lvAddresses.SelectedItems[0].SubItems[2].Text); AddressCall cAddress = new AddressCall(); cAddress.DeletePublicAddress(address.PublicAddressPK, ref strError); if (!string.IsNullOrEmpty(strError)) { MessageBox.Show("An error occurred while trying to delete that address from the database.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { SettingsManager.PublicAddresses.Remove(address); lvAddresses.Items.Remove(lvAddresses.SelectedItems[0]); frmMain main = null; foreach (Form form in Application.OpenForms) if (form.Name == "frmMain") main = (frmMain)form; main.RemoveAddressControl(address); } } else MessageBox.Show("Please select an item", "No Item Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (sender == btnEditAddress) { if (lvAddresses.SelectedItems.Count > 0) { frmEditPublicAddress edit = new frmEditPublicAddress(SettingsManager.PublicAddresses.Single(x => x.Address == lvAddresses.SelectedItems[0].SubItems[2].Text)); edit.ShowDialog(); } else MessageBox.Show("Please select an item", "No Item Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (sender == btnSaveNotificationSettings) { NotificationCall call = new NotificationCall(); Notification notification = new Notification() { EmailAddress = txtEmailAddress.Text, PhoneNumber = txtPhoneNumber.Text, NotificationType = cbxNotificationType.SelectedIndex == -1 ? "" : cbxNotificationType.SelectedItem.ToString(), Carrier = cbxCarrier.SelectedItem.ToString(), CarrierGateway = cbxCarrier.SelectedValue.ToString() }; call.UpdatePublicAddress(notification, ref strError); if (!string.IsNullOrEmpty(strError)) MessageBox.Show("An error occurred while trying to save the notification data.\n\r\n\r" + strError, "", MessageBoxButtons.OK, MessageBoxIcon.Error); else { SettingsManager.AppSettings.NotificationData = notification; MessageBox.Show("Those notification settings have been saved successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (sender == btnAddMarketCapNotification) { frmAddMarketCapNotification notifcation = new frmAddMarketCapNotification(); notifcation.ShowDialog(); } else if (sender == btnEditMarketCapNotification) { if (lvMarketCapNotifications.SelectedItems.Count > 0) { frmEditMarketCapNotification edit = new frmEditMarketCapNotification( SettingsManager.AppSettings.MarketCapNotificationList.Single(x => x.CoinName.ToUpper() == lvMarketCapNotifications.SelectedItems[0].Text.ToUpper())); edit.ShowDialog(); } else MessageBox.Show("Please select an item", "No Item Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (sender == btnDeleteMarketCapNotification) { if (lvMarketCapNotifications.SelectedItems.Count > 0) { MarketCapitalizationCall call = new MarketCapitalizationCall(); call.DeleteMarketCapNotification(lvMarketCapNotifications.SelectedItems[0].Text, ref strError); if (!string.IsNullOrEmpty(strError)) MessageBox.Show("An error occurred while trying to delete that notification: " + strError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); else { lvMarketCapNotifications.Items.Remove(lvMarketCapNotifications.SelectedItems[0]); SettingsManager.AppSettings.MarketCapNotificationList = call.GetMarketCapNotificationList(ref strError); if (!string.IsNullOrEmpty(strError)) MessageBox.Show("An error occurred while trying to get the market cap notifcation list: " + strError, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else MessageBox.Show("Please select an item", "No Item Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } }