protected void ButtonElectionAuthority_OnClick(object sender, EventArgs e)
        {
            switch (ElectionAuthorityReloading.Value)
            {
            case "reloading":
            {
                ElectionAuthorityReloading.Value = Empty;
                _ElectionAuthorityTabInfo.LoadControls();
                FeedbackElectionAuthority.AddInfo("Election authority information loaded.");
            }
            break;

            case "":
            {
                // normal update
                _ElectionAuthorityTabInfo.ClearValidationErrors();
                _ElectionAuthorityTabInfo.Update(FeedbackElectionAuthority);
                NavigateJurisdictionUpdatePanel.Update();
                NavigateJurisdiction.Initialize();
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{ElectionAuthorityReloading.Value}'");
            }
        }
        protected void ButtonSetupCityCouncil_OnClick(object sender, EventArgs e)
        {
            switch (SetupCityCouncilReloading.Value)
            {
            case "reloading":
            {
                SetupCityCouncilReloading.Value = Empty;
                _SetupCityCouncilTabInfo.LoadControls();
                FeedbackSetupCityCouncil.AddInfo("City Council loaded.");
            }
            break;

            case "":
            {
                if (_SetupCityCouncilTabInfo.Length == 1)
                {
                    _SetupCityCouncilTabInfo[0].PrepareForUpdate();
                }
                _SetupCityCouncilTabInfo.Update(FeedbackSetupCityCouncil);
                NavigateJurisdictionUpdatePanel.Update();
                NavigateJurisdiction.Initialize();
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{SetupCityCouncilReloading.Value}'");
            }
        }
示例#3
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}'");
            }
        }
        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}'");
            }
        }
        protected void ButtonBulkAddDistricts_OnClick(object sender, EventArgs e)
        {
            BulkAddDistrictsOverride.AddCssClasses("hidden");
            switch (BulkAddDistrictsReloading.Value)
            {
            case "reloading":
            {
                BulkAddDistrictsReloading.Value = string.Empty;
                _BulkAddDistrictsTabInfo.ClearValidationErrors();
                RefreshCurrentDistrictsList(BulkAddDistrictsCurrentDistricts);
                _BulkAddDistrictsTabInfo.LoadControls();
                FeedbackBulkAddDistricts.AddInfo("Bulk Add Districts information loaded.");
            }
            break;

            case "":
            {
                // normal update
                _BulkAddDistrictsTabInfo.ClearValidationErrors();
                RefreshCurrentDistrictsList(BulkAddDistrictsCurrentDistricts);

                // validate
                if (!_BulkAddDistrictsTabInfo.FindItem("LocalDistrict").Validate() ||
                    //!_BulkAddDistrictsTabInfo.FindItem("LocalCode").Validate() ||
                    !_BulkAddDistrictsTabInfo.FindItem("StartSequence").Validate() ||
                    !_BulkAddDistrictsTabInfo.FindItem("EndSequence").Validate())
                {
                    return;
                }

                // additional validation for sequence numbers
                var startSequence = int.Parse(ControlBulkAddDistrictsStartSequence.Text);
                var endSequence   = int.Parse(ControlBulkAddDistrictsEndSequence.Text);
                if (startSequence < 1 || startSequence > 99 || endSequence < startSequence ||
                    endSequence > 99)
                {
                    FeedbackBulkAddDistricts.PostValidationError(
                        new[]
                        { ControlBulkAddDistrictsStartSequence, ControlBulkAddDistrictsEndSequence },
                        "The sequence numbers must be between 1 and 99 and the ending sequence must be greater than or equal the starting sequence.");
                    return;
                }

                var startCodeText = ControlBulkAddDistrictsLocalCode.Text;
                var startCode     = string.IsNullOrWhiteSpace(startCodeText)
            ? startSequence
            : int.Parse(startCodeText);
                var endCode = startCode + (endSequence - startSequence);
                if (endCode > 99)
                {
                    FeedbackBulkAddDistricts.PostValidationError(ControlBulkAddDistrictsLocalCode,
                                                                 "The ending local code would exceed 99.");
                    return;
                }

                var localCodes =
                    Enumerable.Range(startCode, endCode - startCode + 1)
                    .Select(i => i.ToString().ZeroPad(2))
                    .ToList();

                var localDistrictTemplate = ControlBulkAddDistrictsLocalDistrict.Text;
                var @override             = ControlBulkAddDistrictsOverride.Checked;
                var conflicted            = RefreshCurrentDistrictsList(BulkAddDistrictsCurrentDistricts,
                                                                        null, localCodes);
                if (!@override && conflicted)
                {
                    BulkAddDistrictsOverride.RemoveCssClass("hidden");
                    FeedbackBulkAddDistricts.PostValidationError(BulkAddDistrictsOverride,
                                                                 "Potential local code");
                    return;
                }
                if (!EnsureLocalCodesAreAvailable(localCodes))
                {
                    FeedbackBulkAddDistricts.PostValidationError(BulkAddDistrictsOverride,
                                                                 "Could not find an available code -- all 99 are in use");
                    return;
                }

                // do the adds
                // create a linq that returns the sequence and the code
                //var isPhase2 = IsPhase2(StateCode);
                foreach (var add in
                         Enumerable.Range(startSequence, endSequence - startSequence + 1)
                         .Select((seq, inx) => new { seq, code = localCodes[inx] }))
                {
                    var localDistrict = localDistrictTemplate.Replace("*", add.seq.ToString());
                    LocalDistricts.Insert(StateCode, null, CountyCode, add.code, localDistrict,
                                          /*string.Empty,*/ string.Empty, string.Empty, string.Empty, string.Empty,
                                          string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                                          string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                                          string.Empty, string.Empty, string.Empty, string.Empty, false /*,
                                                                                                         * string.Empty*/);
                    //if (isPhase2)
                    //  LocalIdsCodes.Insert(StateCode, LocalIdsCodes.LocalTypeVote,
                    //    LocalIdsCodes.GetNextVoteIdForState(StateCode), CountyCode, add.code,
                    //    null);
                    FeedbackBulkAddDistricts.AddInfo(
                        $"Local District {localDistrict} ({add.code}) added.");
                }
                _BulkAddDistrictsTabInfo.ClearValidationErrors();
                RefreshCurrentDistrictsList(BulkAddDistrictsCurrentDistricts);
                _BulkAddDistrictsTabInfo.LoadControls();
                NavigateJurisdictionUpdatePanel.Update();
                NavigateJurisdiction.Initialize();
            }
            break;

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