コード例 #1
0
        protected void ButtonRemoveMultiCountyDistricts_OnClick(object sender, EventArgs e)
        {
            switch (RemoveMultiCountyDistrictsReloading.Value)
            {
            case "reloading":
            {
                RemoveMultiCountyDistrictsReloading.Value = Empty;
                _RemoveMultiCountyDistrictsTabInfo.ClearValidationErrors();
                var items =
                    FormatMultiCountyLocalsList(LocalDistricts.GetLocalsForRemove(StateCode, CountyCode));
                PopulateDistrictsToRemoveDropdown(items);
                _RemoveMultiCountyDistrictsTabInfo.LoadControls();
                FeedbackRemoveMultiCountyDistricts.AddInfo("Remove Multi-County Districts settings loaded.");
            }
            break;

            case "":
            {
                try
                {
                    // normal update
                    _RemoveMultiCountyDistrictsTabInfo.ClearValidationErrors();
                    var localKey = ControlRemoveMultiCountyDistrictsLocalKey.GetValue();
                    if (IsNullOrWhiteSpace(localKey))
                    {
                        throw new VoteException("No district was selected");
                    }
                    var lic = LocalIdsCodes.GetDataByStateCodeLocalKey(StateCode, localKey);
                    if (lic.Count != 1)
                    {
                        throw new VoteException("Missing LocalIdsCodes row");
                    }
                    if (lic[0].LocalType != LocalIdsCodes.LocalTypeVote)
                    {
                        throw new VoteException("Invalid LocalType");
                    }
                    TigerPlacesCounties.DeleteByStateCodeCountyCodeTigerCodeTigerType(StateCode,
                                                                                      CountyCode, lic[0].LocalId, lic[0].LocalType);

                    _RemoveMultiCountyDistrictsTabInfo.ClearValidationErrors();
                    var items =
                        FormatMultiCountyLocalsList(LocalDistricts.GetLocalsForRemove(StateCode, CountyCode));
                    PopulateDistrictsToRemoveDropdown(items);
                    _RemoveMultiCountyDistrictsTabInfo.LoadControls();
                    NavigateJurisdictionUpdatePanel.Update();
                    NavigateJurisdiction.Initialize();
                    FeedbackRemoveMultiCountyDistricts.AddInfo("Multi-County District removed.");
                }
                catch (Exception ex)
                {
                    FeedbackRemoveMultiCountyDistricts.HandleException(ex);
                }
            }
            break;

            default:
                throw new VoteException($"Unknown reloading option: '{RemoveMultiCountyDistrictsReloading.Value}'");
            }
        }
コード例 #2
0
        // ReSharper restore UnusedMember.Global
        // ReSharper restore VirtualMemberNeverOverriden.Global
        // ReSharper restore MemberCanBePrivate.Global

        #endregion ReSharper restore

        #endregion Protected

        #region Event handlers and overrides

        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);

            if (AdminPageLevel == AdminPageLevel.Local)
            {
                var licTable = LocalIdsCodes.GetDataByStateCodeLocalKey(StateCode, LocalKey);
                if (licTable.Count == 1)
                {
                    var lic = licTable[0];
                    switch (lic.LocalType)
                    {
                    case LocalIdsCodes.LocalTypeTiger:
                        // Allow council for both places and cosubs - 04/10/19
                        IsTigerPlace =
                            TigerPlacesCounties.CountByStateCodeTigerTypeTigerCode(StateCode,
                                                                                   TigerPlacesCounties.TigerTypePlace, lic.LocalId) +
                            TigerPlacesCounties.CountByStateCodeTigerTypeTigerCode(StateCode,
                                                                                   TigerPlacesCounties.TigerTypeCousub, lic.LocalId) > 0;
                        if (IsTigerPlace)
                        {
                            TigerPlaceCode = lic.LocalId;
                            TigerPlaceName =
                                TigerPlaces.GetNameByStateCodeTigerCode(StateCode, TigerPlaceCode);
                        }
                        break;

                    case LocalIdsCodes.LocalTypeElementary:
                    case LocalIdsCodes.LocalTypeSecondary:
                    case LocalIdsCodes.LocalTypeUnified:
                        IsTigerSchool   = true;
                        TigerSchoolType = lic.LocalType;
                        TigerSchoolCode = lic.LocalId;
                        TigerSchoolName =
                            TigerSchools.GetNameByStateCodeTigerCodeTigerType(StateCode, TigerSchoolCode,
                                                                              TigerSchoolType);
                        break;
                    }
                }
            }
        }
コード例 #3
0
        private void PopulateTigerDistricts(DropDownList dropDownList, string tigerType,
                                            string doNotDisable = null, string selected = null)
        {
            if (selected == null)
            {
                selected = doNotDisable;
            }
            var districtsTable = tigerType == TigerPlacesCounties.TigerTypeCousub
        ? TigerPlacesCounties.GetCousubsByCountyCode(StateCode, CountyCode)
                                 .Rows.Cast <DataRow>().ToArray()
        : TigerPlacesCounties.GetPlacesByCountyCode(StateCode, CountyCode)
                                 .Rows.Cast <DataRow>().ToArray();
            var districtItems = new List <SimpleListItem>
            {
                new SimpleListItem {
                    Text = "<none>", Value = Empty
                },
                districtsTable
                .Select(r => new SimpleListItem {
                    Text = r.LongName(), Value = r.TigerCode()
                })
                .ToArray()
            };

            Utility.PopulateFromList(dropDownList, districtItems, selected);

            // apply disabling
            foreach (var item in dropDownList.Items.OfType <ListItem>())
            {
                if (item.Value != doNotDisable)
                {
                    var matchingRow = districtsTable.FirstOrDefault(r => r.TigerCode() == item.Value);
                    if (!IsNullOrWhiteSpace(matchingRow?.LocalKey()))
                    {
                        item.Attributes.Add("disabled", "disabled");
                    }
                }
            }
        }
コード例 #4
0
        protected void ButtonTigerSettings_OnClick(object sender, EventArgs e)
        {
            switch (TigerSettingsReloading.Value)
            {
            case "reloading":
            {
                TigerSettingsReloading.Value = Empty;
                _TigerSettingsTabInfo.ClearValidationErrors();
                LoadTigerControlsForTigerSettings();
                FeedbackTigerSettings.AddInfo("Tiger settings loaded.");
            }
            break;

            case "":
            {
                try
                {
                    // normal update
                    _TigerSettingsTabInfo.ClearValidationErrors();
                    var tigerData =
                        LocalIdsCodes.GetLocalData(StateCode, LocalKey).Rows.Cast <DataRow>().ToList();
                    PopulateTigerDistrictsForTigerSettings(tigerData, true);

                    // phase 2 checks
                    if (TigerChecks(out var localType, out var localIds,
                                    ControlTigerSettingsEntireCounty, ControlTigerSettingsTigerDistrict,
                                    ControlTigerSettingsTigerPlace, ControlTigerSettingsSchoolDistrict,
                                    ControlTigerSettingsCouncilDistrict, ControlTigerSettingsSupervisorsDistrict,
                                    FeedbackTigerSettings))
                    {
                        return;
                    }

                    // delete TigerPlacesCounties row if type Vote -- these are not intrinsically tied
                    // to county(s)
                    var localIdsCodes = LocalIdsCodes.GetDataByStateCodeLocalKey(StateCode,
                                                                                 LocalKey);
                    Debug.Assert(localIdsCodes.Count == 1);
                    if (localIdsCodes[0].LocalType == LocalIdsCodes.LocalTypeVote)
                    {
                        TigerPlacesCounties.DeleteByStateCodeCountyCodeTigerCodeTigerType(StateCode,
                                                                                          CountyCode, localIdsCodes[0].LocalId, LocalIdsCodes.LocalTypeVote);
                    }
                    // delete existing
                    LocalIdsCodes.DeleteByStateCodeLocalKey(StateCode, LocalKey);

                    // add new
                    foreach (var localId in localIds)
                    {
                        LocalIdsCodes.Insert(StateCode, localType, localId, LocalKey);
                        if (localType == LocalIdsCodes.LocalTypeVote)
                        {
                            TigerPlacesCounties.Insert(StateCode, CountyCode, localId,
                                                       TigerPlacesCounties.TigerTypeVote);
                        }
                    }

                    LoadTigerControlsForTigerSettings();
                    FeedbackTigerSettings.AddInfo("Tiger Settings changed.");
                }
                catch (Exception ex)
                {
                    FeedbackTigerSettings.HandleException(ex);
                }
            }
            break;

            default:
                throw new VoteException($"Unknown reloading option: '{TigerSettingsReloading.Value}'");
            }
        }
コード例 #5
0
        private void AuditSchoolDistricts(ShapeFile shapefile, string tigerType, string description)
        {
            if (shapefile == null)
            {
                throw new Exception("Could not find the shapefile");
            }
            var enumerator = shapefile.GetShapeFileEnumerator();
            var list       = new List <string[]>();

            while (enumerator.MoveNext())
            {
                list.Add(shapefile.GetAttributeFieldValues(enumerator.CurrentShapeIndex));
            }
            // reproject into nicely-named structure and eliminate "F" (ficticious entry)
            var shapefileData = list
                                .Select(i => new
            {
                StateCode = StateCache.StateCodeFromLdsStateCode(i[0].Trim()),
                Id        = i[1].Trim(),
                Name      = i[3].Trim(),
                FuncStat  = i[9].Trim()
            }).Where(i => i.FuncStat != "F").ToList();

            var tigerSchoolsData        = TigerSchools.GetDataByTigerType(tigerType);
            var tigerPlacesCountiesData = TigerPlacesCounties.GetDataByTigerType(tigerType);

            // District is in the shapefile, but is not in TigerSchools.
            var notInDatabase = shapefileData
                                .Where(s => !tigerSchoolsData.Any(d => d.StateCode == s.StateCode &&
                                                                  d.TigerCode == s.Id)).ToList();

            // District is in TigerSchools, but not in the shapefile.
            var notInShapefile = tigerSchoolsData
                                 .Where(d => !shapefileData.Any(s => s.StateCode == d.StateCode &&
                                                                s.Id == d.TigerCode)).ToList();

            // Check TigerSchools in TigerPlacesCounties
            var notInTigerPlacesCounties = tigerSchoolsData.Where(s =>
                                                                  !tigerPlacesCountiesData.Any(c =>
                                                                                               c.StateCode == s.StateCode && c.TigerCode == s.TigerCode)).ToList();

            // Check TigerPlacesCounties in TigerSchools
            var notInTigerSchools = tigerPlacesCountiesData.Where(c =>
                                                                  !tigerSchoolsData.Any(s =>
                                                                                        s.StateCode == c.StateCode && s.TigerCode == c.TigerCode)).ToList();

            var results = new HtmlDiv().AddTo(ResultsPlaceHolder, "results");

            new HtmlP {
                InnerText = $"Audit of {description} School District ShapeFile"
            }.AddTo(results, "head");
            new HtmlP {
                InnerText = $"There are {shapefileData.Count} entries in the shapefile."
            }
            .AddTo(results);
            new HtmlP
            {
                InnerText =
                    $"There are {tigerSchoolsData.Count} district entries and " +
                    $"{tigerPlacesCountiesData.Count} county entries in the database."
            }.AddTo(results);

            new HtmlP
            {
                InnerText =
                    $"{notInDatabase.Count} entries are in the shapefile, but not in the database."
            }.AddTo(results);
            foreach (var i in notInDatabase)
            {
                new HtmlP {
                    InnerText = $"{i.StateCode}:{i.Id} {i.Name}"
                }
            }
コード例 #6
0
        protected void ButtonDeleteDistricts_OnClick(object sender, EventArgs e)
        {
            switch (DeleteDistrictsReloading.Value)
            {
            case "reloading":
            {
                DeleteDistrictOverride.AddCssClasses("hidden");
                ControlDeleteDistrictOverride.Checked = false;
                _DeleteDistrictsTabInfo.ClearValidationErrors();
                DeleteDistrictsReloading.Value = Empty;
                PopulateLocalDistrictDropdown();
                _DeleteDistrictsTabInfo.LoadControls();
                FeedbackDeleteDistricts.AddInfo("Delete Districts information loaded.");
            }
            break;

            case "":
            {
                // normal update
                DeleteDistrictOverride.AddCssClasses("hidden");
                _DeleteDistrictsTabInfo.ClearValidationErrors();
                var localKey      = ControlDeleteDistrictsLocalKey.GetValue();
                var localDistrict = LocalDistricts.GetLocalDistrictByStateCodeLocalKey(StateCode,
                                                                                       localKey);

                var referenceList = new List <string>();
                if (!ControlDeleteDistrictOverride.Checked)
                {
                    // check for references in other counties
                    var otherCounties = new List <string>();
                    foreach (var oc in
                             LocalIdsCodes.GetOtherCountyReferences(StateCode, CountyCode, localKey)
                             .Rows.OfType <DataRow>())
                    {
                        otherCounties.Add(oc.County());
                    }

                    // check for meaningful usages
                    FormatReferences(referenceList, "Elections",
                                     Elections.CountByStateCodeLocalKey(StateCode, localKey));
                    FormatReferences(referenceList, "ElectionsOffices",
                                     ElectionsOffices.CountByStateCodeLocalKey(StateCode, localKey));
                    FormatReferences(referenceList, "ElectionsPoliticians",
                                     ElectionsPoliticians.CountByStateCodeLocalKey(StateCode, localKey));
                    FormatReferences(referenceList, "QuestionsJurisdictions",
                                     QuestionsJurisdictions.CountByIssueLevelStateCodeCountyOrLocal(
                                         Issues.IssueLevelLocal, StateCode, localKey));
                    FormatReferences(referenceList, "Offices",
                                     Offices.CountByStateCodeLocalKey(StateCode, localKey));
                    FormatReferences(referenceList, "OfficesOfficials",
                                     OfficesOfficials.CountByStateCodeLocalKey(StateCode, localKey));
                    FormatReferences(referenceList, "Referendums",
                                     Referendums.CountByStateCodeLocalKey(StateCode, localKey));

                    if (referenceList.Count > 0 || otherCounties.Count > 0)
                    {
                        DeleteDistrictOverride.RemoveCssClass("hidden");
                        if (otherCounties.Count > 0)
                        {
                            FeedbackDeleteDistricts.PostValidationError(ControlDeleteDistrictsLocalKey,
                                                                        "The district is referenced in the following other counties. If you delete this" +
                                                                        " district it will be removed from the other counties also. Check the box to" +
                                                                        " override.");
                            foreach (var oc in otherCounties)
                            {
                                FeedbackDeleteDistricts.AddError(oc);
                            }
                        }
                        if (referenceList.Count > 0)
                        {
                            FeedbackDeleteDistricts.PostValidationError(ControlDeleteDistrictsLocalKey,
                                                                        "Cannot delete because the LocalKey is referenced in the following tables. Check the box to override.");
                            foreach (var @ref in referenceList)
                            {
                                FeedbackDeleteDistricts.AddError(@ref);
                            }
                        }
                        return;
                    }
                }

                // delete
                ControlDeleteDistrictOverride.Checked = false;
                DeleteAllDistictReferences(StateCode, localKey);
                LocalDistricts.DeleteByStateCodeLocalKey(StateCode, localKey);

                // delete TigerPlacesCounties rows if type Vote -- these are not intrinsically tied
                // to county(s)
                var localIdsCodes = LocalIdsCodes.GetDataByStateCodeLocalKey(StateCode, localKey);
                Debug.Assert(localIdsCodes.Count == 1);
                if (localIdsCodes[0].LocalType == LocalIdsCodes.LocalTypeVote)
                {
                    TigerPlacesCounties.DeleteByStateCodeTigerTypeTigerCode(StateCode,
                                                                            LocalIdsCodes.LocalTypeVote, localIdsCodes[0].LocalId);
                }
                LocalIdsCodes.DeleteByStateCodeLocalKey(StateCode, localKey);
                _DeleteDistrictsTabInfo.ClearValidationErrors();
                PopulateLocalDistrictDropdown();
                _DeleteDistrictsTabInfo.LoadControls();
                NavigateJurisdictionUpdatePanel.Update();
                NavigateJurisdiction.Initialize();

                FeedbackDeleteDistricts.AddInfo(
                    $"Local District {localDistrict} ({localKey}) deleted.");
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{DeleteDistrictsReloading.Value}'");
            }
        }