public static Classes.PowerIndexPreviousBest GetVO2MaxProgram1PB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            Classes.PowerIndexPreviousBest vO2MaxProgram1PB = new Classes.PowerIndexPreviousBest();
            List<DataClasses.VO2MaxProgram1> ListVO2MaxProgram1PB = new List<DataClasses.VO2MaxProgram1>();

            ListVO2MaxProgram1PB = (from sessions in dc.GetTable<DataClasses.VO2MaxProgram1>()
                                    where sessions.UserID == UserID && sessions.VO2MaxProgramEnum == 1
                                  select sessions).ToList<DataClasses.VO2MaxProgram1>();

            vO2MaxProgram1PB.LeftAvgConcP = ListVO2MaxProgram1PB.Max(z => z.LeftAvgConcP);
            vO2MaxProgram1PB.LeftAvgEcceP = ListVO2MaxProgram1PB.Max(z => z.LeftAvgEcceP);
            vO2MaxProgram1PB.RightAvgConcP = ListVO2MaxProgram1PB.Max(z => z.RightAvgConcP);
            vO2MaxProgram1PB.RightAvgEcceP = ListVO2MaxProgram1PB.Max(z => z.RightAvgEcceP);

            if (vO2MaxProgram1PB.LeftAvgConcP == null) vO2MaxProgram1PB.LeftAvgConcP = 0;
            if (vO2MaxProgram1PB.LeftAvgEcceP == null) vO2MaxProgram1PB.LeftAvgEcceP = 0;
            if (vO2MaxProgram1PB.RightAvgConcP == null) vO2MaxProgram1PB.RightAvgConcP = 0;
            if (vO2MaxProgram1PB.RightAvgEcceP == null) vO2MaxProgram1PB.RightAvgEcceP = 0;

            if (vO2MaxProgram1PB.RightAvgConcP == null || vO2MaxProgram1PB.LeftAvgConcP == null)
                vO2MaxProgram1PB.AvgConcPowerIndex = 0;
            else
                vO2MaxProgram1PB.AvgConcPowerIndex = (double)((vO2MaxProgram1PB.RightAvgConcP + vO2MaxProgram1PB.LeftAvgConcP) / 2);

            if (vO2MaxProgram1PB.RightAvgEcceP == null || vO2MaxProgram1PB.LeftAvgEcceP == null)
                vO2MaxProgram1PB.AvgEccePowerIndex = 0;
            else
                vO2MaxProgram1PB.AvgEccePowerIndex = (double)((vO2MaxProgram1PB.RightAvgEcceP + vO2MaxProgram1PB.LeftAvgEcceP) / 2);

            if (vO2MaxProgram1PB.LeftAvgConcP == null || vO2MaxProgram1PB.LeftAvgEcceP == null)
                vO2MaxProgram1PB.AvgLeftPowerIndex = 0;
            else
                vO2MaxProgram1PB.AvgLeftPowerIndex = (double)((vO2MaxProgram1PB.LeftAvgConcP + vO2MaxProgram1PB.LeftAvgEcceP) / 2);

            if (vO2MaxProgram1PB.RightAvgEcceP == null || vO2MaxProgram1PB.RightAvgConcP == null)
                vO2MaxProgram1PB.AvgRightPowerIndex = 0;
            else
                vO2MaxProgram1PB.AvgRightPowerIndex = (double)((vO2MaxProgram1PB.RightAvgEcceP + vO2MaxProgram1PB.RightAvgConcP) / 2);

            return vO2MaxProgram1PB;
        }
        public static Classes.PowerIndexPreviousBest GetRehabProgramRightPB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            Classes.PowerIndexPreviousBest rehabProgramRightPB = new Classes.PowerIndexPreviousBest();
            List<DataClasses.RehabProgramRight> ListRehabProgramRightPB = new List<DataClasses.RehabProgramRight>();

            ListRehabProgramRightPB = (from sessions in dc.GetTable<DataClasses.RehabProgramRight>()
                                      where sessions.UserID == UserID
                                      select sessions).ToList<DataClasses.RehabProgramRight>();

            rehabProgramRightPB.LeftAvgConcP = ListRehabProgramRightPB.Max(z => z.LeftAvgConcP);
            rehabProgramRightPB.LeftAvgEcceP = ListRehabProgramRightPB.Max(z => z.LeftAvgEcceP);
            rehabProgramRightPB.RightAvgConcP = ListRehabProgramRightPB.Max(z => z.RightAvgConcP);
            rehabProgramRightPB.RightAvgEcceP = ListRehabProgramRightPB.Max(z => z.RightAvgEcceP);

            if (rehabProgramRightPB.LeftAvgConcP == null) rehabProgramRightPB.LeftAvgConcP = 0;
            if (rehabProgramRightPB.LeftAvgEcceP == null) rehabProgramRightPB.LeftAvgEcceP = 0;
            if (rehabProgramRightPB.RightAvgConcP == null) rehabProgramRightPB.RightAvgConcP = 0;
            if (rehabProgramRightPB.RightAvgEcceP == null) rehabProgramRightPB.RightAvgEcceP = 0;

            if (rehabProgramRightPB.RightAvgConcP == null || rehabProgramRightPB.LeftAvgConcP == null)
                rehabProgramRightPB.AvgConcPowerIndex = 0;
            else
                rehabProgramRightPB.AvgConcPowerIndex = (double)((rehabProgramRightPB.RightAvgConcP + rehabProgramRightPB.LeftAvgConcP) / 2);

            if (rehabProgramRightPB.RightAvgEcceP == null || rehabProgramRightPB.LeftAvgEcceP == null)
                rehabProgramRightPB.AvgEccePowerIndex = 0;
            else
                rehabProgramRightPB.AvgEccePowerIndex = (double)((rehabProgramRightPB.RightAvgEcceP + rehabProgramRightPB.LeftAvgEcceP) / 2);

            if (rehabProgramRightPB.LeftAvgConcP == null || rehabProgramRightPB.LeftAvgEcceP == null)
                rehabProgramRightPB.AvgLeftPowerIndex = 0;
            else
                rehabProgramRightPB.AvgLeftPowerIndex = (double)((rehabProgramRightPB.LeftAvgConcP + rehabProgramRightPB.LeftAvgEcceP) / 2);

            if (rehabProgramRightPB.RightAvgEcceP == null || rehabProgramRightPB.RightAvgConcP == null)
                rehabProgramRightPB.AvgRightPowerIndex = 0;
            else
                rehabProgramRightPB.AvgRightPowerIndex = (double)((rehabProgramRightPB.RightAvgEcceP + rehabProgramRightPB.RightAvgConcP) / 2);

            return rehabProgramRightPB;
        }
        public static Classes.PowerIndexPreviousBest GetProprioceptionProgramPB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            Classes.PowerIndexPreviousBest proprioceptionProgramPB = new Classes.PowerIndexPreviousBest();
            List<DataClasses.ProprioceptionProgram> ProgramPB = new List<DataClasses.ProprioceptionProgram>();

            ProgramPB = (from sessions in dc.GetTable<DataClasses.ProprioceptionProgram>()
                                   where sessions.UserID == UserID
                                   select sessions).ToList<DataClasses.ProprioceptionProgram>();

            proprioceptionProgramPB.LeftAvgConcP = ProgramPB.Max(z => z.LeftAvgConcP);
            proprioceptionProgramPB.LeftAvgEcceP = ProgramPB.Max(z => z.LeftAvgEcceP);
            proprioceptionProgramPB.RightAvgConcP = ProgramPB.Max(z => z.RightAvgConcP);
            proprioceptionProgramPB.RightAvgEcceP = ProgramPB.Max(z => z.RightAvgEcceP);

            if (proprioceptionProgramPB.LeftAvgConcP == null) proprioceptionProgramPB.LeftAvgConcP = 0;
            if (proprioceptionProgramPB.LeftAvgEcceP == null) proprioceptionProgramPB.LeftAvgEcceP = 0;
            if (proprioceptionProgramPB.RightAvgConcP == null) proprioceptionProgramPB.RightAvgConcP = 0;
            if (proprioceptionProgramPB.RightAvgEcceP == null) proprioceptionProgramPB.RightAvgEcceP = 0;

            if (proprioceptionProgramPB.RightAvgConcP == null || proprioceptionProgramPB.LeftAvgConcP == null)
                proprioceptionProgramPB.AvgConcPowerIndex = 0;
            else
                proprioceptionProgramPB.AvgConcPowerIndex = (double)((proprioceptionProgramPB.RightAvgConcP + proprioceptionProgramPB.LeftAvgConcP) / 2);

            if (proprioceptionProgramPB.RightAvgEcceP == null || proprioceptionProgramPB.LeftAvgEcceP == null)
                proprioceptionProgramPB.AvgEccePowerIndex = 0;
            else
                proprioceptionProgramPB.AvgEccePowerIndex = (double)((proprioceptionProgramPB.RightAvgEcceP + proprioceptionProgramPB.LeftAvgEcceP) / 2);

            if (proprioceptionProgramPB.LeftAvgConcP == null || proprioceptionProgramPB.LeftAvgEcceP == null)
                proprioceptionProgramPB.AvgLeftPowerIndex = 0;
            else
                proprioceptionProgramPB.AvgLeftPowerIndex = (double)((proprioceptionProgramPB.LeftAvgConcP + proprioceptionProgramPB.LeftAvgEcceP) / 2);

            if (proprioceptionProgramPB.RightAvgEcceP == null || proprioceptionProgramPB.RightAvgConcP == null)
                proprioceptionProgramPB.AvgRightPowerIndex = 0;
            else
                proprioceptionProgramPB.AvgRightPowerIndex = (double)((proprioceptionProgramPB.RightAvgEcceP + proprioceptionProgramPB.RightAvgConcP) / 2);

            return proprioceptionProgramPB;
        }
        public static Classes.PowerIndexPreviousBest GetRehabProgramBilateralRemotePB(int UserID)
        {
            DataClasses.GrucoxDataClassesRemoteDBDataContext dc = new DataClasses.GrucoxDataClassesRemoteDBDataContext();
            Classes.PowerIndexPreviousBest rehabProgramPB = new Classes.PowerIndexPreviousBest();
            List<DataClasses.GrucoxRehabBilateralSession> ListRehabProgramPB = new List<DataClasses.GrucoxRehabBilateralSession>();

            try
            {
                ListRehabProgramPB = (from sessions in dc.GetTable<DataClasses.GrucoxRehabBilateralSession>()
                                      where sessions.LiveUserID == UserID
                                      select sessions).ToList<DataClasses.GrucoxRehabBilateralSession>();
            }
            catch (Exception)
            {
                //For Diagnostics - Should be removed
                DataComms.CreateThreadInstance("DB Access during GetRehabProgramBilateralRemotePB");
            }
            finally
            {
                rehabProgramPB.LeftAvgConcP = ListRehabProgramPB.Max(z => z.LeftAvgConcP).HasValue ? (double)ListRehabProgramPB.Max(z => z.LeftAvgConcP) : 0.0;         //If you cast a value to a double, it may not be null
                rehabProgramPB.LeftAvgEcceP = ListRehabProgramPB.Max(z => z.LeftAvgEcceP).HasValue ? (double)ListRehabProgramPB.Max(z => z.LeftAvgEcceP) : 0.0;
                rehabProgramPB.RightAvgConcP = ListRehabProgramPB.Max(z => z.RightAvgConcP).HasValue ? (double)ListRehabProgramPB.Max(z => z.RightAvgConcP) : 0.0;
                rehabProgramPB.RightAvgEcceP = ListRehabProgramPB.Max(z => z.RightAvgEcceP).HasValue ? (double)ListRehabProgramPB.Max(z => z.RightAvgEcceP) : 0.0;

                if (rehabProgramPB.RightAvgConcP == 0 || rehabProgramPB.LeftAvgConcP == 0)
                    rehabProgramPB.AvgConcPowerIndex = 0;
                else
                    rehabProgramPB.AvgConcPowerIndex = (double)((rehabProgramPB.RightAvgConcP + rehabProgramPB.LeftAvgConcP) / 2);

                if (rehabProgramPB.RightAvgEcceP == 0 || rehabProgramPB.LeftAvgEcceP == 0)
                    rehabProgramPB.AvgEccePowerIndex = 0;
                else
                    rehabProgramPB.AvgEccePowerIndex = (double)((rehabProgramPB.RightAvgEcceP + rehabProgramPB.LeftAvgEcceP) / 2);

                if (rehabProgramPB.LeftAvgConcP == 0 || rehabProgramPB.LeftAvgEcceP == 0)
                    rehabProgramPB.AvgLeftPowerIndex = 0;
                else
                    rehabProgramPB.AvgLeftPowerIndex = (double)((rehabProgramPB.LeftAvgConcP + rehabProgramPB.LeftAvgEcceP) / 2);

                if (rehabProgramPB.RightAvgEcceP == 0 || rehabProgramPB.RightAvgConcP == 0)
                    rehabProgramPB.AvgRightPowerIndex = 0;
                else
                    rehabProgramPB.AvgRightPowerIndex = (double)((rehabProgramPB.RightAvgEcceP + rehabProgramPB.RightAvgConcP) / 2);
            }
            return rehabProgramPB;     
        }