protected void ButtonIncludeMultiCountyDistricts_OnClick(object sender, EventArgs e)
        {
            switch (IncludeMultiCountyDistrictsReloading.Value)
            {
            case "reloading":
            {
                IncludeMultiCountyDistrictsReloading.Value = Empty;
                _IncludeMultiCountyDistrictsTabInfo.ClearValidationErrors();
                var items =
                    FormatMultiCountyLocalsList(LocalDistricts.GetLocalsForInclude(StateCode, CountyCode));
                PopulateDistrictsToIncludeDropdown(items);
                _IncludeMultiCountyDistrictsTabInfo.LoadControls();
                FeedbackIncludeMultiCountyDistricts.AddInfo("Include Multi-County Districts settings loaded.");
            }
            break;

            case "":
            {
                try
                {
                    // normal update
                    _IncludeMultiCountyDistrictsTabInfo.ClearValidationErrors();
                    var localKey = ControlIncludeMultiCountyDistrictsLocalKey.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.Insert(StateCode, CountyCode, lic[0].LocalId, lic[0].LocalType);

                    _IncludeMultiCountyDistrictsTabInfo.ClearValidationErrors();
                    var items =
                        FormatMultiCountyLocalsList(LocalDistricts.GetLocalsForInclude(StateCode, CountyCode));
                    PopulateDistrictsToIncludeDropdown(items);
                    _IncludeMultiCountyDistrictsTabInfo.LoadControls();
                    NavigateJurisdictionUpdatePanel.Update();
                    NavigateJurisdiction.Initialize();
                    FeedbackIncludeMultiCountyDistricts.AddInfo("Multi-County District included.");
                }
                catch (Exception ex)
                {
                    FeedbackIncludeMultiCountyDistricts.HandleException(ex);
                }
            }
            break;

            default:
                throw new VoteException($"Unknown reloading option: '{IncludeMultiCountyDistrictsReloading.Value}'");
            }
        }
Exemple #2
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}'");
            }
        }