protected void Page_Load(object sender, EventArgs e) { // Pull the current user via the client's sessionID currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); // If a user was found... if (currentUser != null) { // Check if the user is an admin. If yes.. if (currentUser.PermissionLevel > 0) { // Add the buttons to the nav menu for admins addButtons(AppCode.PageAccess.AdminPages); } else // If the user is just a normal user... { // Add the buttons to the nav menu for users addButtons(AppCode.PageAccess.UserPages); } } else { // If no user was found, add the default non-user pages addButtons(AppCode.PageAccess.DefaultPages); } }
CAT_2015.Rank nextRank = null; // Current user's next rank protected void Page_Load(object sender, EventArgs e) { // Get the logged in user currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); if (currentUser != null) // If a user was found.. { // Get the user's current rank currentRank = AppCode.Database.GetRankFromID(currentUser.RankID); // And fill the labels with the relavent information.. labelUsername.Text = "Username: "******"Nickname: " + currentUser.NickName; labelActualname.Text = "Real Name: " + currentUser.RealName; labelTotalPoints.Text = currentUser.Score.ToString() + " Points"; // If the nickname is locked.. if (currentUser.NickLocked) { // Make it red and display (Locked) labelNickname.CssClass = "nickLocked"; labelNickname.Text += " (Locked)"; } if (currentRank != null) // If a current rank was found.. { // Get the next rank nextRank = AppCode.Database.GetNextRankUp(currentRank); // And fill out information relating to the current rank labelRankName.Text = currentRank.Name; labelRankNumber.Text = "Level " + AppCode.Database.GetRankRanking(currentRank).ToString(); imageRank.ImageUrl = currentRank.Image; imageRank.ImageAlign = ImageAlign.Middle; if (nextRank != null) // If the user's next rank was found.. { int percentage = Convert.ToInt16(((double)(currentUser.Score - currentRank.MinScore) / (double)(nextRank.MinScore - currentRank.MinScore)) * 100); progressBar.setPercent(percentage); // Fill the labels with relavent information labelProgressPercentage.Text = "Next Level: " + (currentUser.Score - currentRank.MinScore).ToString() + " / " + (nextRank.MinScore - currentRank.MinScore).ToString() + " ( " + percentage.ToString() + "% ) "; } else { //if (AppCode.Database.IsMaxRank(currentRank)) //{ labelProgressPercentage.Text = "Max Level Achieved!"; // } } } } }
CAT_2015.User currentUser = null; // The current session's associated user protected void Page_Load(object sender, EventArgs e) { // Get the current session's user and set currentUser to it currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); if (currentUser != null) // If a user is found... { // Show the user in the corner of the page labelUser.Text = "User: " + currentUser.Username; } // If no user is found, the label will display nothing }
protected void Page_Load(object sender, EventArgs e) { // Get the current user currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); // If the current user does exist... if (currentUser != null) { // Get the user's obtained and requested achievements List<int> obtainedAchievements = AppCode.Database.GetUserAchievementIDs(currentUser, false, true); List<int> requestedAchievements = AppCode.Database.GetUserAchievementIDs(currentUser, true, false); int obtainedIndex = 0; int requestedIndex = 0; int unachievedIndex = 0; foreach(string s in AppCode.Cache.Achievements.Keys) { createHeaderRow(s); unachievedIndex++; obtainedIndex = unachievedIndex; requestedIndex = unachievedIndex; foreach (Achievement a in AppCode.Cache.Achievements[s]) { if (obtainedAchievements.Contains(a.ID)) { createRow(a, true, false, obtainedIndex); obtainedIndex++; requestedIndex++; unachievedIndex++; } else { if (requestedAchievements.Contains(a.ID)) { createRow(a, false, true, requestedIndex); requestedIndex++; unachievedIndex++; } else { createRow(a, false, false, unachievedIndex); unachievedIndex++; } } } } } }
protected void Page_Load(object sender, EventArgs e) { // Get the current user currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); // If the current user does exist... if (currentUser != null) { // Get the user's obtained and requested achievements List <int> obtainedAchievements = AppCode.Database.GetUserAchievementIDs(currentUser, false, true); List <int> requestedAchievements = AppCode.Database.GetUserAchievementIDs(currentUser, true, false); int obtainedIndex = 0; int requestedIndex = 0; int unachievedIndex = 0; foreach (string s in AppCode.Cache.Achievements.Keys) { createHeaderRow(s); unachievedIndex++; obtainedIndex = unachievedIndex; requestedIndex = unachievedIndex; foreach (Achievement a in AppCode.Cache.Achievements[s]) { if (obtainedAchievements.Contains(a.ID)) { createRow(a, true, false, obtainedIndex); obtainedIndex++; requestedIndex++; unachievedIndex++; } else { if (requestedAchievements.Contains(a.ID)) { createRow(a, false, true, requestedIndex); requestedIndex++; unachievedIndex++; } else { createRow(a, false, false, unachievedIndex); unachievedIndex++; } } } } } }
/// <summary> /// Returns the date that the achievement was obtained. Retuns today if achievement was /// never obtained or the query failed. CREATED 06/01/16 /// </summary> public static DateTime GetUserAchievementDateAchieved(CAT_2015.Achievement achievement, CAT_2015.User user) { // Get the date updated for this achievement from the achievementdata table. string query = "SELECT `DateUpdated` FROM `" + achievementDataTable + "` WHERE `AchievementID`='" + achievement.ID + "' AND `UserID`='" + user.ID + "'"; // Set the dateAchieved to something other than null. DateTime dateAchieved = DateTime.Today; // Create a command from the query and existing connection. OdbcCommand cmd = new OdbcCommand(query, connection); // If the connection is already open... if (connectionOpen()) { try { // Execute the command and open a reader. OdbcDataReader dataReader = cmd.ExecuteReader(); // If any rows are returned... if (dataReader.HasRows) { // Load the first record. dataReader.Read(); // Format the return as a DateTime. dateAchieved = dataReader.GetDateTime(0); // Close the datareader. dataReader.Close(); } } catch (OdbcException ex) { // Displays an error if something bad occurs while executing the command error = ex.Message; } } // Return the dateAchieved. Will return today if something bad occurs or the awarded // achievement could not be found. return(dateAchieved); }
void buttonLogin_Click(object sender, EventArgs e) { // If there is no user logged in... if (currentUser == null) { // Make sure there is something in the textboxes.. if (textBoxUsername.Text.Length >= 1 && textBoxPassword.Text.Length >= 1) { textBoxUsername.Text.Replace(@"\'", ""); // If the password is correct for the user (if the user exists).. if (CAT_2015.AppCode.Database.AuthenticateUser( textBoxUsername.Text.ToUpper(), textBoxPassword.Text, Session.SessionID)) { // Set the current user to that of the user that was logged in, // and set that user's sessionID to this client's sessionID currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); // Then take the user to their appropriate home page redirectHome(); } else { labelError.Text = "Could not authenticate user. Please check your " + "username and password and try again. The user could also no " + "longer be avaialable."; } } else { labelError.Text = "Please enter in a valid username and password."; } } else { // Take the user to their appropriate home page redirectHome(); } }
protected void Page_Load(object sender, EventArgs e) { // Get the current session's user and set currentUser to it currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); if (currentUser != null) // If a user was found... { // Get the achievements that need to be awarded achievementsToBeAwarded = AppCode.Database.GetUserAchievements(currentUser, false, false); if (achievementsToBeAwarded.Count > 0) // If any were found... { foreach (Achievement a in achievementsToBeAwarded) // Award them { // TODO: Show message boxes for the achievements // TODO: Include awards // TODO: Add the achievements here to user achievements } } else { // Otherwise, print to the console that no achievements // were found for this user to be awarded Console.WriteLine("No achievements to be awarded for user " + currentUser.ID); } // Now get the achievements that the user has already had awarded. userAchievements = AppCode.Database.GetUserAchievements(currentUser, false, true); if (userAchievements.Count > 0) // If there are any... { foreach (Achievement a in userAchievements) // Take each one and... { TableRow row = new TableRow(); // Create a row row.Height = 100; TableCell cell = new TableCell(); // Create a cell // Create an achievement element CAT_2015.Pages.User.Controls.AchievementElement achievementElement = (CAT_2015.Pages.User.Controls.AchievementElement)Page.LoadControl ("~/Pages/User/Controls/AchievementElement.ascx"); // Put the achievement element in the cell, the cell in the // row and the row in the achievement table cell.Controls.Add(achievementElement); row.Controls.Add(cell); tableAchievements.Controls.Add(row); // Then set the achievement element to display the current achievement achievementElement.SetAchievement(a, true, false, currentUser); } // Finally, get the most recent achievements' IDs List <int> recentAchievements = AppCode.Database.GetRecentAchievementIDsForUser(currentUser); if (recentAchievements.Count > 0) // If any are found... { // Match them up to the achievements in userAchievements foreach (Achievement a in userAchievements) { foreach (int id in recentAchievements) { if (a.ID == id) { // And create a row, cell and achievement element as before TableRow row = new TableRow(); row.Height = 100; TableCell cell = new TableCell(); CAT_2015.Pages.User.Controls.AchievementElement achievementElement = (CAT_2015.Pages.User.Controls.AchievementElement)Page.LoadControl ("~/Pages/User/Controls/AchievementElement.ascx"); // Put them in eachother as before, and set the achievement cell.Controls.Add(achievementElement); row.Controls.Add(cell); tableRecentAchievements.Controls.Add(row); achievementElement.SetAchievement(a, true, false, currentUser); } } } } } } else { // If no user is found, redirect the client to the default home address as defined // by the app settings. Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["DefaultHome"]); } }
public void SetAchievement(Achievement achievement, bool achieved, bool requested, CAT_2015.User user) { if (achievement != null && user != null) // If the achievement passed was not a null value... { // Set the name, description, image and points value to the correct values. labelName.Text = achievement.Name; labelDescription.Text = achievement.Description; imageAchievement.ImageUrl = achievement.Image; // If the value of the achievement is anything other than 1 or -1... if ((achievement.Value > 1 || achievement.Value < -1) && achievement.Value != 0) { // Make the points value plural labelPointsValue.Text = achievement.Value.ToString() + " " + ConfigurationManager.AppSettings["nameOfPointsValue"]; } else { // Make the points value single labelPointsValue.Text = achievement.Value.ToString() + " " + ConfigurationManager.AppSettings["nameOfPointsValueSingle"]; } if (!achieved) // If the achievement has yet to be achieved... { if (this.Parent != null) { if (this.Parent.Parent != null) { if (this.Parent.Parent.Parent != null) { if (this.Parent.Parent.Parent.ID == "tableAchievements") { CheckBox cb = new CheckBox(); cb.Text = "Request"; cb.CssClass = "base"; cellButtonRequest.Controls.Add(cb); cb.CheckedChanged += cb_CheckedChanged; } } } } if (requested) { Table1.CssClass += "Yellow"; cellImage.CssClass += "Yellow"; imageAchievement.CssClass += "Yellow"; cellName.CssClass += "Yellow"; labelName.CssClass += "Yellow"; cellPointsValue.CssClass += "Yellow"; labelPointsValue.CssClass += "Yellow"; cellDescription.CssClass += "Yellow"; labelDescription.CssClass += "Yellow"; cellDateAchieved.CssClass += "Yellow"; labelDateAchieved.CssClass += "Yellow"; } else { // Make the entire style of the achievement grey Table1.CssClass += "Grey"; cellImage.CssClass += "Grey"; imageAchievement.CssClass += "Grey"; cellName.CssClass += "Grey"; labelName.CssClass += "Grey"; cellPointsValue.CssClass += "Grey"; labelPointsValue.CssClass += "Grey"; cellDescription.CssClass += "Grey"; labelDescription.CssClass += "Grey"; cellDateAchieved.CssClass += "Grey"; labelDateAchieved.CssClass += "Grey"; if (achievement.Hidden) // If the achievement is hidden { // Make it look like the template defined by the Web.config labelName.Text = ConfigurationManager.AppSettings["hiddenAchievementName"]; labelDescription.Text = ConfigurationManager.AppSettings["hiddenAchievementDescription"]; imageAchievement.ImageUrl = AppCode.ImageManager.GetGreyScale( ConfigurationManager.AppSettings["hiddenAchievementImage"]); } else { imageAchievement.ImageUrl = AppCode.ImageManager.GetGreyScale(achievement.Image); } } } else // If the achievement has been achieved... { // Make it display that it was achieved on the specified day labelDateAchieved.Text = "Achieved " + AppCode.Database.GetUserAchievementDateAchieved(achievement, user).ToShortDateString(); } } }
protected void Page_Load(object sender, EventArgs e) { // Get the current session's user and set currentUser to it currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); buttonLogin.Click += buttonLogin_Click; }
protected void Page_Load(object sender, EventArgs e) { // Get the current session's user and set currentUser to it currentUser = AppCode.Database.GetLoggedInUser(Session.SessionID); if (currentUser != null) // If a user was found... { // Get the achievements that need to be awarded achievementsToBeAwarded = AppCode.Database.GetUserAchievements(currentUser, false, false); if (achievementsToBeAwarded.Count > 0) // If any were found... { foreach (Achievement a in achievementsToBeAwarded) // Award them { // TODO: Show message boxes for the achievements // TODO: Include awards // TODO: Add the achievements here to user achievements } } else { // Otherwise, print to the console that no achievements // were found for this user to be awarded Console.WriteLine("No achievements to be awarded for user " + currentUser.ID); } // Now get the achievements that the user has already had awarded. userAchievements = AppCode.Database.GetUserAchievements(currentUser, false, true); if (userAchievements.Count > 0) // If there are any... { foreach (Achievement a in userAchievements) // Take each one and... { TableRow row = new TableRow(); // Create a row row.Height = 100; TableCell cell = new TableCell(); // Create a cell // Create an achievement element CAT_2015.Pages.User.Controls.AchievementElement achievementElement = (CAT_2015.Pages.User.Controls.AchievementElement)Page.LoadControl ("~/Pages/User/Controls/AchievementElement.ascx"); // Put the achievement element in the cell, the cell in the // row and the row in the achievement table cell.Controls.Add(achievementElement); row.Controls.Add(cell); tableAchievements.Controls.Add(row); // Then set the achievement element to display the current achievement achievementElement.SetAchievement(a, true, false, currentUser); } // Finally, get the most recent achievements' IDs List<int> recentAchievements = AppCode.Database.GetRecentAchievementIDsForUser(currentUser); if (recentAchievements.Count > 0) // If any are found... { // Match them up to the achievements in userAchievements foreach (Achievement a in userAchievements) { foreach (int id in recentAchievements) { if (a.ID == id) { // And create a row, cell and achievement element as before TableRow row = new TableRow(); row.Height = 100; TableCell cell = new TableCell(); CAT_2015.Pages.User.Controls.AchievementElement achievementElement = (CAT_2015.Pages.User.Controls.AchievementElement)Page.LoadControl ("~/Pages/User/Controls/AchievementElement.ascx"); // Put them in eachother as before, and set the achievement cell.Controls.Add(achievementElement); row.Controls.Add(cell); tableRecentAchievements.Controls.Add(row); achievementElement.SetAchievement(a, true, false, currentUser); } } } } } } else { // If no user is found, redirect the client to the default home address as defined // by the app settings. Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["DefaultHome"]); } }