//***************************************************************************************** //***************************************************************************************** /// <summary> /// /// </summary> /// <param name="gear"></param> public List <Gear_Note> GetGearNotes(GearType gear) { var notes = new List <Gear_Note>(); SQLiteDataReader sqlite_datareader; string query = "Select note, author, time_stamp FROM gear_notes WHERE gear_cat_id = @catID AND gear_idv_id = @idvID ORDER BY time_stamp ASC;"; SQLiteCommand command = m_dbConnection.CreateCommand(); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@catID", gear.CatId)); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@idvID", gear.IdvId)); command.CommandText = query; sqlite_datareader = command.ExecuteReader(); Gear_Note temp = new Gear_Note(); try { sqlite_datareader.Read(); while (sqlite_datareader.Read()) { temp.NoteText = sqlite_datareader.GetString(0); temp.Author = sqlite_datareader.GetString(1); temp.TimeStamp = DateTime.ParseExact(sqlite_datareader.GetString(2), "yyyy/MM/dd HH:mm::ss", null); notes.Add(temp); //**************************************** // Debug Code //**************************************** //Console.Out.WriteLine(temp.ToString()); //**************************************** temp = new Gear_Note(); } ; } catch (InvalidCastException e) { Console.Out.WriteLine(e.Message); Console.Out.WriteLine(e.InnerException); Console.Out.WriteLine(e.Source); } return(notes); }
//***************************************************************************************** //***************************************************************************************** public void AddGearNote(int catId, int idvId, Gear_Note note) { string query = "INSERT INTO gear_notes (gear_cat_id, gear_idv_id, note, author, time_stamp) VALUES (@gear_cat_id, @gear_idv_id,@note, @author,@time_stamp);"; SQLiteCommand command = m_dbConnection.CreateCommand(); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@gear_cat_id", catId)); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@gear_idv_id", idvId)); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@note", note.NoteText)); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@author", note.Author)); command.Parameters.Add(new System.Data.SQLite.SQLiteParameter("@time_stamp", note.TimeStamp.ToString(DT_FORMAT))); command.CommandText = query; int rows = command.ExecuteNonQuery(); if (rows == 0) { // Error, no rows effected //todo error handling } }
private void Add_Note_Button_Click(object sender, RoutedEventArgs e) { // Assuming that a valid item is scanned. // TODO make sure the "AddNote" button is disabled when an Item is not scanned in Gear_Note note = new Gear_Note(); note.NoteText = NoteTextTextBox.Text; note.Author = NoteAuthorTextBox.Text; note.TimeStamp = DateTime.Now; int catId = 1; int gearId = 1; Sqlite3_Interface.Instance.AddGearNote(catId, gearId, note); UpdateGearNotes(catId, gearId); ClearAddNoteFields(); }