// bk = null, new note, else update. Note systemname/bodyname are not unique. Id it the only unique property public CaptainsLogClass AddOrUpdate(CaptainsLogClass bk, int commander, string systemname, string bodyname, DateTime timeutc, string notes, string tags = null, string parameters = null) { System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop); bool addit = bk == null; if (addit) { bk = new CaptainsLogClass(); globallog.Add(bk); System.Diagnostics.Debug.WriteLine("New log created"); } bk.Set(commander, systemname, bodyname, timeutc, notes, tags, parameters); if (addit) { bk.Add(); } else { System.Diagnostics.Debug.WriteLine(GlobalCaptainsLogList.Instance.LogEntries.Find((xx) => Object.ReferenceEquals(bk, xx)) != null); bk.Update(); } //System.Diagnostics.Debug.WriteLine("Write captains log " + bk.SystemName + ":" + bk.BodyName + " Notes " + notes); OnLogEntryChanged?.Invoke(bk, false); return(bk); }
public void Delete(CaptainsLogClass bk) { System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop); long id = bk.ID; bk.Delete(); globallog.RemoveAll(x => x.ID == id); OnLogEntryChanged?.Invoke(bk, true); }
public static bool LoadLog() { System.Diagnostics.Debug.Assert(gbl == null); // no double instancing! gbl = new GlobalCaptainsLogList(); try { using (SQLiteConnectionUser cn = new SQLiteConnectionUser(mode: SQLLiteExtensions.SQLExtConnection.AccessMode.Reader)) { using (DbCommand cmd = cn.CreateCommand("select * from CaptainsLog")) { DataSet ds = null; ds = cn.SQLQueryText(cmd); if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) { return(false); } foreach (DataRow dr in ds.Tables[0].Rows) { CaptainsLogClass bc = new CaptainsLogClass(dr); gbl.globallog.Add(bc); } return(true); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception " + ex.ToString()); return(false); } }
public void TriggerChange(CaptainsLogClass bk) { OnLogEntryChanged?.Invoke(bk, true); }