ASP.NET+Atlas创建客户端Web应用程序(5)

开发者在线 Builder.com.cn 更新时间:2007-11-06作者:朱先忠编译 来源:ASP.NET

本文关键词: ASP.NET Atlas 客户端 应用程序

在客户端应用程序添加代码

  切换到设计视图,双击生成的Web表单以显示页面相应的代码部分(Default.aspx.cs)。选择Ctrl+A来选择所有的自动生成的代码,并按Delete键清除文档。然后,添加下列代码以消费Amazon ECS服务并且显示搜索结果:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
 protected AWSECommerceService AmazonECS = new AWSECommerceService();
 protected ItemSearch Search = new ItemSearch();
 protected ItemSearchRequest SearchRequest = new ItemSearchRequest();
 protected ItemSearchResponse SearchResponse;
 protected void submitSearch_Click(object sender, EventArgs e)
 {
  Search.AWSAccessKeyId = TxtBAccessKey.Text.ToString();
  SearchRequest.SearchIndex = "Restaurants";
  SearchRequest.Cuisine = ListBoxCuisine.SelectedValue;
  SearchRequest.City = listBoxCity.SelectedValue;
  SearchRequest.Neighborhood = TextBox3.Text.ToString();
  SearchRequest.ResponseGroup = new String[] { "ItemAttributes" };
  Search.Request = new ItemSearchRequest[1] { SearchRequest };
  try
  {
   SearchResponse = AmazonECS.ItemSearch(Search);
   if (SearchResponse.Items == null)
   { labelError.Text = "A Server error has occured."; }
   else
   {
    Items responseItems = SearchResponse.Items[0];
    Item[] response = responseItems.Item;
    if (response != null)
    {
     foreach (Item I in response)
     {
      NoResults.Text = "";
      Label Results = new Label();
      Label Sep = new Label();
      Results.Text = "<strong>" + I.ItemAttributes.Title.ToUpper() + "</strong>" + "<br/>"
+ I.ItemAttributes.Address.Address1.ToString() + "<br/>"
+ I.ItemAttributes.Neighborhood + "<br/>"
+ "Tel:" + " " + I.ItemAttributes.PhoneNumber + "<br/>"
+ "Price Rating:" + " " + priceRating(I.ItemAttributes.PriceRating)+"<br/>"+"<br/>";
      Sep.Text = "<br/>";
      RP1.Controls.Add(Results);
      RP1.Controls.Add(Sep); }
    PriceRange.Text ="Price per person (based on entree, appetizer or salad, one non-alcoholic drink plus tax and tip)";
   }
   else
   {
    NoResults.Text = "No search results found.";
    PriceRange.Text = "";
   }
  }
 }
 catch (Exception ex)
 {
  labelError.Text = ex.Message.ToString();
 }
}
private string priceRating(string str)
{
 if (str=="1"){
  return "under ";}
 else if(str=="2"){
  return "-30";}
 else if(str=="3"){
  return "-45";}
 else if(str=="4"){
  return "over ";}
 else{return null;}
}
protected void listBoxCity_SelectedIndexChanged(object sender, EventArgs e)
{}
protected void ListBoxCuisine_SelectedIndexChanged(object sender, EventArgs e)
{}
}

用户评论

  • 用户名
  • 评论内容