protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { btnHelp.Attributes.Add("onclick", "return window.open('" + STR_HELP_PAGE_URL + "');"); btnLogout.Attributes.Add("onclick", "return confirm('" + STR_ARE_YOU_SURE_YOU_WANT_TO_LOGOUT + "');"); if (User.Identity.IsAuthenticated) { NameBox.Text = Membership.GetUser().UserName; user = EatFit.Data.Users.GetUser(Membership.GetUser().UserName); Session["user"] = user; if (user != null) { AgeDropDown.SelectedValue = Convert.ToString(user.Age); string strGender = user.Gender; if (strGender != null) { if (strGender.Equals(STR_MALE)) { RadioButtonList1.SelectedIndex = 0; } else { RadioButtonList1.SelectedIndex = 1; } } } } } }
protected void MinorGoalNextButton_Click(object sender, EventArgs e) { if (MinorGoalList.SelectedIndex == -1) { lblErrorMinorGoals.Text = "Please Select a Minor Goal"; return; } try { // save minor goal to session Session["MinorGoal"] = MinorGoalList.SelectedIndex; // try saving session to database: if (user == null) { user = (EatFit.Data.User)Session["user"]; } if (user == null) { user = EatFit.Data.Users.GetUser(Membership.GetUser().UserName); } //da.saveToDB(EatFit.Data.Users.GetUser(Membership.GetUser().UserName)); da.saveToDB(user); /* * StringBuilder sb = new StringBuilder(); * System.Collections.Specialized.NameObjectCollectionBase.KeysCollection sessionKeys = Session.Keys; * foreach ( String key in sessionKeys) * { * sb.Append(key + " "); * } * Response.Write("SessionID: ["+Session.SessionID+"]; "+ sb.ToString()); */ } finally { } // label contract stuff next page lblContractMajorGoal.Text = getMajorGoalText(rbtnlistEatingArea.SelectedItem.Text, "my", true); //grab alterante minorgoal text from db lblContractMinorGoal.Text = da.GetMinorGoalAfterText(Convert.ToInt32(MinorGoalList.SelectedValue)); // grab the why lblContractWhy.Text = da.GetMinorGoalWhy(System.Convert.ToInt32((string)Session["EatingArea"]), ((int[])Session["goals"])[0]); MultiView1.ActiveViewIndex = 7; setActiveViewIndex(MultiView1.ActiveViewIndex); }
protected void Page_Load(object sender, EventArgs e) { user = Membership.GetUser(); UserName = user.UserName; userDetail = EatFit.Data.Users.GetUser(UserName); litLastLoginDate.Text = STR_LAST_LOGIN_PREFIX + user.LastLoginDate; litCreationDate.Text = STR_CREATION_DATE_PREFIX + user.CreationDate; litLastPasswordChangedDate.Text = STR_LAST_PASSWORD_CHANGED_PREFIX + user.LastPasswordChangedDate; if (!IsPostBack) { //EatFit.Data.User user = EatFit.Data.Users.GetUser(Membership.GetUser().UserName); lblMessage.Visible = false; tbUserId.Text = user.UserName.ToString(); dlistPasswordQuestion.SelectedValue = user.PasswordQuestion; tbEmail.Text = user.Email; dlistAges.SelectedValue = Convert.ToString(userDetail.Age); /* * // Load the schools into a list. * //System.Collections.Generic.List<School> schoolList = new System.Collections.Generic.List<School>(Schools.GetAllSchools()); * * dlistSchools.DataSource = new System.Collections.Generic.List<School>(Schools.GetAllSchools()); * dlistSchools.DataBind(); */ dlistSchools.SelectedValue = Convert.ToString(userDetail.SchoolId); /* * // Load the grade levels into a list. * //System.Collections.Generic.List<Grade> gradeList = new System.Collections.Generic.List<Grade>(Grades.GetAllGrades()); * dlistGrades.DataSource = new System.Collections.Generic.List<Grade>(Grades.GetAllGrades()); * dlistGrades.DataBind(); */ dlistGrades.SelectedValue = Convert.ToString(userDetail.GradeLevelId); } }
// saves the final analysis results to db public void saveToDB(EatFit.Data.User user) { dops.ResetDops(); dops.Sproc = "usp_InsertSessionInformation"; dops.SetParameter("@SessionID", System.Guid.NewGuid().ToString(), CAESDO.DataOps.DopsDirection.Input); // convert the food list to an xml stream DataSet ds = (DataSet)HttpContext.Current.Session["foodVars"]; string xml; UTF8Encoding encoding = new UTF8Encoding(); using (MemoryStream memoryStream = new MemoryStream()) { ds.WriteXml(memoryStream); xml = encoding.GetString(memoryStream.ToArray()); } // save the daily food list dops.SetParameter("@mealInfoXML", xml, CAESDO.DataOps.DopsDirection.Input); // save the nutrient list System.Collections.Specialized.StringDictionary[] nutinfo; // Convert the nutrients (vScore) list into an XML stream: nutinfo = (System.Collections.Specialized.StringDictionary[])HttpContext.Current.Session["vScore"]; float totFat = 0; float totSugar = 0; float totFruits = 0; float totIron = 0; float totCalcium = 0; float totHabits = 0; float tempInt = 0; foreach (System.Collections.Specialized.StringDictionary nutrients in nutinfo) { totFat += (float.TryParse(nutrients["fat"], out tempInt) ? tempInt : 0); totSugar += (float.TryParse(nutrients["sugar"], out tempInt) ? tempInt : 0); totFruits += (float.TryParse(nutrients["fruits"], out tempInt) ? tempInt : 0); totIron += (float.TryParse(nutrients["iron"], out tempInt) ? tempInt : 0); totCalcium += (float.TryParse(nutrients["calcium"], out tempInt) ? tempInt : 0); totHabits += (float.TryParse(nutrients["habits"], out tempInt) ? tempInt : 0); } dops.SetParameter("@fat", totFat, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@sugar", totSugar, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@fruits", totFruits, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@iron", totIron, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@calcium", totCalcium, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@habits", totHabits, CAESDO.DataOps.DopsDirection.Input); /* * using (MemoryStream ms = new MemoryStream()) * { * BinaryFormatter bf = new BinaryFormatter(); * //bf.FilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; * bf.Serialize(ms, nutinfo); * //UTF8Encoding encoding = new UTF8Encoding(); * xml = Convert.ToBase64String(ms.ToArray()); * //xml = encoding.GetString(ms.ToArray()); * } * */ /* * // Deserialization test. * System.Collections.Specialized.StringDictionary[] nutrientInfo; * using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(xml))) * { * BinaryFormatter bf = new BinaryFormatter(); * nutrientInfo = (System.Collections.Specialized.StringDictionary[])bf.Deserialize(ms); * } */ //dops.SetParameter("@nutinfoxml", xml, CAESDO.DataOps.DopsDirection.Input); // save the user's choices goal choices int[] goals = (int[])HttpContext.Current.Session["goals"]; dops.SetParameter("@goal1", Convert.ToInt16(goals[0]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@goal2", Convert.ToInt16(goals[1]), CAESDO.DataOps.DopsDirection.Input); // save minor goals dops.SetParameter("@minor_goal", Convert.ToInt16(HttpContext.Current.Session["MinorGoal"]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@howto_goal", Convert.ToInt16((string)HttpContext.Current.Session["EatingArea"]), CAESDO.DataOps.DopsDirection.Input); // save user info dops.SetParameter("@name", (string)HttpContext.Current.Session["personName"], CAESDO.DataOps.DopsDirection.Input); //dops.SetParameter("@name", user.UserName, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@age", Convert.ToInt16(HttpContext.Current.Session["age"]), CAESDO.DataOps.DopsDirection.Input); //dops.SetParameter("@age", user.Age, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@gender", (string)HttpContext.Current.Session["gender"], CAESDO.DataOps.DopsDirection.Input); //dops.SetParameter("@gender", user.Gender, CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@UserId", user.UserId, CAESDO.DataOps.DopsDirection.Input); // save eating habits string[] habits = (string[])HttpContext.Current.Session["habits"]; dops.SetParameter("@q1", Convert.ToInt16(habits[0]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@q2", Convert.ToInt16(habits[1]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@q3", Convert.ToInt16(habits[2]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@q4", Convert.ToInt16(habits[3]), CAESDO.DataOps.DopsDirection.Input); dops.SetParameter("@q5", Convert.ToInt16(habits[4]), CAESDO.DataOps.DopsDirection.Input); try { dops.Execute_Sql(); } catch (System.Data.SqlClient.SqlException ex) { throw ex; } }