コード例 #1
0
        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();
            }
        }
コード例 #2
0
        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);
            }
        }