private void tb_Locator_TextChanged(object sender, EventArgs e) { // update lat/lon double mlat, mlon; if (tb_Locator.Focused) { // locator box is focused --> update lat/lon if (MaidenheadLocator.Check(tb_Locator.Text) && tb_Locator.Text.Length >= 6) { MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.MiddleMiddle, out mlat, out mlon); tb_Latitude.SilentValue = mlat; tb_Longitude.SilentValue = mlon; } else { tb_Latitude.SilentValue = double.NaN; tb_Longitude.SilentValue = double.NaN; } } ValidateDetails(); }
private bool ValidateDetails() { // validates user details and sets position on map // enables/disables next button double mlat, mlon; // colour Textbox if more precise lat/lon information is available if (MaidenheadLocator.IsPrecise(tb_Latitude.Value, tb_Longitude.Value, 3)) { if (tb_Locator.BackColor != Color.PaleGreen) { tb_Locator.BackColor = Color.PaleGreen; } } else { if (tb_Locator.BackColor != Color.FloralWhite) { tb_Locator.BackColor = Color.FloralWhite; } } if (GeographicalPoint.Check(tb_Latitude.Value, tb_Longitude.Value)) { // update locator text if not focusd if (!tb_Locator.Focused) { tb_Locator.SilentText = MaidenheadLocator.LocFromLatLon(tb_Latitude.Value, tb_Longitude.Value, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, true); } // get locator polygon Callsignpolygons.Clear(); List <PointLatLng> l = new List <PointLatLng>(); // add loc bounds to map polygons MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.TopLeft, out mlat, out mlon); l.Add(new PointLatLng(mlat, mlon)); MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.TopRight, out mlat, out mlon); l.Add(new PointLatLng(mlat, mlon)); MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.BottomRight, out mlat, out mlon); l.Add(new PointLatLng(mlat, mlon)); MaidenheadLocator.LatLonFromLoc(tb_Locator.Text, PositionInRectangle.BottomLeft, out mlat, out mlon); l.Add(new PointLatLng(mlat, mlon)); GMapPolygon p = new GMapPolygon(l, tb_Locator.Text.ToString()); p.Stroke = new Pen(Color.FromArgb(255, Color.Magenta), 3); p.Fill = new SolidBrush(Color.FromArgb(0, Color.Magenta)); Callsignpolygons.Polygons.Add(p); // update user position UserPos.Position = new PointLatLng(tb_Latitude.Value, tb_Longitude.Value); // update map position if (!IsDraggingMarker) { string loc = MaidenheadLocator.LocFromLatLon(tb_Latitude.Value, tb_Longitude.Value, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, true); MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out mlat, out mlon); gm_Callsign.Position = new PointLatLng(mlat, mlon); // adjust map zoom level int zoom = loc.Length; switch (zoom) { case 6: gm_Callsign.Zoom = 12; break; case 8: gm_Callsign.Zoom = 15; break; case 10: gm_Callsign.Zoom = 17; break; } } } // check all values if (Callsign.Check(tb_Callsign.Text) && MaidenheadLocator.Check(tb_Locator.Text) && !double.IsNaN(tb_Latitude.Value) && !double.IsNaN(tb_Longitude.Value)) { StationLocation.Lat = tb_Latitude.Value; StationLocation.Lon = tb_Longitude.Value; StationLocation.Source = MaidenheadLocator.IsPrecise(tb_Latitude.Value, tb_Longitude.Value, 3) ? GEOSOURCE.FROMUSER : GEOSOURCE.FROMLOC; StationLocation.Loc = MaidenheadLocator.LocFromLatLon(StationLocation.Lat, StationLocation.Lon, false, 3); tb_Elevation.SilentValue = GetElevation(StationLocation.Lat, StationLocation.Lon); return(true); } else { return(false); } }
public DataTableCallsigns FromDTB(string filename) { // imports DTB database from Win-Test DataTableCallsigns dt = new DataTableCallsigns(); if (!File.Exists(filename)) { return(dt); } try { using (StreamReader sr = new StreamReader(File.OpenRead(filename))) { while (!sr.EndOfStream) { char[] buffer = new char[26]; sr.ReadBlock(buffer, 0, 14); sr.ReadBlock(buffer, 14, 12); if (!sr.EndOfStream) { string call = ""; string loc = ""; string lastupdated = ""; double lat = double.NaN; double lon = double.NaN; int i = 0; while ((buffer[i] != 0) && (i < 14)) { call += (char)buffer[i]; i++; } i = 14; while ((i < 21) && (buffer[i] != 0)) { loc += (char)buffer[i]; i++; } i = 21; while ((i < 26) && (buffer[i] != 0)) { lastupdated += (char)buffer[i]; i++; } call = call.Trim().ToUpper(); loc = loc.Trim().ToUpper(); try { if (lastupdated[2] < '5') { lastupdated = "20" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z"; } else { lastupdated = "19" + lastupdated[2] + lastupdated[3] + "-" + lastupdated[0] + lastupdated[1] + "-01 00:00:00Z"; } } catch { } if (MaidenheadLocator.Check(loc)) { MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon); } GEOSOURCE source = GEOSOURCE.FROMLOC; if (GeographicalPoint.Check(lat, lon)) { DataRow row = dt.NewRow(); row["Call"] = call; row["Lat"] = lat; row["Lon"] = lon; row["Source"] = source.ToString(); row["LastUpdated"] = lastupdated; DataRow oldrow = dt.Rows.Find(row["Call"].ToString()); if (oldrow != null) { // call found --> check for update if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0) { oldrow["Lat"] = row["Lat"]; oldrow["Lon"] = row["Lon"]; oldrow["Source"] = row["Source"]; oldrow["LastUpdated"] = row["LastUpdated"]; } } else { // add new row dt.Rows.Add(row); } } } } } } catch (Exception ex) { } return(dt); }
public DataTableCallsigns FromCSV(string filename) { // imports a variable csv format with autodetect of callsign, loc and timestamp DataTableCallsigns dt = new DataTableCallsigns(); if (!File.Exists(filename)) { return(dt); } try { string s = ""; using (StreamReader sr = new StreamReader(File.OpenRead(filename))) { while (!sr.EndOfStream) { s = sr.ReadLine(); if (!String.IsNullOrEmpty(s) && !s.StartsWith("//")) { string[] a = s.Split(';'); if (a.Length < 2) { a = s.Split(','); } string call = ""; double lat = double.NaN; double lon = double.NaN; string loc = ""; GEOSOURCE source = GEOSOURCE.FROMLOC; // set lastupdated to filetime if no timestamp is found on file string filetime = File.GetCreationTimeUtc(filename).ToString("u"); string lastupdated = filetime; foreach (string entry in a) { // search for 1st locator in line if (MaidenheadLocator.Check(entry) && (entry.Length == 6) && String.IsNullOrEmpty(loc)) { MaidenheadLocator.LatLonFromLoc(entry, PositionInRectangle.MiddleMiddle, out lat, out lon); break; } // search for 1st callsign in line if (Callsign.Check(entry) && String.IsNullOrEmpty(call)) { call = entry.Trim().ToUpper(); } DateTime timestamp; if (DateTime.TryParseExact(entry, "yyyy-MM-dd HH:mm:ssZ", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out timestamp)) { lastupdated = timestamp.ToString("u"); } } if (GeographicalPoint.Check(lat, lon)) { // store array values in DataTable DataRow row = dt.NewRow(); row["Call"] = call; row["Lat"] = lat; row["Lon"] = lon; row["Source"] = source.ToString(); row["LastUpdated"] = lastupdated; DataRow oldrow = dt.Rows.Find(row["Call"].ToString()); if (oldrow != null) { // call found --> check for update if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0) { oldrow["Lat"] = row["Lat"]; oldrow["Lon"] = row["Lon"]; oldrow["Source"] = row["Source"]; oldrow["LastUpdated"] = row["LastUpdated"]; } } else { // add new row dt.Rows.Add(row); } } } } } } catch { } return(dt); }
public DataTableCallsigns FromCALL3(string filename) { // imports CALL3.TXT as used by WSJT // fields are // CALLSIGN, LOCATOR, EME FLAG, (these first three fields are used by WSJT) // plus optional fields: // STATE, FIRST NAME, EMAIL ADDRESS, NOTES, REVISION DATE DataTableCallsigns dt = new DataTableCallsigns(); if (!File.Exists(filename)) { return(dt); } try { string s = ""; using (StreamReader sr = new StreamReader(File.OpenRead(filename))) { while (!sr.EndOfStream) { s = sr.ReadLine(); if (!String.IsNullOrEmpty(s) && !s.StartsWith("//")) { string[] a = s.Split(','); // store array values in DataTable string call = a[0]; string loc = a[1]; double lat = double.NaN; double lon = double.NaN; if (MaidenheadLocator.Check(loc)) { MaidenheadLocator.LatLonFromLoc(loc, PositionInRectangle.MiddleMiddle, out lat, out lon); } GEOSOURCE source = GEOSOURCE.FROMLOC; DateTime lastupdated = DateTime.MinValue.ToUniversalTime(); if (a.Length >= 7) { // try to get an revision date maybe in various formats // MMMonVHF try { lastupdated = DateTime.ParseExact(a[7], "MM/yy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } catch (Exception ex) { } } if (GeographicalPoint.Check(lat, lon)) { DataRow row = dt.NewRow(); row["Call"] = call; row["Lat"] = lat; row["Lon"] = lon; row["Source"] = source.ToString(); row["LastUpdated"] = lastupdated.ToString("u"); DataRow oldrow = dt.Rows.Find(row["Call"].ToString()); if (oldrow != null) { // call found --> check for update if (String.Compare(row["LastUpdated"].ToString(), oldrow["LastUpdated"].ToString()) > 0) { oldrow["Lat"] = row["Lat"]; oldrow["Lon"] = row["Lon"]; oldrow["Source"] = row["Source"]; oldrow["LastUpdated"] = row["LastUpdated"]; } } else { // add new row dt.Rows.Add(row); } } } } } } catch (Exception ex) { } return(dt); }