Beispiel #1
0
 private void ShowMovieButton_Click(object sender, RoutedEventArgs e)
 {
     if (Search_Results.SelectedIndex == -1)
     {
         MessageBox.Show("Nie wybrano żadnego filmu");
     }
     else
     {
         SearchingMoviesList selected = Search_Results.Items[Search_Results.SelectedIndex] as SearchingMoviesList;
         int         index            = ListOfMovies.FindIndex(a => a.Title == selected.Title);
         MovieWindow Movie            = new MovieWindow(ListOfMovies[index].IdMovie, Reloading, this);
         Movie.ShowDialog();
     }
 }
Beispiel #2
0
 public void SearchDatabase(string SearchContent)
 {
     if (SearchContent == "Czego szukasz ?" || SearchContent == "")
     {
         Search_Results.Items.Clear();
         try
         {
             using (SQLiteConnection DatabaseConnection = new SQLiteConnection("Data Source=database.sqlite3"))
             {
                 DatabaseConnection.Open();
                 string query = "SELECT Movies.idMovie, Movies.Title, Categories.Name FROM Movies, Categories WHERE Movies.idCategory = Categories.idCategory";
                 using (SQLiteCommand Command = new SQLiteCommand(query, DatabaseConnection))
                 {
                     using (SQLiteDataReader result = Command.ExecuteReader())
                     {
                         if (result.HasRows)
                         {
                             while (result.Read())
                             {
                                 ListOfMovies.Add(new SearchingMoviesList(result.GetInt32(0), result[1].ToString(), result[2].ToString()));
                                 var data = new SearchingMoviesList {
                                     Title = result[1].ToString(), CategoryName = result[2].ToString()
                                 };
                                 Search_Results.Items.Add(data);
                             }
                         }
                         else
                         {
                             Search_Results.Items.Clear();
                             throw new Exception("Nie znaleziono filmu");
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         Search_Results.Items.Clear();
         try
         {
             using (SQLiteConnection DatabaseConnection = new SQLiteConnection("Data Source=database.sqlite3"))
             {
                 DatabaseConnection.Open();
                 string query = "SELECT Movies.idMovie, Movies.Title, Categories.Name FROM Movies, Categories WHERE title LIKE '%'||@search||'%' AND Movies.idCategory = Categories.idCategory";
                 using (SQLiteCommand Command = new SQLiteCommand(query, DatabaseConnection))
                 {
                     Command.Parameters.AddWithValue("@search", SearchContent);
                     using (SQLiteDataReader result = Command.ExecuteReader())
                     {
                         if (result.HasRows)
                         {
                             while (result.Read())
                             {
                                 ListOfMovies.Add(new SearchingMoviesList(result.GetInt32(0), result[1].ToString(), result[2].ToString()));
                                 var data = new SearchingMoviesList {
                                     Title = result[1].ToString(), CategoryName = result[2].ToString()
                                 };
                                 Search_Results.Items.Add(data);
                             }
                         }
                         else
                         {
                             Search_Results.Items.Clear();
                             throw new Exception("Nie znaleziono filmu");
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }