Browse DevX
Sign up for e-mail newsletters from DevX


Monitor eBay Auctions with Visual Studio.NET : Page 4

While you could use eBay's Web interface to enter all your sale items, why waste the time? You're a .NET developer! You can use eBay's API and SDK in conjunction with .NET, XML and Excel for better portability, security, and performance.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Search for Matching Listings
The search for matching listings is invoked when the user presses the search button. The code connecting pressing this button to a routine is shown below:

// associate events with the Search Button object control; control = this.FindControl("cmdSearch"); this.cmdSearch = control as MSForms.CommandButton; // Attaches the events if (this.cmdSearch != null) { // When the button, btn_search, is pressed the handler cmdSearch_Click() is invoked this.cmdSearch.Click += new MSForms.CommandButtonEvents_ClickEventHandler (cmdSearch_Click); }

The actual search of the listings is accomplished by the API object GetSearchResults(). GetSearchResults() has a number of parameters that allow you to specify your search criteria and how results are returned.

The search parameters available include category, lowest price, highest price, region, and query string. The query string is used to search item titles and, optionally, descriptions. The query string contains keywords and relational operators such as OR and AND.

You can tell the object how many results to return by using the MaxResults parameter. If the total number of results matching the criteria, returned in the GrandTotal parameter, is greater than the max results, then you need to call the function again specifying the number of items to bypass with the Skip parameter. This is makes it very easy to implement paging of the results.

The code below shows how to call GetSearchResults():

// Execute Search GetSearchResultsCall SearchRes = new GetSearchResultsCall( apiSession); SearchRes.Timeout = 120000; // Get Search Criteria SearchRes.Query = CriteriaTable.Cell(3,2).Range.Text.TrimEnd(tChars); string sLow = CriteriaTable.Cell(4,2).Range.Text.TrimEnd(tChars); if ( sLow.Length > 0) SearchRes.LowestPrice = Convert.ToDecimal( sLow ); string sHigh = CriteriaTable.Cell(5,2).Range.Text.TrimEnd(tChars); if ( sHigh.Length > 0) SearchRes.HighestPrice = Convert.ToDecimal( sHigh ); // Find matching items IItemFoundCollection Items = SearchRes.GetSearchResults();

The results of the search are returned to the user as a collection of IItemFound objects. These are lightweight objects that have basic information about the item such as whether the object has a photo, has a "Buy It Now" option, or is a new listing. Two more important pieces of information are included, the URL to the item, and the ItemID. The URL to the item can be used to provide a hyperlink to the item. The code below shows how the sample application iterates through the collection of Items returned:

// If any matches are found, display results if ( Items.Count > 0) { sResult = Items.Count.ToString() + " matching items found"; Word.Font ResultFont = new Word.Font(); ResultFont.Underline = Word.WdUnderline.wdUnderlineNone; ResultFont.Bold = 0; ResultFont.Size = 10.0F; int i = 3; // add results from row 3 down Object beforeRow = Type.Missing; foreach ( IItemFound Item in Items) { ResultsTable.Rows.Add(ref beforeRow); ResultsTable.Cell(i,1).Range.Font = ResultFont; ResultsTable.Cell(i,2).Range.Font = ResultFont; AddHyperLink( ResultsTable.Cell(i,1).Range, Item.Title.ToString(), Item.ViewItemLink.ToString() ); ResultsTable.Cell(i,2).Range.Text = Item.CurrentPrice.ToString(); i++; } } else sResult = "no matching items found"; MessageBox.Show( sResult );

The ItemID is used to retrieve detailed information about the item by calling GetItem(). Whether you need to call GetItem depends upon the level of detail about the item your application requires. The sample application does not need additional information about the item so GetItem() is not called.

Easy as eBay
As the sample application shows, it is simple to incorporate eBay functionality into a Word or Excel 2003 document. The Code Behind capabilities of these Office products make it easy to integrate eBay facilities it any .NET application. And, when combined with the Microsoft Visual Studio Tools for the Microsoft Office System, Visual Studio becomes a great facility for creating, developing, and debugging Office applications.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date