private void UpdateMarketCapControl(Result rslt) { string strError = string.Empty; bool alreadyThere = false; foreach (MarketCapControl ctrl in flpMarketCap.Controls) { if (ctrl.MarketCapResult.Name[0].ToUpper() == rslt.Name[0].ToString().ToUpper()) { alreadyThere = true; ctrl.MarketCapResult = rslt; ctrl.RefreshUI(); } } if (!alreadyThere) { MarketCapControl mcc = new MarketCapControl(); mcc.MarketCapResult = rslt; mcc.RefreshUI(); flpMarketCap.Controls.Add(mcc); } foreach (var notifcation in SettingsManager.AppSettings.MarketCapNotificationList) { if (notifcation.Enabled && (notifcation.CoinName.ToUpper() == rslt.Name[0].ToUpper())) { NotificationCall call = new NotificationCall(); string notificationMessage = string.Empty; if (notifcation.Condition == ">") if (Convert.ToDecimal(rslt.Price.Replace("$ ", "")) > Convert.ToDecimal(notifcation.Price)) notificationMessage = "MarketCap Notification: " + notifcation.CoinName + " is above your notification price. Current Price: " + rslt.Price + ", Notification Price: " + notifcation.Price; if (notifcation.Condition == "<") if (Convert.ToDecimal(rslt.Price.Replace("$ ", "")) < Convert.ToDecimal(notifcation.Price)) notificationMessage = "MarketCap Notification: " + notifcation.CoinName + " is below your notification price. Current Price: " + rslt.Price + ", Notification Price: " + notifcation.Price; if (notifcation.Condition == "=") if (Convert.ToDecimal(rslt.Price.Replace("$ ", "")) == Convert.ToDecimal(notifcation.Price)) notificationMessage = "MarketCap Notification: " + notifcation.CoinName + " is the same as your notification price. Current Price: " + rslt.Price + ", Notification Price: " + notifcation.Price; if (notificationMessage != string.Empty) { lblMarketCapStatus.SetThreadSafeProperty(() => lblMarketCapStatus.Text, "Notification enabled and condition met... Sending notification for " + notifcation.CoinName); call.SendNotification(SettingsManager.AppSettings.NotificationData, notificationMessage, ref strError); if (!string.IsNullOrEmpty(strError)) this.InvokeThreadSafeMethod(() => Notify.ShowMessage(this, Notify.MessageType.Error, "Error occurred while trying to send the notification: " + strError)); } } } }
public void RefreshAddressControls() { string strError = string.Empty; lblAddressStatus.SetThreadSafeProperty(() => lblAddressStatus.Text, "Refreshing addresses..."); picRefreshAddresses.Image = Properties.Resources.loading; try { NotificationCall call = new NotificationCall(); AddressCall AddrCall = new AddressCall(); foreach (PublicAddress address in SettingsManager.PublicAddresses) { strError = string.Empty; lblAddressStatus.SetThreadSafeProperty(() => lblAddressStatus.Text, "Getting address data for " + address.CoinName.ToString() + "..."); AddressControl addrControl = addr.GetPublicAddressControl(address, ref strError); if (strError != string.Empty) this.InvokeThreadSafeMethod(() => Notify.ShowMessage(this, Notify.MessageType.Error, "There was an error with " + addrControl.AddressObject.CoinName.ToString() + ": " + strError)); else flpControls.InvokeThreadSafeMethod(() => UpdateExistingAddress(addrControl)); if (address.Notify) { string notificationMessage = string.Empty; if (address.Condition == ">") if (Convert.ToDecimal(address.Balance) > Convert.ToDecimal(address.Price)) notificationMessage = address.CoinName + " is above your notification price. Current Balance: " + address.Balance + ", Notification Price: " + address.Price; if (address.Condition == "<") if (Convert.ToDecimal(address.Balance) < Convert.ToDecimal(address.Price)) notificationMessage = address.CoinName + " is below your notification price. Current Balance: " + address.Balance + ", Notification Price: " + address.Price; if (address.Condition == "=") if (Convert.ToDecimal(address.Balance) == Convert.ToDecimal(address.Price)) notificationMessage = address.CoinName + " is the same as your notification price. Current Balance: " + address.Balance + ", Notification Price: " + address.Price; if (notificationMessage != string.Empty) { lblAddressStatus.SetThreadSafeProperty(() => lblAddressStatus.Text, "Notification enabled and condition met... Sending notification for " + address.CoinName); call.SendNotification(SettingsManager.AppSettings.NotificationData, notificationMessage, ref strError); address.Notify = false; foreach (AddressControl ctrl in flpControls.Controls) if (ctrl.AddressObject.PublicAddressPK == address.PublicAddressPK) ctrl.txtNotify.SetThreadSafeProperty(() => ctrl.txtNotify.Text, "N/A"); if (!string.IsNullOrEmpty(strError)) this.InvokeThreadSafeMethod(() => Notify.ShowMessage(this, Notify.MessageType.Error, "An error occurred while trying to send the notification: " + strError)); AddrCall.UpdateAddressNotification(address, ref strError); if (!string.IsNullOrEmpty(strError)) this.InvokeThreadSafeMethod(() => Notify.ShowMessage(this, Notify.MessageType.Error, "An error occurred while trying to update the address notification: " + strError)); } } } } catch (Exception ex) { this.InvokeThreadSafeMethod(() => Notify.ShowMessage(this, Notify.MessageType.Error, "There was an error while enumerting address list: " + ex.Message)); } picRefreshAddresses.SetThreadSafeProperty(() => picRefreshAddresses.Image, Properties.Resources.refresh); flpControls.InvokeThreadSafeMethod(() => flpControls.Focus()); SettingsManager.AppSettings.AddressCheckData.IsRunning = false; SettingsManager.AppSettings.AddressCheckData.RefreshRateTemp = SettingsManager.AppSettings.AddressCheckData.RefreshRate; //Set the temp interval so that when the time is changed, it can be refreshed here }
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); } }