private void SetCouncilPrefix2(string cityCouncilCode) { string prefix; if (IsNullOrWhiteSpace(cityCouncilCode)) { var prefixes = CityCouncil.GetPrefixes(StateCode); if (prefixes.Count >= 360) { throw new Exception("All City Council prefixes for this state are in use"); } if (prefixes.Count == 0) { prefix = "10"; } else { prefix = GetNextCouncilPrefix(prefixes.Last()); while (prefixes.Contains(prefix)) { prefix = GetNextCouncilPrefix(prefix); } } } else { prefix = cityCouncilCode.Substring(0, 2); } CityCouncilPrefix.Text = prefix; PlaceName.Value = TigerPlaceName; }
protected override bool Update(object newValue) { // everything has been validated already var changed = false; var stateCode = Page.StateCode; foreach (var s in _Submitted) { if (s.New) { CityCouncil.Insert(stateCode, s.Id, s.District, s.Name, Page.TigerPlaceCode, s.InShapefile); if (s.Create) { // also create local district var localKey = LocalDistricts.GetAvailableLocalKey(stateCode); LocalDistricts.Insert(stateCode, localKey, s.Name, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, Empty, false, false); LocalIdsCodes.Insert(stateCode, LocalIdsCodes.LocalTypeCityCouncil, s.Id, localKey); changed = true; } } else if (s.Delete) { // can only delete if no local district entry changed |= CityCouncil.DeleteByStateCodeCityCouncilCode(stateCode, s.Id) != 0; } else { // existing item, but may update IsInShapefile, District or Name changed |= CityCouncil.UpdateDistrictByStateCodeCityCouncilCode(s.District, stateCode, s.Id) != 0; changed |= CityCouncil.UpdateNameByStateCodeCityCouncilCode(s.Name, stateCode, s.Id) != 0; changed |= CityCouncil.UpdateIsInShapefileByStateCodeCityCouncilCode(s.InShapefile, stateCode, s.Id) != 0; } } LoadControl(); return(changed); }
private void LoadCityCouncilDistricts() { CityCouncilTableBody.Controls.Clear(); var districts = CityCouncil .GetCityCouncilDistrictsByTigerCode(StateCode, TigerPlaceCode).Rows .OfType <DataRow>().OrderBy(r => r.CityCouncilCode()).ToList(); foreach (var d in districts) { var tr = new TableRow(); tr.AddTo(CityCouncilTableBody); new TableCell().AddTo(tr, "delete").Controls .Add(new HtmlInputCheckBox { Disabled = d.LocalKey() != null }); new TableCell().AddTo(tr, "exists").Controls.Add( new HtmlInputCheckBox { Disabled = true, Checked = d.LocalKey() != null }); new TableCell().AddTo(tr, "create").Controls .Add(new HtmlInputCheckBox { Disabled = d.LocalKey() != null }); new TableCell().AddTo(tr, "code").Controls.Add(new HtmlInputText { Value = d.CityCouncilCode(), Disabled = d.LocalKey() != null }); new TableCell().AddTo(tr, "in-shapefile").Controls .Add(new HtmlInputCheckBox { Checked = d.IsInShapefile() }); new TableCell().AddTo(tr, "district").Controls .Add(new HtmlInputText { Value = d.District() }); new TableCell().AddTo(tr, "name").Controls .Add(new HtmlInputText { Value = d.Name() }); } SetCouncilPrefix2(districts.Count > 0 ? districts[0].CityCouncilCode() : null); BulkAddCityCouncil.Disabled = districts.Count > 0; }
private void SetCouncilPrefix(string cityCouncilCode) { var prefix = Empty; if (IsNullOrWhiteSpace(cityCouncilCode)) { var prefixes = CityCouncil.GetPrefixes(StateCode); if (prefixes.Count >= 100) { throw new Exception("All City Council prefixes for this state are in use"); } if (prefixes.Count == 0) { prefix = "10"; } else { var last = prefixes.Last(); if (last == "99") { // use highest available for (var p = 98; p >= 0; p--) { prefix = p.ToString("D2"); if (!prefixes.Contains(prefix)) { break; } } } else { prefix = (int.Parse(last) + 1).ToString("D2"); } } } else { prefix = cityCouncilCode.Substring(0, 2); } CityCouncilPrefix.Text = prefix; PlaceName.Value = TigerPlaceName; }
private void PopulateCityCouncilDistricts(DropDownList dropDownList, string doNotDisable = null, string selected = null) { if (selected == null) { selected = doNotDisable; } var districtsTable = CityCouncil.GetCityCouncilDistrictsByCountyCode(StateCode, CountyCode) .Rows.Cast <DataRow>().ToArray(); var districtItems = new List <SimpleListItem> { new SimpleListItem { Text = "<none>", Value = Empty }, districtsTable .Select(r => new SimpleListItem { Text = r.Name(), Value = r.CityCouncilCode() }) .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.CityCouncilCode() == item.Value); if (!IsNullOrWhiteSpace(matchingRow?.LocalKey())) { item.Attributes.Add("disabled", "disabled"); } } } }
protected void Page_Load(object sender, EventArgs e) { //Page.IncludeJs("~/js/jq/jquery.cookie.js"); Title = Format(TitleTag, PublicMasterPage.SiteName); var email = GetQueryString("email"); EmailFixedAddress.InnerText = email; string tigerCode; var address = Request.Cookies["Address"]?.Value; var stateCode = Request.Cookies["State"]?.Value; var county = Request.Cookies["County"]?.Value; var countySupervisors = Request.Cookies["CountySupervisors"]?.Value; var congressionalDistrict = Request.Cookies["Congress"]?.Value; var stateSenateDistrict = Request.Cookies["StateSenate"]?.Value; var stateHouseDistrict = Request.Cookies["StateHouse"]?.Value; var place = Request.Cookies["Place"]?.Value; var district = Request.Cookies["District"]?.Value; var cityCouncil = Request.Cookies["CityCouncil"]?.Value; var elementary = Request.Cookies["Elementary"]?.Value; var secondary = Request.Cookies["Secondary"]?.Value; var unified = Request.Cookies["Unified"]?.Value; var schoolDistrictDistrict = Request.Cookies["SchoolDistrictDistrict"]?.Value; var components = WebService.GetComponentsFromCookies(); var(latitude, longitude) = WebService.GetGeoFromCookies(); if (!StateCache.IsValidStateCode(stateCode) || IsNullOrWhiteSpace(email) || IsNullOrWhiteSpace(congressionalDistrict) || IsNullOrWhiteSpace(stateSenateDistrict) || !Offices.IsValidStateHouseDistrict(stateHouseDistrict, stateCode) || IsNullOrWhiteSpace(county) || components == null || latitude == null || longitude == null) { SafeTransferToError404(); //EmailFixedAddress.InnerText = Join("|", stateCode.SafeString(), email.SafeString(), // congressionalDistrict.SafeString(), stateSenateDistrict.SafeString(), // stateHouseDistrict.SafeString(), county.SafeString(), // components == null ? "null" : "components", // (latitude?.ToString()).SafeString(), (longitude?.ToString()).SafeString()); } WebService.UpdateAddresses(email, "SBRL", Empty, Empty, components, stateCode, congressionalDistrict, stateSenateDistrict, stateHouseDistrict, county, district, place, elementary, secondary, unified, cityCouncil, countySupervisors, schoolDistrictDistrict, latitude, longitude); Control tr; if (!IsNullOrWhiteSpace(address)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Address" }.AddTo(tr); new TableCell { Text = HttpUtility.UrlDecode(address) }.AddTo(tr); } //tr = new TableRow().AddTo(DistrictsTable); //new TableCell { Text = "State" }.AddTo(tr); //new TableCell { Text = StateCache.GetStateName(stateCode) }.AddTo(tr); if (!IsNullOrWhiteSpace(county) && stateCode != "DC") { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "County" }.AddTo(tr); new TableCell { Text = CountyCache.GetCountyName(stateCode, county) }.AddTo(tr); } if (!IsNullOrWhiteSpace(countySupervisors)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = stateCode == "DC" ? "Advisory Neighborhood Commission" : "County Supervisors" }.AddTo(tr); new TableCell { Text = CountySupervisors.GetNameByStateCodeCountySupervisorsCode(stateCode, countySupervisors) }.AddTo(tr); } if (!IsNullOrWhiteSpace(congressionalDistrict) && stateCode != "DC") { if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("CD", stateCode, congressionalDistrict)) != null) { congressionalDistrict = tigerCode; } if (congressionalDistrict != "00") { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Congressional District" }.AddTo(tr); new TableCell { Text = congressionalDistrict.TrimStart('0') }.AddTo(tr); } } if (!IsNullOrWhiteSpace(stateSenateDistrict)) { if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SS", stateCode, stateSenateDistrict)) != null) { stateSenateDistrict = tigerCode; } tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = stateCode == "DC" ? "Ward" : "State Senate District" }.AddTo(tr); new TableCell { Text = stateSenateDistrict?.TrimStart('0') }.AddTo(tr); } if (!IsNullOrWhiteSpace(stateHouseDistrict)) { if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SH", stateCode, stateHouseDistrict)) != null) { stateHouseDistrict = tigerCode; } tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "State House District" }.AddTo(tr); new TableCell { Text = stateHouseDistrict.TrimStart('0') }.AddTo(tr); } if (stateCode != "DC") { var districts = new List <string>(); if (!IsNullOrWhiteSpace(place)) { districts.Add(TigerPlaces.GetNameByStateCodeTigerCode(stateCode, place)); } if (!IsNullOrWhiteSpace(district)) { districts.Add(TigerPlaces.GetNameByStateCodeTigerCode(stateCode, district)); } if (districts.Count > 0) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Local District" }.AddTo(tr); new TableCell { Text = Join(", ", districts.Distinct()) }.AddTo(tr); } } if (!IsNullOrWhiteSpace(cityCouncil) && stateCode != "DC") { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "City Council" }.AddTo(tr); new TableCell { Text = CityCouncil.GetNameByStateCodeCityCouncilCode(stateCode, cityCouncil) }.AddTo(tr); } if (!IsNullOrWhiteSpace(elementary)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Elementary School District" }.AddTo(tr); new TableCell { Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, elementary, "E") }.AddTo(tr); } if (!IsNullOrWhiteSpace(secondary)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Secondary School District" }.AddTo(tr); new TableCell { Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, secondary, "S") }.AddTo(tr); } if (!IsNullOrWhiteSpace(unified)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "Unified School District" }.AddTo(tr); new TableCell { Text = TigerSchools.GetNameByStateCodeTigerCodeTigerType(stateCode, unified, "U") }.AddTo(tr); } if (!IsNullOrWhiteSpace(schoolDistrictDistrict)) { tr = new TableRow().AddTo(DistrictsTable); new TableCell { Text = "School Voting District" }.AddTo(tr); new TableCell { Text = SchoolDistrictDistricts.GetNameByStateCodeSchoolDistrictDistrictCode( stateCode, schoolDistrictDistrict) }.AddTo(tr); } }
public static string FormatLegislativeDistrictsFromQueryString( string separator = "<br />") { var lines = new List <string>(); if (QueryState != "DC") { string county = null; if (!IsNullOrWhiteSpace(QueryCounty)) { lines.Add(county = CountyCache.GetCountyName(QueryState, QueryCounty)); } if (!IsNullOrWhiteSpace(QueryCountySupervisors)) { lines.Add(CountySupervisors.GetNameByStateCodeCountySupervisorsCode(QueryState, QueryCountySupervisors)); } string tigerCode; if (QueryCongress != "000") { var congressionalDistrict = QueryCongress; if (congressionalDistrict.Length == 3) { congressionalDistrict = congressionalDistrict.Substring(1); } if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("CD", QueryState, congressionalDistrict)) != null) { congressionalDistrict = tigerCode; } if (congressionalDistrict != "00") { lines.Add("US House District " + congressionalDistrict.TrimStart('0') + " " + StateCache.GetStateName(QueryState)); } } if (QueryStateSenate != "000") { var stateSenateDistrict = QueryStateSenate; if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SS", QueryState, stateSenateDistrict)) != null) { stateSenateDistrict = tigerCode; } lines.Add(StateCache.GetStateName(QueryState) + " Senate District " + stateSenateDistrict.TrimStart('0')); } if (!IsNullOrWhiteSpace(QueryStateHouse)) { var stateHouseDistrict = QueryStateHouse; if ((tigerCode = TigerToVoteCodes.GetTigerCodeByTableTypeStateCodeVoteCode("SH", QueryState, stateHouseDistrict)) != null) { stateHouseDistrict = tigerCode; } lines.Add(StateCache.GetStateName(QueryState) + " House District " + stateHouseDistrict.TrimStart('0')); } string district = null; string lastResort = null; if (QueryDistrict != Empty) { district = TigerPlaces.GetLongNameByStateCodeTigerCode(QueryState, QueryDistrict); if (!IsNullOrWhiteSpace(district) && district.IsNeIgnoreCase(county)) { if (district.EndsWith(" CCD") || district.EndsWith(" CDP")) { lastResort = district.Substring(0, district.Length - 4); } else { lines.Add(district); } } } if (QueryPlace != Empty) { var place = TigerPlaces.GetLongNameByStateCodeTigerCode(QueryState, QueryPlace); if (!IsNullOrWhiteSpace(place) && place.IsNeIgnoreCase(district) && place.IsNeIgnoreCase(county)) { if (place.EndsWith(" CCD") || place.EndsWith(" CDP")) { lastResort = place.Substring(0, place.Length - 4); } else { lines.Add(place); lastResort = null; } } } if (lastResort != null && (county == null || !county.StartsWith(lastResort, StringComparison.OrdinalIgnoreCase))) { lines.Add(lastResort); } if (!IsNullOrWhiteSpace(QueryCityCouncil)) { lines.Add( CityCouncil.GetNameByStateCodeCityCouncilCode(QueryState, QueryCityCouncil)); } } else if (QueryStateSenate != "000") { if (!IsNullOrWhiteSpace(QueryStateSenate)) { lines.Add("Ward " + QueryStateSenate.TrimStart('0')); } if (!IsNullOrWhiteSpace(QueryCountySupervisors)) { lines.Add( CountySupervisors.GetNameByStateCodeCountySupervisorsCode(QueryState, QueryCountySupervisors)); } } if (!IsNullOrWhiteSpace(QueryElementary)) { lines.Add( TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QueryElementary, "E")); } if (!IsNullOrWhiteSpace(QuerySecondary)) { lines.Add( TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QuerySecondary, "S")); } if (!IsNullOrWhiteSpace(QueryUnified)) { lines.Add( TigerSchools.GetNameByStateCodeTigerCodeTigerType(QueryState, QueryUnified, "U")); } if (!IsNullOrWhiteSpace(QuerySchoolDistrictDistrict)) { lines.Add( SchoolDistrictDistricts.GetNameByStateCodeSchoolDistrictDistrictCode( QueryState, QuerySchoolDistrictDistrict)); } if (separator == null) { return("<span>" + Join("</span><span>", lines) + "</span>"); } return(Join(separator, lines)); }