public void UpDateLastReadPage(ComicBook comicBook, int currentPage) { if (comicBook == null) { return; } ComicProgress progress; if (comicProgress.TryGetValue(comicBook.Id, out progress)) { progress.LastPageRead = currentPage; progress.CurrentPage = currentPage; progress.DateLastRead = System.DateTime.Now.ToString("s"); Database.Instance.ExecuteNonQuery("UPDATE comic_progress SET current_page = " + progress.CurrentPage + ", last_page_read = " + progress.LastPageRead + ", date_last_read = '" + progress.DateLastRead + "' WHERE id = " + progress.DatabaseId); } else { progress = new ComicProgress(); progress.Id = comicBook.Id; progress.LastPageRead = currentPage; progress.CurrentPage = currentPage; progress.DateLastRead = System.DateTime.Now.ToString("s"); Database.Instance.ExecuteNonQuery("INSERT INTO comic_progress (user_id, comic_id, current_page, last_page_read, date_last_read) VALUES(" + UserId + ", '" + progress.Id.ToString() + "', " + progress.CurrentPage + ", " + progress.LastPageRead + ", '" + progress.DateLastRead + "');"); progress.DatabaseId = (int)Database.Instance.GetLastInsertRowId(); comicProgress[comicBook.Id] = progress; } if (settings.use_comicrack_progress) { // Save the progess to the ComicRack database as well comicBook.CurrentPage = currentPage; comicBook.LastPageRead = currentPage; } }
// Cache expensive properties // Drawback: any updates to the original ComicBook will not be propagated. // However, this Comic class is not meant to be used for a long time. It is used for providing a // json serializable class for returning search results. //private readonly Lazy<string> _caption = null; //public string Caption { get { return _caption.Value; } } #endregion Fields #region Constructors public Comic(ComicBook source, BCRUser user) { book = source; useComicrackProgress = user.settings.use_comicrack_progress; progress = useComicrackProgress ? null : user.GetComicProgress(source.Id); //_caption = new Lazy<string>(() => { return book.Caption; }); }
public void Initialize() { settings.Load(this); comicProgress.Clear(); using (SQLiteDataReader reader = Database.Instance.ExecuteReader("SELECT id, comic_id, current_page, last_page_read, date_last_read FROM comic_progress WHERE user_id = " + UserId + ";")) { while (reader.Read()) { ComicProgress progress = new ComicProgress(); progress.DatabaseId = reader.GetInt32(0); progress.Id = new Guid(reader.GetString(1)); progress.CurrentPage = reader.GetInt32(2); progress.LastPageRead = reader.GetInt32(3); progress.DateLastRead = reader.GetString(4); comicProgress[progress.Id] = progress; } } }