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 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.º 2
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.º 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
        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.º 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"
                }
            }
            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.º 8
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.º 9
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.º 10
0
            // ReSharper disable UnusedMember.Local
            // Invoked via Reflection
            internal static void Initialize(BulkEmailPage page)
            // ReSharper restore UnusedMember.Local
            {
                if (!page.IsPostBack)
                {
                    if (IsNullOrWhiteSpace(page.StateCode))
                    {
                        StateCache.Populate(page.PreviewSampleStateDropDownList, "<none>", Empty);
                        Utility.PopulateEmpty(page.PreviewSampleElectionDropDownList);
                        Utility.PopulateEmpty(page.PreviewSamplePartyDropDownList);
                    }
                    else
                    {
                        StateCache.Populate(page.PreviewSampleStateDropDownList, page.StateCode);
                        Utility.PopulateFromList(page.PreviewSampleElectionDropDownList,
                                                 GetPreviewElectionItems(page.StateCode, page.CountyCode, page.LocalKey));
                        Utility.PopulateFromList(page.PreviewSamplePartyDropDownList,
                                                 GetPreviewPartyItems(page.StateCode));
                    }

                    CountyCache.Populate(page.PreviewSampleCountyDropDownList, page.StateCode,
                                         "<none>", Empty, page.CountyCode);
                    LocalDistricts.Populate(page.PreviewSampleLocalDropDownList, page.StateCode,
                                            page.CountyCode, "<none>", Empty, page.LocalKey);
                    Utility.PopulateEmpty(page.PreviewSampleOfficeDropDownList);
                    Utility.PopulateEmpty(page.PreviewSampleCandidateDropDownList);
                    Utility.PopulateEmpty(page.PreviewSamplePartyEmailDropDownList);

                    switch (UserSecurityClass)
                    {
                    case MasterSecurityClass:
                        break;

                    case StateAdminSecurityClass:
                        page.PreviewSampleStateDropDownList.Enabled = false;
                        break;

                    case CountyAdminSecurityClass:
                        page.PreviewSampleStateDropDownList.Enabled      = false;
                        page.PreviewSampleCountyDropDownList.Enabled     = false;
                        page.PreviewSamplePartyDropDownList.Enabled      = false;
                        page.PreviewSamplePartyEmailDropDownList.Enabled = false;
                        break;

                    case LocalAdminSecurityClass:
                        page.PreviewSampleStateDropDownList.Enabled      = false;
                        page.PreviewSampleCountyDropDownList.Enabled     = false;
                        page.PreviewSampleLocalDropDownList.Enabled      = false;
                        page.PreviewSamplePartyDropDownList.Enabled      = false;
                        page.PreviewSamplePartyEmailDropDownList.Enabled = false;
                        break;
                    }
                }
            }
Exemplo n.º 11
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");
            }
        }
Exemplo n.º 12
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.º 13
0
        static void Main(string[] args)
        {
            //var start = DateTime.UtcNow;
            //db2.Report_Officials_Update(PageCache.GetTemporary(), "VA");
            //var elapsed = DateTime.UtcNow - start;

            var allCountyOffices = Offices.CountAllCountyOffices("VA");
            var allLocalOffices  = Offices.CountAllLocalOffices("VA", "059");
            var countyCounts     = Offices.CountCountyOfficesByCounty("VA");
            var localCounts      = Offices.CountLocalOfficesByLocal("VA", "059");
            var counties         = CountyCache.GetCountiesByState("VA");
            var locals           = Offices.GetLocalNamesWithOffices("VA", "059");
        }
Exemplo n.º 14
0
 private void PopulateCountyDropDown(bool includeSelectMessage = false)
 {
     if (includeSelectMessage)
     {
         CountyCache.Populate(CountyDropDownList, _SecureAdminPage.StateCode,
                              "<select a county>", Empty);
     }
     else
     {
         CountyCache.Populate(CountyDropDownList, _SecureAdminPage.StateCode,
                              _SecureAdminPage.CountyCode);
     }
 }
Exemplo n.º 15
0
        public static Dictionary <string, bool> HasCountyOrLocalOfficesByCounty(
            string stateCode, int commandTimeout = -1)
        {
            using (var cn = VoteDb.GetOpenConnection())
            {
                // first create a dictionary of all counties in the state
                var dictionary = CountyCache.GetCountiesByState(stateCode)
                                 .ToDictionary(c => c, c => false);

                // the first query just gets the county offices
                const string cmdText =
                    "SELECT CountyCode,COUNT(*) AS Count FROM Offices" +
                    " WHERE StateCode=@StateCode AND CountyCode<>''" +
                    " GROUP BY CountyCode";
                var cmd = VoteDb.GetCommand(cmdText, commandTimeout);
                VoteDb.AddCommandParameter(cmd, "StateCode", stateCode);
                cmd.Connection = cn;
                var           table   = new DataTable();
                DbDataAdapter adapter = new MySqlDataAdapter(cmd as MySqlCommand);
                adapter.Fill(table);
                // counties tagged for deletion won't be in the table
                foreach (var c in table.Rows.OfType <DataRow>())
                {
                    if (dictionary.ContainsKey(c.CountyCode()) && c.Count() > 0)
                    {
                        dictionary[c.CountyCode()] = true;
                    }
                }

                // we only have to query locals for counties that are still false
                foreach (var c in dictionary.Where(kvp => !kvp.Value).Select(kvp => kvp.Key).ToList())
                {
                    // we need to do a pre-query to get all the locals in the selected county
                    var localKeysClause = LocalDistricts.GetLocalKeysForCounty(stateCode, c)
                                          .SqlIn("LocalKey");
                    var cmdText2 = "SELECT COUNT(*) AS Count FROM Offices" +
                                   $" WHERE StateCode=@StateCode AND {localKeysClause}";
                    var cmd2 = VoteDb.GetCommand(cmdText2, commandTimeout);
                    VoteDb.AddCommandParameter(cmd2, "StateCode", stateCode);
                    cmd2.Connection = cn;
                    if (Convert.ToInt32(cmd2.ExecuteScalar()) > 0)
                    {
                        dictionary[c] = true;
                    }
                }

                // only return the trues
                return(dictionary.Where(kvp => kvp.Value)
                       .ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
            }
        }
        // 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.º 17
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.º 19
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.º 20
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.º 21
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.º 22
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);
        }
Exemplo n.º 24
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);
            }
        }
        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.º 27
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.º 28
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));
 }