Beispiel #1
0
        public static DistanceClass GetDistanceClass(EDDiscovery2.DB.ISystem s1, EDDiscovery2.DB.ISystem s2)
        {
            if (s1 == null || s2 == null)
            {
                return(null);
            }

            try
            {
                using (SQLiteConnectionED cn = new SQLiteConnectionED())
                {
                    using (DbCommand cmd = cn.CreateCommand("SELECT * FROM Distances WHERE (NameA = @NameA and NameB = @NameB) OR (NameA = @NameB and NameB = @NameA) limit 1"))
                    {
                        cmd.AddParameterWithValue("@NameA", s1.name);
                        cmd.AddParameterWithValue("@NameB", s2.name);

                        DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);

                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)     // if found.
                        {
                            DistanceClass dist = new DistanceClass(ds.Tables[0].Rows[0]);
                            return(dist);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);
            }

            return(null);
        }
Beispiel #2
0
        private void UpdateTo(bool updatename)
        {
            changesilence = true;

            if (textBox_To.ReadOnly == false)                // if entering system name..
            {
                EDDiscovery2.DB.ISystem ds1 = SystemClass.GetSystem(SystemNameOnly(textBox_To.Text));

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        textBox_To.Text = ds1.name;
                    }

                    textBox_ToX.Text = ds1.x.ToString("0.00");
                    textBox_ToY.Text = ds1.y.ToString("0.00");
                    textBox_ToZ.Text = ds1.z.ToString("0.00");
                }
                else
                {
                    textBox_ToX.Text = textBox_ToY.Text = textBox_ToZ.Text = "";
                }
            }
            else // Co-ords..
            {
                string  res = "";
                Point3D curpos;
                if (GetCoordsTo(out curpos))
                {
                    ISystem nearest = SystemClass.FindNearestSystem(curpos.X, curpos.Y, curpos.Z);

                    if (nearest != null)
                    {
                        double distance = Point3D.DistanceBetween(curpos, new Point3D(nearest.x, nearest.y, nearest.z));
                        if (distance < 0.1)
                        {
                            res = nearest.name;
                        }
                        else
                        {
                            res = nearest.name + " @ " + distance.ToString("0.00") + "ly";
                        }
                    }
                }

                textBox_To.Text = res;
            }

            UpdateDistance();

            changesilence        = false;
            button_Route.Enabled = IsValid();
        }
Beispiel #3
0
        private void UpdateFrom(bool updatename)
        {
            changesilence = true;

            if (textBox_From.ReadOnly == false)                // if entering system name..
            {
                EDDiscovery2.DB.ISystem ds1 = SystemData.GetSystem(SystemNameOnly(textBox_From.Text));

                if (ds1 != null)
                {
                    if (updatename)                          // can't fix it as you type.. so leave alone
                    {
                        textBox_From.Text = ds1.name;
                    }

                    textBox_FromX.Text = ds1.x.ToString("0.00");
                    textBox_FromY.Text = ds1.y.ToString("0.00");
                    textBox_FromZ.Text = ds1.z.ToString("0.00");
                }
                else
                {
                    textBox_FromX.Text = textBox_FromY.Text = textBox_FromZ.Text = "";
                }
            }
            else
            {
                string  res = "";
                Point3D curpos;
                if (GetCoordsFrom(out curpos))
                {
                    SystemClass nearest;
                    double      distance;
                    FindNearestSystem(curpos, out nearest, out distance);

                    if (distance < 0.1)
                    {
                        res = nearest.name;
                    }
                    else
                    {
                        res = nearest.name + " @ " + distance.ToString("0.00") + "ly";
                    }
                }

                textBox_From.Text = res;
            }

            UpdateDistance();

            changesilence        = false;
            button_Route.Enabled = IsValid();
        }
Beispiel #4
0
        public static double FindDistance(EDDiscovery2.DB.ISystem s1, EDDiscovery2.DB.ISystem s2)
        {
            DistanceClass dst = GetDistanceClass(s1, s2);

            return((dst == null) ? -1 : dst.Dist);
        }