private void btnAdd_Click(object sender, EventArgs e)
        {
            string strError = string.Empty;

            if (txtCoinName.Text == string.Empty)
            {
                MessageBox.Show("Please enter a coin name", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (cbxCondition.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a condition", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtPrice.Text == string.Empty)
            {
                MessageBox.Show("Please enter a price", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (IsNotificationAlreadySetup(txtCoinName.Text))
            {
                MessageBox.Show("That coin has already been added", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MarketCapNotification notifcation = new MarketCapNotification()
            {
                CoinName = txtCoinName.Text,
                Condition = cbxCondition.SelectedItem.ToString(),
                Enabled = true,
                Price = txtPrice.Text
            };

            MarketCapitalizationCall call = new MarketCapitalizationCall();
            call.InsertMarketCapNotification(notifcation, ref strError);

            if (!string.IsNullOrEmpty(strError))
                Notify.ShowMessage(this, Notify.MessageType.Error, strError);
            else
            {
                SettingsManager.AppSettings.MarketCapNotificationList.Add(notifcation);

                frmSettings settings = null;
                foreach (Form form in Application.OpenForms)
                    if (form.Name == "frmSettings")
                        settings = (frmSettings)form;
                settings.RefreshMarketCapNotificationsList();

                this.Close();
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            string strError = string.Empty;

            if (txtPrice.Text == string.Empty)
            {
                MessageBox.Show("Please enter a valid price", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MarketCapNotification notification = new MarketCapNotification()
            {
                CoinName = txtCoinName.Text,
                Price = txtPrice.Text,
                Condition = cbxCondition.SelectedItem.ToString(),
                Enabled = chkEnabled.Checked
            };

            MarketCapitalizationCall call = new MarketCapitalizationCall();
            call.UpdateMarketCapNotification(notification, ref strError);

            if (!string.IsNullOrEmpty(strError))
                MessageBox.Show("An error occurred while trying to update that notification:" + strError, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {
                SettingsManager.AppSettings.MarketCapNotificationList = call.GetMarketCapNotificationList(ref strError);

                frmSettings settings = null;
                foreach (Form form in Application.OpenForms)
                    if (form.Name == "frmSettings")
                        settings = (frmSettings)form;
                settings.RefreshMarketCapNotificationsList();

                if (!string.IsNullOrEmpty(strError))
                    MessageBox.Show("An error occurred while getting the market cap notification list.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                    this.Close();
            }
        }
        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);
            }
        }
        private void txtRefreshRateMarketCap_KeyUp(object sender, KeyEventArgs e)
        {
            string strError = string.Empty;
            int refreshrate = 0;
            int.TryParse(txtRefreshRateMarketCap.Text, out refreshrate);

            if (refreshrate != 0)
            {
                MarketCapitalizationCall call = new MarketCapitalizationCall();
                call.UpdateMarketCapitalization(new MarketCapitalizationSettings() { RefreshRate = refreshrate * 60, Source = SettingsManager.AppSettings.MarketCap.Source }, ref strError);
                if (!string.IsNullOrEmpty(strError))
                {
                    MessageBox.Show("An error occurred while trying to save the market cap refresh rate" + Environment.NewLine + Environment.NewLine + strError, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    SettingsManager.AppSettings.MarketCap.RefreshRate = refreshrate * 60;
                }
            }
        }
        private void RadioButtons_CheckedChanged(object sender, EventArgs e)
        {
            string strError = string.Empty;
            MarketCapitalizationCall call = new MarketCapitalizationCall();
            if (sender == btnCoinMarketCap)
            {
                if (btnCoinMarketCap.Checked)
                    SettingsManager.AppSettings.MarketCap.Source = SettingsManager.AppSettings.MarketCap.CoinMarketCap;
            }
            else if (sender == btnCryptMarketCap)
            {
                if (btnCryptMarketCap.Checked)
                    SettingsManager.AppSettings.MarketCap.Source = SettingsManager.AppSettings.MarketCap.CryptMarketCap;
            }

            call.UpdateMarketCapitalization(new MarketCapitalizationSettings() { Source = SettingsManager.AppSettings.MarketCap.Source, RefreshRate = SettingsManager.AppSettings.MarketCap.RefreshRate }, ref strError);
            if (!string.IsNullOrEmpty(strError))
            {
                MessageBox.Show("An error occurred while trying to update the marketcap source", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }