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); } }
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); }
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); } }
// 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); }
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); }
// 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); }
public void TriggerChange(BookmarkClass bk) { OnBookmarkChange?.Invoke(bk, true); }
// 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)); }
// return any mark public BookmarkClass FindBookmarkOnRegion(string name) { BookmarkClass bc = globalbookmarks.Find(x => x.Heading != null && x.Heading.Equals(name, StringComparison.InvariantCultureIgnoreCase)); return(bc); }