protected void btnAdd_Click(object sender, EventArgs e) { if (!double.TryParse(txtLat.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lat) || !double.TryParse(txtLong.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lon)) { lblErr.Text = Resources.Airports.errInvalidLatLong; return; } bool fAdmin = (IsAdmin && ckAsAdmin.Checked); airport ap = new airport(txtCode.Text.ToUpper(CultureInfo.InvariantCulture), txtName.Text, lat, lon, cmbType.SelectedValue, cmbType.SelectedItem.Text, 0.0, fAdmin ? string.Empty : Page.User.Identity.Name); if (fAdmin && ap.Code.CompareOrdinalIgnoreCase("TBD") == 0) { lblErr.Text = Resources.Airports.errTBDIsInvalidCode; return; } lblErr.Text = string.Empty; if (ap.FCommit(fAdmin, fAdmin)) { // Check to see if this looks like a duplicate - if so, submit it for review List <airport> lstDupes = new List <airport>(airport.AirportsNearPosition(ap.LatLong.Latitude, ap.LatLong.Longitude, 20, ap.FacilityTypeCode.CompareCurrentCultureIgnoreCase("H") == 0)); lstDupes.RemoveAll(a => !a.IsPort || a.Code.CompareCurrentCultureIgnoreCase(ap.Code) == 0 || a.DistanceFromPosition > 3); if (lstDupes.Count > 0) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(CultureInfo.CurrentCulture, "User: {0}, Airport: {1} ({2}) {3} {4}\r\n\r\nCould match:\r\n", ap.UserName, ap.Code, ap.FacilityTypeCode, ap.Name, ap.LatLong.ToDegMinSecString()); foreach (airport a in lstDupes) { sb.AppendFormat(CultureInfo.CurrentCulture, "{0} - ({1}) {2} {3}\r\n", a.Code, a.FacilityTypeCode, a.Name, a.LatLong.ToDegMinSecString()); } util.NotifyAdminEvent("New airport created - needs review", sb.ToString(), ProfileRoles.maskCanManageData); } initForm(); Cache.Remove(CacheKeyUserAirports); if (!fAdmin || ckShowAllUserAirports.Checked) { RefreshMyAirports(); } else { gvMyAirports.DataSource = null; gvMyAirports.DataBind(); } if (fAdmin) { UpdateImportData(); } } else { lblErr.Text = HttpUtility.HtmlEncode(ap.ErrorText); } }
protected void btnAdd_Click(object sender, EventArgs e) { double lat, lon; if (!double.TryParse(txtLat.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out lat) || !double.TryParse(txtLong.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out lon)) { lblErr.Text = Resources.Airports.errInvalidLatLong; return; } bool fAdmin = (IsAdmin && ckAsAdmin.Checked); airport ap = new airport(txtCode.Text.ToUpper(CultureInfo.InvariantCulture), txtName.Text, lat, lon, cmbType.SelectedValue, cmbType.SelectedItem.Text, 0.0, fAdmin ? string.Empty : Page.User.Identity.Name); if (fAdmin && ap.Code.CompareOrdinalIgnoreCase("TBD") == 0) { lblErr.Text = Resources.Airports.errTBDIsInvalidCode; return; } lblErr.Text = ""; if (ap.FCommit(fAdmin, fAdmin)) { initForm(); Cache.Remove(CacheKeyUserAirports); if (!fAdmin || ckShowAllUserAirports.Checked) { RefreshMyAirports(); } else { gvMyAirports.DataSource = null; gvMyAirports.DataBind(); } if (fAdmin) { UpdateImportData(); } } else { lblErr.Text = ap.ErrorText; } }
protected void gvImportResults_RowCommand(object sender, GridViewCommandEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } GridViewRow grow = (GridViewRow)((WebControl)e.CommandSource).NamingContainer; int iRow = grow.RowIndex; airportImportCandidate aic = ImportedAirportCandidates[iRow]; AirportImportRowCommand airc = (AirportImportRowCommand)Enum.Parse(typeof(AirportImportRowCommand), e.CommandName); CheckBox ckUseMap = (CheckBox)grow.FindControl("ckUseMap"); if (ckUseMap.Checked) { aic.LatLong.Latitude = Convert.ToDouble(txtLat.Text, System.Globalization.CultureInfo.InvariantCulture); aic.LatLong.Longitude = Convert.ToDouble(txtLong.Text, System.Globalization.CultureInfo.InvariantCulture); } airport ap = null; switch (e.CommandArgument.ToString()) { case "FAA": ap = aic.FAAMatch; break; case "ICAO": ap = aic.ICAOMatch; break; case "IATA": ap = aic.IATAMatch; break; } switch (airc) { case AirportImportRowCommand.FixLocation: ap.LatLong = aic.LatLong; ap.FCommit(true, false); break; case AirportImportRowCommand.FixType: ap.FDelete(true); // delete the existing one before we update - otherwise REPLACE INTO will not succeed (because we are changing the REPLACE INTO primary key, which includes Type) ap.FacilityTypeCode = aic.FacilityTypeCode; ap.FCommit(true, true); // force this to be treated as a new airport break; case AirportImportRowCommand.Overwrite: case AirportImportRowCommand.AddAirport: if (airc == AirportImportRowCommand.Overwrite) { ap.FDelete(true); // delete the existing airport } switch (e.CommandArgument.ToString()) { case "FAA": aic.Code = aic.FAA; break; case "ICAO": aic.Code = aic.ICAO; break; case "IATA": aic.Code = aic.IATA; break; } aic.Code = Regex.Replace(aic.Code, "[^a-zA-Z0-9]", string.Empty); aic.FCommit(true, true); break; } UpdateImportData(); }
protected void AddAirport(bool forceAdd) { Page.Validate("EditAirport"); if (!Page.IsValid) { return; } bool fValidLatLon = double.TryParse(txtLat.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lat); fValidLatLon = double.TryParse(txtLong.Text, NumberStyles.Any, CultureInfo.InvariantCulture, out double lon) && fValidLatLon; if (!fValidLatLon) { lblErr.Text = Resources.Airports.errInvalidLatLong; } bool fAdmin = (IsAdmin && ckAsAdmin.Checked); airport ap = new airport(txtCode.Text.ToUpper(CultureInfo.InvariantCulture), txtName.Text, lat, lon, cmbType.SelectedValue, cmbType.SelectedItem.Text, 0.0, fAdmin ? string.Empty : Page.User.Identity.Name); if (fAdmin && ap.Code.CompareOrdinalIgnoreCase("TBD") == 0) { lblErr.Text = Resources.Airports.errTBDIsInvalidCode; } lblErr.Text = string.Empty; // Check to see if this looks like a duplicate List <airport> lstDupes = ap.IsPort ? new List <airport>(airport.AirportsNearPosition(ap.LatLong.Latitude, ap.LatLong.Longitude, 20, ap.FacilityTypeCode.CompareCurrentCultureIgnoreCase("H") == 0)) : new List <airport>(); lstDupes.RemoveAll(a => !a.IsPort || a.Code.CompareCurrentCultureIgnoreCase(ap.Code) == 0 || a.DistanceFromPosition > 3); if (lstDupes.Any() && !forceAdd) { gvUserDupes.DataSource = lstDupes; gvUserDupes.DataBind(); mpeDupeAirport.Show(); return; } if (ap.FCommit(fAdmin, fAdmin)) { if (lstDupes.Any()) { // needs review StringBuilder sb = new StringBuilder(); StringBuilder sbViewLink = new StringBuilder(); sbViewLink.AppendFormat(CultureInfo.InvariantCulture, "https://{0}{1}?Airports={2}", Branding.CurrentBrand.HostName, ResolveUrl("~/Public/MapRoute2.aspx"), ap.Code); sb.AppendFormat(CultureInfo.CurrentCulture, "User: {0}, Airport: {1} ({2}) {3} {4}\r\n\r\nCould match:\r\n", ap.UserName, ap.Code, ap.FacilityTypeCode, ap.Name, ap.LatLong.ToDegMinSecString()); foreach (airport a in lstDupes) { sb.AppendFormat(CultureInfo.CurrentCulture, "{0} - ({1}) {2} {3}\r\n", a.Code, a.FacilityTypeCode, a.Name, a.LatLong.ToDegMinSecString()); sbViewLink.AppendFormat(CultureInfo.InvariantCulture, "+{0}", a.Code); } sb.AppendFormat(CultureInfo.InvariantCulture, "\r\n\r\n{0}\r\n", sbViewLink.ToString()); util.NotifyAdminEvent("New airport created - needs review", sb.ToString(), ProfileRoles.maskCanManageData); } initForm(); if (!fAdmin || ckShowAllUserAirports.Checked) { RefreshMyAirports(); } else { gvMyAirports.DataSource = null; gvMyAirports.DataBind(); } if (fAdmin) { UpdateImportData(); } } else { lblErr.Text = HttpUtility.HtmlEncode(ap.ErrorText); } }
public static bool AirportImportCommand(airportImportCandidate aic, string source, string szCommand) { CheckAdmin(); if (aic == null) { throw new ArgumentNullException(nameof(aic)); } if (szCommand == null) { throw new ArgumentNullException(nameof(szCommand)); } AirportImportRowCommand airc = (AirportImportRowCommand)Enum.Parse(typeof(AirportImportRowCommand), szCommand); AirportImportSource ais = (AirportImportSource)Enum.Parse(typeof(AirportImportSource), source); airport ap = null; switch (ais) { case AirportImportSource.FAA: ap = aic.FAAMatch; break; case AirportImportSource.ICAO: ap = aic.ICAOMatch; break; case AirportImportSource.IATA: ap = aic.IATAMatch; break; } switch (airc) { case AirportImportRowCommand.FixLocation: ap.LatLong = aic.LatLong; ap.FCommit(true, false); if (!String.IsNullOrWhiteSpace(aic.Country)) { ap.SetLocale(aic.Country, aic.Admin1); } break; case AirportImportRowCommand.FixType: ap.FDelete(true); // delete the existing one before we update - otherwise REPLACE INTO will not succeed (because we are changing the REPLACE INTO primary key, which includes Type) ap.FacilityTypeCode = aic.FacilityTypeCode; ap.FCommit(true, true); // force this to be treated as a new airport break; case AirportImportRowCommand.Overwrite: case AirportImportRowCommand.AddAirport: if (airc == AirportImportRowCommand.Overwrite) { ap.FDelete(true); // delete the existing airport } switch (ais) { case AirportImportSource.FAA: aic.Code = aic.FAA; break; case AirportImportSource.ICAO: aic.Code = aic.ICAO; break; case AirportImportSource.IATA: aic.Code = aic.IATA; break; } aic.Code = Regex.Replace(aic.Code, "[^a-zA-Z0-9]", string.Empty); aic.FCommit(true, true); if (!String.IsNullOrWhiteSpace(aic.Country)) { aic.SetLocale(aic.Country, aic.Admin1); } break; } return(true); }