public static void AddSomeVotes(Contest ContestEx, int prefsToAdd) { List <int> prefs = new List <int>(); BallotPaper b; b = new BallotPaper(); for (int j = 0; j < ContestEx.Candidates.Count(); j++) { prefs.Add(j); } // prefs = [ 0, 1, 2 ] ShuffleList(prefs); // prefs = [ 2, 0, 1 ] for (int j = 0; j < prefsToAdd; j++) { // j = 0 , 1, 2 b.AddVote(new Vote(ContestEx.Candidates[prefs[j]], j + 1)); } b.Votes.Sort(); ContestEx.AddBallotPaper(b); }
static void SelectBallotPapers(Contest contest) { string sql = "Select Id from BallotPapers"; try { using (SqlConnection cnn = new SqlConnection(ConnectionString)) { cnn.Open(); using (SqlCommand cmd = new SqlCommand(sql, cnn)) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read() != false) { // MessageBox.Show("usrs: " + reader["Id"]); // Console.WriteLine(String.Format("{0}", reader["id"])); int ballotPaperId = (int)reader["Id"]; contest.AddBallotPaper(SelectVote(contest, ballotPaperId)); rowCount++; } } } } } catch (Exception ee) { MessageBox.Show("err: " + ee.Message); } }
public static Contest ExampleContest1() { Contest ContestEx = new Contest(2); ContestEx.AddCandidate(new Candidate("John")); ContestEx.AddCandidate(new Candidate("Mary")); ContestEx.AddCandidate(new Candidate("Dan ")); BallotPaper b; b = new BallotPaper(); b.AddVote(new Vote(ContestEx.Candidates[0], 1)); b.AddVote(new Vote(ContestEx.Candidates[1], 2)); b.AddVote(new Vote(ContestEx.Candidates[2], 3)); b.Votes.Sort(); ContestEx.AddBallotPaper(b); return(ContestEx); }