コード例 #1
0
            public void Generate(ElectionReportResponsive electionReport, string electionKey,
                                 bool isForAllStatesReport = false)
            {
                ElectionReport       = electionReport;
                ElectionKey          = electionKey;
                StateCode            = Elections.GetStateCodeFromKey(electionKey);
                CountyCode           = Elections.GetCountyCodeFromKey(electionKey);
                LocalCode            = Elections.GetLocalCodeFromKey(electionKey);
                IsForAllStatesReport = isForAllStatesReport;

                var offices = GetOffices()
                              .Where(g => g.First().ElectionsPoliticianKey() != null)
                              .ToList();

                if (offices.Count <= 0)
                {
                    return;
                }
                if ((electionReport.ReportUser == ReportUser.Public) &&
                    Elections.IsPrimaryElection(electionKey))
                {
                    offices = FilterUncontestedOffices(offices)
                              .ToList();
                }

                Control container;

                // only create a category wrapper if more than one office
                if ((offices.Count > 1) || isForAllStatesReport)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    (new HtmlDiv().AddTo(ElectionReport.ReportContainer, "category-title accordion-header")
                     as HtmlGenericControl).InnerHtml = GetCategoryTitle();
                    container = new HtmlDiv().AddTo(ElectionReport.ReportContainer,
                                                    "category-content accordion-content");
                }
                else
                {
                    container = ElectionReport.ReportContainer;
                }

                foreach (var office in offices)
                {
                    var politicians = office.ToList();
                    var officeInfo  = politicians[0];

                    var officeContent = new HtmlDiv();
                    ElectionReport.CreateOfficeTitle(container, officeContent, politicians,
                                                     GetOfficeTitle(officeInfo));
                    officeContent.AddTo(container, "office-content accordion-content");
                    var isRunningMateOffice = officeInfo.IsRunningMateOffice() &&
                                              !Elections.IsPrimaryElection(electionKey);
                    ReportOffice(officeContent, isRunningMateOffice, politicians,
                                 ElectionReport._DataManager, false, false,
                                 ElectionReport.ReportUser == ReportUser.Master);
                }
            }
コード例 #2
0
        public static Control GetReport(string electionKey, bool complete)
        {
            var reportObject = new ElectionReportResponsive();

            return(reportObject.GenerateReport(electionKey, complete));
        }
コード例 #3
0
        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]);
                }
            }
        }
コード例 #4
0
        private static void GetLocalElections(Control container, string countyElectionKey, Control multiCountySection = null)
        {
            var stateCode        = Elections.GetStateCodeFromKey(countyElectionKey);
            var countyCode       = Elections.GetCountyCodeFromKey(countyElectionKey);
            var stateElectionKey = Elections.GetStateElectionKeyFromKey(countyElectionKey);

            // We get a dictionary of locals with elections that match the stateElectionKey
            // Key: localKey; Value: local electionKey
            // Locals without an election will not be in the dictionary
            var localElectionDictionary =
                ElectionsOffices.GetLocalElections(stateElectionKey, countyCode);
            // We can't forget the Ballot Measures...
            var localReferendumDictionary =
                Referendums.GetLocalElections(stateElectionKey, countyCode);

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

            // We also get a dictionary of all local names for the county
            var localNamesDictionary = LocalDistricts.GetNamesDictionary(stateCode, countyCode);

            // For reporting we filter only locals with elections and sort by name,
            var locals = localNamesDictionary
                         .Where(kvp => localElectionDictionary.ContainsKey(kvp.Key))
                         .OrderBy(kvp => kvp.Value, new AlphanumericComparer()).ToList();

            // Get all counties for the locals NB: the counties are pre-sorted by county name
            var countiesForLocals =
                LocalIdsCodes.FindCountiesWithNames(stateCode, locals.Select(kvp => kvp.Key));

            foreach (var kvp in locals)
            {
                var localKey         = kvp.Key;
                var localName        = kvp.Value;
                var localElectionKey = localElectionDictionary[localKey];
                var countiesForLocal = countiesForLocals[localKey];

                var electionReport = new ElectionReportResponsive();
                var localReport    = electionReport.GenerateReport(localElectionKey, true);

                // this will be either a state or county report (for local reports, GenerateReport
                // is called directly)

                //for either county or state, inject the name of the local district into the office
                // if this is an office-title oe a referendum header
                for (var inx = 0; inx < localReport.Controls.Count; inx += 2)
                {
                    var header = localReport.Controls[inx] as HtmlContainerControl;
                    if (header?.HasClass("office-title") == true || header?.HasClass("referendum-header") == true)
                    {
                        header.Controls.AddAt(0,
                                              new HtmlSpan {
                            InnerText = $"{localName}, "
                        }.AddCssClasses("local-name"));
                    }
                }

                //switch (reportLevel)
                //{
                //case ReportLevel.StateLevel:
                //  {
                while (localReport.Controls.Count > 0)
                {
                    if (countiesForLocal.Length > 1 && multiCountySection != null)
                    {
                        // if the county is the first in the counties, inject a multi-county message
                        // and move the pair (header and content) to the multi-counties section.
                        // Otherwise, discard it (it's a duplicate)
                        if (countyCode == countiesForLocal[0].Value)
                        {
                            //var countyMessage = "Parts of this district are in" +
                            //  $" {LocalIdsCodes.FormatCountyNames(countiesForLocal, true)}";
                            //var header = localReport.Controls[0] as HtmlContainerControl;
                            //header?.Controls.Add(
                            //  new HtmlP { InnerText = countyMessage }.AddCssClasses("county-message"));
                            //Debug.Assert(multiCountySection != null, "multiCountySection != null");
                            multiCountySection.Controls.Add(localReport.Controls[0]);
                            multiCountySection.Controls.Add(localReport.Controls[0]);
                        }
                        else
                        {
                            localReport.Controls.RemoveAt(0);
                            localReport.Controls.RemoveAt(0);
                        }
                    }
                    else
                    {
                        // move the pair (header and content) to the outer content
                        container.Controls.Add(localReport.Controls[0]);
                        container.Controls.Add(localReport.Controls[0]);
                    }
                }
                //  }
                //  break;

                //case ReportLevel.CountyLevel:
                //  {
                //var first = true;
                //while (localReport.Controls.Count > 0)
                //{
                //  // for multi-county districts, inject an "other counties" message into the
                //  // first office header if multi county
                //  var countyMessage = Empty;
                //  if (first && countiesForLocal.Length > 1)
                //    countyMessage = "Parts of this local district are also in" +
                //      $" {LocalIdsCodes.FormatCountyNames(countiesForLocal, true, countyCode)}";
                //  var header = localReport.Controls[0] as HtmlContainerControl;
                //  if (!IsNullOrWhiteSpace(countyMessage))
                //    header?.Controls.Add(
                //      new HtmlP { InnerText = countyMessage }.AddCssClasses("county-message"));
                //  first = false;
                //  // move the pair (header and content) to the outer content
                //  container.Controls.Add(localReport.Controls[0]);
                //  container.Controls.Add(localReport.Controls[0]);
                //}
                //}
                //break;
                //}
            }
        }
コード例 #5
0
            public void Generate(ElectionReportResponsive electionReport, string electionKey,
                                 bool isForAllStatesReport = false)
            {
                ElectionReport = electionReport;
                ElectionKey    = electionKey;
                StateCode      = Elections.GetStateCodeFromKey(electionKey);
                CountyCode     = Elections.GetCountyCodeFromKey(electionKey);
                LocalKey       = Elections.GetLocalKeyFromKey(electionKey);
                var counties           = LocalIdsCodes.FindCountiesWithNames(StateCode, LocalKey);
                var isMultiCountyLocal = counties.Length > 1;

                IsForAllStatesReport = isForAllStatesReport;

                var offices = GetOffices()
                              .Where(g => g.First().ElectionsPoliticianKey() != null)
                              .ToList();

                if (offices.Count <= 0)
                {
                    return;
                }
                if (Elections.IsPrimaryElection(electionKey))
                {
                    offices = FilterUncontestedOffices(offices)
                              .ToList();
                }

                Control container;

                // only create a category wrapper if more than one office, or isMultiCountyLocal
                if (isMultiCountyLocal || offices.Count > 1 || isForAllStatesReport)
                {
                    // ReSharper disable once PossibleNullReferenceException
                    var title = new PlaceHolder();
                    // ReSharper disable once PossibleNullReferenceException
                    (new HtmlSpan().AddTo(title) as HtmlGenericControl).InnerText = GetCategoryTitle();
                    if (isMultiCountyLocal)
                    {
                        var allCounties =
                            LocalIdsCodes.FormatAllCountyNames(StateCode, LocalKey, true);
                        // ReSharper disable once PossibleNullReferenceException
                        (new HtmlP().AddTo(title) as HtmlGenericControl)
                        .InnerText = $"Parts of this local district are in {allCounties}";
                    }
                    // ReSharper disable once PossibleNullReferenceException
                    new HtmlDiv().AddTo(ElectionReport.ReportContainer, "category-title accordion-header")
                    .Controls.Add(title);
                    container = new HtmlDiv().AddTo(ElectionReport.ReportContainer,
                                                    "category-content accordion-content");
                }
                else
                {
                    container = ElectionReport.ReportContainer;
                }

                foreach (var office in offices)
                {
                    var politicians = office.ToList();
                    var officeInfo  = politicians[0];

                    var officeContent = new HtmlDiv();
                    CreateOfficeTitle(container, officeContent, politicians,
                                      GetOfficeTitle(officeInfo));
                    officeContent.AddTo(container, "office-content accordion-content");
                    //var isRunningMateOffice = officeInfo.IsRunningMateOffice() &&
                    //  !Elections.IsPrimaryElection(electionKey);
                    var isRunningMateOffice = Offices.IsRunningMateOfficeInElection(electionKey,
                                                                                    officeInfo.OfficeKey());
                    ReportOffice(officeContent, isRunningMateOffice, politicians,
                                 ElectionReport._DataManager);
                }
            }
コード例 #6
0
        public static Control GetReport(ReportUser reportUser, string electionKey, bool openAll = false)
        {
            var reportObject = new ElectionReportResponsive();

            return(reportObject.GenerateReport(reportUser, electionKey, openAll));
        }