private void ExtractMatchingAddresses() { ExtractedAddresses = new ExtractedAddresses(); using (var reader = LogAddressesGoodNew.GetDataReaderByParsedStateCodeDateRange( StateComboBoxText, StartDateTimePickerValue, EndDateTimePickerValue, 0)) { while (reader.Read()) { ExtractedAddresses.AddAddress(reader); } } ExtractedAddresses.EliminateExactDuplicates(); if (EditDuplicatesCheckBoxChecked) { ExtractedAddresses.EliminateFuzzyDuplicates(); } ExtractedAddresses.NoFuzzyDuplicatesCount = ExtractedAddresses.Addresses.Count; ExtractedAddresses.WriteToCsv(OutputFileTextBoxText); AppendStatusText("{0} addresses read from database", ExtractedAddresses.RawCount); AppendStatusText("{0} addresses not marked duplicate", ExtractedAddresses.NotMarkedDuplicateCount); AppendStatusText("{0} addresses meet minimum requirements", ExtractedAddresses.MinimumRequirementsCount); AppendStatusText("{0} addresses not exact duplicates", ExtractedAddresses.NoExactDuplicatesCount); AppendStatusText("{0} addresses not fuzzy duplicates", ExtractedAddresses.NoFuzzyDuplicatesCount); if (ExtractedAddresses.DuplicatedAddressIds.Count != 0) { if (MessageBox.Show(string.Format( "There were {0} new duplicates identified." + Environment.NewLine + "Do you want to mark these as duplicates in the database?", ExtractedAddresses.DuplicatedAddressIds.Count), "Mark Duplicates?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { foreach (int id in ExtractedAddresses.DuplicatedAddressIds) { LogAddressesGoodNew.UpdateIsDuplicateById(true, id); } } } }
protected void UpdateAddressesFromLogButton_Click(object sender, EventArgs e) { try { var totalCount = 0; var transferredCount = 0; var insufficientContentCount = 0; var duplicateCount = 0; var done = false; // error recovery retry while (!done) { using (var reader = LogAddressesGoodNew.GetDataReaderByNotTransferredToAddresses(0)) { try { while (reader.Read()) { var address = reader.ParsedAddress.SafeString().Trim().ToUpperInvariant(); var city = reader.ParsedCity.SafeString().Trim().ToUpperInvariant(); var state = reader.ParsedStateCode.SafeString().Trim().ToUpperInvariant(); var zip5 = reader.ParsedZip5.SafeString().Trim().ToUpperInvariant(); var zip4 = reader.ParsedZip4.SafeString().Trim().ToUpperInvariant(); var email = reader.Email.SafeString().Trim(); totalCount++; // We need email, address, city, state, at a minimum if (email != string.Empty /*&& address != string.Empty && city != string.Empty && * state != string.Empty*/) { //var matchCount = Addresses.CountByEmailAddressCityStateCodeZip5Zip4( // email, address, city, state, zip5, zip4); var matchCount = Addresses.EmailExists(email) ? 1 : 0; if (matchCount == 0) // it's new { transferredCount++; //FOR CURT Addresses.Insert(string.Empty, string.Empty, address, city, state, zip5, zip4, email, string.Empty, reader.DateStamp.Date, "LOG", false, // since these are log entries, any email address // indicates an opt-in for sample ballots email != string.Empty, false, VoteDb.DateTimeMin, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, VoteDb.DateTimeMin, 0, DefaultDbDate, false); } else { Addresses.UpdateSendSampleBallotsByEmail(true, email); duplicateCount++; } } else { insufficientContentCount++; } LogAddressesGoodNew.UpdateTransferredToAddressesById(true, reader.Id); } done = true; // no more retries needed } // ReSharper disable once EmptyGeneralCatchClause catch { } } } Feedback.Text = Ok("<br />" + $"{totalCount} log rows read<br />" + $"{transferredCount} addresses transferred<br />" + $"{insufficientContentCount} addresses had insufficient information<br />" + $"{duplicateCount} addresses were exact duplicates"); } catch (Exception ex) { Feedback.Text = Fail(ex.Message); Log_Error_Admin(ex); } }