public static DataClasses.VO2MaxTestConcForward GetVO2MaxConcForwRemotePB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            List<DataClasses.VO2MaxTestConcForward> ListVO2MaxConcForwPB = new List<DataClasses.VO2MaxTestConcForward>();
            DataClasses.VO2MaxTestConcForward VO2MaxConForwPB = new DataClasses.VO2MaxTestConcForward();

            try
            {
                ListVO2MaxConcForwPB = (from sessions in dc.GetTable<DataClasses.VO2MaxTestConcForward>()
                                        where sessions.UserID == UserID
                                        select sessions).ToList<DataClasses.VO2MaxTestConcForward>();
            }
            catch (Exception)
            {

            }
            finally
            {
                if (ListVO2MaxConcForwPB.Count > 0)
                {
                    VO2MaxConForwPB = (ListVO2MaxConcForwPB.First(x => x.VO2Max == (double)ListVO2MaxConcForwPB.Max(i => i.VO2Max)));
                }
                else
                {
                    VO2MaxConForwPB.VO2Max = 0;
                    VO2MaxConForwPB.VO2MaxRel = 0;
                }
            }

            return VO2MaxConForwPB;
        } 
        public static DataClasses.CustomProgram GetCustomProgramLocalPB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            DataClasses.CustomProgram customProgramPB = new DataClasses.CustomProgram();

            try
            {
                var ListcustomProgramPB = (from sessions in dc.GetTable<DataClasses.CustomProgram>()
                                           where sessions.UserID == UserID
                                           select sessions).ToList<DataClasses.CustomProgram>();

                customProgramPB.LeftAvgConcP = ListcustomProgramPB.Max(z => z.LeftAvgConcP);
                customProgramPB.LeftAvgEcceP = ListcustomProgramPB.Max(z => z.LeftAvgEcceP);
                customProgramPB.RightAvgConcP = ListcustomProgramPB.Max(z => z.RightAvgConcP);
                customProgramPB.RightAvgEcceP = ListcustomProgramPB.Max(z => z.RightAvgEcceP);


                if (customProgramPB.LeftAvgConcP == null) customProgramPB.LeftAvgConcP = 0;
                if (customProgramPB.LeftAvgEcceP == null) customProgramPB.LeftAvgEcceP = 0;
                if (customProgramPB.RightAvgConcP == null) customProgramPB.RightAvgConcP = 0;
                if (customProgramPB.RightAvgEcceP == null) customProgramPB.RightAvgEcceP = 0;
            }
            catch (Exception)
            { 
                customProgramPB.LeftAvgConcP = 0;
                customProgramPB.LeftAvgEcceP = 0;
                customProgramPB.RightAvgConcP = 0;
                customProgramPB.RightAvgEcceP = 0;
            }

            return customProgramPB;
        }
        public static List<DataClasses.ProprioceptionProgram> GetProprioceptionSessionsByUserID(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            return (from sessions in dc.GetTable<DataClasses.ProprioceptionProgram>()
                    where sessions.UserID == UserID
                    select sessions).ToList<DataClasses.ProprioceptionProgram>();
        }
        /// <summary>
        /// Update or Register a new user
        /// </summary>
        /// <param name="NewUser"></param>
        public static bool RegisterNewUser(DataClasses.UserProfile NewUser)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            try
            {
                var matchedItem = (from users in dc.GetTable<DataClasses.UserProfile>()        //**************************************
                                   where users.id == NewUser.id                                 //******Check if customer already exists
                                   select users).SingleOrDefault();                             //**************************************

                if (matchedItem == null)                                                //If customer does not exist
                {
                    try
                    {
                        dc.UserProfiles.InsertOnSubmit(NewUser);
                        dc.UserProfiles.Context.SubmitChanges();                      //Add the new customer to the Customers Table
                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }
                }
                else                                                                    //Customer already exists
                {
                    try
                    {
                        dc.SubmitChanges();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }

                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                frmMessageDialog.DisplayBriefMessage("Local Database Connection Error");
                return false;
            }
            catch (Exception ex)
            {
                frmMessageDialog.DisplayBriefMessage(ex.Message);
                return false;
            }
        }
        public static void DeleteUser(DataClasses.UserProfile CurrentUser)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            var matchedUser = (from sessions in dc.GetTable<DataClasses.UserProfile>()
                               where sessions.id == CurrentUser.id
                               select sessions).SingleOrDefault();

            try
            {
                dc.UserProfiles.DeleteOnSubmit(matchedUser);
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        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 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 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 DataClasses.UserProfile GetUserByEmail(string EmailAddress)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            try
            {
                return (from users in dc.GetTable<DataClasses.UserProfile>()
                        where users.EmailAddress.ToLower().Equals(EmailAddress.ToLower())
                        select users).SingleOrDefault();
            }
            catch (System.Data.SqlClient.SqlException)
            {
                //frmMessageDialog.DisplayBriefMessage("Local Database Connection Error");
                return null;
            }
            catch (Exception ex)
            {
                frmMessageDialog.DisplayBriefMessage(ex.Message);
                return null;
            }

        }
        public static List<DataClasses.RehabProgramLeft> GetRehabLeftLegSessionsByUserID(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            return (from sessions in dc.GetTable<DataClasses.RehabProgramLeft>()
                    where sessions.UserID == UserID
                    select sessions).ToList<DataClasses.RehabProgramLeft>();
        }
        public static bool StoreDataVO2Max_LocalDB(DataClasses.VO2MaxProgram1 vO2MaxProgram1, int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            var matchedItem = (from sessions in dc.GetTable<DataClasses.VO2MaxProgram1>()           //**************************************
                               where sessions.id == vO2MaxProgram1.id                               //******Check if customer already exists
                               select sessions).SingleOrDefault();                                 //**************************************

            if (matchedItem == null)                                                //If customer does not exist
            {
                try
                {
                    dc.VO2MaxProgram1s.InsertOnSubmit(vO2MaxProgram1);
                    dc.VO2MaxProgram1s.Context.SubmitChanges();                      //Add the new customer to the Customers Table
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else                                                                    //Customer already exists
            {
                try
                {
                    dc.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }
        }
        public static List<DataClasses.VO2MaxProgram1> GetVO2Max1SessionsByUserID(int UserID, int VO2MaxProgramEnum)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            return (from sessions in dc.GetTable<DataClasses.VO2MaxProgram1>()
                    where sessions.UserID == UserID && sessions.VO2MaxProgramEnum == VO2MaxProgramEnum
                    select sessions).ToList<DataClasses.VO2MaxProgram1>();
        }
        private static bool StoreDataDynamicStrength_LocalDB(DataClasses.DynamicStrengthTest dynamicStrengthTest, int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            var matchedItem = (from sessions in dc.GetTable<DataClasses.DynamicStrengthTest>()          //**************************************
                               where sessions.id == dynamicStrengthTest.id                              //******Check if customer already exists
                               select sessions).SingleOrDefault();                                     //**************************************

            if (matchedItem == null)                                                //If customer does not exist
            {
                try
                {
                    dc.DynamicStrengthTests.InsertOnSubmit(dynamicStrengthTest);
                    dc.DynamicStrengthTests.Context.SubmitChanges();                      //Add the new customer to the Customers Table
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else                                                                    //Customer already exists
            {
                try
                {
                    dc.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
        }
        public static DataClasses.DynamicStrengthTest GetDynamicStrengthPB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            List<DataClasses.DynamicStrengthTest> ListDynamicStrengthPB = new List<DataClasses.DynamicStrengthTest>();
            DataClasses.DynamicStrengthTest DynamicStrengthPB = new DynamicStrengthTest();

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

            if (ListDynamicStrengthPB.Count > 0)
            {
                DynamicStrengthPB.LeftMaxTorqueConc = (ListDynamicStrengthPB.First(x => x.LeftMaxTorqueConc == (double)ListDynamicStrengthPB.Max(i => i.LeftMaxTorqueConc))).LeftMaxTorqueConc;
                DynamicStrengthPB.LeftMaxTorqueEcce = (ListDynamicStrengthPB.First(x => x.LeftMaxTorqueEcce == (double)ListDynamicStrengthPB.Max(i => i.LeftMaxTorqueEcce))).LeftMaxTorqueEcce;
                DynamicStrengthPB.RightMaxTorqueConc = (ListDynamicStrengthPB.First(x => x.RightMaxTorqueConc == (double)ListDynamicStrengthPB.Max(i => i.RightMaxTorqueConc))).RightMaxTorqueConc;
                DynamicStrengthPB.RightMaxTorqueEcce = (ListDynamicStrengthPB.First(x => x.RightMaxTorqueEcce == (double)ListDynamicStrengthPB.Max(i => i.RightMaxTorqueEcce))).RightMaxTorqueEcce;
                DynamicStrengthPB.SpeedLeftMaxConc = (ListDynamicStrengthPB.First(x => x.LeftMaxTorqueConc == (double)ListDynamicStrengthPB.Max(i => i.LeftMaxTorqueConc))).SpeedLeftMaxConc;
                DynamicStrengthPB.SpeedLeftMaxEcce = (ListDynamicStrengthPB.First(x => x.LeftMaxTorqueEcce == (double)ListDynamicStrengthPB.Max(i => i.LeftMaxTorqueEcce))).SpeedLeftMaxEcce;
                DynamicStrengthPB.SpeedRightMaxConc = (ListDynamicStrengthPB.First(x => x.RightMaxTorqueConc == (double)ListDynamicStrengthPB.Max(i => i.RightMaxTorqueConc))).SpeedRightMaxConc;
                DynamicStrengthPB.SpeedRightMaxEcce = (int)(ListDynamicStrengthPB.First(x => x.RightMaxTorqueEcce == (double)ListDynamicStrengthPB.Max(i => i.RightMaxTorqueEcce))).SpeedRightMaxEcce;
            }
            else
            {
                DynamicStrengthPB.LeftMaxTorqueConc = 0;
                DynamicStrengthPB.LeftMaxTorqueEcce = 0;
                DynamicStrengthPB.RightMaxTorqueConc = 0;
                DynamicStrengthPB.RightMaxTorqueEcce = 0;
                DynamicStrengthPB.SpeedLeftMaxConc = 0;
                DynamicStrengthPB.SpeedLeftMaxEcce = 0;
                DynamicStrengthPB.SpeedRightMaxConc = 0;
                DynamicStrengthPB.SpeedRightMaxEcce = 0;
            }

            return DynamicStrengthPB;
        }
        public static List<DataClasses.StaticStrengthTest> GetStaticStrengthSessionByUserID(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            return (from sessions in dc.GetTable<DataClasses.StaticStrengthTest>()
                    where sessions.UserID == UserID
                    select sessions).ToList<DataClasses.StaticStrengthTest>();
        }
        public static float[] GetStaticStrengthPB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            List<DataClasses.StaticStrengthTest> ListStaticStrength_PB = new List<DataClasses.StaticStrengthTest>();
            float[] RetVal = new float[2];

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

            if (ListStaticStrength_PB.Count > 0)
            {
                RetVal[0] = (float)ListStaticStrength_PB.Max(z => z.LeftMaxTorque);
                RetVal[1] = (float)ListStaticStrength_PB.Max(z => z.RightMaxTorque);
            }
            else
            {
                RetVal[0] = 0;
                RetVal[1] = 0;
            }

            return RetVal;
        }
        public static List<DataClasses.CustomProgram> GetCustomProgramSessionsByUserID(int UserID)
        {
            if (CalibrationSettings.Default.IsInternetConfigured == true && UserID != 0)
            {
                GrucoxDataClassesRemoteDBDataContext dc = new GrucoxDataClassesRemoteDBDataContext();
                var CustomProgramSessions = (from sessions in dc.GetTable<GrucoxCustomProgramSession>()
                                            where sessions.LiveUserID == UserID
                                            select sessions).ToList<GrucoxCustomProgramSession>();

                List<DataClasses.CustomProgram> custProgramList = new List<CustomProgram>();
                foreach (var session in CustomProgramSessions)
                {
                    custProgramList.Add(session.ToCustomProgram());
                }
                return custProgramList;
            }
            else
            {
                DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

                return (from sessions in dc.GetTable<DataClasses.CustomProgram>()
                        where sessions.UserID == UserID
                        select sessions).ToList<DataClasses.CustomProgram>();
            }
        }
        public static List<DataClasses.FTPTestConcForward> GetFTPTestSessionByUserID(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            return (from sessions in dc.GetTable<DataClasses.FTPTestConcForward>()
                    where sessions.UserID == UserID
                    select sessions).ToList<DataClasses.FTPTestConcForward>();
        }
        public static float GetFTP_PB(int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            List<DataClasses.FTPTestConcForward> ListFTP_PB = new List<DataClasses.FTPTestConcForward>();

            float RetVal = 0;

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

            if (ListFTP_PB.Count > 0)
                RetVal = (float)ListFTP_PB.Max(z => z.FTPConcForwards);
            else
                RetVal = 0;

            return RetVal;
        }
        public static bool StoreDataRehabLeft_LocalDB(DataClasses.RehabProgramLeft rehabProgramLeft, int UserID)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            var matchedItem = (from sessions in dc.GetTable<DataClasses.RehabProgramLeft>()
                               where sessions.id == rehabProgramLeft.id
                               select sessions).SingleOrDefault();

            if (matchedItem == null)
            {
                try
                {
                    dc.RehabProgramLefts.InsertOnSubmit(rehabProgramLeft);
                    dc.RehabProgramLefts.Context.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else
            {
                try
                {
                    dc.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }
        }
        private static bool StoreDataProprioceptionProgram_LocalDB(DataClasses.ProprioceptionProgram proprioceptionProgram, int UserID, int DifficultyLevel)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();

            var matchedItem = (from sessions in dc.GetTable<DataClasses.ProprioceptionProgram>()           //**************************************
                               where sessions.id == proprioceptionProgram.id                               //******Check if customer already exists
                               select sessions).SingleOrDefault();                                 //**************************************

            if (matchedItem == null)                                                //If customer does not exist
            {
                try
                {
                    dc.ProprioceptionPrograms.InsertOnSubmit(proprioceptionProgram);
                    dc.ProprioceptionPrograms.Context.SubmitChanges();                      //Add the new customer to the Customers Table
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else                                                                    //Customer already exists
            {
                try
                {
                    dc.SubmitChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }
        }
        public static void ResetUserData(DataClasses.UserProfile CurrentUser)
        {
            DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
            var matchedEntries = (from sessions in dc.GetTable<DataClasses.CustomProgram>()
                                  where sessions.UserID == CurrentUser.id
                                  select sessions).ToList<DataClasses.CustomProgram>();

            try
            {
                foreach (DataClasses.CustomProgram entry in matchedEntries)
                    dc.CustomPrograms.DeleteOnSubmit(entry);
                dc.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
 public static List<DataClasses.UserProfile> GetUsers()
 {
     DataClasses.GrucoxDataClassDataContext dc = new DataClasses.GrucoxDataClassDataContext();
     return (from sessions in dc.GetTable<DataClasses.UserProfile>()
             select sessions).ToList<DataClasses.UserProfile>();
 }