예제 #1
0
        private void GetLocalElections(Control container, string countyElectionKey)
        {
            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: localCode; 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);

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

            // 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)
                         .ToList();

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

                new HtmlDiv {
                    InnerText = localName
                }.AddTo(content, "accordion-header");
                new ElectionReportResponsive().GenerateReport(ReportUser, localElectionKey)
                .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 countyElectionKey, bool openAll = false)
    {
      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
      // We can't forget the Ballot Measures...
      var localKeys = LocalDistricts.GetLocalKeysForCounty(stateCode, countyCode);
      var localElectionDictionary = ElectionsOffices.GetLocalElections(stateElectionKey,
        countyCode, localKeys);
      var localReferendumDictionary = Referendums.GetLocalElections(stateElectionKey, countyCode,
        localKeys);
      // 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);

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

      // 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 a dictionary of other county names for multiple counties
      var otherCountyNames =
        LocalIdsCodes.FormatOtherCountyNamesDictionary(stateCode, countyCode,
          locals.Select(l => l.Key));

      foreach (var kvp in locals)
      {
        var localKey = kvp.Key;
        var localName = kvp.Value;
        var otherCounties = otherCountyNames[localKey];
        if (!IsNullOrWhiteSpace(otherCounties))
          localName += $" (also in {otherCounties})";
        var localElectionKey = localElectionDictionary[localKey];
        CreatePublicElectionAnchor(localElectionKey, localName, openAll)
          .AddTo(content, "local-anchor");
      }
    }
        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;
                //}
            }
        }