//Background Worker - Store Program Data
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Structs.StoreDataResult result = new Structs.StoreDataResult();
            result.IsWarmUpSession = false;

            switch (ProgramSelector)
            {
                case Enumerators.ProgramSelect.CustomProgram:
                    if (DataSample.SessionDuration.Minutes > 1)
                        result.IsSuccess = DataClasses.AccessorTrunkCustomProgram.StoreData_TrunkCustomProrgram(DataSample, UserID);
                    else
                    {
                        result.IsWarmUpSession = true;
                        result.IsSuccess = false;
                    }
                    break;
                case Enumerators.ProgramSelect.FTPTest:
                    result.IsSuccess = DataClasses.AccessorMuscleFunctionTests.StoreData_FTPTest((float)FTPTestResult, UserID);
                    break;
                case Enumerators.ProgramSelect.VO2MaxTest:
                    result.IsSuccess = DataClasses.AccessorMuscleFunctionTests.StoreData_VO2MaxTest(UserID, (float)VO2MaxRel, (float)VO2Max, (float)MaxConcPower);
                    break;
                case Enumerators.ProgramSelect.RehabBilateral:
                    result.IsSuccess = DataClasses.AccessorRehabPrograms.StoreDataRehabBilateral(DataSample, UserID);
                    break;
                case Enumerators.ProgramSelect.RehabLeftLeg:
                    result.IsSuccess = DataClasses.AccessorRehabPrograms.StoreDataRehabLeftLeg(DataSample, UserID);
                    break;
                case Enumerators.ProgramSelect.RehabRightLeg:
                    result.IsSuccess = DataClasses.AccessorRehabPrograms.StoreDataRehabRightLeg(DataSample, UserID);
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram1:
                    result.IsSuccess = DataClasses.AccessorHighPerformancePrograms.StoreDataVO2Max(DataSample, UserID, 1);
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram2:
                    result.IsSuccess = DataClasses.AccessorHighPerformancePrograms.StoreDataVO2Max(DataSample, UserID, 2);
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram3:
                    result.IsSuccess = DataClasses.AccessorHighPerformancePrograms.StoreDataVO2Max(DataSample, UserID, 3);
                    break;
                case Enumerators.ProgramSelect.VO2MaxProgram4:
                    result.IsSuccess = DataClasses.AccessorHighPerformancePrograms.StoreDataVO2Max(DataSample, UserID, 4);
                    break;
                case Enumerators.ProgramSelect.CPM:
                    result.IsSuccess = DataClasses.AccessorRehabPrograms.StoreDataCPM(DataSample, UserID);
                    break;
                case Enumerators.ProgramSelect.Proprioception:
                    result.IsSuccess = DataClasses.AccessorProprioceptionPrograms.StoreDataProprioception(DataSample, UserID);
                    break;
                case Enumerators.ProgramSelect.LatsEcceVar:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.LatsEcce75:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.LatsEcce65:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.LatsEcce55:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.AbsEcceVar:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.AbsEcce75:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.AbsEcce65:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                case Enumerators.ProgramSelect.AbsEcce55:
                    result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(UserID, ProgramSelector.ToString(), (float)TrunkEcceStaticMaxTorque, Convert.ToInt32(lblReps.Text));
                    break;
                default:
                break;
            }

            e.Result = result;

            if (backgroundWorker.CancellationPending == true)
            {
                e.Cancel = true;
            }
        }
        private void backgroundWorkerSaveData_DoWork(object sender, DoWorkEventArgs e)
        {
            DialogResult saveDataToFile = (DialogResult)e.Argument;

            Structs.StoreDataResult result = new Structs.StoreDataResult();

            if (GlobalVariables.UserMode == GlobalVariables.UserIdentityMode.ProfileMode)
                result.IsSuccess = DataClasses.AccessorTrunkPrograms.StoreData_TrunkStaticEcce(GlobalVariables.LoggedInUser.id, testMode.ToString(), (float)DataSample.MaxUserTorqueArray.Average(), DataSample.TotalReps);
            else
                result.IsSuccess = true;

            if (saveDataToFile == System.Windows.Forms.DialogResult.OK)
            {
                string stringUserId;
                if (GlobalVariables.LoggedInUser != null)
                {
                    stringUserId = GlobalVariables.LoggedInUser.id.ToString();
                }
                else
                {
                    stringUserId = "0";
                }


                Classes.TrunkStaticTestDataSet torqueDataSet = new Classes.TrunkStaticTestDataSet();

                for (int ii = 0; ii < DataSample.UserTorqueArray.Count; ii++)
                    torqueDataSet.AddNewRow(0, DataSample.UserTorqueArray[ii], DataSample.angleArray[ii]/2);

                if (torqueDataSet != null)
                {
                    string programName = "TrunkTorque_" + stringUserId + "_" + DataSample.ProgramSelector.ToString() + "_" + DataSample.SelectedTorque.ToString() + "_" + Math.Round(DataSample.SelectedStartAngle/2,2).ToString() + "_";
                    string filePath = torqueDataSet.PopulateXmlfile(torqueDataSet, 1, programName);
                    //torqueDataSet.EmailFile(filePath);
                }
            }

            e.Result = result;
        }