/// <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; }
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(); } } }