Develop flight query programs using Web Services provided by the network

Source: Internet
Author: User

This is a winform-based client.ProgramThe Web service provided by the network is used to query air tickets in China. This article mainly describes the development of specific clients.

The main interface is as follows:

 

For more information about how to reference a Web Service, see network materials such as: msdn

Next, I created a class library thread. CS to use multithreading and pass parameters to the thread.CodeAs follows:

 

Thread. CS
Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Data;

Namespace Windows Service
{
Class Thread
{
String Startcity; // Define output parameters, departure city
String Endcity;
String Date; // Departure time
Dataset Ds; // Returned Dataset

Public   String Scity
{
Get { Return Startcity ;}
Set {Startcity = Value ;}
}
Public   String Ecity
{
Get { Return Endcity ;}
Set {Endcity = Value ;}
}
Public   String DT
{
Get { Return Date ;}
Set {Date = Value ;}
}
Public Dataset DS
{
Get { Return DS ;}
}
Public Dataset gettime ()
{
Try
{
Airline. domesticairline airline =   New Windowsservice. Airline. domesticairline (); // Instantiation Service
DS = Airline. getdomesticairlinestime (scity, ecity, DT, "" ); // Enter a parameter to obtain the query result.
Return DS; // Returned results
}
Catch (Exception E)
{
Throw   New Exception (E. tostring ());
}
}
}
}

 

Through this class library, you have completed passing the scity and ecity parameters to the thread. The following code sets the form:

 

Form
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using System. Threading;

Namespace Windows Service
{
Public   Partial   Class Form1: Form
{
Public Form1 ()
{
Initializecomponent ();
Updategridview =   New Gettimeair (gettimes );
}
String Date; // Pre-defined parameters
String SC;
String EC;

Delegate   Void Gettimeair (); // Define delegation and implement Multithreading
Gettimeair updategridview;
Private   Void Button#click ( Object Sender, eventargs E)
{
Try
{
Thread Get   =   New Thread (gettimes );
Get . Isbackground =   True ;
Get . Start ();
Statusbar1.text =   " Retrieving data. Please wait. " ;
}
Catch (Exception ex)
{
MessageBox. Show (ex. tostring ());
}
Finally
{
Statusbar1.text =   " The data is collected and displayed patiently. " ;

}
}
Private   Void Gettimes () // Main Method
{
If (Datagridview1.invokerequired)
{
This . Invoke (updategridview );
}
Else
{
Try
{
Thread th =   New Thread (); // Instantiate the class th of Thread
Th. scity = SC;
Th. ecity = EC;
Th. dt = Date;
Datagridview1.datasource = Th. gettime (). Tables [ 0 ];
}
Catch (Exception ex)
{
MessageBox. Show (ex. tostring ());
}
Finally
{

}
}
}

private void datetimepicker1_valuechanged ( Object sender, eventargs e)
{< br> date = datetimepicker1.value. toshortdatestring (); /// Get departure time
}< br>

private void combobox#selectedindexchanged ( Object sender, eventargs e)
{< br> SC = combobox1.selecteditem. tostring (); // get the target city
}

Private VoidCombobox2_selectedindexchanged (ObjectSender, eventargs E)
{
EC=Combobox2.selecteditem. tostring ();//Get destination city
}

}
}

 

Now, the entire process has been completed. Please be patient because of the network speed and data size problems. Download the entire project: Click to download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.