火車時刻表源代碼


1234

這個應用的皮膚跟上一個手機歸屬地查詢是同一皮膚。

手機歸屬地查詢的博文地址:http://www.cnblogs.com/wildfeng/archive/2012/03/21/2409174.html

這里我用的是Panorama全景視圖做的UI。

其實我一開始是將很多查詢類的小應用集中在一個應用里面的,就像這樣

tt不過后來打算分開做的,至於為什么,你懂的,5送一哦。可惜好事總是輪不上咱。通過再多也沒用。

下載地址:

http://115.com/file/dp7nntwg#
PracticalSearch.xap

聯系QQ:29992379

回到正題,這個應用用的是webxml的服務。

http://webservice.webxml.com.cn/WebServices/TrainTimeWebService.asmx

可以通過出發站和目的站來查詢列車的車次。也可以通過車次查詢列車的起始站和終點站。

之類應用都很簡單,代碼量也少,我在UI上花了不少功夫。效果的代碼就不寫了,只寫功能代碼吧。

 

通過起始站和終點站查詢

private void SearchByStationName_Click(object sender, RoutedEventArgs e)
        {
            if (CheckStartStation() && CheckArriveStation())
            {
                l.Show(this, "查找中......");
                client.getStationAndTimeByStationNameAsync(StartStation.Text, ArriveStation.Text, "");
                client.getStationAndTimeByStationNameCompleted += new EventHandler<TrainService.getStationAndTimeByStationNameCompletedEventArgs>(client_getStationAndTimeByStationNameCompleted);
            }
        }

 

void client_getStationAndTimeByStationNameCompleted(object sender, TrainService.getStationAndTimeByStationNameCompletedEventArgs e)
        {
            if (e.Error==null)
            {
                var re=e.Result.Nodes[0];
                var TimeTable = from zip in re.Descendants("TimeTable")
                              select new TrainInfo
                              {
                                  TrainCode = zip.Element("TrainCode").Value,
                                  FirstStation = zip.Element("FirstStation").Value,
                                  LastStation = zip.Element("LastStation").Value,
                                  StartStation = zip.Element("StartStation").Value,
                                  StartTime = zip.Element("StartTime").Value,
                                  ArriveStation = zip.Element("ArriveStation").Value,
                                  ArriveTime = zip.Element("ArriveTime").Value
                              };
                if (TimeTable.First().FirstStation=="數據沒有被發現")
                {
                    MessageBox.Show("數據沒有被發現"); l.Hide(this, "");
                    return;
                }
                List<TrainInfo> trainlist = new List<TrainInfo>();
                foreach (var item in TimeTable)
                {
                    trainlist.Add(item);
                }
                ListBoxTrainList.ItemsSource = trainlist;
                l.Hide(this, "");
            }
        }

 

通過車次號查詢

private void SearchByTrainCode_Click(object sender, RoutedEventArgs e)
        {
            if (CheckTrainCode())
            {
                l.Show(this, "查找中......");
                client.getStationAndTimeByTrainCodeAsync(TrainCode.Text, "");
                client.getStationAndTimeByTrainCodeCompleted += new EventHandler<TrainService.getStationAndTimeByTrainCodeCompletedEventArgs>(client_getStationAndTimeByTrainCodeCompleted);
            }
        }

        void client_getStationAndTimeByTrainCodeCompleted(object sender, TrainService.getStationAndTimeByTrainCodeCompletedEventArgs e)
        {
            if (e.Error==null)
            {
                string[] strinfo = e.Result;
                if (strinfo[1] != "數據沒有被發現")
                {
                    TextBlockTrainCode.Text = "車次:" + strinfo[0];
                    TextBlockTrainLiu.Text = strinfo[2]+"("+strinfo[4]+")-->"+strinfo[3]+"("+strinfo[6]+")";
                    l.Hide(this, "查找中......");
                }
                else
                {
                    MessageBox.Show("數據沒有被發現");
                }
            }
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM