示例#1
0
        protected void ButtonAddCandidates_OnClick(object sender, EventArgs e)
        {
            switch (AddCandidatesReloading.Value)
            {
            case "reloading":
            {
                // This option just loads the office tree
                AddCandidatesReloading.Value = Empty;
                OfficeControl.OfficeKey      = Empty; // experimental 16/02/16
                SetElectionHeading(HeadingAddCandidates);
                HeadingAddCandidatesOffice.InnerHtml = "No office selected";

                var table =
                    Elections.GetAvailableElectionOfficeData(GetElectionKey(), StateCode,
                                                             CountyCode, LocalKey); //.Rows.Cast<DataRow>().ToList();
                var officeCount = 0;
                if (table.Count == 0)
                {
                    _ManagePoliticiansPanel.Message.RemoveCssClass("hidden");
                    _ManagePoliticiansPanel.Message.InnerText =
                        "No offices were found for this election";
                }
                else
                {
                    _ManagePoliticiansPanel.Message.AddCssClasses("hidden");
                    officeCount = PopulateOfficeTree(table);
                    OfficeControl.ShowSelectOfficePanel = true;
                    OfficeControl.ExpandedNode          = Empty;
                    OfficeControl.Update();
                }
                FeedbackAddCandidates.AddInfo($"{officeCount} offices loaded.");
            }
            break;

            case "loadoffice":
            {
                AddCandidatesReloading.Value        = Empty;
                OfficeControl.ShowSelectOfficePanel = false;
                _ManagePoliticiansPanel.LoadControls();
                SetElectionHeading(HeadingAddCandidates);
                HeadingAddCandidatesOffice.InnerText =
                    Offices.FormatOfficeName(OfficeControl.OfficeKey);
                _ManagePoliticiansPanel.ClearAddNewCandidate(true);
            }
            break;

            case "":
            {
                // normal update
                // We may need to actualize the election,  the electionOffice, and the office
                Elections.ActualizeElection(GetElectionKey());
                OfficeControl.OfficeKey =
                    Offices.ActualizeOffice(OfficeControl.OfficeKey, CountyCode, LocalKey);
                ActualizeElectionOffice(GetElectionKey(), OfficeControl.OfficeKey);

                _ManagePoliticiansPanel.Update();
                _ManagePoliticiansPanel.ClearAddNewCandidate();
                // to update candidate counts...
                var table =
                    Elections.GetAvailableElectionOfficeData(GetElectionKey(), StateCode,
                                                             CountyCode, LocalKey); //.Rows.Cast<DataRow>().ToList();
                // In case counts changed
                PopulateOfficeTree(table);
                OfficeControl.ShowSelectOfficePanel = false;
                OfficeControl.Update();
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{AddCandidatesReloading.Value}'");
            }
        }
        protected void ButtonAddCandidates_OnClick(object sender, EventArgs e)
        {
            switch (AddCandidatesReloading.Value)
            {
            case "reloading":
            {
                DeletePoliticianOverrideContainer.AddCssClasses("hidden");
                DeletePoliticianOverride.Checked = false;
                AddCandidatesReloading.Value     = Empty;
                _ManagePoliticiansPanel.LoadControls();
                _ManagePoliticiansPanel.ClearAddNewCandidate(true);
                break;
            }

            case "deleting":
            {
                AddCandidatesReloading.Value = Empty;
                DeletePoliticianOverrideContainer.AddCssClasses("hidden");
                var keyToDelete = AddCandidatesKeyToDelete.GetValue();

                // check for meaningful usages
                var referenceList = new List <string>();
                FormatReferences(referenceList, "Answers", Answers2.CountByPoliticianKey(keyToDelete));
                FormatReferences(referenceList, "ElectionsPoliticians",
                                 ElectionsPoliticians.CountByPoliticianKey(keyToDelete));
                FormatReferences(referenceList, "ElectionsPoliticians:RunningMateKey",
                                 ElectionsPoliticians.CountByRunningMateKey(keyToDelete));
                FormatReferences(referenceList, "OfficesOfficials",
                                 OfficesOfficials.CountByPoliticianKey(keyToDelete));
                FormatReferences(referenceList, "OfficesOfficials:RunningMateKey",
                                 OfficesOfficials.CountByRunningMateKey(keyToDelete));

                if (referenceList.Count > 0 && !DeletePoliticianOverride.Checked)
                {
                    FeedbackAddCandidates.AddError(
                        "Cannot delete because the PoliticianKey is referenced in the following tables. Check the box to override.");
                    DeletePoliticianOverrideContainer.RemoveCssClass("hidden");
                    foreach (var @ref in referenceList)
                    {
                        FeedbackAddCandidates.AddError(@ref);
                    }
                    return;
                }

                // delete
                DeletePoliticianOverride.Checked = false;
                var name = PageCache.Politicians.GetPoliticianName(keyToDelete);
                if (referenceList.Count > 0)
                {
                    DeleteAllPoliticianReferences(keyToDelete);
                }
                Politicians.DeleteByPoliticianKey(keyToDelete);
                FeedbackAddCandidates.AddInfo($"Politician {name} ({keyToDelete}) deleted.");
                AddCandidatesKeyToDelete.Value = Empty;
                //_DeleteDistrictsTabInfo.ClearValidationErrors();
                //PopulateLocalDistrictDropdown();
                //_DeleteDistrictsTabInfo.LoadControls();

                break;
            }

            case "":
            {
                //// normal update
                //_ManagePoliticiansPanel.Update();
                //_ManagePoliticiansPanel.ClearAddNewCandidate();
                break;
            }

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