Beispiel #1
0
        private static void WriteToDB(string searchText, EpisodeInformation episode)
        {
            var connStr = ConfigurationManager.ConnectionStrings["ShowAlerts.Properties.Settings.ShowDBConnectionString"].ConnectionString;

            using (var connection = new SqlConnection(connStr))
            {
                var cmd = new SqlCommand("Insert into [dbo].[Table] Values (@ShowName, @PrevDate, @PrevEpisode,@NextDate, @NextEpisode)");
                cmd.CommandType = CommandType.Text;
                cmd.Connection  = connection;
                cmd.Parameters.AddWithValue("@ShowName", episode.EpisodeName);
                cmd.Parameters.AddWithValue("@PrevDate", episode.PrevDate);
                cmd.Parameters.AddWithValue("@PrevEpisode", episode.PrevEpisode);
                cmd.Parameters.AddWithValue("@NextDate", episode.NextDate);
                cmd.Parameters.AddWithValue("@NextEpisode", episode.NextEpisode);
                connection.Open();
                cmd.ExecuteNonQuery();
            }
            System.Windows.Forms.MessageBox.Show("Success!");
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (CheckDB(search.Text))
            {
                return;
            }

            EpisodeInformation episode = new EpisodeInformation();

            using (WebClient wc = new WebClient())
            {
                try {
                    var json = wc.DownloadString(@"http://api.tvmaze.com/singlesearch/shows?q=" + search.Text);

                    dynamic showJsonObject = JsonConvert.DeserializeObject(json);
                    episode.SetEpisodeName(showJsonObject.name);
                    if (showJsonObject._links.nextepisode != null)
                    {
                        var nextEpisodeLink = showJsonObject._links.nextepisode.href.Value;
                        episode.GetDateFromJson(wc, nextEpisodeLink, true);
                    }

                    if (showJsonObject._links.previousepisode != null)
                    {
                        var prevEpisodeLink = showJsonObject._links.previousepisode.href.Value;
                        episode.GetDateFromJson(wc, prevEpisodeLink, false);
                    }
                    WriteToDB(search.Text, episode);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("404"))
                    {
                        MessageBox.Show("Could not find tv show");
                    }
                    else
                    {
                        MessageBox.Show("An unknown error has occured");
                    }
                }
            }
        }