private void GetInfoFromISBN(string isbn, string technology) { if (isbn.Length != 10) { return; } AWSProductData productData = new AWSProductData(); ItemLookup lookup = null; try { ItemLookupRequest req = new ItemLookupRequest(); req.IdType = ItemLookupRequestIdType.ASIN; req.ItemId = new string[1]; req.ItemId[0] = isbn; // req.SearchIndex = "Books"; lookup = new ItemLookup(); lookup.AssociateTag = "libertyassocia00A"; lookup.SubscriptionId = "0SD959SZV6KXV3BKE2R2"; lookup.Request = new ItemLookupRequest[1]; lookup.Request[0] = req; } catch (System.Exception e) { lblStatus.Text = e.Message; } ItemLookupResponse response; Items info; Item[] items; Item item; int salesRank = -1; string author = string.Empty; string pubDate = string.Empty; string publisher = string.Empty; string title = string.Empty; string strURL = string.Empty; try { response = productData.ItemLookup(lookup); info = response.Items[0]; items = info.Item; item = items[0]; salesRank = item.SalesRank == null ? -1 : Convert.ToInt32(item.SalesRank); author = FixQuotes(item.ItemAttributes.Author[0]); pubDate = FixQuotes(item.ItemAttributes.PublicationDate); publisher = FixQuotes(item.ItemAttributes.Publisher); title = FixQuotes(item.ItemAttributes.Title); strURL = item.DetailPageURL; } catch (System.Exception ex) { lblStatus.Text = ex.Message; } // update the list box string results = title + " by " + author + ": " + publisher + ", " + pubDate + ". Rank: " + salesRank; lbOutput.Items.Add(results); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; // update the database string commandString = @"Update BookInfo set isbn = '" + isbn + "', title = '" + title + "', publisher = '" + publisher + "', pubDate = '" + pubDate + "', rank = " + salesRank + ", link = '" + strURL + "', lastUpdate = '" + System.DateTime.Now + "', technology = '" + technology + "', author = '" + author + "' where isbn = '" + isbn + "'"; command.CommandText = commandString; try { // if no rows were affected, this is a new record connection.Open(); int numRowsAffected = command.ExecuteNonQuery(); if (numRowsAffected == 0) { commandString = @"Insert into BookInfo values ('" + isbn + "', '" + title + "', '" + publisher + "', '" + pubDate + "', '" + FixQuotes(strURL) + "', " + salesRank + ", '" + System.DateTime.Now + "', '" + technology + "', '" + author + "')"; command.CommandText = commandString; command.ExecuteNonQuery(); } } catch (Exception ex) { lblStatus.Text = ex.Message; lbOutput.Items.Add("Unable to update database!"); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; } finally { connection.Close(); // clean up } } // close for GetInfoFromISBN
private void GetInfoFromAmazon(string keyword, string technology) { AWSProductData productData = new AWSProductData(); ItemSearch srch = null; try { ItemSearchRequest req = new ItemSearchRequest(); req.Keywords = keyword; req.SearchIndex = "Books"; srch = new ItemSearch(); srch.AssociateTag = "libertyassocia00A"; srch.SubscriptionId = "0SD959SZV6KXV3BKE2R2"; srch.Request = new ItemSearchRequest[1]; srch.Request[0] = req; } catch (System.Exception e) { lblStatus.Text = e.Message; } ItemSearchResponse response; int salesRank = -1; string isbn = string.Empty; string author = string.Empty; string pubDate = string.Empty; string publisher = string.Empty; string title = string.Empty; string strURL = string.Empty; Items[] responseItems = null; try { response = productData.ItemSearch(srch); // get back ItemSearchResponse responseItems = response.Items; // Items returns array of Items foreach (Items items in responseItems) { // Item property of Items is an array of Item objects Item[] arrayOfItem = items.Item; foreach (Item item in arrayOfItem) { isbn = FixQuotes(item.ItemAttributes.ISBN); salesRank = item.SalesRank == null ? -1 : Convert.ToInt32(item.SalesRank); author = FixQuotes(item.ItemAttributes.Author[0]); pubDate = FixQuotes(item.ItemAttributes.PublicationDate); publisher = FixQuotes(item.ItemAttributes.Publisher); title = FixQuotes(item.ItemAttributes.Title); strURL = item.DetailPageURL; // update the list box string results = title + " by " + author + ": " + publisher + ", " + pubDate + ". Rank: " + salesRank; lbOutput.Items.Add(results); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; // update the database string commandString = @"Update BookInfo set isbn = '" + isbn + "', title = '" + title + "', publisher = '" + publisher + "', pubDate = '" + pubDate + "', rank = " + salesRank + ", link = '" + strURL + "', lastUpdate = '" + System.DateTime.Now + "', technology = '" + technology + "', author = '" + author + "' where isbn = '" + isbn + "'"; command.CommandText = commandString; try { // if no rows were affected, this is a new record connection.Open(); int numRowsAffected = command.ExecuteNonQuery(); if (numRowsAffected == 0) { commandString = @"Insert into BookInfo values ('" + isbn + "', '" + title + "', '" + publisher + "', '" + pubDate + "', '" + FixQuotes(strURL) + "', " + salesRank + ", '" + System.DateTime.Now + "', '" + technology + "', '" + author + "')"; command.CommandText = commandString; command.ExecuteNonQuery(); } } catch (Exception ex) { lblStatus.Text = ex.Message; lbOutput.Items.Add("Unable to update database!"); lbOutput.SelectedIndex = lbOutput.Items.Count - 1; } finally { connection.Close(); // clean up } Application.DoEvents(); // update the UI } } } catch (System.Exception ex) { lblStatus.Text = ex.Message; } } // close for GetInfoFromISBN