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 static void MergePrimaryWinners(string generalElectionKey, DateTime primaryElectionDate, bool isRunoff, ref int candidateDuplicates, ref int candidatesAdded) { var offices = ElectionsPoliticians .GetPrimaryWinnersForGeneralElection(generalElectionKey, primaryElectionDate, isRunoff).GroupBy(r => r.OfficeKey); foreach (var o in offices) { foreach (var c in o) { if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists( generalElectionKey, c.OfficeKey, c.PoliticianKey)) { candidateDuplicates++; } else { Elections.ActualizeElection(generalElectionKey); ActualizeElectionOffice(generalElectionKey, c.OfficeKey); ElectionsPoliticians.Insert(generalElectionKey, c.OfficeKey, c.PoliticianKey, c.RunningMateKey, Elections.GetStateElectionKeyFromKey(generalElectionKey), Empty, c.StateCode, c.CountyCode, c.LocalKey, c.DistrictCode, 0, false, OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey, c.PoliticianKey), false, Empty, null, null, null, Empty, false, DefaultDbDate, Empty, Empty, false); candidatesAdded++; } } } }
protected override bool Update(object newValue) { var column = Elections.GetColumn(Column); var electionKey = Page.GetElectionKey(); Elections.ActualizeElection(electionKey); Elections.UpdateColumn(column, newValue, electionKey); return(true); }
private static void MergePrimaryWinners(string generalElectionKey, DateTime primaryElectionDate, bool isRunoff, ref int candidateDuplicates, ref int candidatesAdded /*, ref int candidatesSkippedOfficeMissing*/) { var offices = ElectionsPoliticians.GetPrimaryWinnersForGeneralElection( generalElectionKey, primaryElectionDate, isRunoff) .GroupBy(r => r.OfficeKey); foreach (var o in offices) { //var office = o.First(); //if (ElectionsOffices.ElectionKeyOfficeKeyExists(generalElectionKey, // office.OfficeKey)) foreach (var c in o) { if ( ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists( generalElectionKey, c.OfficeKey, c.PoliticianKey)) { candidateDuplicates++; } else { Elections.ActualizeElection(generalElectionKey); ActualizeElectionOffice(generalElectionKey, c.OfficeKey); ElectionsPoliticians.Insert(generalElectionKey, c.OfficeKey, c.PoliticianKey, c.RunningMateKey, Elections.GetStateElectionKeyFromKey(generalElectionKey), string.Empty, Elections.GetCountyElectionKeyFromKey(generalElectionKey), Elections.GetLocalElectionKeyFromKey(generalElectionKey), c.StateCode, c.CountyCode, c.LocalCode, c.DistrictCode, 0, false, OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey, c.PoliticianKey), false); candidatesAdded++; } } // else candidatesSkippedOfficeMissing += o.Count(); } }
public override void LoadControl() { OfficeCount = 0; Elections.ActualizeElection(Page.GetElectionKey()); var table = Elections.GetAvailableElectionOfficeData(Page.GetElectionKey(), Page.StateCode, Page.CountyCode, Page.LocalKey); if (table.Count == 0) { Page.AddOfficesMessage.RemoveCssClass("hidden"); Page.AddOfficesControl.AddCssClasses("hidden"); } else { Page.AddOfficesMessage.AddCssClasses("hidden"); Page.AddOfficesControl.RemoveCssClass("hidden"); var relatedJurisdictions = OfficeControl.CreateRelatedJurisdictionsNodes("/admin/updateElections.aspx", "addoffices", Page.StateCode, Page.CountyCode, Page.LocalKey); OfficeCount = OfficeControl.PopulateOfficeTree(table, Page.PlaceHolderAddOfficesTree, Page.StateCode, true, false, true, Page.AdminPageLevel == AdminPageLevel.State, relatedJurisdictions); } }
protected void ButtonAddCandidates_OnClick(object sender, EventArgs e) { switch (AddCandidatesReloading.Value) { case "reloading": { // This option just loads the office tree AddCandidatesReloading.Value = Empty; OfficeControl.OfficeKey = Empty; // experimental 16/02/16 SetElectionHeading(HeadingAddCandidates); HeadingAddCandidatesOffice.InnerHtml = "No office selected"; var table = Elections.GetAvailableElectionOfficeData(GetElectionKey(), StateCode, CountyCode, LocalKey); //.Rows.Cast<DataRow>().ToList(); var officeCount = 0; if (table.Count == 0) { _ManagePoliticiansPanel.Message.RemoveCssClass("hidden"); _ManagePoliticiansPanel.Message.InnerText = "No offices were found for this election"; } else { _ManagePoliticiansPanel.Message.AddCssClasses("hidden"); officeCount = PopulateOfficeTree(table); OfficeControl.ShowSelectOfficePanel = true; OfficeControl.ExpandedNode = Empty; OfficeControl.Update(); } FeedbackAddCandidates.AddInfo($"{officeCount} offices loaded."); } break; case "loadoffice": { AddCandidatesReloading.Value = Empty; OfficeControl.ShowSelectOfficePanel = false; _ManagePoliticiansPanel.LoadControls(); SetElectionHeading(HeadingAddCandidates); HeadingAddCandidatesOffice.InnerText = Offices.FormatOfficeName(OfficeControl.OfficeKey); _ManagePoliticiansPanel.ClearAddNewCandidate(true); } break; case "": { // normal update // We may need to actualize the election, the electionOffice, and the office Elections.ActualizeElection(GetElectionKey()); OfficeControl.OfficeKey = Offices.ActualizeOffice(OfficeControl.OfficeKey, CountyCode, LocalKey); ActualizeElectionOffice(GetElectionKey(), OfficeControl.OfficeKey); _ManagePoliticiansPanel.Update(); _ManagePoliticiansPanel.ClearAddNewCandidate(); // to update candidate counts... var table = Elections.GetAvailableElectionOfficeData(GetElectionKey(), StateCode, CountyCode, LocalKey); //.Rows.Cast<DataRow>().ToList(); // In case counts changed PopulateOfficeTree(table); OfficeControl.ShowSelectOfficePanel = false; OfficeControl.Update(); } break; default: throw new VoteException( $"Unknown reloading option: '{AddCandidatesReloading.Value}'"); } }
protected void ButtonAddBallotMeasures_OnClick(object sender, EventArgs e) { AddBallotMeasuresRecased.Value = string.Empty; switch (AddBallotMeasuresReloading.Value) { case "loadballotmeasure": { AddBallotMeasuresReloading.Value = string.Empty; AddBallotMeasuresAnimate.Value = "true"; AddBallotMeasuresSubTabIndex.Value = "0"; var referendumKey = GetBallotMeasureKey(); if (referendumKey == "add") { HeadingAddBallotMeasuresBallotMeasure.InnerHtml = "Adding new ballot measure"; ContainerAddBallotMeasures.AddCssClasses("update-all"); _AddBallotMeasuresTabInfo.Reset(); FeedbackAddBallotMeasures.AddInfo("Blank form loaded for new ballot measure."); } else { HeadingAddBallotMeasuresBallotMeasure.InnerHtml = Referendums.GetReferendumTitle(GetElectionKey(), referendumKey); ContainerAddBallotMeasures.RemoveCssClass("update-all"); _AddBallotMeasuresTabInfo.LoadControls(); FeedbackAddBallotMeasures.AddInfo("Ballot measure loaded."); } RefreshAddBallotMeasuresTab(); } break; case "": AddBallotMeasuresAnimate.Value = "false"; var listChanged = false; if (GetBallotMeasureKey() == "add") { if (_AddBallotMeasuresTabInfo.Validate()) { // add, then update listChanged = true; Elections.ActualizeElection(GetElectionKey()); var newReferendumKey = Referendums.GetUniqueKey(GetElectionKey(), ControlAddBallotMeasuresReferendumTitle.GetValue()); AddBallotMeasure(newReferendumKey); ContainerAddBallotMeasures.RemoveCssClass("update-all"); SelectedBallotMeasureKey.Value = newReferendumKey; _AddBallotMeasuresTabInfo.Update(FeedbackAddBallotMeasures, false); RefreshAddBallotMeasuresTab(); FeedbackAddBallotMeasures.Clear(); FeedbackAddBallotMeasures.AddInfo("Ballot measure added."); } } else { // normal update _AddBallotMeasuresTabInfo.Update(FeedbackAddBallotMeasures); listChanged |= AddBallotMeasuresTabItem.ListChanged; RefreshAddBallotMeasuresTab(); } AddBallotMeasuresRecased.Value = string.Join("|", _AddBallotMeasuresTabInfo.WithWarning("recased") .Select(item => item.Description)); if (listChanged) { _SelectBallotMeasureControlInfo.LoadControls(); UpdatePanelSelectBallotMeasure.Update(); HeadingAddBallotMeasuresBallotMeasure.InnerHtml = Referendums.GetReferendumTitle(GetElectionKey(), GetBallotMeasureKey()); } break; default: throw new VoteException("Unknown reloading option"); } }