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++; } } } }
private void CopyRunoffAdvancers() { try { bool success; var candidatesAdded = 0; var officesAdded = 0; var runoffElectionKey = GetElectionKey(); if (!Elections.IsRunoffElection(runoffElectionKey)) { throw new VoteException("This function may only be used with runoff elections."); } var runoffElectionDate = Elections.GetElectionDateFromKey(runoffElectionKey); var previousElectionDate = FeedbackMasterOnly.ValidateDate( ControlMasterOnlyElectionDateToCopy, out success, "Previous Election Date", runoffElectionDate.AddYears(-1), runoffElectionDate.AddDays(-7)); if (!success) { return; } var offices = ElectionsPoliticians.GetRunoffAdvancersForElection( runoffElectionKey, previousElectionDate) .GroupBy(r => r.OfficeKey); ElectionsOffices.DeleteByElectionKey(runoffElectionKey); ElectionsPoliticians.DeleteByElectionKey(runoffElectionKey); foreach (var o in offices) { var office = o.First(); InsertElectionOffice(runoffElectionKey, office.OfficeKey); officesAdded++; foreach (var c in o) { ElectionsPoliticians.Insert(runoffElectionKey, c.OfficeKey, c.PoliticianKey, c.RunningMateKey, Elections.GetStateElectionKeyFromKey(runoffElectionKey), string.Empty, Elections.GetCountyElectionKeyFromKey(runoffElectionKey), Elections.GetLocalElectionKeyFromKey(runoffElectionKey), c.StateCode, c.CountyCode, c.LocalCode, c.DistrictCode, 0, false, OfficesOfficials.OfficeKeyPoliticianKeyExists(c.OfficeKey, c.PoliticianKey), false); candidatesAdded++; } } FeedbackMasterOnly.AddInfo( $"{candidatesAdded} candidates were added, {officesAdded} offices were added."); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyPrimaryDateToCopy, "The candidates could not be copied: " + ex.Message); } }
protected override bool Update(object newValue) { var changed = false; //Parse the value from the UI tree var valueStr = newValue as string; if (valueStr == null) { return(false); } var offices = valueStr.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) .Select(officeStr => { var officeSplit = officeStr.Split(':'); return (new { OfficeKey = officeSplit[0], Incumbents = officeSplit[1].Split(',') }); }) .ToArray(); foreach (var office in offices) { foreach (var incumbent in office.Incumbents) { var table = ElectionsIncumbentsRemoved.GetDataByElectionKeyOfficeKeyPoliticianKey (Page.GetElectionKey(), office.OfficeKey, incumbent); if (table.Count == 1) { var row = table[0]; changed = true; if (!OfficesOfficials.OfficeKeyPoliticianKeyExists(row.OfficeKey, row.PoliticianKey)) { OfficesOfficials.Insert(row.OfficeKey, row.PoliticianKey, row.RunningMateKey, row.StateCode, row.CountyCode, row.LocalCode, row.DistrictCode, //row.LDSVersion, row.LDSUpdateDate, row.DataLastUpdated, row.UserSecurity, row.UserName); } ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey (Page.GetElectionKey(), office.OfficeKey, incumbent); } } } //LoadControl(); return(changed); }
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(); } }
private void Consolidate() { try { var key1Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key1"); var key2Item = _MasterOnlyTabInfo.Single(i => i.Column == "Key2"); var jurisdictionKey = JurisdictionalKey; var success = true; success &= DataItemBase.ValidateRequired(key1Item); var key1Office = key1Item.DataControl.GetValue().Trim(); success &= DataItemBase.ValidateRequired(key2Item); var key2Office = key2Item.DataControl.GetValue().Trim(); if (success && key1Office.IsEqIgnoreCase(key2Office)) { key2Item.Feedback.PostValidationError(key2Item.DataControl, key2Item.Description + " is identical to " + key1Item.Description); success = false; } var officeKey1 = jurisdictionKey + key1Office; var officeKey2 = jurisdictionKey + key2Office; if (!success) { return; } // do the consolidation var updateCount = 0; if (Offices.OfficeKeyExists(officeKey1)) { updateCount += Offices.DeleteByOfficeKey(officeKey2); } else { updateCount += Offices.UpdateOfficeKey(officeKey1, officeKey2); } foreach (var row in ElectionsOffices.GetDataByOfficeKey(officeKey2)) { if (ElectionsOffices.ElectionKeyOfficeKeyExists(row.ElectionKey, officeKey1)) { updateCount += ElectionsOffices.DeleteByElectionKeyOfficeKey(row.ElectionKey, officeKey2); } else { updateCount += ElectionsOffices.UpdateOfficeKeyByElectionKeyOfficeKey(officeKey1, row.ElectionKey, officeKey2); } } foreach (var row in ElectionsPoliticians.GetDataByOfficeKey(officeKey2)) { if (ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsPoliticians.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsPoliticians.UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } foreach (var row in OfficesOfficials.GetDataByOfficeKey(officeKey2)) { if (OfficesOfficials.OfficeKeyPoliticianKeyExists(officeKey1, row.PoliticianKey)) { updateCount += OfficesOfficials.DeleteByOfficeKeyPoliticianKey(officeKey2, row.PoliticianKey); } else { updateCount += OfficesOfficials.UpdateOfficeKeyByOfficeKeyPoliticianKey(officeKey1, officeKey2, row.PoliticianKey); } } foreach (var row in ElectionsIncumbentsRemoved.GetDataByOfficeKey(officeKey2)) { if (ElectionsIncumbentsRemoved.ElectionKeyOfficeKeyPoliticianKeyExists(row.ElectionKey, officeKey1, row.PoliticianKey)) { updateCount += ElectionsIncumbentsRemoved.DeleteByElectionKeyOfficeKeyPoliticianKey( row.ElectionKey, officeKey2, row.PoliticianKey); } else { updateCount += ElectionsIncumbentsRemoved .UpdateOfficeKeyByElectionKeyOfficeKeyPoliticianKey( officeKey1, row.ElectionKey, officeKey2, row.PoliticianKey); } } updateCount += Politicians.UpdateOfficeKeyByOfficeKey(officeKey1, officeKey2); var msg = $"{updateCount} instances of the second office key {officeKey2} were found."; if (updateCount > 0) { msg += $" They were all changed to the first office key {officeKey1}."; } FeedbackMasterOnly.AddInfo(msg); ResetMasterOnlySubTab(MasterOnlySubTab.Consolidate); } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyNewKey, "The office keys could not be consolidated: " + ex.Message); } }
private void CopyCandidates() { var candidatesCopied = 0; var officesCopied = 0; var officesSkipped = 0; try { //if (ElectionsPoliticians.CountByElectionKey(GetElectionKey()) > 0) // throw new VoteException( // "This function can only be used if no candidates have been added for the election."); var offices = ElectionsOffices.GetDataByElectionKey(GetElectionKey()); if (offices.Count == 0) { throw new VoteException( "There are no offices for this election to copy. Use the Add/Remove Offices tab to add the offices you want to copy."); } var electionKeyToCopy = MasterOnlyElectionKeyToCopy.Value; foreach (var office in offices) { if ( ElectionsPoliticians.CountByElectionKeyOfficeKey(GetElectionKey(), office.OfficeKey) > 0) { officesSkipped++; continue; } var oldPoliticians = ElectionsPoliticians.GetDataByElectionKeyOfficeKey(electionKeyToCopy, office.OfficeKey); if (oldPoliticians.Count == 0) { continue; } officesCopied++; candidatesCopied += oldPoliticians.Count; var newPoliticians = new ElectionsPoliticiansTable(); foreach (var oldPolitician in oldPoliticians) { newPoliticians.AddRow(office.ElectionKey, office.OfficeKey, oldPolitician.PoliticianKey, oldPolitician.RunningMateKey, office.ElectionKeyState, office.ElectionKeyFederal, office.ElectionKeyCounty, office.ElectionKeyLocal, office.StateCode, office.CountyCode, office.LocalCode, office.DistrictCode, oldPolitician.OrderOnBallot, false, OfficesOfficials.OfficeKeyPoliticianKeyExists(office.OfficeKey, oldPolitician.PoliticianKey), false); } ElectionsPoliticians.UpdateTable(newPoliticians); } FeedbackMasterOnly.AddInfo( officesCopied > 0 ? $"{candidatesCopied} candidates were copied for {officesCopied} offices." : "There were no candidates that could be copied."); if (officesSkipped > 0) { FeedbackMasterOnly.AddInfo( $"{officesSkipped} offices were skipped because there were already candidates entered."); } } catch (Exception ex) { FeedbackMasterOnly.PostValidationError(ControlMasterOnlyElectionToCopy, "The candidates could not be copied: " + ex.Message); } }