Ejemplo n.º 1
0
        private void onClick_Add(object sender, RoutedEventArgs e)
        {
            ShowRecord record    = (ShowRecord)imdbShows.SelectedItem;
            ShowRecord newRecord = _repo.addFromImdb(record.imdbID);

            _show.Title        = newRecord.Title;
            _show.Genre        = newRecord.Genre;
            _show.IsFinished   = false;
            _show.totalSeasons = newRecord.totalSeasons;
            _show.imdbID       = newRecord.imdbID;
            MessageBoxResult result = MessageBox.Show("Are you sure you want to add the following show?" +
                                                      "\nName of the show: " + _show.Title +
                                                      "\nGenre of the show: " + _show.Genre +
                                                      "\nTotal seasons in the show: " + newRecord.totalSeasons, "Confirmation",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                if (!_repo.addNewShow(_show))
                {
                    MessageBox.Show("The show with the same name already exists");
                }
                else
                {
                    var showEpisodes = _repo.getEpisodesInSeasons(_show.imdbID);
                    var id           = _repo.getIdOfExistingShow(_show.Title);
                    _repo.addEpisodesToShow(id, showEpisodes);
                    MessageBox.Show("The new show has been added. Please select your current episode");
                    ViewAllEpisodes eps = new ViewAllEpisodes(_show.Title);
                    eps.episodes.ItemsSource = _repo.getAllEpisodesInShow(_show.Title);
                    eps.Show();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtains all episodes for particular show
        /// </summary>
        /// <param name="movieId">AN imdb id of the show</param>
        /// <returns>A dictionary of season and episodes</returns>
        public Dictionary <int, List <EpisodeRecord> > getEpisodesInSeasons(string movieId)
        {
            int    seasonCounter = 1;
            string url           = "";
            Dictionary <int, List <EpisodeRecord> > result = new Dictionary <int, List <EpisodeRecord> >();
            ShowRecord record       = new ShowRecord();
            int        totalSeasons = addFromImdb(movieId).totalSeasons;
            var        webClient    = new WebClient();

            while (seasonCounter <= totalSeasons)
            {
                url = "http://www.omdbapi.com/?i=" + movieId + "&type=series&r=json&Season=" + seasonCounter;
                var json = string.Empty;
                try
                {
                    json = webClient.DownloadString(url);
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                record = JsonConvert.DeserializeObject <ShowRecord>(json);
                result.Add(seasonCounter, record.Episodes);
                seasonCounter++;
            }
            return(result);
        }
Ejemplo n.º 3
0
 private void checkForNewEpisodes_Click(object sender, RoutedEventArgs e)
 {
     _show = (ShowRecord)shows.SelectedItem;
     if (_repo.findImdbId(_show.Title) == "Manual")
     {
         MessageBox.Show("Cannot perform the operation for manually added shows");
     }
     else
     {
         if (_repo.checkIfInternetConnectionExists())
         {
             if (_repo.CheckIfApiIsOnline("http://www.omdbapi.com/", 5000))
             {
                 if (_repo.checkForNewEpisodes(_show.Title))
                 {
                     ViewAllEpisodes allEpisodes = new ViewAllEpisodes();
                     allEpisodes.episodes.ItemsSource = _repo.getAllEpisodesInShow(_show.Title);
                     allEpisodes.Show();
                 }
             }
             else
             {
                 MessageBox.Show("The online resource is currently unavailable. Please try again later");
             }
         }
         else
         {
             MessageBox.Show("Please check your internet connection");
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds new show entry to the database
        /// </summary>
        /// <param name="show">A show to add</param>
        public void createNewEntry(ShowRecord show)
        {
            string query = string.Format("Insert into Shows (Title, Genre, CurrentEpisode, CurrentSeason, IsFinished, TotalSeasons, ImdbId)"
                                         + " values (@Title, @Genre, @CurrentEpisode, @CurrentSeason, @IsFinished, @TotalSeasons, @ImdbId);");
            var conn    = new SqlConnection(connectionString);
            var command = new SqlCommand(query, conn);

            command.Parameters.AddWithValue("@Title", show.Title);
            command.Parameters.AddWithValue("@Genre", show.Genre);
            command.Parameters.AddWithValue("@CurrentEpisode", show.CurrentEpisode);
            command.Parameters.AddWithValue("@CurrentSeason", show.CurrentSeason);
            command.Parameters.AddWithValue("@IsFinished", show.IsFinished);
            command.Parameters.AddWithValue("@TotalSeasons", show.totalSeasons);
            command.Parameters.AddWithValue("@ImdbId", show.imdbID);
            try
            {
                conn.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if ((conn.State == ConnectionState.Open))
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Changes details of the show in accordance to the given input
        /// </summary>
        /// <param name="record">A show to change</param>
        /// <param name="oldName">An original name, required for keeping track of the show</param>
        public void editEntry(ShowRecord record, string oldName, int id)
        {
            string query = string.Format("Update Shows set Title=@Title, Genre=@Genre, CurrentEpisode=@CurrentEpisode," +
                                         " CurrentSeason=@CurrentSeason, IsFinished=@IsFinished, TotalSeasons=@TotalSeasons where ShowId=@IdofShow;");
            var conn    = new SqlConnection(connectionString);
            var command = new SqlCommand(query, conn);

            command.Parameters.AddWithValue("@Title", record.Title);
            command.Parameters.AddWithValue("@Genre", record.Genre);
            command.Parameters.AddWithValue("@CurrentEpisode", record.CurrentEpisode);
            command.Parameters.AddWithValue("@CurrentSeason", record.CurrentSeason);
            command.Parameters.AddWithValue("@IsFinished", record.IsFinished);
            command.Parameters.AddWithValue("@TotalSeasons", record.totalSeasons);
            command.Parameters.AddWithValue("@OldTitle", oldName);
            command.Parameters.AddWithValue("@IdofShow", id);
            try
            {
                conn.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if ((conn.State == ConnectionState.Open))
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Removes show from the programme
        /// </summary>
        /// <param name="show">A show to remove</param>
        public void removeShow(ShowRecord show)
        {
            var id = getIdOfExistingShow(show.Title);

            removeEpisodes(id);
            _db.removeEntry(id);
        }
Ejemplo n.º 7
0
        private void ViewEpisodes_Click(object sender, RoutedEventArgs e)
        {
            _record = (ShowRecord)unfinishedShows.SelectedItem;
            ViewAllEpisodes eps = new ViewAllEpisodes();

            eps.episodes.ItemsSource = _repo.getAllEpisodesInShow(_record.Title);
            eps.Show();
        }
Ejemplo n.º 8
0
        private void viewEpisodes_Click(object sender, RoutedEventArgs e)
        {
            _show = (ShowRecord)shows.SelectedItem;
            ViewAllEpisodes allEpisodes = new ViewAllEpisodes(_show.Title);

            allEpisodes.episodes.ItemsSource = _repo.getAllEpisodesInShow(_show.Title);
            allEpisodes.Closed += ChildWindowClosed;
            allEpisodes.Show();
        }
Ejemplo n.º 9
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            _record = (ShowRecord)unfinishedShows.SelectedItem;
            EditEntry entry = new EditEntry(_record.Title);

            entry.Closed     += ChildWindowClosed;
            entry.DataContext = _record;
            entry.Show();
        }
Ejemplo n.º 10
0
        private void onClick_Edit(object sender, RoutedEventArgs e)
        {
            _show = (ShowRecord)shows.SelectedItem;
            EditEntry entry = new EditEntry(_show.Title);

            entry.DataContext = _show;
            entry.Closed     += ChildWindowClosed;
            entry.Show();
        }
Ejemplo n.º 11
0
        private void RemoveUnfinished_Click(object sender, RoutedEventArgs e)
        {
            _record = (ShowRecord)unfinishedShows.SelectedItem;
            MessageBoxResult result = MessageBox.Show("Are you sure you want to remove this show from the list of unfinished shows?"
                                                      , "confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            _record.IsFinished = true;
            _repo.editShow(_record, _record.Title);
            unfinishedShows.ItemsSource = _repo.getAllUnfinishedShows();
        }
Ejemplo n.º 12
0
        private void CompletelyRemove_Click(object sender, RoutedEventArgs e)
        {
            _record = (ShowRecord)unfinishedShows.SelectedItem;
            MessageBoxResult result = MessageBox.Show("Are you sure you want to completely remove this show?This action will remove" +
                                                      " the selected show and all it's related data from the app.", "confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                _repo.removeShow(_record);
            }
        }
Ejemplo n.º 13
0
        private void onClick_Remove(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this record?", "Confirmation",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                _show = (ShowRecord)shows.SelectedItem;
                _repo.removeShow(_show);
            }
            shows.ItemsSource = _repo.getAllShows();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Opens IMDB page of the show
        /// </summary>
        /// <param name="id">Id at imdb to pass to the browser</param>
        public void openTheimdbPage(ShowRecord record)
        {
            string id = findImdbId(record.Title);

            if (id == "Manual")
            {
                MessageBox.Show("Cannot perform this action for manually added TV series");
            }
            else
            {
                System.Diagnostics.Process.Start("http://www.imdb.com/title/" + id);
            }
        }
Ejemplo n.º 15
0
        private void CheckForNewEpisodes_Click(object sender, RoutedEventArgs e)
        {
            _record = (ShowRecord)unfinishedShows.SelectedItem;
            string id = _repo.findImdbId(_record.Title);

            if (id == "Manual")
            {
                MessageBox.Show("Cannot perform the operation for manually added shows");
            }
            else
            {
                _repo.checkForNewEpisodes(_record.Title);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Add new show to the programme
        /// </summary>
        /// <param name="show">A show to add</param>
        /// <returns>Returns true if the show was added successfully, else false</returns>
        public bool addNewShow(ShowRecord show)
        {
            bool success = false;

            if (!checkIfShowAlreadyExists(show))
            {
                if (show.imdbID == null)
                {
                    show.imdbID = "Manual";
                }
                _db.createNewEntry(show);
                success = true;
            }
            return(success);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets all show entries with the name that are similar to the one given by the user
        /// </summary>
        /// <param name="name">A name of the shows to search for</param>
        /// <returns>A list of found shows</returns>
        public List <ShowRecord> getAllEntriesWithName(string name)
        {
            var    shows   = new List <ShowRecord>();
            var    conn    = new SqlConnection(connectionString);
            string query   = "Select * from Shows where Title like @names;";
            var    command = new SqlCommand(query, conn);

            try
            {
                command.Parameters.AddWithValue("@names", name + "%");
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ShowRecord show = new ShowRecord();
                        show.Title          = reader.GetString(reader.GetOrdinal("Title"));
                        show.Genre          = reader.GetString(reader.GetOrdinal("Genre"));
                        show.CurrentEpisode = reader.GetInt32(reader.GetOrdinal("CurrentEpisode"));
                        show.CurrentSeason  = reader.GetInt32(reader.GetOrdinal("CurrentSeason"));
                        show.IsFinished     = reader.GetBoolean(reader.GetOrdinal("IsFinished"));
                        show.totalSeasons   = reader.GetInt32(reader.GetOrdinal("TotalSeasons"));
                        show.imdbID         = reader.GetString(reader.GetOrdinal("ImdbId"));
                        shows.Add(show);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                if ((conn.State == ConnectionState.Open))
                {
                    conn.Close();
                }
            }
            return(shows);
        }
Ejemplo n.º 18
0
        private void button_Save(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Are the new details correct?" +
                                                      "\nName of the show: " + namebox.Text +
                                                      "\nGenre of the show: " + genreBox.Text +
                                                      "\nTotal seasons in the show: " + Int32.Parse(seasonsCountBox.Text) +
                                                      "\nCurrent season: " + Int32.Parse(currentSeasonBox.Text) +
                                                      "\nCurrent episode: " + Int32.Parse(currentEpBox.Text) +
                                                      "\nHave you finished watching the show? " + isFinishedBox.IsChecked.Value, "Confirmation",
                                                      MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                _show                = new ShowRecord();
                _show.Title          = namebox.Text;
                _show.Genre          = genreBox.Text;
                _show.CurrentEpisode = Int32.Parse(currentEpBox.Text);
                _show.CurrentSeason  = Int32.Parse(currentSeasonBox.Text);
                _show.IsFinished     = isFinishedBox.IsChecked.Value;
                _show.totalSeasons   = Int32.Parse(seasonsCountBox.Text);
                if (_show.Title == _oldTitle)
                {
                    _repo.editShow(_show, _oldTitle);
                    this.Close();
                }
                else if (!_repo.checkIfShowAlreadyExists(_show))
                {
                    _repo.editShow(_show, _oldTitle);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("The show with the same name already exists");
                    namebox.Text = _oldTitle;
                }
            }
        }
Ejemplo n.º 19
0
        private void onClick_Imdb(object sender, RoutedEventArgs e)
        {
            ShowRecord record = (ShowRecord)imdbShows.SelectedItem;

            _repo.openTheimdbPage(record);
        }
Ejemplo n.º 20
0
 private void ImdbView_Click(object sender, RoutedEventArgs e)
 {
     _record = (ShowRecord)unfinishedShows.SelectedItem;
     _repo.openTheimdbPage(_record);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Changes details of the show to the new user inputs
        /// </summary>
        /// <param name="show">Shot to change</param>
        /// <param name="oldName">An original name of the show, required for track keeping</param>
        public void editShow(ShowRecord show, string oldName)
        {
            var id = getIdOfExistingShow(oldName);

            _db.editEntry(show, oldName, id);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Checks if particular show already exists in the database while editing the item
 /// </summary>
 /// <param name="show">Show to check</param>
 /// <returns>True if exists else false</returns>
 public bool checkIfShowAlreadyExists(ShowRecord show)
 {
     return(_db.checkForExistingShowEntry(show.Title));
 }
Ejemplo n.º 23
0
 private void Confirm_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     _show     = new ShowRecord();
     e.Handled = true;
 }
Ejemplo n.º 24
0
        private void imdbView_Click(object sender, RoutedEventArgs e)
        {
            ShowRecord record = (ShowRecord)shows.SelectedItem;

            _repo.openTheimdbPage(record);
        }