void getFilmById(int senddata) { var request = (HttpWebRequest)WebRequest.Create(URL + "RechercheCC.GetFilmById?numero=" + senddata); var response = (HttpWebResponse)request.GetResponse(); String json = new StreamReader(response.GetResponseStream()).ReadToEnd(); film = JsonConvert.DeserializeObject <SimpleFilm>(json); }
private void RechercheButton_Click(object sender, RoutedEventArgs e) { DateTime date; films = null; film = null; if (FilmIdBR.IsChecked == true) { try { getFilmById(int.Parse(RechercherTB.Text)); NotFoundLabel.Visibility = Visibility.Hidden; if (film != null) { TitleSimpleTB.Text = film.title; OriginalTitleSimpleTB.Text = film.original_title; StatusSimpleTB.Text = film.status; ReleaseDateSimpleTB.Text = film.release_date; SimpleDisplayCanvas.Visibility = Visibility.Visible; } } catch (ArgumentException) { MessageBox.Show("Vous devez entrer un numéro.", "Id de film invalide !", MessageBoxButton.OK, MessageBoxImage.Error); } catch (FormatException) { MessageBox.Show("Vous devez entrer un numéro.", "Id de film invalide !", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { NotFoundLabel.Visibility = Visibility.Visible; SimpleDisplayCanvas.Visibility = Visibility.Hidden; } return; } else if (FilmBR.IsChecked == true) { getFilmByCritere("TITLE=[" + RechercherTB.Text + "]"); } else if (ActeurBR.IsChecked == true) { getFilmByCritere("ACTORS=[" + RechercherTB.Text + "]"); } else if (DirectorBR.IsChecked == true) { getFilmByCritere("DIRECTORS=[" + RechercherTB.Text + "]"); } else if (DateBR.IsChecked == true) { if (DateTime.TryParse(RechercherTB.Text, out date)) { if (EqualsDateBR.IsChecked == true) { getFilmByCritere("DATE=[eq" + String.Format("{0:d/MM/yyyy}", date) + "]"); } else if (InfDateBR.IsChecked == true) { getFilmByCritere("DATE=[in" + String.Format("{0:d/MM/yyyy}", date) + "]"); } else if (SupDateBR.IsChecked == true) { getFilmByCritere("DATE=[su" + String.Format("{0:d/MM/yyyy}", date) + "]"); } } else { MessageBox.Show("Le champ doit être au format date (exemple: DD-MM-YYYY).", "Date invalide !", MessageBoxButton.OK, MessageBoxImage.Error); return; } } else if (OthersBR.IsChecked == true) { String to_send = ""; int centrale = (!PersoSurCentraleCB.IsChecked.Value) ? 1 : 0; if (PersoDateTB.Text.Length > 0) { if (!DateTime.TryParse(PersoDateTB.Text, out date)) { MessageBox.Show("Le champ Date doit être au format date (exemple: DD-MM-YYYY).", "Date invalide !", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (PersoDateEqRadio.IsChecked == true) { to_send += "DATE=[eq" + PersoDateTB.Text; } else if (PersoDateInRadio.IsChecked == true) { to_send += "DATE=[in" + PersoDateTB.Text; } else if (PersoDateSuRadio.IsChecked == true) { to_send += "DATE=[su" + PersoDateTB.Text; } } if (PersoTitleTB.Text.Length > 0) { if (to_send.Length > 0) { to_send += "]"; } to_send += "TITLE=[" + PersoTitleTB.Text; } if (PersoActorsTB.Text.Length > 0) { if (to_send.Length > 0) { to_send += "]"; } to_send += "ACTORS=[" + PersoActorsTB.Text; } if (PersoDirectorsTB.Text.Length > 0) { if (to_send.Length > 0) { to_send += "]"; } to_send += "DIRECTORS=[" + PersoDirectorsTB.Text; } if (to_send.Length > 0) { to_send += "]"; } getFilmByCritere(to_send, centrale); } if (films == null || films.Count == 0) { MessageBox.Show("L'élément \"" + RechercherTB.Text + "\" ne se trouves pas dans la base de données !", "Rien n'a été trouvé !", MessageBoxButton.OK, MessageBoxImage.Error); } else { PageMinTB.Text = "1"; PageMaxTB.Text = films.Count.ToString(); FilmTitleTB.Text = films.ElementAt(0).title; PreviewButton.Visibility = Visibility.Hidden; InfosFilmCanvas.Visibility = Visibility.Visible; if (films.Count > 1) { NextButton.Visibility = Visibility.Visible; } RefreshFilm(0); } }