public ProjectEvaluation(JudgeMember judge, Contest contest, Criteria criteria, double[,] evaluation) { this.judge = judge; this.contest = contest; this.criteria = criteria; this.evaluation = evaluation; }
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { // Check if anything was selected. if (JudgesComboBox.SelectedItem != null) { JudgeMember judgeMember = (JudgeMember)JudgesComboBox.SelectedItem; contestPage.AddJudge(judgeMember); } else { ErrorTextBlock.Visibility = Visibility.Visible; } }
/// <summary> /// This method retrieves the most up-to-date list of judges from the database. /// </summary> /// <returns>True if success, false otherwise.</returns> public async Task <bool> RefreshJudgesAsync() { // Load the judges from the Database string query = "SELECT id_user, fullname FROM user_table WHERE valid = 1 AND administrator = 0"; SqlCommand cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; // Execute query using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { // Check if user exists if (reader.HasRows) { JudgeMembers.Clear(); while (await reader.ReadAsync()) { // Construct user information from database JudgeMember judge = new JudgeMember((int)reader[0], reader[1].ToString()); // Check if judge is not the current user if (judge.Id != LoggedInUser.Id) { // Add it to the list JudgeMembers.Add(judge); } } return(true); } else { return(false); } } }
/// <summary> /// Add a judge to the contest. /// </summary> /// <param name="judgeMember">The judge to add</param> public void AddJudge(JudgeMember judgeMember) { Judges.Add(judgeMember); JudgesToAdd.Add(judgeMember); }
/// <summary> /// Gets the contest with all details filled out from the database. /// </summary> /// <param name="id">The contest id to retrieve.</param> /// <returns>The contest object if it exists, null otherwise.</returns> public async Task <Contest> GetContest(int id) { // Varaiables declaration. Contest contest; SqlCommand cmd; SqlParameter sqlContestId, sqlUserId; string query; ObservableCollection <Project> contestProjects = new ObservableCollection <Project>(); ObservableCollection <JudgeMember> contestJudges = new ObservableCollection <JudgeMember>(); ObservableCollection <Criteria> contestCriterias = new ObservableCollection <Criteria>(); // Get the contest details from the database. query = "SELECT * " + "FROM contest_table " + "WHERE id_contest = @id_contest"; cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; sqlUserId = new SqlParameter("id_user", SqlDbType.Int); sqlUserId.Value = LoggedInUser.Id; cmd.Parameters.Add(sqlUserId); sqlContestId = new SqlParameter("id_contest", SqlDbType.Int); sqlContestId.Value = id; cmd.Parameters.Add(sqlContestId); using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { // Check if the contest exists. if (reader.HasRows) { await reader.ReadAsync(); ContestDetails contestDetails = new ContestDetails(id, reader.GetString(1), reader.GetString(2), reader.GetDateTime(3), reader.GetDateTime(4), reader.GetDateTime(5), false, false, false); contest = new Contest(id, contestDetails, new ObservableCollection <Project>(), new ObservableCollection <JudgeMember>(), new ObservableCollection <Criteria>()); } else { return(null); } } // Get the contest project list. query = "SELECT id_project, name, descript, id_category, project_year FROM project_table WHERE id_contest = @id_contest ORDER BY id_project"; cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; sqlContestId = new SqlParameter("id_contest", SqlDbType.Int); sqlContestId.Value = id; cmd.Parameters.Add(sqlContestId); using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { // Check if there's any projects in the contest. if (reader.HasRows) { // Read every project, and store it in a list. while (await reader.ReadAsync()) { Project project = new Project(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), new Category(reader.GetInt32(3), ""), reader.GetInt32(4)); contestProjects.Add(project); } } } // Cycle through all projects and get the full category. foreach (Project project in contestProjects) { foreach (Category category in this.Categories) { // Check if the project category id is the same as the category id. if (project.Category.Id == category.Id) { // Assign the category to the project category. project.Category = category; } } // Query the database to get the project promoters. query = "SELECT id_promoter, name, date_of_birth FROM promoter_table WHERE id_project = @id_project"; cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; cmd.Parameters.Add(new SqlParameter("@id_project", project.Id)); project.Promoters = new ObservableCollection <Promoter>(); using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { // Check if there's any projects in the contest. if (reader.HasRows) { // Read every project, and store it in a list. while (await reader.ReadAsync()) { Promoter promoter = new Promoter(reader.GetInt32(0), reader.GetString(1), reader.GetDateTime(2)); project.Promoters.Add(promoter); } } } } contest.Projects = contestProjects; // Get the contest judge list. query = "SELECT id_user, president FROM contest_juri_table WHERE id_contest = @id_contest ORDER BY id_user"; cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; sqlContestId = new SqlParameter("id_contest", SqlDbType.Int); sqlContestId.Value = id; cmd.Parameters.Add(sqlContestId); using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { // Check if there's any judges in the contest. if (reader.HasRows) { // Read every judge, and store it in a list. while (await reader.ReadAsync()) { // Check if it's not the president. if (!reader.GetBoolean(1)) { JudgeMember judge = new JudgeMember(reader.GetInt32(0), ""); contestJudges.Add(judge); } } } } // Cycle through all judges and get the full details. foreach (JudgeMember contestJudge in contestJudges) { foreach (JudgeMember judge in this.JudgeMembers) { // Check if the contest judge id is the same as the stored judge id. if (contestJudge.Id == judge.Id) { // Assign the judge details to the contest judge. contestJudge.Name = judge.Name; } } } contest.JudgeMembers = contestJudges; // Get the contest criteria list. query = "SELECT id_criteria FROM contest_criteria_table WHERE id_contest = @id_contest ORDER BY id_criteria"; cmd = DBSqlHelper.Connection.CreateCommand(); cmd.CommandText = query; sqlContestId = new SqlParameter("id_contest", SqlDbType.Int); sqlContestId.Value = id; cmd.Parameters.Add(sqlContestId); using (DbDataReader reader = cmd.ExecuteReader()) { // Check if there's any criterias in the contest. if (reader.HasRows) { // Read every criteria, and store it in a list. while (reader.Read()) { Criteria criteria = new Criteria(reader.GetInt32(0), "", ""); contestCriterias.Add(criteria); } } } // Refresh the criteria list. await this.RefreshCriteriasAsync(); // Cycle through all criteria and get the full details. foreach (Criteria contestCriteria in contestCriterias) { foreach (Criteria criteria in this.Criterias) { // Check if the criteria judge id is the same as the stored judge id. if (contestCriteria.Id == criteria.Id) { // Assign the criteria details to the contest criteria. contestCriteria.Name = criteria.Name; contestCriteria.Description = criteria.Description; } } } contest.Criterias = contestCriterias; return(contest); }