private static IEnumerable <LinkInfo> GetLinksByCode(string code, string currentDescription, string electionType = "G") { var linkList = new List <LinkInfo>(); var linkInfo = new LinkInfo { Description = currentDescription, HRef = UrlManager.GetOfficialsPageUri(code) }; linkList.Add(linkInfo); var table = Elections.GetDisplayDataByStateCodeElectionTypeIsViewable(code, electionType, true); foreach (var row in table) { linkInfo = new LinkInfo(row) { HRef = UrlManager.GetElectionPageUri(row.ElectionKey) }; linkList.Add(linkInfo); } return(linkList); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Page.Title = "Setup Compare Page Banner Ad"; H1.InnerHtml = "Setup Compare Page Banner Ad"; _SetupAdDialogInfo.LoadControls(); FeedbackSetupAd.AddInfo("Ad information loaded."); SetupSampleAd(); } var election = Elections.GetElectionDesc(QueryElection); var officeTable = Offices.GetCacheData(QueryOffice); var office = officeTable.Count > 0 ? Offices.GetLocalizedOfficeName(officeTable[0]) : null; if (IsNullOrWhiteSpace(election) || IsNullOrWhiteSpace(office)) { Response.StatusCode = 404; return; } Election.InnerText = election; Office.InnerText = office; AdRate.InnerText = DB.Vote.Master.GetContestAdRate(0) .ToString("C", CultureInfo.CreateSpecificCulture("en-US")); }
private static IEnumerable <LinkInfo> GetStateLinks(string stateCode, bool includeFutureElections) { var linkList = new List <LinkInfo>(); if (StateCache.IsValidStateCode(stateCode)) { var table = Elections.GetViewableDisplayDataByStateCode(stateCode); var now = DateTime.UtcNow; foreach (var row in table) { if (includeFutureElections || row.ElectionDate < now) { var linkInfo = new LinkInfo(row) { HRef = UrlManager.GetElectionPageUri(row.ElectionKey, false, false, true) }; linkList.Add(linkInfo); } } } return(linkList); }
public static string GetElectionsWinnersIdentifiedList(string stateCode) { var dateLastGeneralElection = Elections.GetLatestPastGeneralElectionDateByStateCode(stateCode); var electionsWinnersIdentified = Empty; if (dateLastGeneralElection != null) { var tableElections = Elections.GetWinnersIdentified(stateCode, dateLastGeneralElection.Value); foreach (DataRow rowElection in tableElections.Rows) { electionsWinnersIdentified += "<br>"; if (rowElection.IsWinnersIdentified()) { electionsWinnersIdentified += "Winners <span style=color:green>HAVE</span> been Identified"; } else { electionsWinnersIdentified += "Winners have <span style=color:red><strong>NOT</strong></span> been Identified"; } electionsWinnersIdentified += $" - {rowElection.ElectionDescription()}"; } } return(electionsWinnersIdentified); }
/// <summary> /// Gets a collection of all election cycles in which a candidate is active. /// </summary> /// <param name="cutoff">The cutoff for supported election cycles.</param> /// <param name="candidateID">The ID of the candidate whose active election cycles are to be retrieved.</param> /// <returns>A collection of all election cycles in which the candidate is active.</returns> public Elections GetActiveElections(string cutoff, string candidateID) { Elections elections = new Elections(); using (ActiveElectionCycleTds ds = new ActiveElectionCycleTds()) { using (ActiveElectionCyclesTableAdapter ta = new ActiveElectionCyclesTableAdapter()) { ta.ExecuteWithBackupSource(delegate() { ta.Fill(ds.ActiveElectionCycles, candidateID); }); } foreach (ActiveElectionCycleTds.ActiveElectionCyclesRow row in ds.ActiveElectionCycles.Rows) { string ec = row.ElectionCycle.Trim().ToUpper(); if (cutoff.CompareTo(ec) <= 0) { Election election = new Election(ec); foreach (KeyValuePair <byte, Statement> pair in this.GetStatements(election.Cycle)) { election.Statements.Add(pair.Key, pair.Value); } elections.Add(election); } } } return(elections); }
public static ElectoralClass Electoral_Class_Election(string electionKey) { switch (electionKey.Length) { case Elections.ElectionKeyLengthStateOrFederal: return(Electoral_Class( Offices.GetStateCodeFromKey(electionKey) , string.Empty , string.Empty )); case Elections.ElectionKeyLengthCounty: return(Electoral_Class( Offices.GetStateCodeFromKey(electionKey) , Elections.GetCountyCodeFromKey(electionKey) , string.Empty )); case Elections.ElectionKeyLengthLocal: return(Electoral_Class( Offices.GetStateCodeFromKey(electionKey) , Elections.GetCountyCodeFromKey(electionKey) , Elections.GetLocalCodeFromKey(electionKey) )); default: return(Electoral_Class( string.Empty , string.Empty , string.Empty )); } }
private void ReportCountyContests() { var offices = _DataManager.GetOfficeGroups(new CountyFilter(/*_StateCode*/)); if (offices.Count == 0) { return; } var container = new HtmlDiv().AddTo(ReportContainer, "county-contests no-accordion"); var countyKey = Elections.GetCountyElectionKeyFromKey(_ElectionKey, _StateCode, _CountyCode); var countyName = CountyCache.GetCountyName(_StateCode, _CountyCode); new HtmlDiv { InnerText = countyName }.AddTo(container, "offices-heading accordion-header"); var officesDiv = new HtmlDiv().AddTo(container, "office-cells accordion-content"); foreach (var office in offices) { if (ReportOneOffice(countyKey, office, officesDiv)) { //_TotalContests++; _AllOffices.Add(office.First().OfficeKey()); } } }
protected override string GetCategoryTitle() { return(Elections.GetElectionTypeFromKey(ElectionKey) == Elections.ElectionTypeUSPresidentialPrimary ? "US Presidential Candidates" : "US President & Vice President (" + StateCache.GetStateName(StateCode) + ")"); }
private static void InsertElection(ElectionsTable electionsTable, string electionKey, [CanBeNull] string electionKeyToCopyDatesFrom = null, string electionDesc = null) { var stateCode = Elections.GetStateCodeFromKey(electionKey); var electionDate = Elections.GetElectionDateFromKey(electionKey); var electionDateString = Elections.GetElectionDateStringFromKey(electionKey); if (electionDesc == null) { electionDesc = Elections.FormatElectionDescription(electionKey); } var electionType = Elections.GetElectionTypeFromKey(electionKey); var nationalPartyCode = Elections.GetNationalPartyCodeFromKey(electionKey); var partyCode = Parties.FormatPartyKey(stateCode, nationalPartyCode); var electionOrder = Parties.GetNationalPartyOrder(nationalPartyCode); // Dates var registrationDeadline = DefaultDbDate; var earlyVotingBegin = DefaultDbDate; var earlyVotingEnd = DefaultDbDate; var mailBallotBegin = DefaultDbDate; var mailBallotEnd = DefaultDbDate; var mailBallotDeadline = DefaultDbDate; var absenteeBallotBegin = DefaultDbDate; var absenteeBallotEnd = DefaultDbDate; var absenteeBallotDeadline = DefaultDbDate; var electionAdditionalInfo = Empty; //States.GetElectionAdditionalInfo(stateCode).SafeString(); var ballotInstructions = Empty; //States.GetBallotInstructions(stateCode).SafeString(); if (!IsNullOrWhiteSpace(electionKeyToCopyDatesFrom)) { var electionToCopyDatesFrom = Elections.GetData(electionKeyToCopyDatesFrom); if (electionToCopyDatesFrom.Count == 1) { var row = electionToCopyDatesFrom[0]; registrationDeadline = row.RegistrationDeadline; earlyVotingBegin = row.EarlyVotingBegin; earlyVotingEnd = row.EarlyVotingEnd; mailBallotBegin = row.MailBallotBegin; mailBallotEnd = row.MailBallotEnd; mailBallotDeadline = row.MailBallotDeadline; absenteeBallotBegin = row.AbsenteeBallotBegin; absenteeBallotEnd = row.AbsenteeBallotEnd; absenteeBallotDeadline = row.AbsenteeBallotDeadline; electionAdditionalInfo = row.ElectionAdditionalInfo; ballotInstructions = row.BallotInstructions; } } electionsTable.AddRow(electionKey, stateCode, Empty, Empty, electionDate, electionDateString, electionType, nationalPartyCode, partyCode, Empty, electionDesc, electionAdditionalInfo, Empty, DefaultDbDate, ballotInstructions, false, /*0, DefaultDbDate, 0, DefaultDbDate, 0, * DefaultDbDate, 0, DefaultDbDate, 0,*/Empty, electionOrder, false, false, registrationDeadline, earlyVotingBegin, earlyVotingEnd, mailBallotBegin, mailBallotEnd, mailBallotDeadline, absenteeBallotBegin, absenteeBallotEnd, absenteeBallotDeadline, null); }
protected override bool Update(object newValue) { if (Column == "ChangeLocals") { return(false); } // for IsViewable on a state election, we update all corresponding county // and local elections too. if (((Page.AdminPageLevel == AdminPageLevel.State) || (Page.AdminPageLevel == AdminPageLevel.Federal)) && (Column == "IsViewable")) { Elections.UpdateIsViewableForElectionFamily((bool)newValue, Page.GetElectionKey()); return(true); } // for ElectionDesc on a state election, we update all corresponding county // and local elections too if ChangeLocals is checked. if (Page.ControlChangeInfoChangeLocals.Checked && (Column == "ElectionDesc")) { Elections.UpdateElectionDescForElectionFamily(newValue as string, Page.GetElectionKey()); Page.ControlChangeInfoChangeLocals.Checked = false; return(true); } return(base.Update(newValue)); }
protected void Page_Load(object sender, EventArgs e) { _ElectionDescription = PageCache.Elections.GetElectionDesc(_ElectionKey); // This could be a county election with no county offices, just local links, // in which case the county Elections row won't exist. In that case, // use the state description if (IsNullOrWhiteSpace(_ElectionDescription)) { _ElectionDescription = PageCache.Elections.GetElectionDesc(Elections.GetStateElectionKeyFromKey(_ElectionKey)); } _StateCode = Elections.GetStateCodeFromKey(_ElectionKey); if (AdminPageLevel == AdminPageLevel.Local) { FormatMultiCountiesMessage(MuliCountyMessage); } PopulateMetaTags(); FillInTitles(); FillInReport(); var iframe = GetQueryString("iframe").IsEqIgnoreCase("y") ? " for-iframe" : Empty; Master.FindControl("Body").AddCssClasses($"open-all-accordions{iframe}"); }
private Control GenerateReport(string electionKey, string countyCode, string district, string place, string elementary, string secondary, string unified, string cityCouncil, string countySupervisors, string schoolDistrictDistrict) { _ElectionKey = electionKey; _StateCode = Elections.GetStateCodeFromKey(_ElectionKey); _CountyCode = countyCode; _DataManager.GetData(electionKey, countyCode, district, place, elementary, secondary, unified, cityCouncil, countySupervisors, schoolDistrictDistrict); if (Elections.IsStateElection(_ElectionKey)) { ReportStateReferendums(); } if (Elections.IsStateElection(_ElectionKey) || Elections.IsCountyElection(_ElectionKey)) { ReportCountyReferendums(); } if (Elections.IsLocalElection(_ElectionKey)) { ReportLocalReferendumsForOneLocal(); } else { ReportLocalReferendumsForAllLocals(); } return(ReportContainer.AddCssClasses("ballot-referendum-report ballot-checks-container")); }
public static string FindLocalKey() { var stateCode = FindStateCode(); if (IsNullOrWhiteSpace(stateCode)) { return(Empty); } var localKey = QueryLocal; if (IsNullOrWhiteSpace(localKey)) { if (IsMasterUser || IsAdminUser) { localKey = UserLocalKey; if (IsNullOrWhiteSpace(localKey)) { localKey = Elections.GetLocalKeyFromKey(QueryElection); } if (IsNullOrWhiteSpace(localKey)) { localKey = Offices.GetLocalKeyFromKey(QueryOffice); } } } return(!IsNullOrWhiteSpace(localKey) && LocalDistricts.IsValidKey(stateCode, localKey) ? localKey : Empty); }
public Hashtable Build(string electionKey) { try { var electionsRecord = new Hashtable(); var electionsTable = Elections.GetData(electionKey); if (electionsTable.Count != 1 || electionsTable[0].CountyCode != Empty || !electionsTable[0].IsViewable) { electionsRecord.Add("error", "Invalid electionKey"); } else { var electionsRow = electionsTable[0]; AddElectionFields(electionsRecord, electionsRow); if (_Offices) { AddOfficeFields(electionsRecord, electionKey); } } return(electionsRecord); } catch { var result = new Hashtable { { "error", "an unrecoverable error occurred" } }; return(result); } }
protected void ButtonIdentifyWinnersBeta_OnClick(object sender, EventArgs e) { switch (IdentifyWinnersBetaReloading.Value) { case "reloading": { if (!Elections.IsPrimaryElection(GetElectionKey())) { throw new VoteException("This tab is only for primary elections"); } IdentifyWinnersBetaReloading.Value = Empty; IdentifyWinnersBetaDataArea.RemoveCssClass("hidden"); _IdentifyWinnersBetaTabInfo.LoadControls(); SetElectionHeading(HeadingIdentifyWinnersBeta); FeedbackIdentifyWinnersBeta.AddInfo( $"{IdentifyWinnersBetaTabItem.OfficeCount} offices loaded."); } break; case "": { // normal update _IdentifyWinnersBetaTabInfo.Update(FeedbackIdentifyWinnersBeta); } break; default: throw new VoteException( $"Unknown reloading option: '{IdentifyWinnersBetaReloading.Value}'"); } }
protected void ButtonAdjustIncumbents_OnClick(object sender, EventArgs e) { switch (AdjustIncumbentsReloading.Value) { case "reloading": { if (Elections.IsPrimaryElection(GetElectionKey())) { throw new VoteException("This tab is only for general elections"); } AdjustIncumbentsReloading.Value = string.Empty; AdjustIncumbentsDataArea.RemoveCssClass("hidden"); _AdjustIncumbentsTabInfo.LoadControls(); SetElectionHeading(HeadingAdjustIncumbents); FeedbackAdjustIncumbents.AddInfo( $"{AdjustIncumbentsTabItem.OfficeCount} offices need incumbent adjustments."); } break; case "": { // normal update _AdjustIncumbentsTabInfo.Update(FeedbackAdjustIncumbents); _AdjustIncumbentsTabInfo.LoadControls(); } break; default: throw new VoteException("Unknown reloading option"); } }
private void LoadControlManageCandidates() { var electionKey = _ThisControl.SafeGetElectionKey(); var officeKey = _ThisControl.SafeGetOfficeKey(); var table = Elections.GetOneElectionOffice(electionKey, officeKey); var candidates = table.Rows.Cast <DataRow>() .Where(row => !row.IsRunningMate()) .OrderBy(row => row.OrderOnBallot()) .ThenBy(row => row.PoliticianKey(), StringComparer.OrdinalIgnoreCase) .ToList(); _ThisControl.PageFeedback.AddInfo( $"{candidates.Count} candidate{candidates.Count.Plural()} loaded."); if (candidates.Count == 0) { _ThisControl.Message.RemoveCssClass("hidden"); _ThisControl.Message.InnerHtml = "No candidates were found for this office."; } else { _ThisControl.Message.AddCssClasses("hidden"); foreach (var candidate in candidates) { var li = new HtmlLi { ID = "candidate-" + candidate.PoliticianKey(), ClientIDMode = ClientIDMode.Static }.AddTo( _ThisControl.ControlAddCandidatesCandidateList); var outerDiv = new HtmlDiv().AddTo(li, "outer shadow-2"); CreateCandidateEntry(candidate, DataMode.ManageCandidates) .AddTo(outerDiv); var runningMateKey = candidate.RunningMateKey(); if (!candidate.IsRunningMateOffice() || Elections.IsPrimaryElection(electionKey)) { continue; } DataRow runningMate = null; if (!string.IsNullOrWhiteSpace(runningMateKey)) { runningMate = table.Rows.Cast <DataRow>() .FirstOrDefault(row => row.PoliticianKey() .IsEqIgnoreCase(runningMateKey)); } if (runningMate == null) { CreateNoRunningMateEntry() .AddTo(outerDiv); } else { CreateCandidateEntry(runningMate, DataMode.ManageCandidates, candidate.PartyCode()) .AddTo(outerDiv); } } } }
private void ReportLocalContestsForOneLocal() { var localKey = Elections.GetLocalKeyFromKey(_ElectionKey); var offices = _DataManager.GetOfficeGroups(new OneLocalFilter(localKey)); if (offices.Count == 0) { return; } var container = new HtmlDiv().AddTo(ReportContainer, "one-local-contests no-accordion"); var localInfo = offices.First() .First(); var localDistrict = localInfo.LocalDistrict(); new HtmlDiv { InnerText = localDistrict }.AddTo(container, "offices-heading accordion-header"); var officesDiv = new HtmlDiv().AddTo(container, "office-cells accordion-content"); foreach (var office in offices) { if (ReportOneOffice(_ElectionKey, office, officesDiv)) { //_TotalContests++; _AllOffices.Add(office.First().OfficeKey()); } } }
private void HandleElectionPage() { var electionKey = MemCache.IsValidElection(GetQueryParm("Election")) ? GetQueryParm("Election") : FixElectionKeyFromQueryString(); var forIFrame = OriginalUri.AbsolutePath.ToLower() == "/electionforiframe.aspx"; if (!string.IsNullOrEmpty(electionKey)) { var stateCode = Elections.GetValidatedStateCodeFromKey(electionKey); if (string.IsNullOrEmpty(stateCode)) { // Build normalized uri without state NormalizedUri = UrlManager.GetElectionPageUri(electionKey, false, forIFrame); _IsCanonicalUsa = true; } else if (StateCache.IsValidStateCode(stateCode)) { // Build normalized uri with state NormalizedUri = UrlManager.GetElectionPageUri(stateCode, electionKey, false, forIFrame); } else { ErrorMessage = "Invalid_StateCode"; } } else { ErrorMessage = "Invalid_ElectionKey|StateCode"; } }
private Control GenerateReport(string electionKey, string countyCode) { _ElectionKey = electionKey; _StateCode = Elections.GetStateCodeFromKey(_ElectionKey); _CountyCode = countyCode; _DataManager.GetData(_ElectionKey, _CountyCode); //_MainHtmlTable = // new HtmlTable {CellSpacing = 0, CellPadding = 0}.AddCssClasses("tablePage"); if (Elections.IsStateElection(_ElectionKey)) { ReportStateReferendums(); } if (Elections.IsStateElection(_ElectionKey) || Elections.IsCountyElection(_ElectionKey)) { ReportCountyReferendums(); } if (Elections.IsLocalElection(_ElectionKey)) { ReportLocalReferendumsForOneLocal(); } else { ReportLocalReferendumsForAllLocals(); } //return _MainHtmlTable; return(ReportContainer.AddCssClasses("ballot-referendum-report ballot-checks-container")); }
private static bool IsValidElectionKey(string electionKey) { if (MemCache.IsValidElection(electionKey)) { if (Electoral_Class_Election(electionKey) == ElectoralClass.State || Electoral_Class_Election(electionKey) == ElectoralClass.County || Electoral_Class_Election(electionKey) == ElectoralClass.Local) { return(true); } else if (Electoral_Class_Election(electionKey) == ElectoralClass.County && Elections.GetCountyCodeFromKey(electionKey) == "000") { //Report of County Links to County Elections return(true); } else if (Electoral_Class_Election(electionKey) == ElectoralClass.Local && Elections.GetLocalCodeFromKey(electionKey) == "00") { //Report of Local Links to Local Elections return(true); } else { return(false); } } return(false); }
protected void Page_Load(object sender, EventArgs e) { var result = new AjaxResponse(); try { // assume success unless an exception is thrown result.Success = true; // there should always be exactly one file if (Request.Files.Count == 0) { throw new VoteException("The upload file is missing"); } if (Request.Files.Count > 1) { throw new VoteException("Unexpected files in the upload package"); } // Test error handling //throw new VoteException("Some weird-ass error"); // get the file var postedFile = Request.Files[0]; var electionKey = Request.Form["electionKey"]; Elections.ActualizeElection(electionKey); var jurisdictionScope = Request.Form["jurisdictionScope"]; var electionScope = Request.Form["electionScope"]; using (var memoryStream = new MemoryStream()) { postedFile.InputStream.Position = 0; postedFile.InputStream.CopyTo(memoryStream); var spreadsheet = ParseSpreadsheet(memoryStream, IsExcel(postedFile.FileName)); var columns = spreadsheet.Columns.OfType <DataColumn>().Select(c => c.ColumnName) .ToList(); var id = ElectionSpreadsheets.Insert(postedFile.FileName, DateTime.UtcNow, memoryStream.ToArray(), electionKey, false, columns.Count, spreadsheet.Rows.Count, jurisdictionScope, electionScope); for (var x = 0; x < columns.Count; x++) { ElectionSpreadsheetsColumns.Insert(id, x, columns[x], Empty); } for (var x = 0; x < spreadsheet.Rows.Count; x++) { ElectionSpreadsheetsRows.Insert(id, x, Empty, Empty, Empty, Empty); } result.Html = GetSpreadsheetListHtml(false, id); } result.Message = "Ok"; } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } WriteJsonResultToResponse(result); }
private void ReportLocalContestsForOneLocal() { var localCode = Elections.GetLocalCodeFromKey(ElectionKey); var offices = _DataManager.GetOfficeGroups(new OneLocalFilter(localCode)); OnBeginLocals(offices.Count == 0 ? 0 : 1); if (offices.Count == 0) { return; } var localInfo = offices.First() .First(); var localDistrict = localInfo.LocalDistrict(); OnBeginLocal(ElectionKey, localCode, localDistrict, offices.Count); foreach (var office in offices) { ReportOneOffice(ElectionKey, office); _TotalContests++; } OnEndLocal(ElectionKey); OnEndLocals(); }
public override void LoadControl() { OfficeCount = 0; var table = Elections.GetWinnersData(Page.GetElectionKey()); var incumbentsToEliminate = ElectionsOffices.GetOfficesWithCandidatesToEliminate(Page.GetElectionKey()); if (table.Rows.Count == 0) { Page.IdentifyWinnersMessage.RemoveCssClass("hidden"); Page.IdentifyWinnersInstructions.RemoveCssClass("hidden"); Page.IdentifyWinnersControl.AddCssClasses("hidden"); Page.IdentifyWinnersMessage.InnerHtml = "No offices were found for this election"; } else if (incumbentsToEliminate.Count > 0) { Page.IdentifyWinnersMessage.RemoveCssClass("hidden"); Page.IdentifyWinnersInstructions.AddCssClasses("hidden"); Page.IdentifyWinnersControl.AddCssClasses("hidden"); Page.IdentifyWinnersMessage.InnerHtml = "<em>There are too many incumbents for the following offices:</em><br/><br/>" + Join("<br/>", incumbentsToEliminate.Select(g => Offices.FormatOfficeName(g.First()))) + "<br/><br/><em>Please use the </em>Adjust Incumbents<em> tab to remove the extra incumbents or use the </em>Add/Remove Offices<em> tab to remove the office contest.</em>"; } else { Page.IdentifyWinnersMessage.AddCssClasses("hidden"); Page.IdentifyWinnersInstructions.RemoveCssClass("hidden"); Page.IdentifyWinnersControl.RemoveCssClass("hidden"); OfficeCount = Page.PopulateWinnersTree(table, Page.PlaceHolderIdentifyWinnersTree); } }
protected void ButtonChangeInfo_OnClick(object sender, EventArgs e) { var electionKey = GetElectionKey(); switch (ChangeInfoReloading.Value) { case "reloading": { ChangeInfoReloading.Value = string.Empty; _ChangeInfoTabInfo.LoadControls(); LoadDefaultText(); SetElectionHeading(HeadingChangeInfo); FeedbackChangeInfo.AddInfo("Election information loaded."); } break; case "": { // normal update _ChangeInfoTabInfo.ClearValidationErrors(); var originalDesc = Elections.GetElectionDesc(electionKey); _ChangeInfoTabInfo.Update(FeedbackChangeInfo); if (originalDesc != Elections.GetElectionDesc(electionKey)) { SetElectionHeading(HeadingChangeInfo); ReloadElectionControl(); } } break; default: throw new VoteException("Unknown reloading option"); } }
/// <summary> /// Gets a collection of all supported election cycles. /// </summary> /// <param name="cutoff">The cutoff for supported election cycles.</param> /// <returns>A collection of all supported election cycles.</returns> public Elections GetElections(string cutoff) { Elections elections = new Elections(); using (ElectionCycleTds ds = new ElectionCycleTds()) { using (ElectionCyclesTableAdapter ta = new ElectionCyclesTableAdapter()) { ta.ExecuteWithBackupSource(delegate() { ta.Fill(ds.ElectionCycles, cutoff); }); } foreach (ElectionCycleTds.ElectionCyclesRow row in ds.ElectionCycles.Rows) { int year; Election election = new Election(row.ElectionCycle.Trim().ToUpper()) { Year = int.TryParse(row.Year, out year) ? year : -1, ElectionDate = row.IsElectionDateNull() ? null : row.ElectionDate as DateTime?, IsTIE = !row.IsIsTIENull() && row.IsTIE }; foreach (KeyValuePair <byte, Statement> pair in this.GetStatements(election.Cycle)) { election.Statements.Add(pair.Key, pair.Value); } elections.Add(election); } } return(elections); }
public USPresidentFilter(string stateCode, string electionKey) { _StateCode = stateCode; _IsPresidentialComparison = Elections.GetElectionTypeFromKey(electionKey) == Elections.ElectionTypeUSPresidentialPrimary; }
public static void SwapCandidates(ref Elections candidate1, ref Elections candidate2) { var temp = candidate1; candidate1 = candidate2; candidate2 = temp; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { var partyName = Parties.GetPartyName(PartyKey); Page.Title = partyName; H1.InnerHtml = partyName; try { var electionKey = Elections.GetNextViewableElectionForParty(PartyKey, StateCode); if (!string.IsNullOrEmpty(electionKey)) { Table_Election_Candidates.Visible = true; Label_Election_Candidates.Text = Elections.GetElectionDesc(electionKey); } } catch (Exception ex) { Msg.Text = Fail(ex.Message); Log_Error_Admin(ex); } } }
private void HandleCompareCandidatesPage() { var officeKey = string.Empty; var electionKey = MemCache.IsValidElection(GetQueryParm("Election")) ? GetQueryParm("Election") : FixElectionKeyFromQueryString(); if (!string.IsNullOrEmpty(electionKey)) { if (Offices.IsInElection(GetQueryParm("Office"), electionKey)) { officeKey = GetQueryParm("Office"); } } var stateCode = Elections.GetStateCodeFromKey(electionKey); if (!string.IsNullOrEmpty(electionKey) && !string.IsNullOrEmpty(officeKey)) { NormalizedUri = UrlManager.GetCompareCandidatesPageUri(stateCode, electionKey, officeKey); } else { ErrorMessage = "Cannot find this combination of State, Election and Office"; } }
// END CUT HERE // BEGIN CUT HERE public static void Main() { try { Elections ___test = new Elections(); ___test.run_test(-1); } catch(Exception e) { //Console.WriteLine(e.StackTrace); Console.WriteLine(e.ToString()); } }
public static void OrderListOfCandidatesByVotes(ref Elections[] finalList) { int j; for (int i = 1; i < finalList.Length; i++) { j = i; while (j > 0 && finalList[j - 1].votes < finalList[j].votes) { SwapCandidates(ref finalList[j], ref finalList[j - 1]); j = j - 1; } } }