private void frmMain_Load(object sender, EventArgs e) { string localAppFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Personal TV Organiser"; _dbManager.DataSource = localAppFolder + "\\db.sqlite"; if (!File.Exists(localAppFolder + "\\db.sqlite")) { if (!Directory.Exists(localAppFolder)) { Directory.CreateDirectory(localAppFolder); } try { _dbManager.CreateDatabase(); _dbManager.InitializeConnection(); _dbManager.OpenConnection(); _dbManager.BeginTransaction(); InitializeDatabase(); _dbManager.Commit(); } catch (Exception ex) { MessageBox.Show("There was a problem creating the database"); } finally { if (_dbManager.TheTransaction != null) { _dbManager.Rollback(); } _dbManager.CloseConnection(); } } else { prgMain.Value = 0; prgMain.Visible = true; lblStatus.Visible = true; lblStatus.Text = "Getting Updates..."; _dbManager.InitializeConnection(); bgwUpdate.RunWorkerAsync(); StartTimer(); } try { _dbManager.OpenConnection(); _favourites = _dbManager.GetFavourites(); } catch (Exception ex) { MessageBox.Show("Couldn't read favoutites"); } finally { _dbManager.CloseConnection(); } PopulateUpcomingEpisodes(); PopulateMissedEpisodes(); }
private void chkWatched_Click(object sender, EventArgs e) { if (chkWatched.Checked) { DialogResult result = MessageBox.Show("Are you sure you want to mark this episode as watched?", "Mark as Watched", MessageBoxButtons.YesNo); switch (result) { case System.Windows.Forms.DialogResult.Yes: lastSelectedEpisode.Watched = true; _dbManager.OpenConnection(); _dbManager.BeginTransaction(); _dbManager.UpdateWatchedEpisodes(new List <Episode> { lastSelectedEpisode }); _dbManager.Commit(); _dbManager.CloseConnection(); _items[lastSelectedEpisode.EpisodeID].ApplyColor(Color.FromArgb(0, 192, 192, 192)); break; case System.Windows.Forms.DialogResult.No: chkWatched.Checked = false; break; default: break; } } else { DialogResult result = MessageBox.Show("Are you sure you want to mark this episode as unwatched?", "Mark as Unwatched", MessageBoxButtons.YesNo); switch (result) { case System.Windows.Forms.DialogResult.Yes: lastSelectedEpisode.Watched = false; _dbManager.OpenConnection(); _dbManager.BeginTransaction(); _dbManager.UpdateWatchedEpisodes(new List <Episode> { lastSelectedEpisode }); _dbManager.Commit(); _dbManager.CloseConnection(); if (lastSelectedEpisode.FirstAired <= DateTime.Now) { _items[lastSelectedEpisode.EpisodeID].ApplyColor(Color.FromArgb(0, 255, 0, 0)); } else { _items[lastSelectedEpisode.EpisodeID].RemoveColors(); } break; case System.Windows.Forms.DialogResult.No: chkWatched.Checked = true; break; default: break; } } calendar1.Items.Clear(); PlaceItems(); }
private void btnFavourite_Click(object sender, EventArgs e) { if (btnFavourite.ImageIndex == 0) { Cursor.Current = Cursors.WaitCursor; try { _dbManager.OpenConnection(); _dbManager.BeginTransaction(); _dbManager.InsertSeries(_series); _dbManager.Commit(); dgvEpisodes.Columns["Watched"].Visible = true; MessageBox.Show("Added to Favourites"); toolTip1.SetToolTip(btnFavourite, "Unfavourite"); btnSelectAll.Enabled = true; btnDeselectAll.Enabled = true; btnConfirm.Enabled = true; _favouriteFlag = true; } catch (Exception ex) { MessageBox.Show("Couldn't add series to favourites. Please try again later"); } finally { if (_dbManager.TheTransaction != null) { _dbManager.Rollback(); } _dbManager.CloseConnection(); Cursor.Current = Cursors.Default; } } else { Cursor.Current = Cursors.WaitCursor; try { _dbManager.OpenConnection(); _dbManager.BeginTransaction(); _dbManager.DeleteSeries(_series.SeriesID); _dbManager.Commit(); dgvEpisodes.Columns["Watched"].Visible = false; MessageBox.Show("Removed from Favourites"); toolTip1.SetToolTip(btnFavourite, "Favourite"); btnSelectAll.Enabled = false; btnDeselectAll.Enabled = false; btnConfirm.Enabled = false; _favouriteFlag = true; } catch (Exception ex) { MessageBox.Show("Couldn't remove series from favourites. Please try again later"); } finally { if (_dbManager.TheTransaction != null) { _dbManager.Rollback(); } Cursor.Current = Cursors.Default; } } }
private void bgwUpdate_DoWork(object sender, DoWorkEventArgs e) { Thread.Sleep(100); DatabaseManager.DatabaseManager databaseManager = new DatabaseManager.DatabaseManager(); string localAppFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Personal TV Organiser"; databaseManager.DataSource = localAppFolder + "\\db.sqlite"; databaseManager.InitializeConnection(); Update update = new Update(); List <Series> seriesToUpdate = new List <Series>(); List <Episode> episodesToUpdate = new List <Episode>(); try { databaseManager.OpenConnection(); Dictionary <string, string> settings = databaseManager.GetSettings("previousServerTime"); databaseManager.CloseConnection(); Update updates = _tvdbAPI.GetUpdates(settings["previousServerTime"]); int totalUpdates = _favourites.Count + updates.EpisodeUpdates.Count; int percentProgress = 0; double progress = 0; bgwUpdate.ReportProgress(percentProgress); foreach (int seriesID in _favourites.Keys) { if (updates.SeriesUpdates.Contains(seriesID)) { Series seriesUpdates = _tvdbAPI.GetSeriesUpdates(seriesID); if (seriesUpdates != null) { seriesToUpdate.Add(seriesUpdates); } } ++progress; bgwUpdate.ReportProgress((int)Math.Round(progress / totalUpdates * 100.0)); } foreach (int episodeID in updates.EpisodeUpdates) { Episode episodeUpdates = _tvdbAPI.GetEpisodeUpdates(episodeID); if (episodeUpdates != null) { if (_favourites.Keys.Contains(episodeUpdates.SeriesID)) { episodesToUpdate.Add(episodeUpdates); } } ++progress; bgwUpdate.ReportProgress((int)Math.Round(progress / totalUpdates * 100.0)); } databaseManager.OpenConnection(); databaseManager.BeginTransaction(); foreach (Series series in seriesToUpdate) { databaseManager.UpdateSeries(series); } string seriesName = ""; foreach (Episode episode in episodesToUpdate) { seriesName = _favourites[episode.SeriesID].SeriesName; databaseManager.UpdateEpisode(episode, seriesName); } databaseManager.UpdateSetting("previousServerTime", updates.Time); databaseManager.Commit(); bgwUpdate.ReportProgress(100); } catch (Exception ex) { } finally { if (databaseManager.TheTransaction != null) { databaseManager.Rollback(); } databaseManager.CloseConnection(); } }