protected void btnLog_Click(object sender, EventArgs e) { if (checkZeroes()) { exerciseID = Session["exerciseID"] != null ? (int)Session["exerciseID"] : -1; //pnlExerciseDetails.Visible = false; string note = tbNotes.Text.Trim(); int weight = Convert.ToInt32(tbWeight.Text.ToString()); float distance = (float)Convert.ToDouble(tbDistance.Text.ToString()); // convert the 2 text boxes to seconds int time = Convert.ToInt32(tbTime_min.Text.ToString()) * 60 + Convert.ToInt32(tbTime_sec.Text.ToString()); int rep = Convert.ToInt32(tbRep.Text.ToString()); ExperienceManager expMngr = new ExperienceManager(); int exp = logManager.logExerciseIntoRoutine(userID, exerciseID, routineID, rep, time, weight, distance, note); ExerciseGoal eg = goalMngr.getUnachievedGoalByExerciseNameAndUserID(sysManager.getExerciseInfo(exerciseID).name, userID); if (eg != null) { if (goalMngr.achieveGoal(eg, rep, time, weight, distance)) { goalAchievedLbl.Text = "Congratulations! You have achieved your goal for this exercise. You can view your goals "; goalsLink.Visible = true; } else { goalAchievedLbl.Text = ""; goalsLink.Visible = false; } } bool leveled = expMngr.rewardExperienceToUser(userID, exp); expRewardLbl.Text = "<br />You received " + exp.ToString() + " experience"; if (leveled) expRewardLbl.Text += "<br />Congratulations, you have leveled up!"; init(); pnlInfo.Visible = true; } }
protected void recordSet_Click(object sender, EventArgs e) { int timeValue, weightValue, repValue; double distanceValue; if (timeOn) { timeValue = createTime(Convert.ToInt32(timeMinutes.Text.Trim()), Convert.ToInt32(timeSeconds.Text.Trim())); } else { timeValue = 0; } if (weightOn) { weightValue = Convert.ToInt32(weight.Text.Trim()); } else { weightValue = 0; } if (repOn) { repValue = Convert.ToInt32(rep.Text.Trim()); } else { repValue = 0; } if (distanceOn) { distanceValue = Convert.ToDouble(distance.Text.Trim()); } else { distanceValue = 0; } //Begin log operations and exp extraction ExperienceManager expMngr = new ExperienceManager(); int exp = logManager.logExercise(user.id, selectedExercise.id, repValue, timeValue, weightValue, distanceValue); ExerciseGoal eg = goalMngr.getUnachievedGoalByExerciseNameAndUserID(selectedExercise.name, user.id); if (eg != null) { if (goalMngr.achieveGoal(eg, repValue, timeValue, weightValue, distanceValue)) { goalAchievedLbl.Text = "Congratulations! You have achieved your goal for this exercise. You can view your goals "; goalsLink.Visible = true; } } if (exp != 0) { bool leveled = expMngr.rewardExperienceToUser(user.id, exp); successLbl.Visible = true; expRewardLbl.Visible = true; expRewardLbl.Text = "You received " + exp.ToString() + " experience for logging a set for " + ucViewExercise.ddlValue; if (leveled) expRewardLbl.Text += "<br />Congratulations, you have leveled up!"; displayLogs(); //Manually set the selected index to 0 (the most recently logged exercise) and set the logID to the selected one to display the most recent log (this one) loggedExercises.SelectedIndex = 0; logID = Convert.ToInt64(loggedExercises.SelectedValue); loggedExercises_SelectedIndexChanged(sender, e); } else { successLbl.Visible = true; successLbl.Text = "Something went wrong!"; successLbl.ForeColor = Color.Red; } }