protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnClass objSqlConnClass = new SqlConnClass();
        TextAreaClass objTextAreaClass;
        objTextAreaClass = new TextAreaClass(objSqlConnClass.OpenConnection());
        DataSet DSCMS = objTextAreaClass.TxA_Get_TextAreas(Request.QueryString["cmstype"].ToString(), "2");

        try
        {

            if (DSCMS.Tables[0].Rows.Count > 0)//There needs to be at least 1 row
            {
                lblTextAreaHtml.Text = DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString();
                lblHeading.Text = DSCMS.Tables[0].Rows[0]["strDefaultName"].ToString();
                #region Insert visited log details

                AppLib.InsertVisitedSectionDetails(lblHeading.Text);

                #endregion
            }
        }
        catch { }
        finally
        {
            objSqlConnClass.CloseConnection();
            objSqlConnClass = null;
            objTextAreaClass = null;
            DSCMS = null;
        }
    }
    protected void lnkBtnSubmit_Click(object sender, EventArgs e)
    {
        try
        {

            SqlConnClass objSqlConnClass = new SqlConnClass();
            BackofficeClass objBackOfficeClass = new BackofficeClass();
            DDClass objDDClass;
            objDDClass = new DDClass(objSqlConnClass.OpenConnection());
            objBackOfficeClass = new BackofficeClass(objSqlConnClass.sqlConnection);
            DataSet DS1 = objBackOfficeClass.Mem_GET_UserInfo(AppLib.GetLoggedInUserName());
            if (DS1 != null)
            {
                if (DS1.Tables[0].Rows.Count > 0)
                {
                    DataSet DS = objDDClass.DD_INSERT_DdUsers(DS1.Tables[0].Rows[0]["USER_ID"].ToString(), txtCalories.Text.Trim());
                    objSqlConnClass.CloseConnection();
                    objBackOfficeClass = null;
                    objDDClass = null;
                }
            }

            BLL.UserLib oUserLib = new BLL.UserLib();
            oUserLib.UpdateUserStratificationStep(new Guid(DS1.Tables[0].Rows[0]["USER_ID"].ToString()), "5");
            oUserLib = null;

            Response.Redirect(AppConfig.GetBaseSiteUrl() + "Users/RiskStratificationProcessStep6.aspx?id=" + Request.QueryString["id"].ToString() + "&c=" + Request.QueryString["c"].ToString() + "&sc=" + Request.QueryString["sc"].ToString());
        }
        catch { }
    }
    protected void lnkBtnSubmit_Click(object sender, EventArgs e)
    {
        if (hfCategoryId.Value.ToString() == null)
        {
            lblError.Text = "Please accept the waiver agreement";
            return;
        }
        else
        {
            try
            {
                SqlConnClass objSqlConnClass = new SqlConnClass();
                BackofficeClass objBackOfficeClass = new BackofficeClass();
                PALClass objPALClass;
                objPALClass = new PALClass(objSqlConnClass.OpenConnection());
                objBackOfficeClass = new BackofficeClass(objSqlConnClass.sqlConnection);

                DataSet DS1 = objBackOfficeClass.Mem_GET_UserInfo(AppLib.GetLoggedInUserName());
                if (DS1 != null)
                {
                    if (DS1.Tables[0].Rows.Count > 0)
                    {
                        DataSet DS = objPALClass.PAL_INSERTMULTIPLE_PalStarts(DS1.Tables[0].Rows[0]["USER_ID"].ToString(), hfCategoryId.Value, DateTime.Now.ToString("MM/dd/yyyy"), "1");

                        objSqlConnClass.CloseConnection();

                        objBackOfficeClass = null;
                        objPALClass = null;
                        BLL.UserLib oUserLib = new BLL.UserLib();
                        oUserLib.UpdateUserStratificationStep(new Guid(DS1.Tables[0].Rows[0]["USER_ID"].ToString()), "4");
                        oUserLib = null;
                        DS = null;

                        Response.Redirect(AppConfig.GetBaseSiteUrl() + "Users/RiskStratificationProcessStep5.aspx?id=" + Request.QueryString["id"].ToString() + "&c=" + Request.QueryString["c"].ToString() + "&sc=" + Request.QueryString["sc"].ToString());

                    }
                }

                objSqlConnClass.CloseConnection();
                objBackOfficeClass = null;
                objPALClass = null;
            }
            catch { }
        }
    }
    private void fillOutForm()
    {
        SqlConnClass objSqlConnClass = new SqlConnClass();
        FoodExchangeClass objFoodExchangeClass = new FoodExchangeClass(objSqlConnClass.OpenConnection());

        literalFoodExchange.Text = objFoodExchangeClass.GetFoodExchangeTable();

        objSqlConnClass.CloseConnection();
    }
    /// <summary>
    /// BindDetails() function used to bind all the details that need to be display on the page load.
    /// </summary>
    private void BindCMSDetails()
    {
        SqlConnClass objSqlConnClass = new SqlConnClass();
        TextAreaClass objTextAreaClass;
        objTextAreaClass = new TextAreaClass(objSqlConnClass.OpenConnection());
        DataSet DSCMS = objTextAreaClass.TxA_Get_TextAreas("MyNutritionOverview", "2");

        try
        {
            if (DSCMS.Tables[0].Rows.Count > 0)//There needs to be at least 1 row
            {
                if (DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString().Length > 900)
                    lblNutritionOverview.Text = DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblNutritionOverview.Text = DSCMS.Tables[0].Rows[0]["TextAreaHTML"].ToString();
            }
        }
        catch { }
        finally
        {
            objSqlConnClass.CloseConnection();
            objSqlConnClass = null;
            objTextAreaClass = null;
            DSCMS = null;
        }
    }
    private void BindCMSText()
    {
        TextAreaClass objTextAreaClass;
        SqlConnClass objSqlConnClass = new SqlConnClass();
        objTextAreaClass = new TextAreaClass(objSqlConnClass.OpenConnection());

        DataSet DS = objTextAreaClass.Get_MultipleCMSPagesText();

        for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
        {
            string strTemp = DS.Tables[0].Rows[i]["strPageName"].ToString();
            if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("tutorialsandnavigation"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblTutorialNavigationHTMLText.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblTutorialNavigationHTMLText.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("goalsobjectives"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblGoalsObjectives.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblGoalsObjectives.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }

            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("levelofintensity"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblLevelOfIntensity.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblLevelOfIntensity.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("howwemeasure"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblHowWeMeasure.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblHowWeMeasure.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("nutritioncenter"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblNutritionCenter.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblNutritionCenter.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("personalfitness"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lbPersonalFitness.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lbPersonalFitness.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("wellnessdairy"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblWellnessDiary.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblWellnessDiary.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
            else if (DS.Tables[0].Rows[i]["strPageName"].ToString().ToLower().Equals("wellnessdairyforum"))
            {
                if (DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Length > 900)
                    lblWellnessDairyForum.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString().Substring(0, 900);
                else
                    lblWellnessDairyForum.Text = DS.Tables[0].Rows[i]["TextAreaHTML"].ToString();
            }
        }

        DS = null;
        objTextAreaClass = null;
        objSqlConnClass.CloseConnection();
        objSqlConnClass = null;
    }
    /// <summary>
    /// following function is used to bind the nutritional journal details
    /// </summary>
    private void BindNutritionalJournal()
    {
        BLL.UserLib oUserLib = new BLL.UserLib();
        Entity.UserInfo oUserInfo = new Entity.UserInfo();
        SqlConnClass objSqlConnClass = new SqlConnClass();
        DDClass objDDClass = new DDClass(objSqlConnClass.OpenConnection());
        try
        {

        }
        catch
        { }
        finally
        {
            objSqlConnClass.CloseConnection();
            objSqlConnClass = null;
            objDDClass = null;
            oUserLib = null;
            oUserInfo = null;
        }
    }
        private void ProcessMembershipLogin(string username)
        {
            username = username.Replace("'", "''");
            this.cmd.Parameters.Clear();
               // this.cmd.CommandText = string.Format("SELECT UserID, UserName FROM ForumUsers WHERE UserName='******' AND Disabled=0", username);
            this.cmd.CommandText = string.Format("SELECT UserID, Email FROM ForumUsers WHERE Email='{0}' AND Disabled=0", username);
            this.cn.Open();
            DbDataReader dr = cmd.ExecuteReader();
            if (dr.Read()) //if user found if db (already exists)
            {
                Session["aspnetforumUserID"] = (dr[0]).ToString();
                Session["aspnetforumUserName"] = (dr[1]).ToString();
                dr.Close();
            }
            else //user not exists YET - let's add him to our ForumUsers table
            {

                SqlConnClass objSqlConnClass = new SqlConnClass();
                UsersClass objUsersClass = new UsersClass(objSqlConnClass.OpenConnection());

                //DataRow DR = objUsersClass.USR_GET_GetUserInfo(Membership.GetUser().ProviderUserKey.ToString()).Tables[0].Rows[0];
                /*Above line is commented by Netsmartz*/
                DataSet ds = objUsersClass.USR_GET_GetUserInfo(Membership.GetUser().ProviderUserKey.ToString());
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataRow DR = ds.Tables[0].Rows[0];
                    string sUserDisplayName = "";
                    if (DR != null)
                    {
                        sUserDisplayName = DR["FNAME"].ToString() + " " + DR["LNAME"].ToString();
                    }
                    objSqlConnClass.CloseConnection();

                    dr.Close();
                    this.cmd.Parameters.Clear();
                    this.cmd.CommandText = "INSERT INTO ForumUsers (UserID, UserName, Email, [Password], UserDisplayName, Homepage, Interests, RegistrationDate, Disabled, ActivationCode) " +
                        "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
                    Utils.DB.PrepareCommandText(ref cmd);
                    Utils.DB.FillCommandParamaters(ref cmd, Membership.GetUser().ProviderUserKey.ToString(), username, "none", "none", sUserDisplayName, string.Empty, string.Empty, Utils.GetCurrTime(), false, string.Empty);
                    this.cmd.ExecuteNonQuery();

                    this.cmd.Parameters.Clear();
                    this.cmd.CommandText = string.Format("SELECT UserID, UserName FROM ForumUsers WHERE UserName='******' AND Disabled=0", username);
                    dr = cmd.ExecuteReader();
                    dr.Read();
                    Session["aspnetforumUserID"] = (dr[0]).ToString();
                    Session["aspnetforumUserName"] = dr[1].ToString();
                    dr.Close();
                }

            }

            this.cn.Close();
        }
    /// <summary>
    /// following function is used to bind the nutritional journal details
    /// </summary>
    private void BindNutritionalJournal()
    {
        BLL.UserLib oUserLib = new BLL.UserLib();
        Entity.UserInfo oUserInfo = new Entity.UserInfo();
        SqlConnClass objSqlConnClass = new SqlConnClass();
        DDClass objDDClass = new DDClass(objSqlConnClass.OpenConnection());
        DataSet DS = objDDClass.get_User_Calorie(Membership.GetUser().ProviderUserKey.ToString());
        try
        {
            if (DS.Tables[0].Rows.Count > 0)
                txtCurrentCalorie.Text = DS.Tables[0].Rows[0]["CALORIE_NUMBER"].ToString();

            oUserInfo = oUserLib.GetFoodExchangeChartByCalories(Convert.ToInt32(DS.Tables[0].Rows[0]["CALORIE_NUMBER"]));
            if (oUserInfo != null)
            {
                lblMilk.Text = oUserInfo.IntMilk.ToString();
                lblFruit.Text = oUserInfo.IntFruit.ToString();
                lblVegetables.Text = oUserInfo.IntVegetable.ToString();
                lblStarch.Text = oUserInfo.IntStarch.ToString();
                lblProtein.Text = oUserInfo.IntProtein.ToString();
                lblFat.Text = oUserInfo.IntFat.ToString();
                lblWater.Text = oUserInfo.IntWater.ToString();
            }
        }
        catch
        { }
        finally
        {
            objSqlConnClass.CloseConnection();
            objSqlConnClass = null;
            objDDClass = null;
            DS = null;
            oUserLib = null;
            oUserInfo = null;
        }
    }