public static List <Aktor> PobierzAktorow() { List <Aktor> aktorzy = new List <Aktor>(); string konfiguracja = "data source=localhost;port=3306;username=root;password=Zizou130"; MySqlConnection laczBaze = new MySqlConnection(konfiguracja); MySqlCommand zapytanie = new MySqlCommand("SELECT * FROM sakila.actor;", laczBaze); MySqlDataReader odczytanie; try { MySqlDataAdapter dataAdapter = new MySqlDataAdapter(zapytanie); laczBaze.Open(); odczytanie = zapytanie.ExecuteReader(); while (odczytanie.Read()) { DateTime dt = new DateTime(); Aktor aktor = new Aktor { ActorID = int.Parse(odczytanie.GetString(0)), FirstName = odczytanie.GetString(1), LastName = odczytanie.GetString(2), LastUpdateOfActor = dt = Convert.ToDateTime(odczytanie.GetString(3)) }; aktorzy.Add(aktor); } } catch (Exception komunikat) { MessageBox.Show(komunikat.Message); } return(aktorzy); }
private void WyswietlAktorowBtn_Click(object sender, RoutedEventArgs e) { WyswietlFimyBtn.Visibility = Visibility.Visible; WyswietlAktorowBtn.Visibility = Visibility.Collapsed; Aktor actor = new Aktor(); List <Aktor> actors = new List <Aktor>(); List <FilmAktor> FM = new List <FilmAktor>(); int filmID = 0; try { filmID = Tabela.SelectedIndex + 1; FM = (film_aktor.Where(x => x.FilmId == filmID)).ToList(); foreach (var item in FM) { foreach (var i in aktor.Where(x => x.ActorID == item.AktorId).ToList()) { actors.Add(i); } } Tabela.ItemsSource = actors; LiczbaRekrdowTxt.Text = actors.Count.ToString(); AktualnyRekordTxt.Text = (Tabela.SelectedIndex + 1).ToString(); } catch (Exception komunikat) { MessageBox.Show(komunikat.Message); } }