Esempio n. 1
0
        public static bool GetAllBookmarks()
        {
            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(mode: EDDbAccessMode.Reader))
                {
                    using (DbCommand cmd = cn.CreateCommand("select * from Bookmarks"))
                    {
                        DataSet ds = null;

                        ds = SQLiteDBClass.SQLQueryText(cn, cmd);

                        if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            return(false);
                        }

                        bookmarks.Clear();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            BookmarkClass bc = new BookmarkClass(dr);
                            bookmarks.Add(bc);
                        }

                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static BookmarkClass FindBookmarkOnSystem(string name)
        {
            // star name may be null if its a region mark
            BookmarkClass bk = bookmarks.Find(x => x.StarName != null && x.StarName.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            return(bk);
        }
Esempio n. 3
0
        public static bool LoadBookmarks()
        {
            System.Diagnostics.Debug.Assert(gbl == null);       // no double instancing!
            gbl = new GlobalBookMarkList();

            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(mode: EDDbAccessMode.Reader))
                {
                    using (DbCommand cmd = cn.CreateCommand("select * from Bookmarks"))
                    {
                        DataSet ds = null;

                        ds = SQLiteDBClass.SQLQueryText(cn, cmd);

                        if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            return(false);
                        }

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            BookmarkClass bc = new BookmarkClass(dr);
                            gbl.globalbookmarks.Add(bc);
                        }

                        return(true);
                    }
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 4
0
        // bk = null, new bookmark, else update.  isstar = true, region = false.
        public static BookmarkClass AddOrUpdateBookmark(BookmarkClass bk, bool isstar, string name, double x, double y, double z, DateTime tme, string notes)
        {
            bool addit = bk == null;

            if (bk == null)
            {
                bk = new BookmarkClass();
            }

            if (isstar)
            {
                bk.StarName = name;
            }
            else
            {
                bk.Heading = name;
            }

            bk.x    = x;
            bk.y    = y;
            bk.z    = z;
            bk.Time = tme;
            bk.Note = notes;

            if (addit)
            {
                bk.Add();
            }
            else
            {
                bk.Update();
            }

            return(bk);
        }
Esempio n. 5
0
        public void Delete(BookmarkClass bk)
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);
            long id = bk.id;

            bk.Delete();
            globalbookmarks.RemoveAll(x => x.id == id);
            OnBookmarkChange?.Invoke(bk, true);
        }
Esempio n. 6
0
        // bk = null, new bookmark, else update.  isstar = true, region = false.
        public BookmarkClass AddOrUpdateBookmark(BookmarkClass bk, bool isstar, string name, double x, double y, double z, DateTime tme, string notes = null, PlanetMarks planetMarks = null)
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);
            bool addit = bk == null;

            if (addit)
            {
                bk      = new BookmarkClass();
                bk.Note = "";       // set empty, in case notes==null
                globalbookmarks.Add(bk);
                System.Diagnostics.Debug.WriteLine("New bookmark created");
            }

            if (isstar)
            {
                bk.StarName = name;
            }
            else
            {
                bk.Heading = name;
            }

            bk.x              = x;
            bk.y              = y;
            bk.z              = z;
            bk.Time           = tme;
            bk.PlanetaryMarks = planetMarks ?? bk.PlanetaryMarks;
            bk.Note           = notes ?? bk.Note; // only override notes if its set.

            if (addit)
            {
                bk.Add();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(GlobalBookMarkList.Instance.Bookmarks.Find((xx) => Object.ReferenceEquals(bk, xx)) != null);
                bk.Update();
            }

            System.Diagnostics.Debug.WriteLine("Write bookmark " + bk.Name + " Notes " + notes);

            OnBookmarkChange?.Invoke(bk, false);

            return(bk);
        }
Esempio n. 7
0
 public void TriggerChange(BookmarkClass bk)
 {
     OnBookmarkChange?.Invoke(bk, true);
 }
Esempio n. 8
0
        // on a star system, if an existing bookmark, return it, else create a new one with these properties
        public BookmarkClass EnsureBookmarkOnSystem(string name, double x, double y, double z, DateTime tme, string notes = null)
        {
            BookmarkClass bk = FindBookmarkOnSystem(name);

            return(bk != null ? bk : AddOrUpdateBookmark(null, true, name, x, y, z, tme, notes));
        }
Esempio n. 9
0
        // return any mark
        public BookmarkClass FindBookmarkOnRegion(string name)
        {
            BookmarkClass bc = globalbookmarks.Find(x => x.Heading != null && x.Heading.Equals(name, StringComparison.InvariantCultureIgnoreCase));

            return(bc);
        }