(1)API去友商100里申请

布局代码:

Exp.xaml

<phone:PhoneApplicationPage
x:Class="WindowsPhone_Express.Exp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="False">

<!--LayoutRoot 包含放置所有其他頁面的根資料格-->
<Grid x:Name="LayoutRoot">
<controls:Panorama Title="快递查询">

<!--Panorama 項目 1-->
<controls:PanoramaItem Header="快递商选择" Loaded="PanoramaItem_Loaded">
<Grid>
<!--<my:ExpressItem Margin="9,6,6,0" x:Name="expressItem1" VerticalAlignment="Top" />-->
<ListBox Margin="12,6,6,6" x:Name="listBox_Express">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Width="50" Height="50"
VerticalAlignment="Top" Background="#FF15B7EF">
<TextBlock Text="{Binding Letter}" HorizontalAlignment="Center" Margin="0,0,0,0" x:Name="Letter"
Foreground="White" FontSize="30"
/>
</Border>

<StackPanel Orientation="Horizontal">
<ItemsControl x:Name="ExpListBox" ItemsSource="{Binding ExpressInfoList}" Margin="0,0,0,0">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Tag="{Binding Code}"
x:Name="ExpName" Content="{Binding Name}" Margin="0,0,0,0" FontSize="40"
Foreground="White"
BorderThickness="0"
HorizontalAlignment="Left"
Click="ExpName_Click"

/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</Grid>
</controls:PanoramaItem>

<!--Panorama 項目 2-->
<controls:PanoramaItem Header="关于">
<Grid>
<TextBlock Margin="25,58,74,403" Name="textBlock1" Text="本应用用于开发学习" Height="37" FontSize="30" Width="321" />
<TextBlock Height="37" HorizontalAlignment="Left" Margin="23,119,0,342" Name="textBlock2" FontSize="30" Text="如有问题请到我的博客留言" Width="380" />
<TextBlock Height="37" HorizontalAlignment="Left" FontSize="25" Margin="31,381,0,80" Name="textBlock3" Text="http://www.cnblog.com/lsmayday" Width="390" />
<TextBlock Height="37" HorizontalAlignment="Left" FontSize="20" Margin="240,440,0,21" Name="textBlock4" Text="API由友商100提供" Width="169" />
</Grid>
</controls:PanoramaItem>
</controls:Panorama>
</Grid>

<!--Panorama 應用程式不應該顯示 ApplicationBar-->

</phone:PhoneApplicationPage>

 1 <phone:PhoneApplicationPage 
2 x:Class="WindowsPhone_Express.Exp"
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
6 xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
7 xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
8 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
9 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10 mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800"
11 FontFamily="{StaticResource PhoneFontFamilyNormal}"
12 FontSize="{StaticResource PhoneFontSizeNormal}"
13 Foreground="{StaticResource PhoneForegroundBrush}"
14 SupportedOrientations="Portrait" Orientation="Portrait"
15 shell:SystemTray.IsVisible="False">
16
17 <!--LayoutRoot 包含放置所有其他頁面的根資料格-->
18 <Grid x:Name="LayoutRoot">
19 <controls:Panorama Title="快递查询">
20
21 <!--Panorama 項目 1-->
22 <controls:PanoramaItem Header="快递商选择" Loaded="PanoramaItem_Loaded">
23 <Grid>
24 <!--<my:ExpressItem Margin="9,6,6,0" x:Name="expressItem1" VerticalAlignment="Top" />-->
25 <ListBox Margin="12,6,6,6" x:Name="listBox_Express">
26 <ListBox.ItemTemplate>
27 <DataTemplate>
28 <StackPanel Orientation="Horizontal">
29 <Border Width="50" Height="50"
30 VerticalAlignment="Top" Background="#FF15B7EF">
31 <TextBlock Text="{Binding Letter}" HorizontalAlignment="Center" Margin="0,0,0,0" x:Name="Letter"
32 Foreground="White" FontSize="30"
33 />
34 </Border>
35
36 <StackPanel Orientation="Horizontal">
37 <ItemsControl x:Name="ExpListBox" ItemsSource="{Binding ExpressInfoList}" Margin="0,0,0,0">
38 <ItemsControl.ItemTemplate>
39 <DataTemplate>
40 <Button Tag="{Binding Code}"
41 x:Name="ExpName" Content="{Binding Name}" Margin="0,0,0,0" FontSize="40"
42 Foreground="White"
43 BorderThickness="0"
44 HorizontalAlignment="Left"
45 Click="ExpName_Click"
46
47 />
48 </DataTemplate>
49 </ItemsControl.ItemTemplate>
50 </ItemsControl>
51
52 </StackPanel>
53 </StackPanel>
54 </DataTemplate>
55 </ListBox.ItemTemplate>
56 </ListBox>
57
58 </Grid>
59 </controls:PanoramaItem>
60
61 <!--Panorama 項目 2-->
62 <controls:PanoramaItem Header="关于">
63 <Grid>
64 <TextBlock Margin="25,58,74,403" Name="textBlock1" Text="本应用用于开发学习" Height="37" FontSize="30" Width="321"/>
65 <TextBlock Height="37" HorizontalAlignment="Left" Margin="23,119,0,342" Name="textBlock2" FontSize="30" Text="如有问题请到我的博客留言" Width="380"/>
66 <TextBlock Height="37" HorizontalAlignment="Left" FontSize="25" Margin="31,381,0,80" Name="textBlock3" Text="http://www.cnblog.com/lsmayday" Width="390"/>
67 <TextBlock Height="37" HorizontalAlignment="Left" FontSize="20" Margin="240,440,0,21" Name="textBlock4" Text="API由友商100提供" Width="169"/>
68 </Grid>
69 </controls:PanoramaItem>
70 </controls:Panorama>
71 </Grid>
72
73 <!--Panorama 應用程式不應該顯示 ApplicationBar-->
74
75 </phone:PhoneApplicationPage>

SelectExp.xaml

<phone:PhoneApplicationPage
x:Class="WindowsPhone_Express.SelectExp"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True"
Loaded="PhoneApplicationPage_Loaded"
>

<!--LayoutRoot 是放置所有頁面的根資料格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel 包含應用程式的名稱和頁面標題-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="快递查询" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - 其他內容置於此-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,59,0,0" Name="textBlock1" Text="单号:" VerticalAlignment="Top" />
<TextBox Margin="63,36,6,0"
BorderThickness="0"
Background="Beige"
Name="textBox_ExpNumber" Text="" Height="72" VerticalAlignment="Top" />
<Button Background="Beige" Foreground="Black" BorderThickness="0" Content="查询" Height="72" Margin="290,114,6,0" Name="button_Ok" VerticalAlignment="Top" Click="button_Ok_Click" />
<ProgressBar x:Name="ProgressBar_Loading" Visibility="Collapsed" Margin="12,114,172,0" IsIndeterminate="True" Height="72" VerticalAlignment="Top"></ProgressBar>
<ListBox x:Name="ExpInfo_List" Margin="12,192,6,6" ItemsSource="{Binding ExpressInfoDataList}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Margin="0" >
<TextBlock x:Name="Text_Date" TextAlignment="Left" Margin="0,0,0,0" Height="35" Padding="0" FontSize="25" Text="{Binding Time}" Foreground="#FF17AEDE"></TextBlock>
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="50">
<TextBlock x:Name="Text_Content" Margin="0,0,0,0" FontSize="35" Text="{Binding Context}"></TextBlock>
</ScrollViewer>

</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</Grid>
</Grid>

<!--顯示 ApplicationBar 使用方式的程式碼範例-->
<!--<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="按鈕 1"/>
<shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="按鈕 2"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="功能表項目 1"/>
<shell:ApplicationBarMenuItem Text="功能表項目 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>

 1 <phone:PhoneApplicationPage 
2 x:Class="WindowsPhone_Express.SelectExp"
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
6 xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
7 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9 FontFamily="{StaticResource PhoneFontFamilyNormal}"
10 FontSize="{StaticResource PhoneFontSizeNormal}"
11 Foreground="{StaticResource PhoneForegroundBrush}"
12 SupportedOrientations="Portrait" Orientation="Portrait"
13 mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
14 shell:SystemTray.IsVisible="True"
15 Loaded="PhoneApplicationPage_Loaded"
16 >
17
18 <!--LayoutRoot 是放置所有頁面的根資料格-->
19 <Grid x:Name="LayoutRoot" Background="Transparent">
20 <Grid.RowDefinitions>
21 <RowDefinition Height="Auto"/>
22 <RowDefinition Height="*"/>
23 </Grid.RowDefinitions>
24
25 <!--TitlePanel 包含應用程式的名稱和頁面標題-->
26 <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
27 <TextBlock x:Name="ApplicationTitle" Text="快递查询" Style="{StaticResource PhoneTextNormalStyle}"/>
28 <TextBlock x:Name="PageTitle" Text="" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
29 </StackPanel>
30 <!--ContentPanel - 其他內容置於此-->
31 <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
32 <TextBlock Height="30" HorizontalAlignment="Left" Margin="12,59,0,0" Name="textBlock1" Text="单号:" VerticalAlignment="Top"/>
33 <TextBox Margin="63,36,6,0"
34 BorderThickness="0"
35 Background="Beige"
36 Name="textBox_ExpNumber" Text="" Height="72" VerticalAlignment="Top"/>
37 <Button Background="Beige" Foreground="Black" BorderThickness="0" Content="查询" Height="72" Margin="290,114,6,0" Name="button_Ok" VerticalAlignment="Top" Click="button_Ok_Click"/>
38 <ProgressBar x:Name="ProgressBar_Loading" Visibility="Collapsed" Margin="12,114,172,0" IsIndeterminate="True" Height="72" VerticalAlignment="Top"></ProgressBar>
39 <ListBox x:Name="ExpInfo_List" Margin="12,192,6,6" ItemsSource="{Binding ExpressInfoDataList}">
40 <ListBox.ItemTemplate>
41 <DataTemplate>
42 <StackPanel Orientation="Vertical" Margin="0">
43 <TextBlock x:Name="Text_Date" TextAlignment="Left" Margin="0,0,0,0" Height="35" Padding="0" FontSize="25" Text="{Binding Time}" Foreground="#FF17AEDE"></TextBlock>
44 <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="50">
45 <TextBlock x:Name="Text_Content" Margin="0,0,0,0" FontSize="35" Text="{Binding Context}"></TextBlock>
46 </ScrollViewer>
47
48 </StackPanel>
49 </DataTemplate>
50 </ListBox.ItemTemplate>
51 </ListBox>
52
53 </Grid>
54 </Grid>
55
56 <!--顯示 ApplicationBar 使用方式的程式碼範例-->
57 <!--<phone:PhoneApplicationPage.ApplicationBar>
58 <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
59 <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="按鈕 1"/>
60 <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="按鈕 2"/>
61 <shell:ApplicationBar.MenuItems>
62 <shell:ApplicationBarMenuItem Text="功能表項目 1"/>
63 <shell:ApplicationBarMenuItem Text="功能表項目 2"/>
64 </shell:ApplicationBar.MenuItems>
65 </shell:ApplicationBar>
66 </phone:PhoneApplicationPage.ApplicationBar>-->
67
68 </phone:PhoneApplicationPage>

Exp.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml;
using System.Xml.Linq;
using System.Collections.ObjectModel;
namespace WindowsPhone_Express
{
public partial class Exp : PhoneApplicationPage
{
public Exp()
{
InitializeComponent();
}

/// <summary>
/// 读取快递列表数据
/// </summary>
private void Reader()
{
ObservableCollection<Cls.Express> Exp = new ObservableCollection<Cls.Express>();

XDocument Xdocument = XDocument.Load("Xml_Data/Express.xml");
foreach (XElement Xelement in Xdocument.Element("Data").Descendants("Express"))
{
Cls.Express ExpInfo = new Cls.Express();
ExpInfo.Letter = Xelement.Attribute("Letter").Value.ToString();

ExpInfo.ExpressInfoList = new List<Cls.ExpressInfo>();
foreach (XElement Xnode in Xelement.Nodes())
{
ExpInfo.ExpressInfoList.Add(new Cls.ExpressInfo { Code = Xnode.Attribute("Code").Value.ToString(), Name = Xnode.Value.ToString() });
}
Exp.Add(ExpInfo);
}
this.listBox_Express.ItemsSource = Exp;
}

private void ExpName_Click(object sender, RoutedEventArgs e)
{
if (!e.OriginalSource.Equals(null))
{
Button But = (Button)e.OriginalSource;
string Code = But.Tag.ToString();
string Name = But.Content.ToString();
this.NavigationService.Navigate(new Uri(string.Format("/SelectExp.xaml?Code={0}&Name={1}",
Code,
Name
), UriKind.Relative));
}

}

private void PanoramaItem_Loaded(object sender, RoutedEventArgs e)
{
Reader();
}
}
}

 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using Microsoft.Phone.Controls;
13 using System.Xml;
14 using System.Xml.Linq;
15 using System.Collections.ObjectModel;
16 namespace WindowsPhone_Express
17 {
18 public partial class Exp : PhoneApplicationPage
19 {
20 public Exp()
21 {
22 InitializeComponent();
23 }
24
25 ///<summary>
26 /// 读取快递列表数据
27 ///</summary>
28 private void Reader()
29 {
30 ObservableCollection<Cls.Express> Exp = new ObservableCollection<Cls.Express>();
31
32 XDocument Xdocument = XDocument.Load("Xml_Data/Express.xml");
33 foreach (XElement Xelement in Xdocument.Element("Data").Descendants("Express"))
34 {
35 Cls.Express ExpInfo = new Cls.Express();
36 ExpInfo.Letter = Xelement.Attribute("Letter").Value.ToString();
37
38 ExpInfo.ExpressInfoList = new List<Cls.ExpressInfo>();
39 foreach (XElement Xnode in Xelement.Nodes())
40 {
41 ExpInfo.ExpressInfoList.Add(new Cls.ExpressInfo { Code = Xnode.Attribute("Code").Value.ToString(), Name = Xnode.Value.ToString() });
42 }
43 Exp.Add(ExpInfo);
44 }
45 this.listBox_Express.ItemsSource = Exp;
46 }
47
48
49
50 private void ExpName_Click(object sender, RoutedEventArgs e)
51 {
52 if (!e.OriginalSource.Equals(null))
53 {
54 Button But = (Button)e.OriginalSource;
55 string Code = But.Tag.ToString();
56 string Name = But.Content.ToString();
57 this.NavigationService.Navigate(new Uri(string.Format("/SelectExp.xaml?Code={0}&Name={1}",
58 Code,
59 Name
60 ), UriKind.Relative));
61 }
62
63 }
64
65 private void PanoramaItem_Loaded(object sender, RoutedEventArgs e)
66 {
67 Reader();
68 }
69 }
70 }

SelectExp.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml;
using System.Xml.Linq;
using System.Threading;
using System.IO;
using System.Collections.ObjectModel;
namespace WindowsPhone_Express
{
public partial class SelectExp : PhoneApplicationPage
{
Cls.ExpressInfo ExpInfo = new Cls.ExpressInfo();
string Api_Url = "http://api.kuaidi100.com/api?id={0}&com={1}&nu={2}&show=1&muti=1&order=desc";
/// <summary>
/// 快递号
/// </summary>
string ExpNumber = "";
public SelectExp()
{
InitializeComponent();
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
if (this.NavigationContext.QueryString["Code"] != null && this.NavigationContext.QueryString["Name"] != null)
{
ExpInfo
.Code = this.NavigationContext.QueryString["Code"].ToString();
ExpInfo
.Name = this.NavigationContext.QueryString["Name"].ToString();
}
else
{
this.NavigationService.GoBack();
}
this.PageTitle.Text = this.ExpInfo.Name;
}

private void button_Ok_Click(object sender, RoutedEventArgs e)
{
if (this.textBox_ExpNumber.Text.ToString().Trim().Equals(""))
{
MessageBox.Show("请输入单号", "错误提示", MessageBoxButton.OK);
}
else {
this.ProgressBar_Loading.Visibility = System.Windows.Visibility.Visible;
this.textBox_ExpNumber.IsEnabled = false;
this.button_Ok.IsEnabled = false;
ExpNumber = this.textBox_ExpNumber.Text;

this.ExpInfo_List.ItemsSource = null;
new Thread(new ThreadStart(ResponseApi)).Start();

}
}

#region
delegate void ResponseXmldelegate(
ObservableCollection<Cls.ExpressInfoList> List
);
/// <summary>
/// 请求API,返回XML文档
/// </summary>
private void ResponseApi() {
string Url = string.Format(Api_Url,
new Config().Key,
this.ExpInfo.Code,
ExpNumber
).ToString();

GetHttpHtml(Url);

}
private void ShowExpInfoList(ObservableCollection<Cls.ExpressInfoList> List)
{
this.textBox_ExpNumber.IsEnabled = true;
this.button_Ok.IsEnabled = true;
this.ProgressBar_Loading.Visibility = System.Windows.Visibility.Collapsed;
if (List[0].Status.Equals("0"))
{
MessageBox.Show(List[0].Message.ToString(), "错误提示", MessageBoxButton.OK);
}
else {
this.ExpInfo_List.ItemsSource = List[0].DataList;
}
}
#endregion

/// <summary>
/// 返回指定URL页面内容
/// </summary>
/// <param name="Url"></param>
/// <returns></returns>
private void GetHttpHtml(string Url) {

WebRequest request = WebRequest.Create(Url);
request.BeginGetResponse(new AsyncCallback(HttpHtmlResponse), request);

}
private void HttpHtmlResponse(IAsyncResult request)
{
HttpWebRequest HttpRequest = (HttpWebRequest)request.AsyncState;
HttpWebResponse HttpResponse = (HttpWebResponse)HttpRequest.EndGetResponse(request);
using (Stream _Stream = HttpResponse.GetResponseStream()) {

ObservableCollection<Cls.ExpressInfoList> ExpList = new ObservableCollection<Cls.ExpressInfoList>();
XDocument Xdoc = XDocument.Load(_Stream);
Cls.ExpressInfoList InfoList = new Cls.ExpressInfoList();

InfoList.Message = Xdoc.Element("xml").Element("message").Value.ToString();
InfoList.Status = Xdoc.Element("xml").Element("status").Value.ToString();
InfoList.DataList = new List<Cls.ExpressInfoDataList>();
foreach (XElement Xelement in Xdoc.Element("xml").Descendants("data"))
{
InfoList.DataList.Add(new Cls.ExpressInfoDataList { Context = Xelement.Element("context").Value.ToString(), Time = Xelement.Element("time").Value.ToString() });
}
ExpList.Add(InfoList);
Dispatcher.BeginInvoke(new ResponseXmldelegate(ShowExpInfoList), ExpList);
}
}
}
}

  1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using Microsoft.Phone.Controls;
13 using System.Xml;
14 using System.Xml.Linq;
15 using System.Threading;
16 using System.IO;
17 using System.Collections.ObjectModel;
18 namespace WindowsPhone_Express
19 {
20 public partial class SelectExp : PhoneApplicationPage
21 {
22 Cls.ExpressInfo ExpInfo = new Cls.ExpressInfo();
23 string Api_Url = "http://api.kuaidi100.com/api?id={0}&com={1}&nu={2}&show=1&muti=1&order=desc";
24 ///<summary>
25 /// 快递号
26 ///</summary>
27 string ExpNumber = "";
28 public SelectExp()
29 {
30 InitializeComponent();
31 }
32
33 private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
34 {
35 if (this.NavigationContext.QueryString["Code"] != null && this.NavigationContext.QueryString["Name"] != null)
36 {
37 ExpInfo
38 .Code = this.NavigationContext.QueryString["Code"].ToString();
39 ExpInfo
40 .Name = this.NavigationContext.QueryString["Name"].ToString();
41 }
42 else
43 {
44 this.NavigationService.GoBack();
45 }
46 this.PageTitle.Text = this.ExpInfo.Name;
47 }
48
49 private void button_Ok_Click(object sender, RoutedEventArgs e)
50 {
51 if (this.textBox_ExpNumber.Text.ToString().Trim().Equals(""))
52 {
53 MessageBox.Show("请输入单号", "错误提示", MessageBoxButton.OK);
54 }
55 else {
56 this.ProgressBar_Loading.Visibility = System.Windows.Visibility.Visible;
57 this.textBox_ExpNumber.IsEnabled = false;
58 this.button_Ok.IsEnabled = false;
59 ExpNumber = this.textBox_ExpNumber.Text;
60
61 this.ExpInfo_List.ItemsSource = null;
62 new Thread(new ThreadStart(ResponseApi)).Start();
63
64 }
65 }
66
67
68 #region
69 delegate void ResponseXmldelegate(
70 ObservableCollection<Cls.ExpressInfoList> List
71 );
72 ///<summary>
73 /// 请求API,返回XML文档
74 ///</summary>
75 private void ResponseApi() {
76 string Url = string.Format(Api_Url,
77 new Config().Key,
78 this.ExpInfo.Code,
79 ExpNumber
80 ).ToString();
81
82 GetHttpHtml(Url);
83
84 }
85 private void ShowExpInfoList(ObservableCollection<Cls.ExpressInfoList> List)
86 {
87 this.textBox_ExpNumber.IsEnabled = true;
88 this.button_Ok.IsEnabled = true;
89 this.ProgressBar_Loading.Visibility = System.Windows.Visibility.Collapsed;
90 if (List[0].Status.Equals("0"))
91 {
92 MessageBox.Show(List[0].Message.ToString(), "错误提示", MessageBoxButton.OK);
93 }
94 else {
95 this.ExpInfo_List.ItemsSource = List[0].DataList;
96 }
97 }
98 #endregion
99
100 ///<summary>
101 /// 返回指定URL页面内容
102 ///</summary>
103 ///<param name="Url"></param>
104 ///<returns></returns>
105 private void GetHttpHtml(string Url) {
106
107 WebRequest request = WebRequest.Create(Url);
108 request.BeginGetResponse(new AsyncCallback(HttpHtmlResponse), request);
109
110
111 }
112 private void HttpHtmlResponse(IAsyncResult request)
113 {
114 HttpWebRequest HttpRequest = (HttpWebRequest)request.AsyncState;
115 HttpWebResponse HttpResponse = (HttpWebResponse)HttpRequest.EndGetResponse(request);
116 using (Stream _Stream = HttpResponse.GetResponseStream()) {
117
118 ObservableCollection<Cls.ExpressInfoList> ExpList = new ObservableCollection<Cls.ExpressInfoList>();
119 XDocument Xdoc = XDocument.Load(_Stream);
120 Cls.ExpressInfoList InfoList = new Cls.ExpressInfoList();
121
122 InfoList.Message = Xdoc.Element("xml").Element("message").Value.ToString();
123 InfoList.Status = Xdoc.Element("xml").Element("status").Value.ToString();
124 InfoList.DataList = new List<Cls.ExpressInfoDataList>();
125 foreach (XElement Xelement in Xdoc.Element("xml").Descendants("data"))
126 {
127 InfoList.DataList.Add(new Cls.ExpressInfoDataList { Context = Xelement.Element("context").Value.ToString(), Time = Xelement.Element("time").Value.ToString() });
128 }
129 ExpList.Add(InfoList);
130 Dispatcher.BeginInvoke(new ResponseXmldelegate(ShowExpInfoList), ExpList);
131 }
132 }
133 }
134 }

Windows Phone7 快递查询的更多相关文章

  1. 快递查询API接口(trackingmore)

    快递查询接口 目前提供快递查询的接口平台有: Trackingmore 快递100 快递网 不同接口的区别: (1)Trackingmore支持380家快递公司,其中有55家为国内的快递,其余325家 ...

  2. 常用免费快递查询API对接案例

    现在许多电商公司和ERP都会寻找比较适用的集成快递查询接口,减少对接难度,现在整理一下常用的免费快递查询接口,并附上调用案例,如果有觉得不对的地方,望能够一起沟通探讨! 一.快递查询接口 目前有提供免 ...

  3. 快递查询API接口对接方法

    各类接口 快递查询API有即时查询和订阅查询两种,即时是请求即返回数据,订阅则是订阅快递单号到接口,有物流轨迹更新则全量返回数据.目前常用的有快递鸟.快递100.快递网等. 快递鸟即时API可以查询3 ...

  4. 装饰者模式的学习(c#) EF SaveChanges() 报错(转载) C# 四舍五入 保留两位小数(转载) DataGridView样式生成器使用说明 MSSQL如何将查询结果拼接成字符串 快递查询 C# 通过smtp直接发送邮件 C# 带参访问接口,WebClient方式 C# 发送手机短信 文件 日志 写入 与读取

    装饰者模式的学习(c#) 案例转自https://www.cnblogs.com/stonefeng/p/5679638.html //主体基类 using System;using System.C ...

  5. python爬虫入门之快递查询

    现在快递遍布生活的角角落落,一个快递其实是信息的集合体,里面包含大量的物流信息,那能不能自己实现一个快递查询的小功能?答案是能的!现在也有别人整理好的快递查询api,比如说快递100,可以通过它提供的 ...

  6. 快递查询SDK

    简介: 快递查询的SDK,使用的是快递100的智能查询,此SDK只是中间包装了一层而已,单对于普通的快递业务查询已经足够,也省去开发者研究的时间,拿来即用. 用途: 1.对接微信公众平台 2.对接需要 ...

  7. baidu 快递查询API

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. 快递查询api(多接口方案)

    /** 本环境使用php+smarty,结合两种快递api调取快递数据 * 说明,先快递鸟调取数据,失败后再调取快递网的数据* 快递鸟 http://www.kdniao.com 快递网 http:/ ...

  9. 各种快递查询--Api接口

    授权成功我的密钥 爱查快递API使用说明文档 API地址: 以前:http://api.ickd.cn/?com=[]&nu=[]&id=[]&type=[]&enco ...

随机推荐

  1. 【Python】Python XML 读写

    class ACTIVE_FILE_PROTECT_RULE_VIEW(APIView): renderer_classes = (JSONRenderer, BrowsableAPIRenderer ...

  2. ReverseString

    [本文链接] http://www.cnblogs.com/hellogiser/p/reverse-string.html reverse string [代码]  C++ Code  123456 ...

  3. kettle job如何利用java的反射机制获取执行的sql语句

    kettle job中的JavaScript如何获取同一个job中SQL步骤的执行语句并让执行语句记录在日志中呢?首先写日志需要用到job中JavaScript写日志的方法,其次是利用java反射机制 ...

  4. ARM 处理器的几个相关术语

    生产ARM的厂商很多,自然ARM处理器的名字就五花八门.但是,它们有些共同点,那就是:架构和核心. 架构这个概念太宽不太懂,一般不同的架构会有不同的指令集,在不同的架构下面还可以有多种核心.核心就是指 ...

  5. 利用FFmpeg生成视频缩略图 2.3.1

    1.下载FFmpeg文件包,解压包里的\bin\下的文件解压到 D:\ffmpeg\ 目录下. 下载地址 http://ffmpeg.zeranoe.com/builds/win32/static/ ...

  6. window.open()读取本地图片简单使用总结

    最近做了一个项目,需要读取本地图片出来,问了一些人,感觉在数据库中存取路径比较合适,故做此方法. 后台查询出来的路径

  7. mybatis的jdbcType类型

    在用mybatis的时候,如果传过来的参数有可能为空,那么就要指定jdbcType是什么了,否则会有异常,jdbcType有以下几种: BIT         FLOAT      CHAR      ...

  8. POSIX线程--同时执行

    //#define _REENTRANT//#define _POSIX_C_SOURCE#include <iostream>#include <string>#includ ...

  9. 各大OJ

    北大POJ 杭电HDU 浙大ZOj 蓝桥杯 PAT

  10. callsession新功能版

    可以getopt解析参数. 也实现了将参数用空格分隔,来传给进程. 注意string和LPSTR数据类型的转换方法: LPSTR(lpCmdLine.c_str()) #include <win ...