protected override string GetCategoryTitle()
            {
                var pageCache = VotePage.GetPageCache();

                return(pageCache.LocalDistricts.GetLocalDistrict(StateCode, LocalKey) + ", " +
                       CountyCache.GetCountyDescription(StateCode, CountyCode, LocalKey) + ", " +
                       StateCache.GetStateName(StateCode) + " - Local Offices");
            }
Exemplo n.º 2
0
        public static Dictionary <string, SimpleListItem> GetFocusedNamesDictionary(
            DataTable tableIn)
        {
            var rows = tableIn.Rows.OfType <DataRow>()
                       .Where(r => !IsNullOrWhiteSpace(r.LocalKey())).ToList();

            if (rows.Count == 0)
            {
                return(new Dictionary <string, SimpleListItem>());
            }

            // group the jurisdictions and eliminate dups
            var grouped = rows
                          .Select(row => new { StateCode = row.StateCode(), LocalKey = row.LocalKey() })
                          .Distinct().GroupBy(i => i.StateCode);

            // build the where clause
            var statesConditions = new List <string>();

            foreach (var stateGroup in grouped)
            {
                var locals          = stateGroup.ToList();
                var localsCondition = "IN ('" + Join("','", locals.Select(l => l.LocalKey)) + "')";
                statesConditions.Add("StateCode='" + stateGroup.Key + "' AND LocalKey " +
                                     localsCondition);
            }

            var cmdText = "SELECT StateCode,LocalKey,LocalDistrict" +
                          " FROM LocalDistricts WHERE " + Join(" OR ", statesConditions);

            var cmd = VoteDb.GetCommand(cmdText, 0);

            using (var cn = VoteDb.GetOpenConnection())
            {
                cmd.Connection = cn;
                var           table   = new DataTable();
                DbDataAdapter adapter = new MySqlDataAdapter(cmd as MySqlCommand);
                adapter.Fill(table);
                return(table.Rows.Cast <DataRow>().ToDictionary(
                           row => row.StateCode() + "|" + row.LocalKey(), row =>
                {
                    string countyCode = null;
                    var countyName = CountyCache.GetCountyDescription(row.StateCode(),
                                                                      ref countyCode, row.LocalKey());
                    return new SimpleListItem
                    {
                        Value = countyCode,
                        Text = row.LocalDistrict() + ", " + countyName
                    };
                }));
            }
        }
Exemplo n.º 3
0
        public static HtmlGenericControl GetCandidateListItem(DataRow politician,
                                                              string idPrefix = null, bool noCache = false)
        {
            string OfficeDescription()
            {
                var officeKey = politician.LiveOfficeKey();

                if (IsNullOrWhiteSpace(officeKey))
                {
                    return(Empty);
                }

                var result = politician.OfficeLine1();

                if (!IsNullOrWhiteSpace(politician.OfficeLine2()) &&
                    politician.OfficeClass() != OfficeClass.USPresident)
                {
                    result += " " + politician.OfficeLine2();
                }
                if (politician.OfficeClass() != OfficeClass.USPresident)
                {
                    var stateCode  = Offices.GetStateCodeFromKey(officeKey);
                    var countyCode = Offices.GetCountyCodeFromKey(officeKey);
                    var localKey   = Offices.GetLocalKeyFromKey(officeKey);
                    if (IsNullOrWhiteSpace(countyCode))
                    {
                        result = StateCache.GetStateName(stateCode) + " " + result;
                    }
                    else if (IsNullOrWhiteSpace(localKey))
                    {
                        result = CountyCache.GetCountyName(stateCode, countyCode) + ", " +
                                 StateCache.GetStateName(stateCode) + " " + result;
                    }
                    else
                    {
                        result = CountyCache.GetCountyDescription(stateCode, localKey) + ", " +
                                 StateCache.GetStateName(stateCode) + ", " + politician.LocalDistrict() + " " +
                                 result;
                    }
                }
                return(politician.LivePoliticianStatus().GetOfficeStatusDescription() + result);
            }

            string AddressLine()
            {
                var result       = politician.PublicAddress();
                var cityStateZip = politician.PublicCityStateZip();

                if (!IsNullOrWhiteSpace(result) && !IsNullOrWhiteSpace(cityStateZip))
                {
                    result += ", ";
                }
                result += cityStateZip;
                return(result);
            }

            var div = new HtmlDiv();

            div.AddCssClasses("search-politician unselectable clearfix");
            if (!IsNullOrWhiteSpace(idPrefix))
            {
                div.ID = idPrefix + politician.PoliticianKey();
            }
            Report.CreatePoliticianImageTag(politician.PoliticianKey(), 35, noCache).AddTo(div);
            var text = FormatName(politician);

            if (!IsNullOrWhiteSpace(politician.PartyCode()))
            {
                text += " (" + politician.PartyCode() + ")";
            }
            new HtmlDiv {
                InnerHtml = text
            }.AddTo(div, "name");
            text = OfficeDescription();
            if (!IsNullOrWhiteSpace(text))
            {
                new HtmlDiv {
                    InnerHtml = text
                }
            }