private void ButtonDelete_Click(object sender, EventArgs e) { GlobalsatProtocol device = this.fitnessDevice.Device(); //device should already be checked, no error if (device is GlobalsatProtocol2) { //Delete date time not fully working, keep structure for now DateTime oldest = DateTime.MaxValue; //this.dateTimePickerOldest.Value.ToLocalTime().ToShortDateString() //string msg = string.Format("Are you sure you want to delete all activities older than {0}?", this.dateTimePickerOldest.Value.ToLocalTime().ToShortDateString()); string msg = string.Format("Are you sure you want to delete all device activities?"); if (MessageDialog.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.OK) { GlobalsatProtocol2 device2 = device as GlobalsatProtocol2; JobMonitor jobMonitor = new JobMonitor(); int n = device2.DeleteTracks(oldest, jobMonitor); if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { msg = jobMonitor.ErrorText; } else if (n >= 0) { msg = string.Format("Deleted {0} activities", n); } else { msg = string.Format("Failed to delete activities"); } MessageDialog.Show(msg, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } } }
private void LabelRemainingTime_Click() { GlobalsatProtocol device = this.fitnessDevice.Device(); if (device is GlobalsatProtocol2) { GlobalsatProtocol2 device2 = device as GlobalsatProtocol2; JobMonitor jobMonitor = new JobMonitor(); TimeSpan time = device2.GetRemainingTime(jobMonitor); if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { this.labelRemainingTime.Text = "Remaining time: " + jobMonitor.ErrorText; //MessageDialog.Show(jobMonitor.ErrorText, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else if (time <= TimeSpan.MinValue) { MessageDialog.Show(Properties.Resources.Device_Unsupported, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } else { this.labelRemainingTime.Text = "Remaining time: " + time; } } }
private void ButtonCaptureScreen_Click(object sender, EventArgs e) { JobMonitor jobMonitor = new JobMonitor(); try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); if (device2 != null) { Bitmap screenshot = device2.GetScreenshot(jobMonitor); if (screenshot != null) { this.Height += screenshot.Height - pictureBox1.Height; this.groupBoxScreenCapture.Height += screenshot.Height - pictureBox1.Height; this.pictureBox1.ClientSize = new Size(screenshot.Width, screenshot.Height); this.pictureBox1.Image = screenshot; this.Refresh(); this.buttonSave.Enabled = true; } } } catch (Exception ex) { jobMonitor.ErrorText += ex.Message; } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ScreenCapture_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ButtonImportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();; openFileDialog1.Filter = "Configuration Files (*.cfg)|*.cfg"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { GlobalsatDeviceConfiguration importedDeviceConfig = null; try { importedDeviceConfig = GlobalsatDeviceConfiguration.Load(openFileDialog1.FileName); } catch (Exception) { importedDeviceConfig = null; } if (importedDeviceConfig == null || importedDeviceConfig.SystemConfigDataRaw == null) { MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } JobMonitor jobMonitor = new JobMonitor(); try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); if (device2 != null) { GlobalsatDeviceConfiguration currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); if (importedDeviceConfig != null && currentDeviceConfig != null && importedDeviceConfig.DeviceName == currentDeviceConfig.DeviceName && importedDeviceConfig.SystemConfigDataRaw.Length == currentDeviceConfig.SystemConfigDataRaw.Length) { device2.SetSystemConfiguration2(importedDeviceConfig, jobMonitor); labelStatus.Text = CommonResources.Text.Devices.ImportJob_Status_ImportComplete; } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error + "Received " + importedDeviceConfig.SystemConfigDataRaw.Length + " bytes "; //MessageDialog.Show(Properties.Resources.UI_Settings_ImportConfig_InvalidConfiguration, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { jobMonitor.ErrorText += ex.Message; } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ImportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void ButtonExportDeviceConfig_Click(object sender, EventArgs e) { labelStatus.Text = ""; try { GlobalsatProtocol device2 = this.fitnessDevice.Device(); GlobalsatDeviceConfiguration currentDeviceConfig = null; JobMonitor jobMonitor = new JobMonitor(); if (device2 != null) { currentDeviceConfig = device2.GetSystemConfiguration2(jobMonitor); } if (!string.IsNullOrEmpty(jobMonitor.ErrorText)) { MessageDialog.Show(jobMonitor.ErrorText, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (currentDeviceConfig != null) { System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog() { Filter = "Configuration Files (*.cfg)|*.cfg", FileName = currentDeviceConfig.DeviceName }; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { currentDeviceConfig.Save(saveFileDialog1.FileName); labelStatus.Text = CommonResources.Text.MessageExportComplete; //MessageDialog.Show(CommonResources.Text.MessageExportComplete, Properties.Resources.UI_Settings_ExportConfigButton_Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { labelStatus.Text = Properties.Resources.Device_OpenDevice_Error; } } catch (Exception ex) { MessageDialog.Show(ex.Message, Properties.Resources.UI_Settings_ExportConfig_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }