예제 #1
0
        /// <summary>
        /// Adds a new user account.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public void AddAccount(string username, string password)
        {
            try
            {
                using (var conn = new SQLite.SQLiteConnection (dbPath))
                {
                    var cmd = new SQLite.SQLiteCommand (conn);
                    cmd.CommandText = "insert into accounts(username,password) values('" + username + "','" + password + "')";
                    cmd.ExecuteNonQuery();
                }

            } catch (Exception ex) {
                Console.WriteLine ("Error:" + ex.Message);
            }
        }
예제 #2
0
 //Function for executing qurey to the database, pass in query string
 public void runQuery(string query)
 {
     try
     {
         using (var conn = new SQLite.SQLiteConnection(dbPath))
         {
             var cmd = new SQLite.SQLiteCommand(conn);
             cmd.CommandText = query;
             var rowcount = cmd.ExecuteNonQuery();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error:" + e.Message);
     }
 }
예제 #3
0
 public void editNote(string title, string body, string id)
 {
     try
     {
         using (var conn = new SQLite.SQLiteConnection(dbPath)) //----------------------------------------------------------Prepares connection to database
         {
             var cmd = new SQLite.SQLiteCommand(conn); //-------------------------------------------------------------------Prepares communication with database
             string sql = "UPDATE NOTES_TBL SET Title = '" + title + "', Body = '" + body + "' WHERE  NoteID = " + id; //---SQLite query to pass back
             cmd.CommandText = sql; //--------------------------------------------------------------------------------------Passes query to db
             cmd.ExecuteNonQuery(); //--------------------------------------------------------------------------------------Writes information to db
             ViewAll(); //--------------------------------------------------------------------------------------------------Gets a list of the notes and passes it in
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error: " + e.Message); //-----------------------------------------------------------------------Write error in english to output
     }
 }
예제 #4
0
 public void writeNote(string title, string dt, string body)
 {
     try
     {
         using (var conn = new SQLite.SQLiteConnection(dbPath)) //--------------------------------------------------------------Prepares connection to database
         {
             var cmd = new SQLite.SQLiteCommand(conn); //-----------------------------------------------------------------------Prepares communication with database
             string sql = "Insert into NOTES_TBL (Title, Body, Dt) values ('" + title + "','" + body + "', '" + dt + "')"; //---SQLite query to pass back
             cmd.CommandText = sql; //------------------------------------------------------------------------------------------Passes query to db
             cmd.ExecuteNonQuery(); //------------------------------------------------------------------------------------------Writes information to db
             ViewAll(); //------------------------------------------------------------------------------------------------------Gets a list of the notes and passes it in
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error: " + e.Message); //---------------------------------------------------------------------------Write error in english to output
     }
 }
예제 #5
0
        /// <summary>
        /// Sets the new highscore.
        /// </summary>
        /// <param name="username">Username.</param>
        /// <param name="score">Score.</param>
        public void setNewHighscore(string username, int score)
        {
            try
            {
                using (var conn = new SQLite.SQLiteConnection (dbPath))
                {
                    var cmd = new SQLite.SQLiteCommand (conn);
                    cmd.CommandText = "insert into highscores(username,score) values('" + username + "','" + score + "')";
                    cmd.ExecuteNonQuery();
                }

            } catch (Exception ex) {
                Console.WriteLine ("Error:" + ex.Message);
            }
        }