コード例 #1
0
ファイル: SystemNoteClass.cs プロジェクト: mwerle/EDDiscovery
        public static bool GetAllSystemNotes()
        {
            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
                {
                    using (DbCommand cmd = cn.CreateCommand("select * from SystemNote"))
                    {
                        DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                        if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            return false;
                        }

                        globalSystemNotes.Clear();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            SystemNoteClass sys = new SystemNoteClass(dr);
                            globalSystemNotes[sys.Name.ToLower()] = sys;
                        }

                        return true;

                    }
                }
            }
            catch
            {
                return false;
            }
        }
コード例 #2
0
        public static List<WantedSystemClass> GetAllWantedSystems()
        {
            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(mode: EDDbAccessMode.Reader))
                {
                    using (DbCommand cmd = cn.CreateCommand("select * from wanted_systems"))
                    {
                        DataSet ds = SQLiteDBClass.SQLQueryText(cn, cmd);
                        if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                        {
                            return null;
                        }

                        List<WantedSystemClass> retVal = new List<WantedSystemClass>();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            WantedSystemClass sys = new WantedSystemClass(dr);
                            retVal.Add(sys);
                        }

                        return retVal;
                    }
                }
            }
            catch
            {
                return null;
            }
        }
コード例 #3
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
        public static bool GetAllBookmarks()
        {
            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
                {
                    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;
            }
        }
コード例 #4
0
 public bool Add()
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         bool ret = Add(cn);
         return ret;
     }
 }
コード例 #5
0
ファイル: TravelLogUnit.cs プロジェクト: mwerle/EDDiscovery
        public static TravelLogUnit Get(string name)
        {
            using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = cn.CreateCommand("SELECT * FROM TravelLogUnit WHERE Name = @name ORDER BY Id DESC"))
                {
                    cmd.AddParameterWithValue("@name", name);
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            return new TravelLogUnit(reader);
                        }
                    }
                }
            }

            return null;
        }
コード例 #6
0
        public static List<SavedRouteClass> GetAllSavedRoutes()
        {
            List<SavedRouteClass> retVal = new List<SavedRouteClass>();

            try
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(mode: EDDbAccessMode.Reader))
                {
                    using (DbCommand cmd1 = cn.CreateCommand("select * from routes_expeditions"))
                    {
                        DataSet ds1 = SQLiteDBClass.SQLQueryText(cn, cmd1);

                        if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                        {
                            using (DbCommand cmd2 = cn.CreateCommand("select * from route_systems"))
                            {
                                DataSet ds2 = SQLiteDBClass.SQLQueryText(cn, cmd2);

                                foreach (DataRow dr in ds1.Tables[0].Rows)
                                {
                                    DataRow[] syslist = new DataRow[0];
                                    if (ds2.Tables.Count != 0)
                                    {
                                        syslist = ds2.Tables[0].Select(String.Format("routeid = {0}", dr["id"]), "id ASC");
                                    }
                                    SavedRouteClass sys = new SavedRouteClass(dr, syslist);
                                    retVal.Add(sys);
                                }

                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return retVal;
        }
コード例 #7
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
        private bool Update(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("Update Bookmarks set StarName=@sname, x = @xp, y = @yp, z = @zp, Time=@time, Heading = @head, Note=@note  where ID=@id"))
            {
                cmd.AddParameterWithValue("@ID", id);
                cmd.AddParameterWithValue("@sname", StarName);
                cmd.AddParameterWithValue("@xp", x);
                cmd.AddParameterWithValue("@yp", y);
                cmd.AddParameterWithValue("@zp", z);
                cmd.AddParameterWithValue("@time", Time);
                cmd.AddParameterWithValue("@head", Heading);
                cmd.AddParameterWithValue("@note", Note);

                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                bookmarks.RemoveAll(x => x.id == id);     // remove from list any containing id.
                bookmarks.Add(this);

                return true;
            }
        }
コード例 #8
0
 static public bool PutSettingBool(string key, bool boolvalue)
 {
     return(SQLiteConnectionUser.PutSettingBool(key, boolvalue));
 }
コード例 #9
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 ///----------------------------
 /// STATIC functions for discrete values
 public static bool keyExists(string sKey)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return keyExists(sKey, cn);
     }
 }
コード例 #10
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 public static int GetSettingInt(string key, int defaultvalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return GetSettingInt(key, defaultvalue, cn);
     }
 }
コード例 #11
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 public static bool GetSettingBool(string key, bool defaultvalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return GetSettingBool(key, defaultvalue, cn);
     }
 }
コード例 #12
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
        private static void InitializeDatabase()
        {
            string dbv4file = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDiscovery);
            string dbuserfile = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDUser);
            string dbsystemsfile = SQLiteConnectionED.GetSQLiteDBFile(EDDSqlDbSelection.EDDSystem);
            DbFactory = GetSqliteProviderFactory();

            try
            {
                bool fileexist = File.Exists(dbv4file);
                bool UseV5Databases;

                UseV5Databases = File.Exists(dbuserfile);

                if (!fileexist && UseV5Databases==false)                                         // no file, create it
                    SQLiteConnection.CreateFile(dbv4file);

                if (UseV5Databases == false)
                {
                    using (var conn = new SQLiteConnectionOld())
                    {
                        if (!fileexist)                                       // first time, create the register
                            ExecuteQuery(conn, "CREATE TABLE Register (ID TEXT PRIMARY KEY  NOT NULL  UNIQUE , \"ValueInt\" INTEGER, \"ValueDouble\" DOUBLE, \"ValueString\" TEXT, \"ValueBlob\" BLOB)");

                        UpgradeDB(conn);                                            // upgrade it
                    }

                    SplitDataBase();
                }

                using (var conn = new SQLiteConnectionUser())
                {
                    UpgradeUserDB(conn);                                            // upgrade it
                }

                using (var conn = new SQLiteConnectionSystem())
                {
                    UpgradeSystemsDB(conn);                                            // upgrade it
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error creating data base file, Exception", System.Windows.Forms.MessageBoxButtons.OK);
            }
        }
コード例 #13
0
ファイル: EDSMSync.cs プロジェクト: vendolis/EDDiscovery
        private void Sync(EDSMClass edsm)
        {
            try
            {
                mainForm.LogLine("EDSM sync begin");

                List<HistoryEntry> hlfsdunsyncedlist = mainForm.history.FilterByNotEDSMSyncedAndFSD;        // first entry is oldest

                if ( _syncTo && hlfsdunsyncedlist.Count > 0 )                   // send systems to edsm (verified with dates, 29/9/2016, utc throughout)
                {
                    DateTime utcmin = hlfsdunsyncedlist[0].EventTimeUTC.AddDays(-1);        // 1 days for margin ;-)  only get them back to this date for speed..

                    mainForm.LogLine("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries");

                    List<HistoryEntry> edsmsystemlog = null;
                    edsm.GetLogs(utcmin, out edsmsystemlog);        // always returns a log, time is in UTC as per HistoryEntry and JournalEntry

                    int edsmsystemssent = 0;

                    foreach (var he in hlfsdunsyncedlist)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault();

                        if (ps2 != null)                // it did, just make sure EDSM sync flag is set..
                        {
                            he.SetEdsmSync();
                        }
                        else
                        {
                            string errmsg;              // (verified with EDSM 29/9/2016)

                                                        // it converts to UTC inside the function, supply local for now
                            if ( edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg) )
                                he.SetEdsmSync();

                            if (errmsg.Length > 0)
                                mainForm.LogLine(errmsg);

                            edsmsystemssent++;
                        }
                    }

                    mainForm.LogLine(string.Format("EDSM Systems sent {0}", edsmsystemssent));
                }

                // TBD Comments to edsm?

                if ( _syncFrom )                                                            // Verified ok with time 29/9/2016
                {
                    var json = edsm.GetComments(new DateTime(2011, 1, 1));

                    if (json != null)
                    {
                        JObject msg = JObject.Parse(json);
                        int msgnr = msg["msgnum"].Value<int>();

                        JArray comments = (JArray)msg["comments"];
                        if (comments != null)
                        {
                            int commentsadded = 0;

                            foreach (JObject jo in comments)
                            {
                                string name = jo["system"].Value<string>();
                                string note = jo["comment"].Value<string>();
                                string utctime = jo["lastUpdate"].Value<string>();
                                int edsmid = 0;

                                if (!Int32.TryParse(JSONHelper.GetStringDef(jo["systemId"], "0"), out edsmid))
                                    edsmid = 0;

                                DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss",
                                            CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                                SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid);

                                if (curnote != null)
                                {
                                                                                // curnote uses local time to store
                                    if (localtime.Ticks > curnote.Time.Ticks)   // if newer, add on (verified with EDSM 29/9/2016)
                                    {
                                        curnote.Note += ". EDSM: " + note;
                                        curnote.Time = localtime;
                                        curnote.EdsmId = edsmid;
                                        curnote.Update();
                                        commentsadded++;
                                    }
                                }
                                else
                                {
                                    curnote = new SystemNoteClass();
                                    curnote.Note = note;
                                    curnote.Time = localtime;
                                    curnote.Name = name;
                                    curnote.Journalid = 0;
                                    curnote.EdsmId = edsmid;
                                    curnote.Add();
                                    commentsadded++;
                                }
                            }

                            mainForm.LogLine(string.Format("EDSM Comments downloaded/updated {0}", commentsadded));
                        }
                    }
                }

                if (_syncFrom )     // verified after struggle 29/9/2016
                {
                    List<HistoryEntry> edsmsystemlog = null;
                    edsm.GetLogs(new DateTime(2011, 1, 1), out edsmsystemlog);        // get the full list of systems
                    edsmsystemlog = edsmsystemlog.OrderBy(s => s.EventTimeUTC).ToList();

                    List<HistoryEntry> hlfsdlist = mainForm.history.FilterByTravel.Where(h => h.IsLocOrJump).OrderBy(h => h.EventTimeUTC).ToList();  // FSD jumps only

                    List<HistoryEntry> toadd = new List<HistoryEntry>();

                    int previdx = -1;
                    foreach (HistoryEntry he in edsmsystemlog)      // find out list of ones not present
                    {
                        int index = hlfsdlist.FindIndex(x => x.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase) && x.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks);

                        if (index < 0)
                        {
                            // Look for any entries where DST may have thrown off the time
                            foreach (var vi in hlfsdlist.Select((v,i) => new {v = v, i = i}).Where(vi => vi.v.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (vi.i > previdx)
                                {
                                    double hdiff = vi.v.EventTimeUTC.Subtract(he.EventTimeUTC).TotalHours;
                                    if (hdiff >= -2 && hdiff <= 2 && hdiff == Math.Floor(hdiff))
                                    {
                                        if (vi.v.System.id_edsm <= 0)
                                        {
                                            vi.v.System.id_edsm = 0;
                                            mainForm.history.FillEDSM(vi.v);
                                        }

                                        if (vi.v.System.id_edsm <= 0 || vi.v.System.id_edsm == he.System.id_edsm)
                                        {
                                            index = vi.i;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (index < 0)
                        {
                            toadd.Add(he);
                        }
                        else
                        {
                            previdx = index;
                        }
                    }

                    if ( toadd.Count >0 )  // if we have any, we can add
                    {
                        TravelLogUnit tlu = new TravelLogUnit();    // need a tlu for it
                        tlu.type = 2;  // EDSM
                        tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                        tlu.Size = 0;
                        tlu.Path = "EDSM";
                        tlu.CommanderId = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr;
                        tlu.Add();  // Add to Database

                        using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                        {
                            foreach (HistoryEntry he in toadd)
                            {
                                EDDiscovery.EliteDangerous.JournalEntry je =
                                    EDDiscovery.EliteDangerous.JournalEntry.CreateFSDJournalEntry(tlu.id, tlu.CommanderId.Value, he.EventTimeUTC,
                                                                                                  he.System.name, he.System.x, he.System.y, he.System.z,
                                                                                                  _defmapcolour, (int)EDDiscovery.EliteDangerous.SyncFlags.EDSM);

                                System.Diagnostics.Trace.WriteLine(string.Format("Add {0} {1}", je.EventTimeUTC, he.System.name));
                                je.Add(cn);
                            }
                        }

                        if (OnDownloadedSystems != null)
                            OnDownloadedSystems();

                        mainForm.LogLine(string.Format("EDSM downloaded {0} systems", toadd.Count));
                    }
                }

                mainForm.LogLine("EDSM sync Done");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message);
            }
        }
コード例 #14
0
 static public bool PutSettingDouble(string key, double doublevalue)
 {
     return(SQLiteConnectionUser.PutSettingDouble(key, doublevalue));
 }
コード例 #15
0
        ///----------------------------
        /// STATIC functions for discrete values

        static public bool keyExists(string sKey)
        {
            return(SQLiteConnectionUser.keyExists(sKey));
        }
コード例 #16
0
 static public bool PutSettingString(string key, string strvalue)
 {
     return(SQLiteConnectionUser.PutSettingString(key, strvalue));
 }
コード例 #17
0
 static public string GetSettingString(string key, string defaultvalue)
 {
     return(SQLiteConnectionUser.GetSettingString(key, defaultvalue));
 }
コード例 #18
0
 static public bool PutSettingInt(string key, int intvalue)
 {
     return(SQLiteConnectionUser.PutSettingInt(key, intvalue));
 }
コード例 #19
0
        private bool Update(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("Update VisitedSystems set Name=@Name, Time=@Time, Unit=@Unit, Commander=@commander, Source=@Source, edsm_sync=@edsm_sync, map_colour=@map_colour, X=@x, Y=@y, Z=@z, id_edsm_assigned=@id_edsm_assigned where ID=@id"))
            {
                cmd.AddParameterWithValue("@ID", id);
                cmd.AddParameterWithValue("@Name", Name);
                cmd.AddParameterWithValue("@Time", Time);
                cmd.AddParameterWithValue("@unit", Unit);
                cmd.AddParameterWithValue("@commander", Commander);
                cmd.AddParameterWithValue("@source", Source);
                cmd.AddParameterWithValue("@edsm_sync", EDSM_sync);
                cmd.AddParameterWithValue("@map_colour", MapColour);
                cmd.AddParameterWithValue("@x", X);
                cmd.AddParameterWithValue("@y", Y);
                cmd.AddParameterWithValue("@z", Z);
                cmd.AddParameterWithValue("@id_edsm_assigned", id_edsm_assigned);
                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                return true;
            }
        }
コード例 #20
0
        private static void UpgradeUserDB103(SQLiteConnectionUser conn)
        {
            string query1 = "CREATE TABLE Journals ( " +
                "Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " +
                "Type INTEGER NOT NULL, " +
                "Name TEXT NOT NULL COLLATE NOCASE, " +
                "Path TEXT COLLATE NOCASE, " +
                "CommanderId INTEGER REFERENCES Commanders(Id), " +
                "Size INTEGER " +
                ") ";

            string query2 = "CREATE TABLE JournalEntries ( " +
                 "Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT," +
                 "JournalId INTEGER NOT NULL REFERENCES Journals(Id), " +
                 "EventTypeId INTEGER NOT NULL, " +
                 "EventType TEXT, " +
                 "EventTime DATETIME NOT NULL, " +
                 "EventData TEXT, " + //--JSON String of complete line" +
                 "EdsmId INTEGER, " + //--0 if not set yet." +
                 "Synced INTEGER " +
                 ")";

            SQLiteDBClass.PerformUpgrade(conn, 103, true, false, new[] { query1, query2 });
        }
コード例 #21
0
        private bool Delete(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("DELETE FROM wanted_systems WHERE id = @id"))
            {
                cmd.AddParameterWithValue("@id", id);

                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                return true;
            }
        }
コード例 #22
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 private static void CreateUserDBTableIndexes()
 {
     string[] queries = new[]
     {
         "CREATE INDEX IF NOT EXISTS stationIndex ON Stations (system_id ASC)",
         "CREATE INDEX IF NOT EXISTS VisitedSystemIndex ON VisitedSystems (Name ASC, Time ASC)",
         "CREATE INDEX IF NOT EXISTS station_commodities_index ON station_commodities (station_id ASC, commodity_id ASC, type ASC)",
         "CREATE INDEX IF NOT EXISTS StationsIndex_ID  ON Stations (id ASC)",
         "CREATE INDEX IF NOT EXISTS StationsIndex_system_ID  ON Stations (system_id ASC)",
         "CREATE INDEX IF NOT EXISTS StationsIndex_system_Name  ON Stations (Name ASC)",
         "CREATE INDEX IF NOT EXISTS VisitedSystems_id_edsm_assigned ON VisitedSystems (id_edsm_assigned)",
         "CREATE INDEX IF NOT EXISTS VisitedSystems_position ON VisitedSystems (X, Y, Z)",
         "CREATE INDEX IF NOT EXISTS TravelLogUnit_Name ON TravelLogUnit (Name)"
     };
     using (SQLiteConnectionUser conn = new SQLiteConnectionUser())
     {
         foreach (string query in queries)
         {
             using (DbCommand cmd = conn.CreateCommand(query))
             {
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
コード例 #23
0
 static public double GetSettingDouble(string key, double defaultvalue)
 {
     return(SQLiteConnectionUser.GetSettingDouble(key, defaultvalue));
 }
コード例 #24
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
        private static bool UpgradeUserDB(SQLiteConnectionUser conn)
        {
            int dbver;
            try
            {
                dbver = GetSettingInt("DBVer", 1, conn);        // use the constring one, as don't want to go back into ConnectionString code
                if (dbver < 101)
                    UpgradeUserDB101(conn);
                if (dbver < 102)
                    UpgradeUserDB102(conn);

                CreateUserDBTableIndexes();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("UpgradeUserDB error: " + ex.Message);
                MessageBox.Show(ex.StackTrace);
                return false;
            }
        }
コード例 #25
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 // public IF
 public static bool PutSettingString(string key, string strvalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         bool ret = PutSettingString(key, strvalue, cn);
         return ret;
     }
 }
コード例 #26
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 public static double GetSettingDouble(string key, double defaultvalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return GetSettingDouble(key, defaultvalue, cn);
     }
 }
コード例 #27
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
 public bool Delete()
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return Delete(cn);
     }
 }
コード例 #28
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 public static string GetSettingString(string key, string defaultvalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return GetSettingString(key, defaultvalue, cn);
     }
 }
コード例 #29
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
        private bool Add(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("Insert into Bookmarks (StarName, x, y, z, Time, Heading, Note) values (@sname, @xp, @yp, @zp, @time, @head, @note)"))
            {
                cmd.AddParameterWithValue("@sname", StarName);
                cmd.AddParameterWithValue("@xp", x);
                cmd.AddParameterWithValue("@yp", y);
                cmd.AddParameterWithValue("@zp", z);
                cmd.AddParameterWithValue("@time", Time);
                cmd.AddParameterWithValue("@head", Heading);
                cmd.AddParameterWithValue("@note", Note);

                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from Bookmarks"))
                {
                    id = (long)SQLiteDBClass.SQLScalar(cn, cmd2);
                }

                bookmarks.Add(this);
                return true;
            }
        }
コード例 #30
0
ファイル: SQLiteDBClass.cs プロジェクト: mwerle/EDDiscovery
 public static bool PutSettingDouble(string key, double doublevalue)
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         bool ret = PutSettingDouble(key, doublevalue, cn);
         return ret;
     }
 }
コード例 #31
0
 static public bool GetSettingBool(string key, bool defaultvalue)
 {
     return(SQLiteConnectionUser.GetSettingBool(key, defaultvalue));
 }
コード例 #32
0
ファイル: EDDConfig.cs プロジェクト: iainross/EDDiscovery
        public void DeleteCommander(EDCommander cmdr)
        {
            using (SQLiteConnectionUser conn = new SQLiteConnectionUser())
            {
                using (DbCommand cmd = conn.CreateCommand("UPDATE Commanders SET Deleted = 1 WHERE Id = @Id"))
                {
                    cmd.AddParameterWithValue("@Id", cmdr.Nr);
                    cmd.ExecuteNonQuery();
                }
            }

            LoadCommanders();       // refresh in-memory copy
        }
コード例 #33
0
        private bool Add(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("Insert into wanted_systems (systemname) values (@systemname)"))
            {
                cmd.AddParameterWithValue("@systemname", system);
                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                using (DbCommand cmd2 = cn.CreateCommand("Select Max(id) as id from wanted_systems"))
                {
                    id = (long)SQLiteDBClass.SQLScalar(cn, cmd2);
                }
                return true;
            }
        }
コード例 #34
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
 public bool Update()
 {
     using (SQLiteConnectionUser cn = new SQLiteConnectionUser())
     {
         return Update(cn);
     }
 }
コード例 #35
0
        public static bool UpgradeUserDB(SQLiteConnectionUser conn)
        {
            int dbver;
            try
            {
                SQLiteDBClass.ExecuteQuery(conn, "CREATE TABLE IF NOT EXISTS Register (ID TEXT PRIMARY KEY NOT NULL, ValueInt INTEGER, ValueDouble DOUBLE, ValueString TEXT, ValueBlob BLOB)");
                dbver = conn.GetSettingIntCN("DBVer", 1);        // use the constring one, as don't want to go back into ConnectionString code

                DropOldUserTables(conn);

                if (dbver < 2)
                    UpgradeUserDB2(conn);

                if (dbver < 4)
                    UpgradeUserDB4(conn);

                if (dbver < 7)
                    UpgradeUserDB7(conn);

                if (dbver < 9)
                    UpgradeUserDB9(conn);

                if (dbver < 10)
                    UpgradeUserDB10(conn);

                if (dbver < 11)
                    UpgradeUserDB11(conn);

                if (dbver < 12)
                    UpgradeUserDB12(conn);

                if (dbver < 16)
                    UpgradeUserDB16(conn);

                if (dbver < 101)
                    UpgradeUserDB101(conn);

                if (dbver < 102)
                    UpgradeUserDB102(conn);

                if (dbver < 103)
                    UpgradeUserDB103(conn);

                if (dbver < 104)
                    UpgradeUserDB104(conn);

                if (dbver < 105)
                    UpgradeUserDB105(conn);

                CreateUserDBTableIndexes();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("UpgradeUserDB error: " + ex.Message);
                MessageBox.Show(ex.StackTrace);
                return false;
            }
        }
コード例 #36
0
ファイル: BookmarkClass.cs プロジェクト: amatos/EDDiscovery
        private bool Delete(SQLiteConnectionUser cn)
        {
            using (DbCommand cmd = cn.CreateCommand("DELETE FROM Bookmarks WHERE id = @id"))
            {
                cmd.AddParameterWithValue("@id", id);
                SQLiteDBClass.SQLNonQueryText(cn, cmd);

                bookmarks.RemoveAll(x => x.id == id);     // remove from list any containing id.
                return true;
            }
        }
コード例 #37
0
 private static void CreateUserDBTableIndexes()
 {
     string[] queries = new[]
     {
         "CREATE INDEX IF NOT EXISTS TravelLogUnit_Name ON TravelLogUnit (Name)",
         "CREATE INDEX IF NOT EXISTS TravelLogUnit_Commander ON TravelLogUnit(CommanderId)",
         "CREATE INDEX IF NOT EXISTS JournalEntry_TravelLogId ON JournalEntries (TravelLogId)",
         "CREATE INDEX IF NOT EXISTS JournalEntry_EventTypeId ON JournalEntries (EventTypeId)",
         "CREATE INDEX IF NOT EXISTS JournalEntry_EventType ON JournalEntries (EventType)",
         "CREATE INDEX IF NOT EXISTS JournalEntry_EventTime ON JournalEntries (EventTime)",
     };
     using (SQLiteConnectionUser conn = new SQLiteConnectionUser())
     {
         foreach (string query in queries)
         {
             using (DbCommand cmd = conn.CreateCommand(query))
             {
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
コード例 #38
0
        private static void DropOldUserTables(SQLiteConnectionUser conn)
        {
            string[] queries = new[]
            {
                "DROP TABLE IF EXISTS Systems",
                "DROP TABLE IF EXISTS SystemAliases",
                "DROP TABLE IF EXISTS Distances",
                "DROP TABLE IF EXISTS Stations",
                "DROP TABLE IF EXISTS station_commodities",
                "DROP TABLE IF EXISTS Journals",
                "DROP TABLE IF EXISTS VisitedSystems"
            };

            foreach (string query in queries)
            {
                using (DbCommand cmd = conn.CreateCommand(query))
                {
                    cmd.ExecuteNonQuery();
                }
            }
        }
コード例 #39
0
 static public int GetSettingInt(string key, int defaultvalue)
 {
     return(SQLiteConnectionUser.GetSettingInt(key, defaultvalue));
 }