Ejemplo n.º 1
0
        private bool TestTextBox(TextBox tb, int method = 0)
        {
            bool ParsedResult = false;

            if (tb.Name.IndexOf("Lat") != -1)
            {
                method = 1;
            }
            if (tb.Name.IndexOf("Lon") != -1)
            {
                method = 2;
            }
            // Determine the format if not forced (aka, method 0)
            if ((tb.Text.ToUpperInvariant().IndexOf("N") > -1) || (tb.Text.ToUpperInvariant().IndexOf("S") > -1))
            {
                method = 1;
            }
            if ((tb.Text.ToUpperInvariant().IndexOf("W") > -1) || (tb.Text.ToUpperInvariant().IndexOf("E") > -1))
            {
                method += 2;
            }

            if ((tb.Modified) && tb.TextLength != 0)
            {
                if (LatLonParser.TryParseAny(tb))
                {
                    switch (method)
                    {
                    case 0:
                    case 3:
                        PasteLat     = LatLonParser.ParsedLatitude;
                        PasteLon     = LatLonParser.ParsedLongitude;
                        ParsedResult = true;
                        tb.Text      = Conversions.DecDeg2SCT(PasteLat, true) + " " +
                                       Conversions.DecDeg2SCT(PasteLon, false);
                        break;

                    case 1:
                        PasteLat     = LatLonParser.ParsedLatitude;
                        tb.Text      = Conversions.DecDeg2SCT(PasteLat, true);
                        ParsedResult = true;
                        break;

                    case 2:
                        PasteLon     = LatLonParser.ParsedLongitude;
                        tb.Text      = Conversions.DecDeg2SCT(PasteLon, false);
                        ParsedResult = true;
                        break;
                    }
                    tb.BackColor = Color.White;
                }
                else
                {
                    tb.BackColor = Color.Yellow;
                }
            }
            return(ParsedResult);
        }
Ejemplo n.º 2
0
        private bool ValidateDMS(TextBox tb)
        {
            bool result = LatLonParser.TryParseAny(tb);

            if (result)
            {
                tb.BackColor = Color.White;
            }
            else
            {
                tb.BackColor = Color.Yellow;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private double TestTextBox(TextBox tb)
        {
            double ParsedResult = -199;
            int    method       = 0;

            if (tb.Name.IndexOf("Lat") != -1)
            {
                method = 1;
            }
            if (tb.Name.IndexOf("Lon") != -1)
            {
                method = 2;
            }
            if ((tb.Modified) && tb.TextLength != 0)
            {
                if (LatLonParser.TryParseAny(tb))
                {
                    switch (method)
                    {
                    case 0:
                        PasteLat = ParsedResult = LatLonParser.ParsedLatitude;
                        PasteLon = LatLonParser.ParsedLongitude;
                        tb.Text  = Conversions.DecDeg2SCT(PasteLat, true) + " " +
                                   Conversions.DecDeg2SCT(PasteLon, false);
                        break;

                    case 1:
                        PasteLat = ParsedResult = LatLonParser.ParsedLatitude;
                        PasteLon = -199;
                        tb.Text  = Conversions.DecDeg2SCT(ParsedResult, true);
                        break;

                    case 2:
                        PasteLon = ParsedResult = LatLonParser.ParsedLongitude;
                        PasteLat = -199;
                        tb.Text  = Conversions.DecDeg2SCT(ParsedResult, false);
                        break;
                    }
                    tb.BackColor = Color.White;
                }
                else
                {
                    tb.BackColor = Color.Yellow;
                }
            }
            return(ParsedResult);
        }
Ejemplo n.º 4
0
        public static bool TestTextBox(TextBox tb, int method = 0)
        {
            // Tests the string for correct coordinate format
            // Places Lat and/or Lon in public field above
            // Returns FALSE if unable to parse text  and sets public fields to -1
            bool ParsedResult = false;

            if (tb.Name.IndexOf("Lat") != -1)
            {
                method = 1;
            }
            if (tb.Name.IndexOf("Lon") != -1)
            {
                method = 2;
            }
            if (method == 0)
            {
                // Determine the format if not forced (aka, method 0)
                if ((tb.Text.ToUpperInvariant().IndexOf("N") != -1) || (tb.Text.ToUpperInvariant().IndexOf("S") != -1))
                {
                    method = 1;
                }
                if ((tb.Text.ToUpperInvariant().IndexOf("W") != -1) || (tb.Text.ToUpperInvariant().IndexOf("E") != -1))
                {
                    method += 2;
                }
            }
            if (tb.TextLength != 0)
            {
                if (LatLonParser.TryParseAny(tb, method))
                {
                    switch (method)
                    {
                    case 0:
                    case 3:
                        Lat          = LatLonParser.ParsedLatitude;
                        Lon          = LatLonParser.ParsedLongitude;
                        ParsedResult = true;
                        tb.Text      = Conversions.Degrees2SCT(Lat, true) + " " +
                                       Conversions.Degrees2SCT(Lon, false);
                        break;

                    case 1:
                        Lat          = LatLonParser.ParsedLatitude;
                        Lon          = -1;
                        tb.Text      = Conversions.Degrees2SCT(Lat, true);
                        ParsedResult = true;
                        break;

                    case 2:
                        Lon          = LatLonParser.ParsedLongitude;
                        Lat          = -1;
                        tb.Text      = Conversions.Degrees2SCT(Lon, false);
                        ParsedResult = true;
                        break;
                    }
                    tb.BackColor = Color.White;
                }
                else
                {
                    tb.BackColor = Color.Yellow;
                    Lat          = Lon = -1;
                }
            }
            return(ParsedResult);
        }