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
    // 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.º 4
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.º 5
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.º 6
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");
            }
        }
        // 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.º 9
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);
        }
        // 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]);
                }
            }
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        // ReSharper disable MemberCanBePrivate.Global
        // ReSharper disable MemberCanBeProtected.Global
        // ReSharper disable UnusedMember.Global
        // ReSharper disable UnusedMethodReturnValue.Global
        // ReSharper disable UnusedAutoPropertyAccessor.Global

        public static ReadOnlyCollection <string> GetCountiesByState(string stateCode) =>
        CountyCache.GetCountiesByState(stateCode);