public static Contest RandomContest2() { Contest ContestEx = new Contest(3); ContestEx.AddCandidate(new Candidate("John")); ContestEx.AddCandidate(new Candidate("Mary")); ContestEx.AddCandidate(new Candidate("Dan ")); ContestEx.AddCandidate(new Candidate("Lady")); for (int i = 0; i < 5; i++) { AddSomeVotes(ContestEx, 4); } for (int i = 0; i < 5; i++) { AddSomeVotes(ContestEx, 3); } for (int i = 0; i < 5; i++) { AddSomeVotes(ContestEx, 2); } for (int i = 0; i < 5; i++) { AddSomeVotes(ContestEx, 1); } ContestEx.BallotPapers.Sort(); return(ContestEx); }
static void SelectCandidates(Contest contest) { string sql = "Select CandidateName from Candidates "; 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["CandidateName"] ) ; // Console.WriteLine(String.Format("{0}", reader["id"])); string s = (string)reader["CandidateName"]; contest.AddCandidate(new Candidate(s)); 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); }
private void AddTheName() { try { string newName = AddName.Text; if (newName == "") { MessageBox.Show("Name must not be blank"); } else { Contest.AddCandidate(new Candidate(newName)); ListBoxCandidates.Items.Refresh(); // this.Close(); AddName.Text = ""; } } catch (Exception exc) { MessageBox.Show("error:" + " add-okay " + exc.Message); } }