/// <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> /// 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 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; }
/// <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); } }
/// <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> /// 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); }
/// <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); }