Пример #1
0
        public static string Anchor_Master_FindPolitician(string politicianKey)
        {
            var anchor = string.Empty;

            anchor += "<a href=";
            anchor += "\"";
            anchor += Url_Master_FindPolitician(politicianKey);
            anchor += "\"";

            anchor += ">";
            anchor += "<nobr>" + Politicians.GetFormattedName(politicianKey) + "</nobr>";
            anchor += "</a>";
            return(anchor);
        }
Пример #2
0
        private void SetLabelsFromItem(PoliticianImagesInfo item)
        {
            if (item == null)
            {
                return;
            }
            LabelUploadDate.Text =
                item.ProfileOriginalDate.ToString(CultureInfo.InvariantCulture);
            //UploadDatePlaceHolder.Controls.Clear();
            //new LocalDate(item.ProfileOriginalDate, "M/D/YYYY h:mm:ss A")
            //  .AddTo(UploadDatePlaceHolder);
            LabelPoliticianKey.Text = item.PoliticianKey;
            LabelOfficeLevel.Text   = item.OfficeLevel.ToString(CultureInfo.InvariantCulture);
            LabelPolitician.Text    = Politicians.GetFormattedName(item.PoliticianKey) + " - " +
                                      Politician_PartyCode(item.PoliticianKey);
            var officeKey = GetPageCache().Politicians.GetOfficeKey(item.PoliticianKey);

            LabelOffice.Text = Offices.GetStateCodeFromKey(officeKey) + " - " +
                               Offices.FormatOfficeName(officeKey);
        }
Пример #3
0
        public static string GetOfficeData(string officeKey)
        {
            var officeData = string.Empty;

            if (Offices.IsValid(officeKey))
            {
                officeData += "<br>StateCode:" + Offices.GetStateCodeFromKey(officeKey);
                officeData += ", CountyCode:" + Offices.GetCountyCodeFromKey(officeKey);
                officeData += ", LocalCode:" + Offices.GetLocalCodeFromKey(officeKey);
                officeData += "<br>OfficeClass:"
                              + " (" + Offices.GetOfficeClass(officeKey).ToInt() + ") "
                              + Offices.GetOfficeClassDescription(officeKey);

                officeData += "<br>";
                officeData += Offices.GetOfficeClassDescription(
                    Offices.GetOfficeClass(officeKey)
                    , Offices.GetStateCodeFromKey(officeKey));
                officeData += "<br>";
                officeData += "<strong>"
                              + Name_Office_Contest_And_Electoral(officeKey)
                              + "</strong>";

                officeData += "<br>";
                officeData += "In the following ELECTIONS:";
                var sql = string.Empty;
                sql += " ElectionsOffices";
                sql += " WHERE OfficeKey = " + SqlLit(officeKey);
                if (G.Rows_Count_From(sql) > 0)
                {
                    sql  = string.Empty;
                    sql += " SELECT";
                    sql += " ElectionKey";
                    sql += " FROM ElectionsOffices";
                    sql += " ElectionsOffices";
                    sql += " WHERE OfficeKey = " + SqlLit(officeKey);
                    var electionsTable = G.Table(sql);
                    if (electionsTable != null)
                    {
                        foreach (DataRow electionsRow in electionsTable.Rows)
                        {
                            officeData += "<br><strong>"
                                          + Name_Election(electionsRow["ElectionKey"].ToString())
                                          + "</strong>";
                        }
                    }
                }
                else
                {
                    officeData += "<br><strong>NONE</strong>";
                }

                officeData += "<br>";
                officeData += "POLITICIAN(S) as Incumbnet to this office:";
                sql         = string.Empty;
                sql        += " OfficesOfficials";
                sql        += " WHERE OfficeKey = " + SqlLit(officeKey);
                if (G.Rows_Count_From(sql) > 0)
                {
                    sql  = string.Empty;
                    sql += " SELECT";
                    sql += " PoliticianKey";
                    sql += " FROM OfficesOfficials";
                    sql += " WHERE OfficeKey = " + SqlLit(officeKey);
                    var politiciansTable = G.Table(sql);
                    if (politiciansTable != null)
                    {
                        foreach (DataRow politicianRow in politiciansTable.Rows)
                        {
                            officeData += "<br><strong>"
                                          + Politicians.GetFormattedName(politicianRow["PoliticianKey"].ToString())
                                          + "</strong>";
                        }
                    }
                }
                else
                {
                    officeData += "<br><strong>NONE</strong>";
                }
            }
            else
            {
                officeData += "<br><strong>Office does not exist</strong>";
            }

            return(officeData);
        }
Пример #4
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            var candidates = new List <List <KeyValuePair <string, string> > >();

            // read CSV into memory structure
            var exactMatches    = 0;
            var verifiedMatches = 0;
            var rejectedMatches = 0;
            var noMatches       = 0;
            var multipleMatches = 0;

            using (var csvReader = new CsvReader(File.OpenText(InputTextBox.Text), true))
            {
                var headers = csvReader.GetFieldHeaders();
                if (!headers.Contains("FirstName"))
                {
                    throw new VoteException("FirstName column missing");
                }
                if (!headers.Contains("LastName"))
                {
                    throw new VoteException("LastName column missing");
                }
                if (!headers.Contains("State"))
                {
                    throw new VoteException("State column missing");
                }
                while (csvReader.ReadNextRecord())
                {
                    var data = new List <KeyValuePair <string, string> >();
                    candidates.Add(data);
                    var firstName = string.Empty;
                    var lastName  = string.Empty;
                    var state     = string.Empty;
                    var id        = string.Empty;
                    var introPage = string.Empty;
                    foreach (var header in headers)
                    {
                        var value = csvReader[header];
                        switch (header)
                        {
                        case "FirstName":
                            firstName = value;
                            break;

                        case "LastName":
                            lastName = value;
                            break;

                        case "State":
                            state = value;
                            break;
                        }
                        data.Add(new KeyValuePair <string, string>(header, value));
                    }
                    var stateCode = StateCache.GetStateCode(state);
                    if (!string.IsNullOrEmpty(stateCode))
                    {
                        var table = Politicians.GetNamesDataByStateCodeLastName(stateCode,
                                                                                lastName);
                        var matches = table
                                      .Where(row => row.FirstName.IsEqIgnoreCase(firstName))
                                      .ToList();
                        if (matches.Count == 1)
                        {
                            exactMatches++;
                            id        = matches[0].PoliticianKey;
                            introPage = GetIntroPageUrl(id);
                        }
                        else
                        {
                            switch (table.Count)
                            {
                            case 1:
                            {
                                var message = string.Format("BallotPedia: {0} {1}\n" +
                                                            "Vote-USA: {2}\n\nUse?",
                                                            firstName, lastName, Politicians.GetFormattedName(table[0].PoliticianKey));
                                if (
                                    MessageBox.Show(message, "No Exact Match", MessageBoxButtons.YesNo) ==
                                    DialogResult.Yes)
                                {
                                    verifiedMatches++;
                                    id        = table[0].PoliticianKey;
                                    introPage = GetIntroPageUrl(id);
                                }
                                else
                                {
                                    rejectedMatches++;
                                }
                            }
                            break;

                            case 0:
                                noMatches++;
                                break;

                            default:
                                multipleMatches++;
                                break;
                            }
                        }
                    }
                    data.Add(new KeyValuePair <string, string>("VoteUSA Id", id));
                    data.Add(new KeyValuePair <string, string>("VoteUSA Url", introPage));
                }

                var summary =
                    string.Format(
                        "Candidates: {0}\nExact matches: {1}\n" +
                        "Verified matches: {2}\nRejected: {3}\nNo matches: {4}\nMultiple matches: {5}",
                        candidates.Count, exactMatches, verifiedMatches, rejectedMatches,
                        noMatches, multipleMatches);
                MessageBox.Show(summary, "Summary");

                if (candidates.Count > 0)
                {
                    var directory = Path.GetDirectoryName(InputTextBox.Text);
                    var filename  = Path.GetFileNameWithoutExtension(InputTextBox.Text);
                    var extension = Path.GetExtension(InputTextBox.Text);
                    Debug.Assert(directory != null, "directory != null");
                    var outputPath = Path.Combine(directory, filename + ".coded" + extension);
                    var textWriter = File.CreateText(outputPath);
                    var csvWriter  = new SimpleCsvWriter();
                    // write headings
                    foreach (var kvp in candidates[0])
                    {
                        csvWriter.AddField(kvp.Key);
                    }
                    csvWriter.Write(textWriter);
                    foreach (var row in candidates)
                    {
                        foreach (var kvp in row)
                        {
                            csvWriter.AddField(kvp.Value);
                        }
                        csvWriter.Write(textWriter);
                    }
                    textWriter.Close();
                }
            }
        }