示例#1
0
        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);
        }
示例#2
0
        static BallotPaper SelectVote(Contest contest, int ballotPaperId)
        {
            string sql = "Select CandidateId, VotePreference from Votes where BallotPaperId = @BallotPaperId ";

            try
            {
                BallotPaper ballotPaper = new BallotPaper();

                using (SqlConnection cnn = new SqlConnection(ConnectionString))
                {
                    cnn.Open();
                    using (SqlCommand cmd = new SqlCommand(sql, cnn))
                    {
                        cmd.Parameters.Add("@BallotPaperId", SqlDbType.Int).Value = ballotPaperId;

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read() != false)
                            {
                                int candidateId    = (int)reader["CandidateId"];
                                int votePreference = (int)reader["VotePreference"];

                                Candidate c = contest.GetCandidateById(candidateId);

                                Vote v = new Vote(c, votePreference);
                                ballotPaper.AddVote(v);
                                rowCount++;
                            }
                        }
                    }
                }
                return(ballotPaper);
            }
            catch (Exception ee)
            {
                MessageBox.Show("err: " + ee.Message);
            }
            return(null);
        }
        private void Btn_NewContest(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("You said: " + " Btn_NewContest: " );

            int exampleNo = CmbBx_Example.SelectedIndex;

            if (exampleNo == 0)
            {
                ContestCurrent = new Contest(2);
            }
            if (exampleNo == 1)
            {
                ContestCurrent = ContestMaker.ExampleContest1();
            }
            if (exampleNo == 2)
            {
                ContestCurrent = ContestMaker.ExampleContest2();
            }
            if (exampleNo == 3)
            {
                ContestCurrent = ContestMaker.RandomContest1();
            }
            if (exampleNo == 4)
            {
                ContestCurrent = ContestMaker.RandomContest2();
            }

            Txb_Seats.Text = ContestCurrent.Seats + "";

            Lsb_Candidates.ItemsSource = ContestCurrent.Candidates;
            Lsb_Candidates.Items.Refresh();

            Lsb_Votes.ItemsSource = ContestCurrent.BallotPapers;
            Lsb_Votes.Items.Refresh();

            // doSimpleCount();
        }
示例#4
0
 public AddCandidate(Contest contest, ListBox listBox)
 {
     InitializeComponent();
     Contest           = contest;
     ListBoxCandidates = listBox;
 }
示例#5
0
 public SimpleCount1(Contest contest)
 {
     Candidates   = contest.Candidates;
     BallotPapers = contest.BallotPapers;
     Seats        = contest.Seats;
 }