Exemplo n.º 1
0
        //ApiKey = "9f2df9da";
        //

        public static void GetResponse(string SearchType, string SearchParam, ref MovieResponse RespObj)
        {
            string url = "http://www.omdbapi.com/?t=&apikey=9f2df9da" + "&" + SearchType + "=" + SearchParam;

            using (var webClient = new WebClient())
            {
                webClient.Encoding = Encoding.UTF8;
                var json       = webClient.DownloadString(url);
                var jsonObject = JObject.Parse(json);

                if (jsonObject["Response"].ToString() == "True")
                {
                    if (SearchType == "i")
                    {
                        RespObj = JsonConvert.DeserializeObject <Movie>(json);
                    }
                    else if (SearchType == "s")
                    {
                        RespObj = JsonConvert.DeserializeObject <SearchMovie>(json);
                    }
                }
                else
                {
                    throw new Exception("Error: Movie not found!");
                }
            }
        }
Exemplo n.º 2
0
        //------------------------------------------------------------------------------------
        private void MoreForm_Load(object sender, EventArgs e)
        {
            if (Uri.IsWellFormedUriString(SelectedMovie.Poster, UriKind.Absolute))
            {
                Poster.Load(SelectedMovie.Poster);
            }

            var mr = new MovieResponse();

            try
            {
                DBConnect.GetResponse("i", SelectedMovie.imdbID, ref mr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Movie movie = mr as Movie;

            labelTitle.Text = movie.Title;
            MyLabel LabelMore = new MyLabel();

            tableLayoutPanel1.Controls.Add(LabelMore);
            LabelMore.Dock = DockStyle.Fill;

            LabelMore.Text = movie.ToString();

            buttonOK.Focus();
        }
Exemplo n.º 3
0
        //------------------------------------------------------------------------------------
        private void SearchButton_Click(object sender, EventArgs e)
        {
            shortMList.Clear();

            var mr = new MovieResponse();

            try
            {
                DBConnect.GetResponse("s", Title.Text.Trim(), ref mr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MoreButton.Enabled = false;
            }

            SearchMovie ms = mr as SearchMovie;

            foreach (var item in ms.Search)
            {
                shortMList.Add(item);
            }

            MovieListBox.DataSource = null;
            MovieListBox.DataSource = shortMList;
            MoreButton.Enabled      = true;
            MovieListBox.Focus();
            MovieListBox.SelectedIndex = 0;
            if (Uri.IsWellFormedUriString(shortMList[0].Poster, UriKind.Absolute))
            {
                Poster.Load(shortMList[0].Poster);
            }
        }