Exemplo n.º 1
0
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        public static void GetReport(Control container, string stateCode)
        {
            // We get a dictionary of office counts by county
            // Key: countyCode; Value: count of offices
            // Counties with no offices will not be in the dictionary
            var countCountyOfficesDictionary =
                Offices.CountCountyOfficesByCounty(stateCode);

            if (countCountyOfficesDictionary.Count == 0)
            {
                return;
            }

            new HtmlDiv {
                InnerText = "County Elected Representatives"
            }.AddTo(container, "accordion-header");
            var content = new HtmlDiv().AddTo(container, "local-anchors accordion-content");

            // For reporting we start with all counties for the state (it will be in
            // order by county name). Then we select only those in the offices dictionary.
            var reorderedCounties = CountyCache.GetCountiesByState(stateCode)
                                    .Where(countCountyOfficesDictionary.ContainsKey)
                                    .ToList();

            foreach (var iteratedCountyCode in reorderedCounties)
            {
                var countyName = CountyCache.GetCountyName(stateCode, iteratedCountyCode);
                CreatePublicOfficalsAnchor(countyName, stateCode, iteratedCountyCode)
                .AddTo(content, "local-anchor");
            }
        }
Exemplo n.º 2
0
        private void ReportCountyContests()
        {
            var offices = _DataManager.GetOfficeGroups(new CountyFilter(/*_StateCode*/));

            if (offices.Count == 0)
            {
                return;
            }

            var container = new HtmlDiv().AddTo(ReportContainer,
                                                "county-contests no-accordion");

            var countyKey = Elections.GetCountyElectionKeyFromKey(_ElectionKey,
                                                                  _StateCode, _CountyCode);
            var countyName = CountyCache.GetCountyName(_StateCode, _CountyCode);

            new HtmlDiv {
                InnerText = countyName
            }.AddTo(container, "offices-heading accordion-header");

            var officesDiv = new HtmlDiv().AddTo(container, "office-cells accordion-content");

            foreach (var office in offices)
            {
                if (ReportOneOffice(countyKey, office, officesDiv))
                {
                    //_TotalContests++;
                    _AllOffices.Add(office.First().OfficeKey());
                }
            }
        }
Exemplo n.º 3
0
 protected override string GetCategoryTitle()
 {
     return(VotePage.GetPageCache()
            .LocalDistricts.GetLocalDistrict(StateCode, CountyCode, LocalCode) + ", " +
            CountyCache.GetCountyName(StateCode, CountyCode) + ", " +
            StateCache.GetStateName(StateCode) + " Offices");
 }
Exemplo n.º 4
0
        public static string GetLocalizedOfficeName(string officeKey,
                                                    string officeLine1, string officeLine2, string separator = " ")
        {
            var stateCode  = GetStateCodeFromKey(officeKey);
            var countyCode = GetCountyCodeFromKey(officeKey);
            var localCode  = GetLocalCodeFromKey(officeKey);
            var officeName = string.Empty;

            if (IsCountyOffice(officeKey))
            {
                officeName += CountyCache.GetCountyName(stateCode, countyCode);
            }
            else if (IsLocalOffice(officeKey))
            {
                officeName += VotePage.GetPageCache()
                              .LocalDistricts.GetLocalDistrict(stateCode, countyCode, localCode);
            }

            if (!string.IsNullOrEmpty(officeName))
            {
                officeName += separator;
            }

            officeName += FormatOfficeName(officeLine1, officeLine2, officeKey, separator);

            return(officeName);
        }
Exemplo n.º 5
0
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        public static Control GetReport(ReportUser reportUser, string stateCode)
        {
            // We get a dictionary of office counts by county
            // Key: countyCode; Value: count of offices
            // Counties with no offices will not be in the dictionary
            var countCountyOfficesDictionary =
                Offices.CountCountyOfficesByCounty(stateCode);

            if (countCountyOfficesDictionary.Count == 0)
            {
                return(null);
            }

            // For reporting we start with all counties for the state (it will be in
            // order by county name). Then we select only those in the offices dictionary
            // and reorder for vertical presentation.
            var reorderedCounties = CountyCache.GetCountiesByState(stateCode)
                                    .Where(countCountyOfficesDictionary.ContainsKey)
                                    .ToList()
                                    .ReorderVertically(MaxCellsInRow);

            var          htmlTable           = CreateHtmlTableWithHeading(reportUser, stateCode);
            HtmlTableRow tr                  = null;
            var          cellsDisplayedInRow = MaxCellsInRow; // force new row

            foreach (var iteratedCountyCode in reorderedCounties)
            {
                var countyName = CountyCache.GetCountyName(stateCode, iteratedCountyCode);
                cellsDisplayedInRow = CreateOneAnchorCell(reportUser, htmlTable, ref tr,
                                                          countyName, cellsDisplayedInRow, stateCode, iteratedCountyCode);
            }

            return(htmlTable);
        }
Exemplo n.º 6
0
        private Control CreateOfficeTitleAndKeyAnchor(
            OfficesAdminReportViewRow row)
        {
            var officeClass = row.OfficeLevel.ToOfficeClass();

            var container = new PlaceHolder();
            var text      = Offices.FormatOfficeName(row.OfficeLine1, row.OfficeLine2,
                                                     row.OfficeKey);

            if (officeClass.IsLocal())
            {
                text += ", " +
                        VotePage.GetPageCache()
                        .LocalDistricts.GetLocalDistrict(_Options.StateCode, _Options.LocalKey);
            }

            if (officeClass.IsCounty() || officeClass.IsLocal())
            {
                text += ", " + CountyCache.GetCountyName(_Options.StateCode, _Options.CountyCode);
            }

            CreateOfficePageAnchor(row.OfficeKey, text)
            .AddTo(container);

            if (row.IsInactive)
            {
                new Literal {
                    Text = " - INACTIVE"
                }
            }
Exemplo n.º 7
0
    // ReSharper disable MemberCanBePrivate.Global
    // ReSharper disable MemberCanBeProtected.Global
    // ReSharper disable UnusedMember.Global
    // ReSharper disable UnusedMethodReturnValue.Global
    // ReSharper disable UnusedAutoPropertyAccessor.Global
    // ReSharper disable UnassignedField.Global

    #endregion ReSharper disable

    public static void AddLinks(Control parent, string stateCode,
      Func<string, string, string, Control> getAnchor, bool sortByCode = false)
    {
      var counties = CountyCache.GetCountiesByState(stateCode)
        .AsEnumerable();
      if (sortByCode) counties = counties.OrderBy(code => code);
      foreach (var countyCode in counties)
        getAnchor(stateCode, countyCode, CountyCache.GetCountyName(stateCode, countyCode))
          .AddTo(parent);
    }
Exemplo n.º 8
0
        private static void Main()
        {
            const string dir           = @"D:\Users\CurtNew\Dropbox\Documents\vote\tiger";
            var          shapeFile     = new ShapeFile(Path.Combine(dir, @"2016\tl_2016_us_cousub\tl_2016_us_cousub.shp"));
            var          enumerator    = shapeFile.GetShapeFileEnumerator();
            var          districtInfos = new List <DistrictInfo>();

            while (enumerator.MoveNext())
            {
                var fieldValues = shapeFile.GetAttributeFieldValues(enumerator.CurrentShapeIndex);
                var stateFips   = fieldValues[0].Trim();
                var stateCode   = StateCache.StateCodeFromLdsStateCode(stateFips);
                var countyFips  = fieldValues[1].Trim();
                districtInfos.Add(new DistrictInfo
                {
                    StateFips        = stateFips,
                    CountyFips       = countyFips,
                    DistrictFips     = fieldValues[2].Trim(),
                    DistrictName     = fieldValues[5].Trim(),
                    DistrictLongName = fieldValues[6].Trim(),
                    StateCode        = stateCode,
                    StateName        = StateCache.GetStateName(stateCode),
                    CountyName       = CountyCache.GetCountyName(stateCode, countyFips)
                });
            }
            var textWriter = new StreamWriter(Path.Combine(dir, @"districts.csv"));
            var csvWriter  = new SimpleCsvWriter();

            csvWriter.AddField("State FIPS");
            csvWriter.AddField("County FIPS");
            csvWriter.AddField("District FIPS");
            csvWriter.AddField("State Code");
            csvWriter.AddField("State Name");
            csvWriter.AddField("County Name");
            csvWriter.AddField("District Name");
            csvWriter.AddField("District Long Name");
            csvWriter.Write(textWriter);
            foreach (
                var district in
                districtInfos.OrderBy(d => d.StateName)
                .ThenBy(d => d.CountyName)
                .ThenBy(d => d.DistrictLongName))
            {
                csvWriter.AddField(district.StateFips);
                csvWriter.AddField(district.CountyFips);
                csvWriter.AddField(district.DistrictFips);
                csvWriter.AddField(district.StateCode);
                csvWriter.AddField(district.StateName);
                csvWriter.AddField(district.CountyName);
                csvWriter.AddField(district.DistrictName);
                csvWriter.AddField(district.DistrictLongName);
                csvWriter.Write(textWriter);
            }
            textWriter.Close();
        }
Exemplo n.º 9
0
        private void GetCountyElections(Control container, string stateElectionKey)
        {
            var stateCode = Elections.GetStateCodeFromKey(stateElectionKey);

            // We get a dictionary of counties with elections that match the stateElectionKey
            // Key: countyCode; Value: county electionKey
            // Counties without an election will not be in the dictionary
            // We include local elections too, to account for situations where there is no county
            // election but there are local elections.
            var countyElectionDictionary =
                ElectionsOffices.GetCountyAndLocalElections(stateElectionKey);
            // We can't forget the Ballot Measures...
            var countyReferendumDictionary =
                Referendums.GetCountyAndLocalElections(stateElectionKey);

            // merge them into the first dictionary
            foreach (var kvp in countyReferendumDictionary)
            {
                if (!countyElectionDictionary.ContainsKey(kvp.Key))
                {
                    countyElectionDictionary.Add(kvp.Key, kvp.Value);
                }
            }
            if (countyElectionDictionary.Count == 0)
            {
                return;
            }

            new HtmlDiv {
                InnerText = "County Elections"
            }.AddTo(container, "accordion-header");
            var content = new HtmlDiv().AddTo(container, "category-content accordion-content");

            // For reporting we start with all counties for the state (it will be in
            // order by county name) and select only those in the election dictionary.

            var counties = CountyCache.GetCountiesByState(stateCode)
                           .Where(countyElectionDictionary.ContainsKey)
                           .ToList();

            // each county report is in its own accordion
            foreach (var countyCode in counties)
            {
                var countyName        = CountyCache.GetCountyName(stateCode, countyCode);
                var countyElectionKey = countyElectionDictionary[countyCode];

                new HtmlDiv {
                    InnerText = countyName
                }.AddTo(content, "accordion-header");
                new ElectionReportResponsive().GenerateReport(ReportUser, countyElectionKey)
                .AddTo(content, "accordion-content");
            }
        }
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        public static void GetReport(Control container, string stateElectionKey, bool openAll = false)
        {
            var stateCode = Elections.GetStateCodeFromKey(stateElectionKey);

            // We get a dictionary of counties with elections that match the stateElectionKey
            // Key: countyCode; Value: county electionKey
            // Counties without an election will not be in the dictionary
            // Update: we now include local elections too, to account for situations where there is no county
            // election but there are local elections.
            var countyElectionDictionary =
                ElectionsOffices.GetCountyAndLocalElections(stateElectionKey);
            // We can't forget the Ballot Measures...
            var countyReferendumDictionary =
                Referendums.GetCountyAndLocalElections(stateElectionKey);

            // merge them into the first dictionary
            foreach (var kvp in countyReferendumDictionary)
            {
                if (!countyElectionDictionary.ContainsKey(kvp.Key))
                {
                    countyElectionDictionary.Add(kvp.Key, kvp.Value);
                }
            }
            if (countyElectionDictionary.Count == 0)
            {
                return;
            }

            new HtmlDiv {
                InnerText = "County Elections"
            }.AddTo(container, "accordion-header");
            var content = new HtmlDiv().AddTo(container, "local-anchors accordion-content");

            // For reporting we start with all counties for the state (it will be in
            // order by county name) and select only those in the election dictionary.

            var counties = CountyCache.GetCountiesByState(stateCode)
                           .Where(countyElectionDictionary.ContainsKey)
                           .ToList();

            foreach (var countyCode in counties)
            {
                var countyName        = CountyCache.GetCountyName(stateCode, countyCode);
                var countyElectionKey = countyElectionDictionary[countyCode];
                CreatePublicElectionAnchor(countyElectionKey, countyName, openAll)
                .AddTo(content, "local-anchor");
            }
        }
Exemplo n.º 11
0
        private static string FormatOfficeNameForBallot(DataRow officeInfo)
        {
            var officeKey  = officeInfo.OfficeKey();
            var officeName = Offices.FormatOfficeName(officeInfo, "</span><span>");

            if (Offices.IsCountyOffice(officeKey) || Offices.IsLocalOffice(officeKey))
            {
                officeName += "</span><span>" +
                              CountyCache.GetCountyName(Offices.GetStateCodeFromKey(officeKey),
                                                        Offices.GetCountyCodeFromKey(officeKey));
            }
            if (Offices.IsLocalOffice(officeKey))
            {
                officeName += "</span><span>" + officeInfo.LocalDistrict();
            }
            return("<span>" + officeName + "</span>");
        }
        // ReSharper restore UnusedAutoPropertyAccessor.Global

        private void BuildCountiesList(string stateCode, string singleCounty = null)
        {
            CountiesPickerList.Controls.Clear();
            foreach (var countyCode in CountyCache.GetCountiesByState(stateCode))
            {
                if (singleCounty == null || singleCounty == countyCode)
                {
                    var countyName = CountyCache.GetCountyName(stateCode, countyCode);
                    var p          = new HtmlP().AddTo(CountiesPickerList, "sub-label");
                    p.Attributes["title"] = countyName;
                    new HtmlInputCheckBox {
                        Value = countyCode, Checked = true
                    }.AddTo(p);
                    new HtmlSpan {
                        InnerHtml = countyName
                    }.AddTo(p);
                }
            }
        }
Exemplo n.º 13
0
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        public static Control GetReport(string stateCode,
                                        Func <string, string, string, Control> getAnchor, bool sortByCode = false)
        {
            const int maxCellsInRow = 5; // "override" default of 4

            var counties = CountyCache.GetCountiesByState(stateCode)
                           .AsEnumerable();

            if (sortByCode)
            {
                counties = counties.OrderBy(code => code);
            }
            var reorderedCounties = counties.ReorderVertically(maxCellsInRow);

            var htmlTable =
                new HtmlTable {
                CellSpacing = 0, Border = 0
            }.AddCssClasses("tableAdmin");
            HtmlTableRow tr = null;
            var          cellsInCurrentRow = int.MaxValue; // force initial new row

            foreach (var countyCode in reorderedCounties)
            {
                if (cellsInCurrentRow >= maxCellsInRow)
                {
                    tr = new HtmlTableRow().AddTo(htmlTable, "trLinks");
                    cellsInCurrentRow = 0;
                }
                cellsInCurrentRow++;

                var td = new HtmlTableCell().AddTo(tr, "tdLinks");
                getAnchor(stateCode, countyCode,
                          CountyCache.GetCountyName(stateCode, countyCode))
                .AddTo(td);
            }

            return(htmlTable);
        }
Exemplo n.º 14
0
        private void ReportCountyReferendums()
        {
            var referendums = _DataManager.GetDataSubset(new CountyFilter(),
                                                         new RererendumOrderBy());

            if (referendums.Count == 0)
            {
                return;
            }

            var outer = new HtmlDiv().AddTo(ReportContainer, "referendums-list");

            // ReSharper disable once PossibleNullReferenceException
            (new HtmlDiv().AddTo(outer, "accordion-header")
             as HtmlGenericControl).InnerHtml = CountyCache.GetCountyName(_StateCode, _CountyCode) +
                                                " Ballot Measures";
            var container = new HtmlDiv().AddTo(outer, "referendums-content accordion-content");

            foreach (var referendum in referendums)
            {
                ReportOneReferendum(container, referendum, true);
            }
        }
Exemplo n.º 15
0
        private void ReportCountyContests()
        {
            var offices = _DataManager.GetOfficeGroups(new CountyFilter());

            var countyKey = Elections.GetCountyElectionKeyFromKey(ElectionKey,
                                                                  StateCode, CountyCode);

            OnBeginCounty(countyKey, CountyCache.GetCountyName(StateCode, CountyCode),
                          offices.Count);

            if (offices.Count == 0)
            {
                return;
            }

            foreach (var office in offices)
            {
                ReportOneOffice(countyKey, office);
                _TotalContests++;
            }

            OnEndCounty(countyKey);
        }
Exemplo n.º 16
0
        private Control CreateOfficeNameAndKey(PoliticiansAdminReportViewRow row)
        {
            var     officeClass = row.OfficeLevel.ToOfficeClass();
            var     countyName  = row.County.SafeString();
            Control control;
            string  literalText;

            if (officeClass.IsCounty())
            {
                literalText = FormatOfficeName(row) + ", " + countyName;
            }
            else if (officeClass.IsLocal())
            {
                countyName = CountyCache.GetCountyName(_Options.StateCode, _Options.CountyCode);
                var localName =
                    VotePage.GetPageCache()
                    .LocalDistricts.GetLocalDistrict(_Options.StateCode, _Options.LocalKey);
                literalText = FormatOfficeName(row) + ", " + localName + ", " + countyName;
            }
            else
            {
                literalText = FormatOfficeName(row);
            }

            if (officeClass != OfficeClass.USPresident)
            {
                control = CreateAdminOfficeAnchor(row.OfficeKey, literalText, Empty);
            }
            else
            {
                control = new Literal {
                    Text = literalText
                }
            };

            return(control);
        }
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global
        // ReSharper disable UnassignedField.Global

        #endregion ReSharper disable

        public static Control GetReport(ReportUser reportUser, string stateElectionKey)
        {
            var stateCode = Elections.GetStateCodeFromKey(stateElectionKey);

            // We get a dictionary of counties with elections that match the stateElectionKey
            // Key: countyCode; Value: county electionKey
            // Counties without an election will not be in the dictionary
            var countyElectionDictionary =
                ElectionsOffices.GetCountyAndLocalElections(stateElectionKey);

            if (countyElectionDictionary.Count == 0)
            {
                return(null);
            }

            // For reporting we start with all counties for the state (it will be in
            // order by county name). Then we select only those in the election dictionary
            // and reorder for vertical presentation.
            var reorderedCounties = CountyCache.GetCountiesByState(stateCode)
                                    .Where(countyElectionDictionary.ContainsKey)
                                    .ToList()
                                    .ReorderVertically(MaxCellsInRow);

            var          htmlTable           = CreateHtmlTableWithHeading(reportUser, true);
            HtmlTableRow tr                  = null;
            var          cellsDisplayedInRow = MaxCellsInRow; // force new row

            foreach (var countyCode in reorderedCounties)
            {
                var countyName        = CountyCache.GetCountyName(stateCode, countyCode);
                var countyElectionKey = countyElectionDictionary[countyCode];
                cellsDisplayedInRow = CreateOneAnchorCell(reportUser, htmlTable, ref tr,
                                                          countyName, countyElectionKey, cellsDisplayedInRow);
            }

            return(htmlTable);
        }
        private static void GetCountyElections(Control container, string stateElectionKey)
        {
            var stateCode = Elections.GetStateCodeFromKey(stateElectionKey);

            // We get a dictionary of counties with elections that match the stateElectionKey
            // Key: countyCode; Value: countyElectionKey
            // Counties without an election will not be in the dictionary
            // We include local elections too, to account for situations where there is no county
            // election but there are local elections.
            var countyElectionDictionary =
                ElectionsOffices.GetCountyAndLocalElections(stateElectionKey);
            // We can't forget the Ballot Measures...
            var countyReferendumDictionary =
                Referendums.GetCountyAndLocalElections(stateElectionKey);

            // merge them into the first dictionary
            foreach (var kvp in countyReferendumDictionary)
            {
                if (!countyElectionDictionary.ContainsKey(kvp.Key))
                {
                    countyElectionDictionary.Add(kvp.Key, kvp.Value);
                }
            }
            if (countyElectionDictionary.Count == 0)
            {
                return;
            }

            // For reporting we start with all counties for the state (it will be in
            // order by county name) and select only those in the election dictionary.
            var counties = CountyCache.GetCountiesByState(stateCode)
                           .Where(countyElectionDictionary.ContainsKey).ToList();

            var multiCountySection = new PlaceHolder();

            multiCountySection.AddTo(container);

            // each county report is in its own accordion
            foreach (var countyCode in counties)
            {
                var countyName        = CountyCache.GetCountyName(stateCode, countyCode);
                var countyElectionKey = countyElectionDictionary[countyCode];

                var electionReport = new ElectionReportResponsive();
                var countyReport   = electionReport.GenerateReport(countyElectionKey, true, multiCountySection);

                for (var inx = 0; inx < countyReport.Controls.Count; inx += 2)
                {
                    // this will always be a state report (for county reports, GenerateReport
                    // is called directly. Inject the county name into the office title header for context
                    var header = countyReport.Controls[inx] as HtmlContainerControl;
                    header?.Controls.Add(
                        new HtmlP {
                        InnerText = countyName
                    }.AddCssClasses("county-message"));
                }

                // move them to the content
                while (countyReport.Controls.Count > 0)
                {
                    container.Controls.Add(countyReport.Controls[0]);
                }
            }
        }
 protected override string GetCategoryTitle()
 {
     return(CountyCache.GetCountyName(StateCode, CountyCode) + ", " +
            StateCache.GetStateName(StateCode) + " - Countywide Offices");
 }
Exemplo n.º 20
0
        public static Control CreateRelatedJurisdictionsNodes(string href, string tab,
                                                              string stateCode, string countyCode, string localKey)
        {
            if (!StateCache.IsValidStateCode(stateCode))
            {
                return(new PlaceHolder());
            }
            var mainNode = new HtmlLi {
                InnerHtml = "Related Jurisdictions"
            };
            var data =
                "addClass:'related-jurisdictions office-class',hideCheckbox:true,unselectable:true";

            // start this node expanded if county or local
            if (!IsNullOrWhiteSpace(countyCode) || !IsNullOrWhiteSpace(localKey))
            {
                data += ", expand:true";
            }
            mainNode.Attributes.Add("data", data);
            var subTree = new HtmlUl().AddTo(mainNode);

            if (!IsNullOrWhiteSpace(localKey))
            {
                // For Locals, the state, the county, and all other locals
                CreateRelatedJurisdictionsNode(subTree, StateCache.GetStateName(stateCode), href,
                                               tab, stateCode, Empty, Empty);
                CreateRelatedJurisdictionsNode(subTree,
                                               MakeJurisdictionName(CountyCache.GetCountyName(stateCode, countyCode), countyCode,
                                                                    "County {0}"), href, tab, stateCode, countyCode, Empty);
                foreach (var l in LocalDistricts.GetLocalsForCounty(stateCode, countyCode).Rows
                         .OfType <DataRow>().OrderBy(l => l.LocalDistrict(), new AlphanumericComparer()))
                {
                    if (l.LocalKey() != localKey)
                    {
                        CreateRelatedJurisdictionsNode(subTree,
                                                       MakeJurisdictionName(l.LocalDistrict(), l.LocalKey(), "Local District {0}"),
                                                       href, tab, stateCode, countyCode, l.LocalKey());
                    }
                }
            }
            else if (!IsNullOrWhiteSpace(countyCode))
            {
                // For Counties, the state and all other counties (in sub-tree) plus all locals for the county
                CreateRelatedJurisdictionsNode(subTree, StateCache.GetStateName(stateCode), href,
                                               tab, stateCode, Empty, Empty);
                var subNode = new HtmlLi {
                    InnerHtml = "Counties"
                };
                const string subData =
                    "addClass:'office-class',hideCheckbox:true,unselectable:true";
                subNode.Attributes.Add("data", subData);
                subNode.AddTo(subTree);
                var subSubTree = new HtmlUl().AddTo(subNode);
                foreach (var c in CountyCache.GetCountiesByState(stateCode))
                {
                    if (c != countyCode)
                    {
                        CreateRelatedJurisdictionsNode(subSubTree,
                                                       MakeJurisdictionName(CountyCache.GetCountyName(stateCode, c), c,
                                                                            "County {0}"), href, tab, stateCode, c, Empty);
                    }
                }
                foreach (var l in LocalDistricts.GetLocalsForCounty(stateCode, countyCode).Rows
                         .OfType <DataRow>().OrderBy(l => l.LocalDistrict(), new AlphanumericComparer()))
                {
                    CreateRelatedJurisdictionsNode(subTree,
                                                   MakeJurisdictionName(l.LocalDistrict(), l.LocalKey(), "Local District {0}"),
                                                   href, tab, stateCode, countyCode, l.LocalKey());
                }
            }
            else
            {
                // For State, a list of counties
                foreach (var c in CountyCache.GetCountiesByState(stateCode))
                {
                    CreateRelatedJurisdictionsNode(subTree,
                                                   MakeJurisdictionName(CountyCache.GetCountyName(stateCode, c), c, "County {0}"),
                                                   href, tab, stateCode, c, Empty);
                }
            }

            return(mainNode);
        }
 protected override string GetCategoryTitle()
 {
     return(LocalName + ", " + CountyCache.GetCountyName(StateCode, CountyCode) +
            ", " + StateCache.GetStateName(StateCode) + " Elected Officials");
 }
 protected override string GetOfficeTitle(DataRow officeInfo)
 {
     return(CountyCache.GetCountyName(StateCode, CountyCode) + " " +
            Offices.FormatOfficeName(officeInfo));
 }
Exemplo n.º 23
0
 public void Initialize(string stateCode = null, string countyCode = null,
                        string localCode = null)
 {
     if (stateCode != null)
     {
         StatesPickerSpecific.InnerText =
             StateCache.GetStateName(stateCode);
     }
     CountiesPickerAllCheckbox.Checked  = true;
     CountiesPickerAllCheckbox.Disabled = true;
     CountiesPickerListButton.Disabled  = true;
     LocalsPickerAllCheckbox.Checked    = true;
     LocalsPickerAllCheckbox.Disabled   = true;
     LocalsPickerListButton.Disabled    = true;
     if (stateCode == null)
     {
         StatesPickerAll.RemoveCssClass("hidden");
         StatesPickerAllCheckbox.Checked = true;
         StatesPickerSpecific.AddCssClasses("hidden");
         StatesPickerList.RemoveCssClass("hidden");
         BuildStatesList();
         CountiesPicker.AddCssClasses("disabled hidden");
         CountiesPickerListButtonContainer.RemoveCssClass("hidden");
         LocalsPicker.AddCssClasses("disabled hidden");
     }
     else if (countyCode == null)
     {
         CountiesPicker.AddCssClasses("hidden");
         CountiesPickerAllCheckbox.Disabled = false;
         BuildStatesList(stateCode);
         CountiesPickerList.RemoveCssClass("hidden");
         BuildCountiesList(stateCode);
         LocalsPicker.AddCssClasses("disabled hidden");
     }
     else if (localCode == null)
     {
         BuildStatesList(stateCode);
         CountiesPickerAll.AddCssClasses("hidden");
         CountiesPickerAllCheckbox.Checked = false;
         CountiesPickerSpecific.RemoveCssClass("hidden");
         CountiesPickerSpecific.InnerText =
             CountyCache.GetCountyName(stateCode, countyCode);
         BuildCountiesList(stateCode, countyCode);
         LocalsPicker.RemoveCssClass("disabled");
         LocalsPickerAllCheckbox.Disabled = false;
         LocalsPickerListButtonContainer.AddCssClasses("hidden");
         LocalsPickerList.RemoveCssClass("hidden");
         LocalsPicker.AddCssClasses("disabled hidden");
         BuildLocalsList(stateCode, countyCode);
     }
     else
     {
         BuildStatesList(stateCode);
         CountiesPickerAll.AddCssClasses("hidden");
         CountiesPickerAllCheckbox.Checked = false;
         CountiesPickerSpecific.RemoveCssClass("hidden");
         CountiesPickerSpecific.InnerText =
             CountyCache.GetCountyName(stateCode, countyCode);
         BuildCountiesList(stateCode, countyCode);
         LocalsPicker.RemoveCssClass("disabled");
         LocalsPickerAll.AddCssClasses("hidden");
         LocalsPickerAllCheckbox.Checked = false;
         LocalsPickerSpecific.RemoveCssClass("hidden");
         LocalsPickerSpecific.InnerText =
             LocalDistricts.GetLocalDistrict(stateCode, countyCode,
                                             localCode);
         LocalsPickerListButtonContainer.AddCssClasses("hidden");
         BuildLocalsList(stateCode, countyCode, localCode);
     }
 }
Exemplo n.º 24
0
 public static string GetName(string stateCode, string countyCode)
 {
     return(CountyCache.GetCountyName(stateCode, countyCode));
 }
Exemplo n.º 25
0
        public static string GetElectoralClassShortDescription(string stateCode,
                                                               string countyCode = "", string localCode = "")
        {
            switch (GetElectoralClass(stateCode, countyCode, localCode))
            {
            case ElectoralClass.USPresident:
                return("US President");

            case ElectoralClass.USSenate:
                return("US Senate");

            case ElectoralClass.USHouse:
                return("US House");

            case ElectoralClass.USGovernors:
                return("Governors");

            case ElectoralClass.State:
                return(StateCache.IsValidStateCode(stateCode)
            ? StateCache.GetShortName(stateCode)
            : string.Empty);

            case ElectoralClass.County:
                if (countyCode == "000")
                {
                    return(GetElectoralClassShortDescription(stateCode) + " Counties");
                }
                if (CountyCache.CountyExists(stateCode, countyCode))
                {
                    if (stateCode != "DC")
                    {
                        return(CountyCache.GetCountyName(stateCode, countyCode) + ", " +
                               StateCache.GetShortName(stateCode));
                    }
                    else
                    {
                        return(StateCache.GetShortName(stateCode) + " Local");
                    }
                }
                return(string.Empty);

            case ElectoralClass.Local:
                if (countyCode == "000")
                {
                    return(GetElectoralClassShortDescription(stateCode, countyCode) +
                           " Locals");
                }
                var localName = VotePage.GetPageCache()
                                .LocalDistricts.GetLocalDistrict(stateCode, countyCode, localCode);
                if (!string.IsNullOrWhiteSpace(localName))
                {
                    return(localName + ", " +
                           CountyCache.GetCountyName(stateCode, countyCode) + ", " +
                           StateCache.GetShortName(stateCode));
                }
                return(string.Empty);

            default:
                return(string.Empty);
            }
        }
Exemplo n.º 26
0
 public static string GetName(string stateCode, string countyCode) =>
 CountyCache.GetCountyName(stateCode, countyCode);
Exemplo n.º 27
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
                }
            }
Exemplo n.º 28
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _SecureAdminPage = VotePage.GetPage <SecureAdminPage>();
            if (_SecureAdminPage == null)
            {
                throw new VoteException(
                          "The SelectJurisdictionButton control can only be used in the" +
                          " SecureAdminPage class");
            }

            if (!IsPostBack)
            {
                Page.IncludeCss("~/css/vote/controls/SelectJurisdictionButton.css");

                if (IsNullOrWhiteSpace(AdminPageName))
                {
                    var match = Regex.Match(VotePage.CurrentPath, @"/([^./]+)\.");
                    if (!match.Success)
                    {
                        throw new VoteException("Missing AdminPageName");
                    }
                    AdminPageName = match.Groups[1].Value;
                }

                StateLink.NavigateUrl =
                    SecureAdminPage.GetAdminFolderPageUrl(AdminPageName, "state",
                                                          _SecureAdminPage.StateCode);
                StateLink.Text = "► " + StateCache.GetStateName(_SecureAdminPage.StateCode);

                switch (_SecureAdminPage.AdminPageLevel)
                {
                case AdminPageLevel.State:
                    if (AddClasses)
                    {
                        Container.AddCssClasses("state");
                    }
                    break;

                case AdminPageLevel.County:
                    StateLink.Visible = true;
                    if (AddClasses)
                    {
                        Container.AddCssClasses("county");
                    }
                    break;

                case AdminPageLevel.Local:
                    StateLink.Visible = true;
                    if (AddClasses)
                    {
                        Container.AddCssClasses("local");
                    }
                    CountyLink.Visible     = true;
                    CountyLink.NavigateUrl = SecureAdminPage.GetAdminFolderPageUrl(AdminPageName,
                                                                                   "state", _SecureAdminPage.StateCode, "county", _SecureAdminPage.CountyCode);
                    CountyLink.Text = "► " +
                                      CountyCache.GetCountyName(_SecureAdminPage.StateCode,
                                                                _SecureAdminPage.CountyCode);
                    break;
                }
            }
        }