Пример #1
0
        /// <summary>
        ///     Loads the election parameters
        /// </summary>
        /// <param name="strConnection">The STR connection.</param>
        /// <param name="machineAssignmentId">The machine assignment id.</param>
        /// <externalUnit/>
        /// <revision revisor="dev16" date="1/11/2009" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        private void LoadElecParams(
            string strConnection,
            int machineAssignmentId)
        {
            BallotEntrySet elecParam = new BallotEntrySet(typeof(StpElecParam));

            // pass in the machineAssignmentId to the proc if we got one
            if (machineAssignmentId != 0)
            {
                elecParam.Load(strConnection, machineAssignmentId);
            }
            else
            {
                elecParam.Load(strConnection);
            }

            for (int i = 0; i < elecParam.Count; i = i + 1)
            {
                ElectionParameter parameter = new ElectionParameter();
                parameter.Name = elecParam.GetValueStr(
                    i, StpElecParam.ParamName);
                parameter.Value = elecParam.GetValueStr(
                    i, StpElecParam.ParamValue);
                this.electionParameters.Add(parameter);
            }
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PaperBallotRichTextTemplate"/> class.
        /// </summary>
        /// <param name="parameters">The pdf layout parameters.</param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="4/11/2009" version="1.0.11.0201">
        ///     Member Created
        /// </revision>
        public PaperBallotRichTextTemplate(BallotEntrySet parameters)
        {
            try
            {
                int idx = parameters.FindIndex(
                    StpParam.PDFLayoutParamId,
                    Convert.ToInt32(PdfParam.DataFolder));
                string txmlFullPath = Path.Combine(
                    parameters.GetValueStr(idx, StpParam.ParamValue),
                    FileName);

                // load the xml (TXML) from the file as plain text since this
                // is what AquaPDF's engine uses
                StreamReader reader = new StreamReader(txmlFullPath);
                this.txml = reader.ReadToEnd();
                reader.Close();

                // parse the file simply to verify it is well-formed XML. No
                // TXML-specific tests are done here on the XML
                // X mlDocument xmlDocument = new XmlDocument();

                // x mlDocument.LoadXml(txml);

                // no exception thrown means that the XML is valid and loaded
                this.isValidXml = true;
            }
            catch
            {
                // drop any loaded text
                this.txml = null;

                // set the flag to false
                this.isValidXml = false;
            }
        }
        /// <summary>
        ///     Loads a candidate from the DB using supplied entry sets
        /// </summary>
        /// <param name="ballots">The ballots.</param>
        /// <param name="candidates">The candidates.</param>
        /// <param name="id">The candidate id.</param>
        /// <param name="ballotId">The ballot id.</param>
        /// <returns>
        ///     A <see cref="Candidate" /> from the database.
        /// </returns>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="BreakType"/>
        /// <externalUnit cref="Candidate"/>
        /// <externalUnit cref="StpBallot"/>
        /// <externalUnit cref="StpCand"/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="04/14/2009" version="1.0.11.0401">
        ///     added ballot style id
        /// </revision>
        public static Candidate LoadFromDb(
            BallotEntrySet ballots,
            BallotEntrySet candidates,
            int id,
            int ballotId)
        {
            int idxBal = ballots.FindIndex(
                StpBallot.BallotStyleId,
                ballotId,
                StpBallot.CandidateId,
                id),
                idxCnd   = candidates.FindIndex(StpCand.CandidateId, id),
                maskCnd  = ballots.GetValueInt(idxBal, StpBallot.CandDispFormat),
                intBreak = (int)BreakType.Column;
            string name  = candidates.GetValueStr(
                idxCnd, StpCand.CandidateDisplayName);
            Candidate cand = new Candidate(
                id,
                name,
                (maskCnd & VotedFlag) == VotedFlag,
                (maskCnd & intBreak) == intBreak);

            cand.Type = (CandidateType)Enum.ToObject(
                typeof(CandidateType),
                candidates.GetValueInt(
                    idxCnd, StpCand.CandidateType));

            return(cand);
        }
        /// <summary>
        ///     Loads from db.
        /// </summary>
        /// <param name="contests">The contests.</param>
        /// <param name="index">The index.</param>
        /// <param name="defFont">The def font.</param>
        /// <param name="defSize">Size of the def.</param>
        /// <returns>
        ///     An <see cref="OfficeText" /> from the database.
        /// </returns>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="OfficeText"/>
        /// <externalUnit cref="StpCont"/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        public static OfficeText LoadFromDb(
            BallotEntrySet contests, int index, string defFont, double defSize)
        {
            string text = contests.GetValueStr(index, StpCont.DisplayText);

            return(new OfficeText(text, defFont, defSize));
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="MatrixPtyCstPaperBallot"/> class.
        /// </summary>
        /// <param name="entrySetBallots">The es ballots.</param>
        /// <param name="entrySetContests">The es conts.</param>
        /// <param name="entrySetCandidates">The es cands.</param>
        /// <param name="entrySetParams">The es params.</param>
        /// <param name="esContList">The es cont list.</param>
        /// <param name="entrySetCandidateList">The es cand list.</param>
        /// <param name="esParties">The es parties.</param>
        /// <param name="target">The target.</param>
        /// <param name="ballotStyleId">The ballot style id.</param>
        /// <param name="currentCardCount">The current card count.</param>
        /// <param name="currentFaceCount">The current face count.</param>
        /// <revision revisor="dev11" date="03/11/2009" version="1.0.8.2101">
        ///     Member created
        /// </revision>
        /// <revision revisor="dev11" date="03/11/2009" version="1.0.8.2201">
        ///     Added party information (StpParty)
        /// </revision>
        public MatrixPtyCstPaperBallot(BallotEntrySet entrySetBallots,
                                       BallotEntrySet entrySetContests,
                                       BallotEntrySet entrySetCandidates,
                                       BallotEntrySet entrySetParams,
                                       BallotEntrySet esContList,
                                       BallotEntrySet entrySetCandidateList,
                                       BallotEntrySet esParties,
                                       PaperBallotTarget target,
                                       int ballotStyleId,
                                       int currentCardCount,
                                       int currentFaceCount) : base()
        {
            this.target = target;

            // set the card and face counts
            this.currentCardCount = currentCardCount;
            this.currentFaceCount = currentFaceCount;

            this.esParties = esParties;

            Load(
                entrySetBallots,
                entrySetContests,
                entrySetCandidates,
                entrySetParams,
                ballotStyleId);
            this.LoadExtended(esContList, entrySetCandidateList);
            this.Position();
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PaperBallotElectionInfo"/> class.
        /// </summary>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="4/2/2009" version="1.0.9.1701">
        ///     Member Created
        /// </revision>
        public PaperBallotElectionInfo(string strConnection)
        {
            BallotEntrySet entrySet = new BallotEntrySet(typeof(StpElecParam));

            entrySet.Load(strConnection, DefaultMachineId);

            int idx = entrySet.FindIndex(
                StpElecParam.ParamName, ParamElectionName);

            if (idx >= 0)
            {
                this.electionName = entrySet.GetValueStr(
                    idx, StpElecParam.ParamValue);
            }
            else
            {
                // no election name found, use empty string
                this.electionName = string.Empty;
            }

            idx = entrySet.FindIndex(StpElecParam.ParamName, ParamElectionDate);
            try
            {
                this.electionDate = entrySet.GetValueDate(
                    idx, StpElecParam.ParamValue);
            }
            catch
            {
                // do nothing and let election date be null
            }
        }
        /// <summary>
        ///     Loads the extended data. This is the [vote for] number for the
        ///     contests and the [party id] for the candidates. Also at the same
        ///     time determine the number of columns and rows of the matrix
        /// </summary>
        /// <param name="esContList">The contest list entry set (StpContList)</param>
        /// <param name="entrySetCandidateList">The candidate list (StpCandList)</param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="3/10/2009" version="1.0.8.2101">
        ///     Member Created
        /// </revision>
        private void LoadExtended(
            BallotEntrySet esContList, BallotEntrySet entrySetCandidateList)
        {
            // a variable for the id (contest or candidate)
            // and a index of the corresponding record of a given id on the
            // appropriate entry set
            int id, idx;

            // initialize counters
            this.columnCount = 0;
            this.rowCount    = 0;

            // get a collection of party ids
            this.partyColumns = new Dictionary <int, int>();

            // for every contest, find it on the contest list and get the
            // vote for from there
            foreach (Contest contest in contests)
            {
                // get the contest id
                id = contest.Id;

                // find it on the contest list entry set
                idx = esContList.FindIndex(StpContList.ContestId, id);

                // get the vote for from that entry
                contest.VoteFor = esContList.GetValueInt(
                    idx, StpContList.VoteFor);

                // increment the row count by the vote for number
                this.rowCount = this.rowCount + contest.VoteFor;

                // for every candidate of the current contest, find it on the
                // candidate list and get the party id from there
                foreach (Candidate candidate in contest.Candidates)
                {
                    // same here
                    id  = candidate.Id;
                    idx =
                        entrySetCandidateList.FindIndex(
                            StpCandList.CandidateId, id);
                    candidate.PartyId = entrySetCandidateList.GetValueInt(
                        idx, StpCandList.PartyId);

                    // add the party id if it's new
                    if (!this.partyColumns.ContainsKey(candidate.PartyId))
                    {
                        // the current number of entries in the dictionary is
                        // the column number
                        this.partyColumns.Add(
                            candidate.PartyId, this.partyColumns.Count);
                    }
                }
            }

            this.columnCount = this.partyColumns.Count;
        }
Пример #8
0
        /// <summary>
        ///     Sets the mask.
        /// </summary>
        /// <param name="entrySetParams">The es params.</param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="3/4/2009" version="1.0.">
        ///     Member Created
        /// </revision>
        public void SetMask(BallotEntrySet entrySetParams)
        {
            int idx = entrySetParams.FindIndex(
                StpParam.PDFLayoutParamId, (int)PdfParam.IdentifierMask);

            if (idx >= 0)
            {
                this.mask =
                    entrySetParams.GetValueInt(idx, StpParam.ParamValue);
            }
        }
Пример #9
0
        /// <summary>
        ///     Loads the machine parameters
        /// </summary>
        /// <param name="strConnection">The STR connection.</param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        private void LoadMachParams(string strConnection)
        {
            BallotEntrySet machParm = new BallotEntrySet(typeof(StpMachParm));

            machParm.Load(strConnection);

            for (int i = 0; i < machParm.Count; i = i + 1)
            {
                ParameterFile file = new ParameterFile();
                file.Name = machParm.GetValueStr(i, StpMachParm.ParamName);
                this.machineParams.ParameterFiles.Add(file);
            }
        }
Пример #10
0
        /// <summary>
        ///     Loads the machine options
        /// </summary>
        /// <param name="strConnection">The STR connection.</param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        private void LoadMachOptn(string strConnection)
        {
            BallotEntrySet machOptn = new BallotEntrySet(typeof(StpMachOptn));

            machOptn.Load(strConnection);

            for (int i = 0; i < machOptn.Count; i = i + 1)
            {
                MachineOption option = new MachineOption();
                option.Name  = machOptn.GetValueStr(i, StpMachOptn.OptionName);
                option.Value = machOptn.GetValueStr(i, StpMachOptn.OptionValue);
                this.machineOptions.Add(option);
            }
        }
Пример #11
0
        /// <summary>
        ///     Loads the contest list.
        /// </summary>
        /// <param name="contList">Contest List</param>
        /// <param name="candList">Candidate List</param>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="contests"/>
        /// <externalUnit cref="DomainObjects.Contest"/>
        /// <externalUnit cref="GetContest"/>
        /// <externalUnit cref="StpCandList"/>
        /// <externalUnit cref="StpContList"/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="04/14/2009" version="1.0.11.0401">
        ///     each candidate is added now only once. This assumes obviously
        ///     that each contest appearance has the exact same candidates
        /// </revision>
        private void LoadContList(
            BallotEntrySet contList, BallotEntrySet candList)
        {
            // B allotEntrySet candList = new BallotEntrySet(typeof (StpCandList)),
            // contList = new BallotEntrySet(typeof (StpContList));
            Dictionary <int, DomainObjects.Contest> contMap =
                new Dictionary <int, DomainObjects.Contest>();
            List <int> candidateIds = new List <int>();

            DomainObjects.Contest cont;
            int contId, candId;

            // for every candidate, find the corresponding contest
            for (int i = 0; i < candList.Count; i = i + 1)
            {
                contId = candList.GetValueInt(i, StpCandList.ContestId);
                if (contMap.ContainsKey(contId) == false)
                {
                    // this contest has not been created yet, so create an
                    // instance for it, add it to the map for easy access and
                    // to the contest collection
                    cont = this.GetContest(contList, contId);
                    contMap.Add(contId, cont);
                    this.contests.Add(cont);
                }
                else
                {
                    // get the contest from the map
                    cont = contMap[contId];
                }

                candId = candList.GetValueInt(i, StpCandList.CandidateId);
                if (candidateIds.Contains(candId) == false)
                {
                    DomainObjects.Candidate cand =
                        new DomainObjects.Candidate();
                    cand.Id   = candId;
                    cand.Name = candList.GetValueStr(
                        i, StpCandList.CandidateDisplayName);
                    cand.BallotStatusId = candList.GetValueInt(
                        i, StpCandList.BallotStatusId);
                    cand.CandidateType = candList.GetValueInt(
                        i, StpCandList.CandidateType);
                    cand.PartyId = candList.GetValueInt(i, StpCandList.PartyId);
                    cont.Candidates.Add(cand);
                    candidateIds.Add(candId);
                }
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PaperBallotTarget"/> class.
        /// </summary>
        /// <param name="connectionString">
        ///     The connection String.
        /// </param>
        /// <param name="targetType">
        ///     The target Type.
        /// </param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="3/23/2009" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        public PaperBallotTarget(string connectionString, TargetType targetType)
        {
            this.Type     = targetType;
            this.entrySet = new BallotEntrySet(typeof(StpTargetParam));
            this.entrySet.Load(connectionString, Convert.ToInt32(targetType));

            float density = this.GetFltParam(TargetParam.LineDensity)
                            / LineDensityMax;

            // density 100 -> black
            // density 0   -> white
            this.lineDensityColor = new JColor(
                1 - density, 1 - density, 1 - density, 1f);
            this.InitializeTargetMark();
        }
Пример #13
0
        /// <summary>
        ///     Determines whether a given identifier field is selected
        /// </summary>
        /// <param name="entrySetParams">
        ///     The parameters. See <see cref="StpParam"/>
        /// </param>
        /// <param name="idField">
        ///     The id field. See <see cref="IdField"/>
        /// </param>
        /// <returns>
        ///     <c>true</c> if the identifier field is selected;
        ///     otherwise, <c>false</c>.
        /// </returns>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="Enum"/>
        /// <externalUnit cref="PdfParam"/>
        /// <externalUnit cref="StpParam"/>
        /// <revision revisor="dev11" date="3/4/2009" version="1.0.">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="03/24/2009" version="1.0.9.0801">
        ///     Updated to work with enum types and ids instead of names when
        ///     searching on the entry set of pdf parameters.
        /// </revision>
        public static bool IsFieldSelected(BallotEntrySet entrySetParams, Enum idField)
        {
            int idx = entrySetParams.FindIndex(
                StpParam.PDFLayoutParamId, (int)PdfParam.IdentifierMask),
                field = Convert.ToInt32(idField),
                mask;
            bool selected = false;

            if (idx >= 0)
            {
                mask     = entrySetParams.GetValueInt(idx, StpParam.ParamValue);
                selected = (mask & field) == field;
            }

            return(selected);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="PaperBallotTarget"/> class.
        /// </summary>
        /// <param name="entrySetTargetParams">
        ///     An entry set (StpTargetParam). See <see cref="StpTargetParam"/>.
        /// </param>
        /// <param name="targetType">
        ///     Type of the target. See <see cref="TargetType"/>.
        /// </param>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="3/24/2009" version="1.0.9.0701">
        ///     Member Created
        /// </revision>
        public PaperBallotTarget(
            BallotEntrySet entrySetTargetParams,
            TargetType targetType)
        {
            this.Type     = targetType;
            this.entrySet = entrySetTargetParams;

            float density =
                this.GetFltParam(TargetParam.LineDensity) / LineDensityMax;

            // density 100 -> black
            // density 0   -> white
            this.lineDensityColor = new JColor(
                1 - density, 1 - density, 1 - density, 1f);
            this.InitializeTargetMark();
        }
        /// <summary>
        ///     Gets the type of the target.
        /// </summary>
        /// <param name="parms">The parms.</param>
        /// <returns>A targettype for that param</returns>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="PdfParam"/>
        /// <externalUnit cref="StpParam"/>
        /// <externalUnit cref="TargetType"/>
        /// <revision revisor="dev11" date="3/24/2009" version="1.0.9.0701">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="03/24/2009" version="1.0.9.0801">
        ///     updated to work with enum types and ids instead of names when
        ///     searching on the entry set of pdf parameters
        /// </revision>
        public static TargetType GetTargetType(BallotEntrySet parms)
        {
            TargetType type;

            try
            {
                int idx = parms.FindIndex(
                    StpParam.PDFLayoutParamId, (int)PdfParam.TargetType);
                int val = parms.GetValueInt(idx, StpParam.ParamValue);
                type = (TargetType)Enum.ToObject(typeof(TargetType), val);
            }
            catch (Exception)
            {
                // use arrow as the default
                type = TargetType.Arrow;
            }

            return(type);
        }
Пример #16
0
        /// <summary>
        ///     Loads all other collections from the DB using the supplied
        ///     connection string.
        /// </summary>
        /// <param name="strConnection">The connection string.</param>
        /// <param name="machineAssignmentId">The machine assignment id.</param>
        /// <param name="contList">List of Contests</param>
        /// <param name="candList">List of Candidates</param>
        /// <externalUnit cref="contests"/>
        /// <externalUnit cref="electionParameters"/>
        /// <externalUnit cref="LoadContList"/>
        /// <externalUnit cref="LoadElecParams"/>
        /// <externalUnit cref="LoadMachOptn"/>
        /// <externalUnit cref="LoadMachParams"/>
        /// <externalUnit cref="MachineOptions"/>
        /// <externalUnit cref="MachineParams"/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev14" date="3/13/2009" version="1.0.8.2301">
        ///     Added machine assignmentId to pass to get election parameters
        /// </revision>
        /// <revision revisor="dev11" date="04/14/2009" version="1.0.11.0401">
        ///     added entry sets for contest list and candidate list
        /// </revision>
        public void Load(
            string strConnection,
            int machineAssignmentId,
            BallotEntrySet contList,
            BallotEntrySet candList)
        {
            this.contests.Clear();
            this.LoadContList(contList, candList);

            this.machineOptions.Clear();
            this.LoadMachOptn(strConnection);

            this.machineParams.ParameterFiles.Clear();
            this.LoadMachParams(strConnection);

            // Load up the election paramters based on the assignment of the
            // machine being initialized
            this.electionParameters.Clear();
            this.LoadElecParams(strConnection, machineAssignmentId);
        }
Пример #17
0
        /// <summary>
        ///     Creates a new instance of Contest from the entry set of contests
        ///     using a supplied contest id.
        /// </summary>
        /// <param name="contList">The contest entry set.</param>
        /// <param name="contId">The contest id.</param>
        /// <returns>The Contest</returns>
        /// <externalUnit cref="BallotEntrySet"/>
        /// <externalUnit cref="DomainObjects.Contest"/>
        /// <externalUnit cref="StpContList"/>
        /// <revision revisor="dev11" date="12/23/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev01" date="11/16/2009" version="1.1.3.4">
        ///     Changed party assigment
        /// </revision>
        private DomainObjects.Contest GetContest(
            BallotEntrySet contList, int contId)
        {
            int idx = contList.FindIndex(StpContList.ContestId, contId);

            DomainObjects.Contest contest = new DomainObjects.Contest();
            contest.Id             = contId;
            contest.Name           = contList.GetValueStr(idx, StpContList.ContestName);
            contest.VoteFor        = contList.GetValueInt(idx, StpContList.VoteFor);
            contest.BallotStatusId = contList.GetValueInt(
                idx, StpContList.BallotStatusId);
            contest.ContestType = contList.GetValueInt(
                idx, StpContList.ContestType);
            contest.ListOrder =
                contList.GetValueInt(idx, StpContList.ListOrder);
            contest.Party = new Party(
                contList.GetValueInt(idx, StpContList.PartyId),
                string.Empty,
                string.Empty,
                0,
                false);
            return(contest);
        }
        /// <summary>
        ///     Loads from db.
        /// </summary>
        /// <param name="ballots">The ballots.</param>
        /// <param name="contests">The contests (StpCont).</param>
        /// <param name="candidates">The candidates.</param>
        /// <param name="ballotId">The ballot id.</param>
        /// <param name="contId">The contest id.</param>
        /// <param name="defFont">The def font.</param>
        /// <param name="defSize">Size of the def.</param>
        /// <returns>
        ///     A <see cref="Contest" /> from the database.
        /// </returns>
        /// <externalUnit/>
        /// <revision revisor="dev11" date="12/19/2008" version="1.0.0.0">
        ///     Member Created
        /// </revision>
        /// <revision revisor="dev11" date="04/14/2009" version="1.0.11.0401">
        ///     Passing ballot style id to candidates as well since candidate
        ///     may appear more than once on the ballot entry set.
        /// </revision>
        public static Contest LoadFromDb(
            BallotEntrySet ballots,
            BallotEntrySet contests,
            BallotEntrySet candidates,
            int ballotId,
            int contId,
            string defFont,
            double defSize)
        {
            int idxBal = ballots.FindIndex(
                StpBallot.BallotStyleId,
                ballotId,
                StpBallot.ContestId,
                contId),
                idxCst = contests.FindIndex(StpCont.ContestId, contId),
                curCst,
                curCnd = ballots.GetValueInt(idxBal, StpBallot.CandDispFormat),

            // using 0x0003 since this is a 2-bit flag that can take all 4
            // values: 0, 1, 2, 3
                cstFormat = // 0x0003 &
                            ballots.GetValueInt(idxBal, StpBallot.ContDispFormat);
            var contest = new Contest(contId);

            // read break format settings
            contest.Break =
                (BreakType)Enum.ToObject(typeof(BreakType), cstFormat);

            do
            {
                // Load office texts from the contest entry set until a
                // different contest id is found. Start at the current index
                // found above.
                contest.Texts.Add(
                    OfficeText.LoadFromDb(contests, idxCst, defFont, defSize));

                // Increment the index by 1 and test if the contest id is
                // the same
                idxCst = idxCst + 1;
                if (idxCst < contests.Count)
                {
                    curCst = contests.GetValueInt(idxCst, StpCont.ContestId);
                }
                else
                {
                    // idxCst is greater than the number of elements in the
                    // collection, so simply use -1 to break the loop
                    curCst = -1;
                }
            }while (curCst == contId);

            do
            {
                // get the current candidate id
                curCnd = ballots.GetValueInt(idxBal, StpBallot.CandidateId);

                // load all candidates for this contest
                contest.Candidates.Add(
                    Candidate.LoadFromDb(
                        ballots,
                        candidates,
                        curCnd,
                        ballotId));

                // increment the index by 1 and test if the contest id is
                // the same
                idxBal = idxBal + 1;

                if (idxBal < ballots.Count)
                {
                    curCst = ballots.GetValueInt(idxBal, StpBallot.ContestId);
                }
                else
                {
                    curCst = -1;
                }
            }while (curCst == contId);

            return(contest);
        }