protected void ButtonEditOffice_OnClick(object sender, EventArgs e) { switch (EditOfficeReloading.Value) { case "reloading": { EditOfficeReloading.Value = string.Empty; _EditOfficeDialogInfo.LoadControls(); FeedbackEditOffice.AddInfo("Office information loaded."); } break; case "": { // normal update _EditOfficeDialogInfo.ClearValidationErrors(); if (AdminPageLevel != AdminPageLevel.State) { OfficeToEdit.Value = Offices.ActualizeOffice(GetOfficeKeyToEdit(), CountyCode, LocalCode); } if (_EditOfficeDialogInfo.Update(FeedbackEditOffice) == 0) { LoadOfficeControl(OfficeToEdit.Value); } } break; default: throw new VoteException("Unknown reloading option"); } }
protected override bool Update(object newValue) { var electionKey = Page.GetElectionKey(); var changed = false; var stringValue = newValue.ToString(); // get the list of officeKeys var officeKeys = stringValue.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList(); // actualize any virtuals foreach (var officeKey in officeKeys) { Offices.ActualizeOffice(officeKey, Page.CountyCode, Page.LocalCode); } // create a dictionary of office keys from the updated tree var officeKeyDictionary = officeKeys .ToDictionary(ActualizeOfficeKey, key => false, StringComparer.OrdinalIgnoreCase); // get the current list of office keys for the election var offices = ElectionsOffices.GetOfficeKeysData(electionKey); // delete any that aren't in the dictionary (and from // ElectionsPoliticians too), and mark those that are there // so we know what to add foreach (var office in offices) { var officeKey = office.OfficeKey; if (officeKeyDictionary.ContainsKey(officeKey)) { officeKeyDictionary[officeKey] = true; } else { LogElectionsOfficesDelete(electionKey, officeKey); ElectionsOffices.DeleteByElectionKeyOfficeKey(electionKey, officeKey); ElectionsPoliticians.DeleteByElectionKeyOfficeKey(electionKey, officeKey); changed = true; } } // add offices from the dictionary that aren't marked foreach (var officeKey in officeKeyDictionary.Where(kvp => !kvp.Value) .Select(kvp => kvp.Key)) { LogElectionsOfficesInsert(electionKey, officeKey); InsertElectionOffice(electionKey, officeKey); changed = true; } LoadControl(); return(changed); }
protected void ButtonAddCandidates_OnClick(object sender, EventArgs e) { switch (AddCandidatesReloading.Value) { case "reloading": { AddCandidatesReloading.Value = string.Empty; OfficeControl.ShowSelectOfficePanel = false; _ManagePoliticiansPanel.LoadControls(); var officeName = Offices.FormatOfficeName(OfficeControl.OfficeKey); if (string.IsNullOrWhiteSpace(officeName)) { officeName = "Invalid office"; } HeadingAddCandidatesOffice.InnerText = officeName; _ManagePoliticiansPanel.ClearAddNewCandidate(true); } break; case "": { var isVirtualOffice = Offices.IsVirtualKey(OfficeControl.OfficeKey); if (isVirtualOffice) { OfficeControl.OfficeKey = Offices.ActualizeOffice(OfficeControl.OfficeKey, CountyCode, LocalCode); } // normal update _ManagePoliticiansPanel.Update(); _ManagePoliticiansPanel.ClearAddNewCandidate(); if (isVirtualOffice) { LoadOfficeControl(); } } break; default: throw new VoteException("Unknown reloading option"); } }
protected void ButtonEditOffice_OnClick(object sender, EventArgs e) { switch (EditOfficeReloading.Value) { case "reloading": { EditOfficeReloading.Value = Empty; if (AdminPageLevel != AdminPageLevel.State) { OfficeToEdit.Value = Offices.ActualizeOffice(GetOfficeKeyToEdit(), CountyCode, LocalKey); } _EditOfficeDialogInfo.LoadControls(); var adRates = Offices.GetDefaultAdRates(GetOfficeKeyToEdit()); PrimaryAdRateDefault.InnerText = adRates.PrimaryAdRate.ToString(CultureInfo.InvariantCulture); GeneralAdRateDefault.InnerText = adRates.GeneralAdRate.ToString(CultureInfo.InvariantCulture); FeedbackEditOffice.AddInfo("Office information loaded."); } break; case "": { // normal update _EditOfficeDialogInfo.ClearValidationErrors(); if (AdminPageLevel != AdminPageLevel.State) { OfficeToEdit.Value = Offices.ActualizeOffice(GetOfficeKeyToEdit(), CountyCode, LocalKey); } if (_EditOfficeDialogInfo.Update(FeedbackEditOffice) == 0) { LoadOfficeControl(OfficeToEdit.Value); } } break; default: throw new VoteException($"Unknown reloading option: '{EditOfficeReloading.Value}'"); } }
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}'"); } }