private void updateOptionsButton_Click(object sender, EventArgs e) { //update options to file string type = notifyOptionsCombo.Text; notifyInterval = int.Parse(notifyIntervalCombo.Text); //map the notify type to the numeric code switch (type) { case "Email Only": notifyType = 1; break; case "Popup Only": notifyType = 2; break; case "Email & Popup": notifyType = 3; break; default: notifyType = 2; break; } Config config = new Config(); config.setNotfyInterval(notifyInterval); config.setNotifyType(notifyType); //stop/start the scheduler thread and timer schedulerWorker.CancelAsync(); schedulerWorker.RunWorkerAsync(); aTimer.Stop(); appStatusValue.Text += " - updated"; }
private bool closing = false; //track what is initiating the close (x'ing the form or shutdown) #endregion Fields #region Constructors public EnvatoTrackerFrame() { InitializeComponent(); User user = new User(); EnvatoAPI api = new EnvatoAPI(); //get ini config data, or create default file if not exists Config config = new Config(); if (config.initializeConfig() < 5) MessageBox.Show("Please verify you have set all configuration parameters and relaunch"); //load all window elements from config data usernameTextbox.Text = username; apikeyTextbox.Text = apiKey; emailTextbox.Text = emailTo; notifyIntervalCombo.Text = notifyInterval.ToString(); switch (notifyType) { case 1: notifyOptionsCombo.Text = "Email Only"; break; case 2: notifyOptionsCombo.Text = "Popup Only"; break; case 3: notifyOptionsCombo.Text = "Email & Popup"; break; default: notifyOptionsCombo.Text = "Popup Only"; break; } //remove from task bar on startup (should onlyl show in system tray) this.ShowInTaskbar = false; //display a popup that shows we're minimized and to make sure things are configured notifyIcon.ShowBalloonTip(18000000, "EnvatoTracker", "Remember to set your configuration information\nor you won't get any updates. (you should see your sales total if configured properly)", ToolTipIcon.None); //lets check if configured user is valid, if not we shouldn't do anything, otherwise lets initialize //set status (user is configured so we're polling)only if the username/key are successful if (user.isValidApiKey(username, apiKey)) { //get total sales int totalSales = api.getTotalSales(username); //update account balance & show balance if hover over tray icon accountBalance = api.getAccountBalance(username, apiKey, ref notifyIcon); if (accountBalance == "") accountBalance = "0.0"; notifyIcon.Text = "EnvatoTracker\nAccount Balance: $" + accountBalance + "\nTotal Sales: " + totalSales; //check if sales file exists, if it does we should compare the total to the number returned from the //api if (user.hasNewSales(username)) { notifyIcon.ShowBalloonTip(18000000, "New sales!", "You have received new sales since last time!\nAccount Balance:" + accountBalance, ToolTipIcon.None); //update the sales total in sales.txt user.setSalesTotal(totalSales); } appStatusValue.Text = "API polling active"; totalSalesLabelTextValue.Text = totalSales.ToString(); } else appStatusValue.Text = "API polling inactive"; //and finally we kick off the scheduler schedulerWorker.RunWorkerAsync(); }
private void updateButton_Click_1(object sender, EventArgs e) { //write user info to file username = usernameTextbox.Text; apiKey = apikeyTextbox.Text; emailTo = emailTextbox.Text; EnvatoAPI api = new EnvatoAPI(); User user = new User(); //validate fields if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(apiKey) || String.IsNullOrEmpty(emailTo)) MessageBox.Show("Please fill in all details and resubmit"); else if (!user.IsValidEmailAddress(emailTo)) MessageBox.Show("Invalid email address"); else { //check if user is valid, if so we notify that we're polling, otherwise display warning if (user.isValidApiKey(username, apiKey)) { //update config Config config = new Config(); config.setUsername(username); config.setApiKey(apiKey); config.setEmailTo(emailTo); //update total sales status label int totalSales = api.getTotalSales(username); totalSalesLabelTextValue.Text = totalSales.ToString(); //write sales total to file StreamWriter sr2 = new StreamWriter("sales.txt"); sr2.WriteLine("TotalSales:" + totalSales); sr2.Close(); //update account balance & show balance if hover over tray icon accountBalance = api.getAccountBalance(username, apiKey, ref notifyIcon); if (accountBalance == "") accountBalance = "0.0"; notifyIcon.Text = "EnvatoTracker\nAccount Balance: $" + accountBalance + "\nTotal Sales: " + totalSales; appStatusValue.Text = "API polling active"; totalSalesLabelTextValue.Text = totalSales.ToString(); } else appStatusValue.Text = "API polling inactive - invalid key/username combo"; } }