//Button Position Sequence
        private void btnPositionPedals_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            DisableButtons();

            if (GlobalVariables.ServoController.InitiateMotor(4, 80, Enumerators.Direction.Forward, GlobalVariables.leftSerialPort).IsSuccess == false)
                return;
            else
            {
                GlobalVariables.leftSerialPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived_PositionSequence);
            }

            FormMessageDialog = new frmMessageDialog("Positioning sequence in progress...", MessageBoxButtons.OK);
            FormMessageDialog.btnOK.Visible = false;
            FormMessageDialog.ShowDialog();
        }
        //Start the Calibration Sequence
        private bool InitiateCalibrationSequence()
        {
            if (backgroundWorkerOpenSerialPort.IsBusy != true)
            {
                // Start the asynchronous operation.
                backgroundWorkerOpenSerialPort.RunWorkerAsync();
            }
            else
                return false;

            frmObject_CustomDialog = new frmMessageDialog("Establishing Communications Link...", MessageBoxButtons.RetryCancel);
            frmObject_CustomDialog.btnCancel.Visible = false;
            DialogResult result = frmObject_CustomDialog.ShowDialog();

            return true;
        }
        //Button - Next
        private void btnNext_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();

            if (backgroundWorker_CheckUserEmail.IsBusy != true)
            {
                backgroundWorker_CheckUserEmail.RunWorkerAsync();    // Start the asynchronous operation.
            }

            FormMessageDialog = new frmMessageDialog("Validating User E-mail Address...", MessageBoxButtons.OK);
            FormMessageDialog.btnOK.Visible = false;
            FormMessageDialog.ShowDialog();

            switch (VerifyUserResponse)
            { 
                case "UserNotFound":
                    break;
                case "VerifyUserFailed":
                    break;
                case "UserFound":
                    GlobalVariables.WriteToRemoteServer = true;
                    SelectedUser = new DataClasses.UserProfile();
                    SelectedUser.EmailAddress = tbUserEmailAddress.Text;
                    string lblDialogText = "Please enter the Password for user: "******"";
                    ShowFormPassCodeCheck(lblDialogText, SelectedUser);
                    //((frmPassCodeCheck)Application.OpenForms["frmPassCodeCheck"]).SelectedUser.EmailAddress = tbUserEmailAddress.Text;
                    break;
                case "ConnectionToServerFailed":
                    if (SelectedUser != null)
                    {
                        GlobalVariables.WriteToRemoteServer = false;
                        string lblDialogText1 = "Please enter the Password for user: "******"";
                        ShowFormPassCodeCheck(lblDialogText1, SelectedUser);
                    }
                    break;
                case "SystemInOfflineMode":
                    if (SelectedUser != null)
                    {
                        GlobalVariables.WriteToRemoteServer = false;
                        string lblDialogText1 = "Please enter the Password for user: "******"";
                        ShowFormPassCodeCheck(lblDialogText1, SelectedUser);
                    }
                    break;
                default:
                    break;
            }
        }
        //Button - Reset Profile
        private void btnResetProfile_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            timerSuspend.Enabled = false;
            DialogResult dr = new DialogResult();
            frmMessageDialog MessageDialog = new frmMessageDialog(MessageBoxButtons.OKCancel);
            MessageDialog.lblDialogText.Text = "Are you sure?";
            dr = MessageDialog.ShowDialog();

            if (dr == DialogResult.OK)
            {
                this.Enabled = false;
                DataClasses.AccessorUsers.ResetUserData(GlobalVariables.LoggedInUser);

                frmMessageDialog.DisplayBriefMessage("Your profile performance history has been reset");
            }
        }
        //Function called to load the form
        public void Initialize()
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            if (backgroundWorker_SearchProfiles.IsBusy != true)
            {
                backgroundWorker_SearchProfiles.RunWorkerAsync();    // Start the asynchronous operation.
            }
            FormMessageDialog = new frmMessageDialog("Loading Existing Profiles...", MessageBoxButtons.RetryCancel);
            DialogResult result = FormMessageDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                backgroundWorker_SearchProfiles.CancelAsync();
            }

            this.textBoxFirstName.Focus();
        }
        //Button to Close the form
        private void btnClose_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            StopSequence();

            if (DataSample.IsTestDataAvailible == true)
            {
                frmMessageDialog FormQuestionDialog = new frmMessageDialog(MessageBoxButtons.OKCancel);
                FormQuestionDialog.lblDialogText.Text = "Save Data to User Profile?";
                FormQuestionDialog.lblTitle.Text = "Save Data";
                FormQuestionDialog.btnOK.ButtonText = "Yes";
                FormQuestionDialog.btnCancel.ButtonText = "No";
                DialogResult result = FormQuestionDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
                    if (backgroundWorker1.IsBusy != true)
                    {
                        backgroundWorker1.RunWorkerAsync();    // Start the asynchronous operation.
                    }
                    FormMessageDialog = new frmMessageDialog("Processing Results...", MessageBoxButtons.RetryCancel);
                    DialogResult result1 = FormMessageDialog.ShowDialog();

                    if (result1 != DialogResult.OK)
                    {
                        backgroundWorker1.CancelAsync();
                    }
                }
            }

            Application.OpenForms["frmUserMenu"].Focus();
        }
        //Button - Delete Profile
        private void btnDelete_MouseUp(object sender, MouseEventArgs e)
        {
            if (backgroundWorkerOpenSerialPort.IsBusy != true)
            {
                backgroundWorkerOpenSerialPort.RunWorkerAsync();
            }
            else
                return;

            frmCustomMessage = new frmMessageDialog("Establishing Communications Link...", MessageBoxButtons.RetryCancel);
            DialogResult result = frmCustomMessage.ShowDialog();

            if (result == DialogResult.OK)
            {
                frmSetupMenuPedals SetupMenuPedals = new frmSetupMenuPedals();
                SetupMenuPedals.ShowDialog();
            }
            else
            {
                backgroundWorkerOpenSerialPort.CancelAsync();
            }
        }
 public static void DisplayBriefMessage(string MessageText)
 {
     frmMessageDialog MessageDialog = new frmMessageDialog(MessageText, true);
     MessageDialog.ShowDialog();
 }
        //Read Current Feedback Parameters
        public objServoResult ReadFeedBack()
        {
            Result = SerialMotorControl.ReadFeedback(serialPort, FeedbackParams, ReadSuccess, currentByte1, streamArray, currentSpeed, currentPulse, currentTorque, currentContactStatus, ref ErrorCode, TimeOutCounter, ServoResult, sb, ByteString);
            if (Result.IsSuccess == false)
            {
                frmMessageDialog ErrorMessage = new frmMessageDialog();
                ErrorMessage.lblDialogText.Text = "Error Occured. Error Code: \"" + Result.ErrorCode.ToString() + "\"";
                ErrorMessage.Show();
                return Result;
            }
            else if (FeedbackParams[3] == 0x0B)
            {
                Result.IsSuccess = false;
                Result.ErrorCode = 5;
                Result.ErrorMessage = "Emergency Stop Activated!";
                return Result;
            }
            else
            {
                FeedbackTorque = (FeedbackParams[2] / 100 / 100) * CalibrationSettings.Default.RatedMotorTorque * CalibrationSettings.Default.GearRatio;
                FeedbackSpeed = FeedbackParams[0] / (CalibrationSettings.Default.GearRatio * 10);
                FeedbackPower = Math.Abs(FeedbackTorque * FeedbackSpeed * 2 * Math.PI / 60);
                FeedbackPulse = FeedbackParams[1];
                FeedbackContactStatus = FeedbackParams[3];

                DataSampleCalculations();

                return Result;
            }

        }
        //Button Save Weight
        private void btnSaveWeight_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();

            btnPositionPedals.Enabled = true;
            btnSaveWeight.Enabled = true;
            btnStart.ButtonText = "Start";
            

            StopSequence();

            if (backgroundWorker1.IsBusy != true)
            {
                backgroundWorker1.RunWorkerAsync();    // Start the asynchronous operation.
            }
            FormMessageDialog = new frmMessageDialog("Updating User Profile...", MessageBoxButtons.OK);
            FormMessageDialog.btnOK.Visible = false;
            FormMessageDialog.ShowDialog();
        }
        //Form Code (Button - Tabcontrol Navigation)
        private void btnLocalDrive_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();

            if (FormValidationCheck() == false)
            {
                return;
            }
            else
            {
                switch (tablessControl1.SelectedTab.Name)
                { 
                    case "tabPage1":
                            tablessControl1.SelectedTab = tabPage2;
                            tabPage2.Show();
                            tbSurname.Focus();
                        break;
                    case "tabPage2":
                            tablessControl1.SelectedTab = tabPage6;
                            tabPage6.Show();
                            tbWeight.Focus();
                        break;
                    case "tabPage3":
                            tablessControl1.SelectedTab = tabPage4;
                            tabPage4.Show();
                        break;
                    case "tabPage4":
                            Gender = RadioBtnMale.Checked == true ? "Male" : "Female";
                            tablessControl1.SelectedTab = tabPage5;
                            tabPage5.Show();
                            tbBirthYear.Focus();
                        break;
                    case "tabPage5":
                            tablessControl1.SelectedTab = tabPage6;
                            tabPage6.Show();
                            tbWeight.Focus();
                        break;
                    case "tabPage6":
                            tablessControl1.SelectedTab = tabPageEmail;
                            tabPageEmail.Show();
                            tbEmail.Focus();
                        break;
                    case "tabPageEmail":
                            btnNext.ButtonText = "Create Profile";
                            tablessControl1.SelectedTab = tabPage8;
                            tabPage8.Show();
                            tbPassword.Focus();
                        break;
                    case "tabPage8":
                            
                            DataComms.CreateThreadInstance("New User Created!");

                            if (backgroundWorkerOpenSerialPort.IsBusy != true)
                            {
                                btnNext.Enabled = false;
                                backgroundWorkerOpenSerialPort.RunWorkerAsync();    // Start the asynchronous operation.
                            }

                            FormMessageDialog = new frmMessageDialog("Creating user Profile...", MessageBoxButtons.OK);
                            FormMessageDialog.btnOK.Visible = false;
                            FormMessageDialog.btnCancel.Visible = true;
                            DialogResult result = FormMessageDialog.ShowDialog();

                            if (result == DialogResult.OK)
                            {
                                if (GlobalVariables.GlobUserLoggedIn == true)
                                {
                                    ((frmUserMenu)(Application.OpenForms["frmUserMenu"])).InitializeUserMenu();
                                }
                                else
                                {
                                    GlobalVariables.FormCollection.FormMainMenu.Focus();
                                    //MessageBox.Show("Error Loading UserMenu - GlobUserLoggedIn is false");
                                }
                                ResetForm();
                            }
                            else
                            {
                                backgroundWorkerOpenSerialPort.CancelAsync();
                                btnNext.Enabled = true;
                                GlobalVariables.FormCollection.FormMainMenu.Focus();
                            }
                            btnNext.Enabled = true;
                        break;
                    default:
                        break;
                }
            }
        }
Exemplo n.º 12
0
        private void btnSetupBaud_MouseUp(object sender, MouseEventArgs e)
        {
            objServoResult result = objServoController.TrySetServoBaudRate(GlobalVariables.leftSerialPort);

            if (result.IsSuccess == true)
                result = objServoController.TrySetServoBaudRate(GlobalVariables.rightSerialPort);
            else
            {
                FormMessageDialog = new frmMessageDialog("Failed to set left Servo Drive baud rate.", true);
                FormMessageDialog.ShowDialog();
            }

            if (result.IsSuccess == true)
            {
                FormMessageDialog = new frmMessageDialog("Done! Please Restart the Servo Controller", true);
                FormMessageDialog.ShowDialog();
            }
            else
            {
                FormMessageDialog = new frmMessageDialog("Failed to set Right Drive baud rate.", true);
                FormMessageDialog.ShowDialog();
            }
        }
        private void TestComplete()
        {
            System.Media.SoundPlayer ClickSound = new System.Media.SoundPlayer(Properties.Resources.beep_7);
            ClickSound.Play();

            StopSequence();
            StopSequence();

            lblRepsCompleted.Text = DataSample.RepsCompleted + " / " + DataSample.TotalReps;
            lblTorque.Text = Math.Round(DataSample.MaxUserTorqueArray.Average(), 1).ToString();

            btnStart.Enabled = false;

            frmMessageDialog dialog = new frmMessageDialog("Average Torque: " + Math.Round(DataSample.MaxUserTorqueArray.Average(), 1).ToString() + " (Nm). Save Data to Disk?", MessageBoxButtons.OKCancel);
            DialogResult result = dialog.ShowDialog();

            //if (result == System.Windows.Forms.DialogResult.OK)
            //{ 

            //}

            //frmMessageDialog.DisplayBriefMessage("Test Complete. Average Torque: " + Math.Round(DataSample.MaxUserTorqueArray.Average(), 1).ToString() + " (Nm)");


            if (backgroundWorkerSaveData.IsBusy != true)
            {
                backgroundWorkerSaveData.RunWorkerAsync(result);    // Start the asynchronous operation.
            }


            TorqueChart.Series[0].Points.Clear();

            foreach (double torque in DataSample.UserTorqueArray)
            {
                TorqueChart.Series[0].Points.Add(torque);
            }

            //frmProgramResults frmObject_SaveSession = new frmProgramResults();

            //frmObject_SaveSession.UserID = Convert.ToInt32(GlobalVariables.LoggedInUser.id);
            //frmObject_SaveSession.ProgramSelector = DataSample.ProgramSelector;

            //frmObject_SaveSession.tabControlResults.SelectedTab = frmObject_SaveSession.tabPageStaticTrunkTest;
            //frmObject_SaveSession.TrunkEcceStaticMaxTorque = DataSample.MaxUserTorqueArray.Average();
            //frmObject_SaveSession.lblTrunkStaticEcceTorque.Text = Math.Round(DataSample.MaxUserTorqueArray.Average(), 1).ToString();
            //frmObject_SaveSession.lblProgram.Text = DataSample.ProgramSelector.ToString();
            //frmObject_SaveSession.lblReps.Text = DataSample.TotalReps.ToString();

            //frmObject_SaveSession.Width -= 100;
            //frmObject_SaveSession.Height -= 100;
            //frmObject_SaveSession.WindowState = FormWindowState.Normal;
            //frmObject_SaveSession.ShowDialog();
        }
        //Button - Confirm
        private void btnConfirm_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            switch (ReasonForCall)
            {
                case 1:
                    {
                        EnteredPassCode = tbCode.Text;
                        tbCode.Text = "";
                        if (CalibrationSettings.Default.AdminPassCode == EnteredPassCode)
                        {
                            GlobalVariables.FormCollection.FormSetup.Focus();
                        }
                        else if (EnteredPassCode == CalibrationSettings.Default.AdminPassCodeX)
                        {
                            GlobalVariables.FormCollection.FormSetupMenuX.Focus();
                        }
                        else
                        {
                            frmMessageDialog.DisplayBriefMessage("Pass Code entered incorrectly");
                        }
                        break;
                    }
                case 2:
                    {
                        if (backgroundWorkerOpenSerialPort.IsBusy != true)
                        {
                            btnConfirm.Enabled = false;
                            backgroundWorkerOpenSerialPort.RunWorkerAsync();
                        }
                        else
                            return;

                        frmCustomMessage = new frmMessageDialog("Validating entered password...", MessageBoxButtons.RetryCancel);
                        DialogResult result = frmCustomMessage.ShowDialog();

                        if (result == DialogResult.OK)
                        {
                            if (GlobalVariables.GlobUserLoggedIn == true)
                            {
                                //frmCustomMessage.Close();          
                                tbCode.Text = "";
                                Stopwatch sw = new Stopwatch();
                                sw.Start();
                                GlobalVariables.FormCollection.FormUserMenu.InitializeUserMenu();
                                sw.Stop();
                                logger.Info("Show User Menu: " + sw.ElapsedMilliseconds.ToString());
                            }
                        }
                        else
                        {
                            backgroundWorkerOpenSerialPort.CancelAsync();
                        }

                        break;
                    }
                default:
                    break;
            }
        }
 private void ShowMessage()
 {
     if (MessageDialog == null)
     {
         MessageDialog = new frmMessageDialog("Ready!!!", false);
         MessageDialog.Show();
     }
 }
 public void ProcessErrorCalibration()
 {
     switch (Result.ErrorCode)
     {
         case 5:     //Emergency Stop during Session
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.leftSerialPort);
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.rightSerialPort);
             frmMessageDialog ErrorMessage = new frmMessageDialog();
             ErrorMessage.lblDialogText.Text = Result.ErrorMessage;
             ErrorMessage.ShowDialog();
             break;
         default:
             break;
     }
 }
 public void ProcessErrorSession()
 {
     switch (Result.ErrorCode)
     {
         case 5:     //Emergency Stop during Session
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.leftSerialPort);
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.rightSerialPort);
             frmMessageDialog ErrorMessage = new frmMessageDialog();
             ErrorMessage.lblDialogText.Text = Result.ErrorMessage;
             ErrorMessage.ShowDialog();
             Application.OpenForms["frmUserMenu"].Focus();
             break;
         case 6:     //Emergency Stop during Session
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.leftSerialPort);
             GlobalVariables.ServoController.SetMotorTorque(0, GlobalVariables.rightSerialPort);
             frmMessageDialog ErrorMessage1 = new frmMessageDialog();
             ErrorMessage1.lblDialogText.Text = Result.ErrorMessage;
             ErrorMessage1.ShowDialog();
             break;
         default:
             GlobalVariables.ServoController.SetMotorTorque(5, GlobalVariables.leftSerialPort);
             GlobalVariables.ServoController.SetMotorTorque(5, GlobalVariables.rightSerialPort);
             frmMessageDialog ErrorMessage2 = new frmMessageDialog();
             ErrorMessage2.lblDialogText.Text = "Unknown error while reading serial port";
             ErrorMessage2.ShowDialog();
             break;
     }
 }
        //Button - Close (Upload Data to Server)
        private void retroButton1_MouseUp(object sender, MouseEventArgs e)
        {
            if (GlobalVariables.UserMode == GlobalVariables.UserIdentityMode.AnonymousMode)
            {
                //GlobalVariables.FormCollection.FormBasicRunSerial.WindowState = FormWindowState.Minimized;
                GlobalVariables.FormCollection.FormUserMenu.Focus();
                this.Close();
                return;
            }

            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            if (backgroundWorker.IsBusy != true)
            {
                backgroundWorker.RunWorkerAsync();    // Start the asynchronous operation.
            }
            FormMessageDialog = new frmMessageDialog("Processing Results...", MessageBoxButtons.RetryCancel);
            DialogResult result = FormMessageDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                backgroundWorker.CancelAsync();
            }

            if (DataSample != null)
                DataComms.CreateThreadInstance(ProgramSelector.ToString() + " Completed - Duration: " + DataSample.SessionDuration.ToString() + ", User ID: " + GlobalVariables.LoggedInUser.id.ToString());
            GlobalVariables.FormCollection.FormUserMenu.Focus();
            this.Close();
        }
 private void btnConfigureCPM5588_MouseUp(object sender, MouseEventArgs e)
 {
     if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
     if (backgroundWorkerCPM2.IsBusy != true)
     {
         backgroundWorkerCPM2.RunWorkerAsync();    // Start the asynchronous operation.
     }
     FormMessageDialog = new frmMessageDialog("Configuring Drive Parameters...", MessageBoxButtons.OK);
     FormMessageDialog.btnOK.Visible = false;
     FormMessageDialog.ShowDialog();
 }
 private void CloseMessage()
 {
     if (MessageDialog != null)
     {
         MessageDialog.Close();
         MessageDialog.Dispose();
         MessageDialog = null;
     }
 }
Exemplo n.º 21
0
        private void btnQuickStart_MouseUp(object sender, MouseEventArgs e)
        {
            GlobalVariables.UserMode = GlobalVariables.UserIdentityMode.AnonymousMode;

            if (backgroundWorkerOpenSerialPort.IsBusy != true)
            {
                backgroundWorkerOpenSerialPort.RunWorkerAsync();
            }
            else
                return;

            frmCustomMessage = new frmMessageDialog("Establishing Communications Link...", MessageBoxButtons.RetryCancel);
            DialogResult result = frmCustomMessage.ShowDialog();

            if (result == DialogResult.OK)
            {
                //GlobalVariables.FormCollection.FormBasicRunSerial.InitiateProgram(20, 20, new TimeSpan(0,5,0), Enumerators.Direction.Forward );
                GlobalVariables.FormCollection.FormUserMenu.InitializeUserMenu();
            }
            else
            {
                backgroundWorkerOpenSerialPort.CancelAsync();
            }
        }
        private void retroButton1_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            if (backgroundWorker_SearchProfiles.IsBusy != true)
            {
                backgroundWorker_SearchProfiles.RunWorkerAsync();    // Start the asynchronous operation.
            }
            FormMessageDialog = new frmMessageDialog("Loading Existing Profiles...", MessageBoxButtons.RetryCancel);
            DialogResult result = FormMessageDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                backgroundWorker_SearchProfiles.CancelAsync();
            }

            GlobalVariables.FormCollection.FormLoadProfiles.textBoxFirstName.Focus();
        }
        //Test Complete
        private void TestComplete()
        {
            StopSequence();
            UpdateUI_Labels();

            //Implement Save Data Dialog
            frmMessageDialog DialogTestCompleteMessage = new frmMessageDialog("Test Complete", true);
            DialogTestCompleteMessage.ShowDialog();
        }
        //Timer - Seconds
        private void timerElapsedTime_Tick(object sender, EventArgs e)
        {
            TimeSpan StageTimeRemaining;
            TimeSpan SetTimeRemaining;
            StageTimeRemaining = CurrentVO2MaxProgram.CurrentVO2MaxStage.StageTimeRemaining - TimeSpan.FromMilliseconds(1000);
            SetTimeRemaining = CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.TimeRemaining - TimeSpan.FromMilliseconds(1000);
            CurrentVO2MaxProgram.ProgramTime = CurrentVO2MaxProgram.ProgramTime - TimeSpan.FromMilliseconds(1000);
            CurrentVO2MaxProgram.CurrentVO2MaxStage.StageTimeRemaining = StageTimeRemaining;
            CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.TimeRemaining = SetTimeRemaining;
            DataSample.SessionDuration = DataSample.SessionDuration + TimeSpan.FromMilliseconds(1000);

            string RootDiretory = AppDomain.CurrentDomain.BaseDirectory;
            String format = @"mm\:ss";
            if (SetTimeRemaining.Milliseconds <= 0 && SetTimeRemaining.Seconds == 3 && SetTimeRemaining.Minutes == 0)
            {
                //Check if the current set and stage is not the last in its collection - End of Program
                if (CurrentVO2MaxProgram.CurrentVO2MaxStage.StageNumber != CurrentVO2MaxProgram.VO2MaxStageCollection.Count || CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.SetNumber != CurrentVO2MaxProgram.CurrentVO2MaxStage.VO2MaxSetCollection.Count)
                {
                    SoundPlayer ClickSound = new SoundPlayer(Properties.Resources.beep_7);
                    ClickSound.Play();
                    FormCustomDialog = new frmMessageDialog("Next set will start in: " + CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.TimeRemaining.ToString(format) + "", false);
                    FormCustomDialog.ShowDialog();
                }
            }
            else if (SetTimeRemaining.Milliseconds <= 0 && SetTimeRemaining.Seconds == 2 && SetTimeRemaining.Minutes == 0)
            {
                if (FormCustomDialog != null)
                    FormCustomDialog.lblDialogText.Text = "Next set will start in: " + CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.TimeRemaining.ToString(format) + "";
            }
            else if (SetTimeRemaining.Milliseconds <= 0 && SetTimeRemaining.Seconds == 1 && SetTimeRemaining.Minutes == 0)
            {
                if (FormCustomDialog != null)
                    FormCustomDialog.lblDialogText.Text = "Next set will start in: " + CurrentVO2MaxProgram.CurrentVO2MaxStage.CurrentVO2MaxSet.TimeRemaining.ToString(format) + "";
            }
            else if (SetTimeRemaining.Milliseconds <= 1 && SetTimeRemaining.Seconds == 0 && SetTimeRemaining.Minutes == 0)
            {
                if (FormCustomDialog != null)
                    FormCustomDialog.Close();
            }

            if (StageTimeRemaining.Milliseconds <= 0 && StageTimeRemaining.Seconds == 0 && StageTimeRemaining.Minutes == 0)
            {
                GlobalVariables.leftSerialPort.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived);
                timerElapsedTime.Enabled = false;
                timerTorqueAcc.Enabled = false;
                UpdateStage();
            }
            else if (SetTimeRemaining.Milliseconds <= 0 && SetTimeRemaining.Seconds == 0 && SetTimeRemaining.Minutes == 0)
            {
                GlobalVariables.leftSerialPort.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(serialPort_DataReceived);
                timerElapsedTime.Enabled = false;
                timerTorqueAcc.Enabled = false;
                UpdateSet();
            }

            UpdateTimerLabel();
        }
        private void btnCustomProgram2_MouseUp(object sender, MouseEventArgs e)
        {
            if (backgroundWorkerOpenSerialPort.IsBusy != true)
            {
                backgroundWorkerOpenSerialPort.RunWorkerAsync();
            }
            else
                return;

            frmCustomMessage = new frmMessageDialog("Establishing Communications Link...", MessageBoxButtons.RetryCancel);
            DialogResult result = frmCustomMessage.ShowDialog();

            if (result == DialogResult.OK)
            {
                GlobalVariables.FormCollection.FormCustomProgramCPM.AutoRetractMode = true;
                if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
                this.ProgramSelector = Enumerators.ProgramSelect.CustomProgramCPM;
                this.tabControlSelectProgramGroup.SelectedTab = GlobalVariables.FormCollection.FormProgramSetup.tabPageSetup;
                this.tabControl1.SelectedTab = GlobalVariables.FormCollection.FormProgramSetup.tabPageSpeed;
                this.textBoxSpeed.Focus();
            }
            else
            {
                backgroundWorkerOpenSerialPort.CancelAsync();
            }
        }
        private void retroButton1_MouseUp(object sender, MouseEventArgs e)
        {
            if (CalibrationSettings.Default.SoundEnabled == true) GlobalFunctions.PlayClickSound();
            if (SelectedUser == null)
            {
                frmMessageDialog.DisplayBriefMessage("Please select a valid profile.");
            }
            else
            {
                if (CalibrationSettings.Default.IsInternetConfigured == true)
                {
                    GlobalVariables.WriteToRemoteServer = true;
                    //SelectedUser = new DataClasses.UserProfile();
                    //SelectedUser.EmailAddress = tbUserID.Text;
                    //string lblDialogText = "Please enter the Password for user: "******"";
                    //ShowFormPassCodeCheck(lblDialogText, SelectedUser);
                }
                else
                {
                    GlobalVariables.WriteToRemoteServer = false;
                    //string lblDialogText1 = "Please enter the Password for user: "******"";
                    //ShowFormPassCodeCheck(lblDialogText1, SelectedUser);
                }

                if (backgroundWorkerLoadProfile.IsBusy != true)
                {
                    backgroundWorkerLoadProfile.RunWorkerAsync();
                }
                else
                    return;

                FormMessageDialog = new frmMessageDialog("Loading user data...", MessageBoxButtons.RetryCancel);
                DialogResult result = FormMessageDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    if (GlobalVariables.GlobUserLoggedIn == true)
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        GlobalVariables.FormCollection.FormUserMenu.InitializeUserMenu();
                        sw.Stop();
                        ///logger.Info("Show User Menu: " + sw.ElapsedMilliseconds.ToString());
                    }
                }
                else
                {
                    backgroundWorkerLoadProfile.CancelAsync();
                }
            }   
        }