public static List<Book> Select(string condition, SQLiteDatabase db) { try { List<Book> books = new List<Book>(); DataTable resultSet = db.GetDataTable(String.Format("SELECT * FROM 'Books' {0}", condition)); foreach (DataRow row in resultSet.Rows) { Book book = new Book(); book.ID = row["id"].ToString(); book.Title = row["Title"].ToString(); book.Isbn = row["ISBN"].ToString(); book.Authors = GetAuthorsFromString(row["Authors"].ToString()); book.Genres = GetGenresFromString(row["Genres"].ToString()); book.Description = row["Description"].ToString(); book.PathName = row["FilePath"].ToString(); book.Publisher = row["Publisher"].ToString(); int siteRating = 0; bool succParsingSite = int.TryParse(row["SiteRating"].ToString(), out siteRating); book.SiteRating = siteRating; int userRating = 0; bool succParsingUser = int.TryParse(row["UserRating"].ToString(), out userRating); book.UserRating = userRating; DateTime publicationDate = DateTime.MinValue; bool succParsingDateTime = DateTime.TryParse(row["PublicationDate"].ToString(), out publicationDate); book.PublicationDate = publicationDate; ulong numOfPages = 0; bool succParsingNumOfPages = ulong.TryParse(row["Pages"].ToString(), out numOfPages); book.NumberOfPages = numOfPages; book.Cover = row["CoverImage"].ToString(); /*string taskStatus = row["taskStatus"].ToString(); switch (int.Parse(taskStatus)) { case 1: tsk.CurrentState = State.InProgress; break; case 2: tsk.CurrentState = State.Failed; break; case 3: tsk.CurrentState = State.Completed; break; default: tsk.CurrentState = State.Waiting; break; }*/ books.Add(book); } return books; } catch (Exception fail) { throw new FSSQLiteException("An error occurred when trying to select a book."); } }
public static Task[] SelectAllTasks(SQLiteDatabase db) { try { List<Task> tasks = new List<Task>(); DataTable resultSet = db.GetDataTable("SELECT * FROM 'Tasks' WHERE taskStatus>=0 ORDER BY taskStatus DESC"); foreach (DataRow row in resultSet.Rows) { Task tsk = new Task(); tsk.PathName = row["taskString"].ToString(); tsk.ID = row["id"].ToString(); tsk.ISBN = row["ISBN"].ToString(); string taskStatus = row["taskStatus"].ToString(); switch (int.Parse(taskStatus)) { case 1: tsk.CurrentState = State.InProgress; break; case 2: tsk.CurrentState = State.Failed; break; case 3: tsk.CurrentState = State.Completed; break; default: tsk.CurrentState = State.Waiting; break; } tasks.Add(tsk); } return tasks.ToArray(); } catch (Exception fail) { throw new FSSQLiteException("An error occurred when trying to select a task."); } }
/// <summary> /// Get all books from DB and insert them in a List /// </summary> public override void CreateMediaLibrary() { SQLiteDatabase database = new SQLiteDatabase(); string query = "SELECT * FROM Books"; DataTable books = database.GetDataTable(query); foreach (DataRow b in books.Rows) { Book book = new Book(); book.Isbn = b["isbn"].ToString(); book.Title = b["title"].ToString(); book.Publisher = b["publisher"].ToString(); //book.SiteRating = (decimal?)b["rating"]??0; book.SiteRating = 0; //book.UserRating = (decimal?)b["userRating"]; book.UserRating = 0; //book.PublicationDate = (DateTime?)b["datePublication"] ?? DateTime.MinValue; int genreId = int.Parse(b["genres"].ToString()); DataTable genresTable = database.GetItemById("Genres", genreId); foreach (DataRow genre in genresTable.Rows) { book.Genres.Add(new Genre { Name = genre.ToString() }); } //book.NumberOfPages = ulong.Parse(b["pages"].ToString()); book.NumberOfPages = 0; book.Description = b["description"].ToString(); this.MediaList.Add(book); } //throw new NotImplementedException(); }