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