C # Window Aviation Summary

Source: Internet
Author: User
Tags ticket

public string con = "Data source=.;i Nitial catalog=ticket;integrated security=true ";//Connect database statements
private void Form1_Load (object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection (con);//Connect to Database

String sql = "SELECT * from Cityinfo";//sql statement

SqlCommand cmd = new SqlCommand (SQL, conn);

SqlDataAdapter da = new SqlDataAdapter ();//Truck Object
Da. SelectCommand = cmd;
DataSet ds = new DataSet ();//Create two temporary data tables
Da. Fill (ds, "Cityinfo");
Da. Fill (ds, "CityInfo2");


Add data to the first row of the dataset, select
DataRow row = ds. tables["Cityinfo"]. NewRow ();
row["Id"] =-1;
row["CityName"] = "Please select";
Ds. tables["Cityinfo"]. Rows.insertat (row, 0);

DataRow Row1 = ds. tables["CityInfo2"]. NewRow ();
row1["Id"] =-1;
row1["CityName"] = "Please select";
Ds. tables["CityInfo2"]. Rows.insertat (row1, 0);

Drop-down box fills data
This.comboBox1.DataSource = ds. tables["Cityinfo"];
This.comboBox1.ValueMember = "Id";
This.comboBox1.DisplayMember = "CityName";

This.comboBox2.DataSource = ds. tables["CityInfo2"];
This.comboBox2.ValueMember = "Id";
This.comboBox2.DisplayMember = "CityName";

}

private void But1_click (object sender, EventArgs e)
{

int go = Convert.ToInt32 (combobox1.selectedvalue);//Accept the value of the drop-down box
int qu = Convert.ToInt32 (combobox2.selectedvalue);
String str = "Data source=.;i Nitial catalog=ticket;integrated security=true ";//Connect database statements
String sql = "Select F.flightno,a.airways, F.leavetime,f.landtime,f.price from Airwaysinfo as a,flightinfo as F where a.i D=f.airwaysid and leavecity= ' + Go + "' and destination= '" + qu + "'";//Even Table query statements
SqlConnection conn = new SqlConnection (str);
SqlDataAdapter da = new SqlDataAdapter (SQL, conn);
DataSet ds = new DataSet ();
Da. Fill (ds, "AA");//Save in temporary data table
Dgv1. DataSource = ds. tables["AA"];

}

private void Dgv1_cellmouseclick (object sender, DataGridViewCellMouseEventArgs e)
{

Get the value in the database, assign to the variable
String no = Dgv1. Selectedrows[0]. Cells[0]. Value.tostring ();
String Hangban = Dgv1. Selectedrows[0]. CELLS[1]. Value.tostring ();
String chu = Convert.ToString (dgv1. Selectedrows[0]. CELLS[2]. Value);
String Mudidi = Dgv1. Selectedrows[0]. CELLS[3]. Value.tostring ();
int Piaojia = Convert.ToInt32 (dgv1. Selectedrows[0]. CELLS[4]. Value);
Txt1. Text = no;//Flight number
Txt5. Text = hangban;//Flight Company
Txt2. Text = combobox1.text;//Departure
Txt6. Text = combobox2.text;//Destination
Txt3. Text = convert.tostring (chu);//Departure time
Txt7. Text = mudidi;//Arrival time
Txt4. Text = Piaojia. ToString ();//Adult Fares

}

private void But2_click (object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection (con);
String date = Dtp1. Value.tostring ();//Time Control go string
Conn. Open ();
Random rd = new random ();
int num1 = Rd. Next (10000, 10000000);//random number
String sql [email protected] "INSERT into OrderInfo ([Orderid],[flightno],
[Leavedate],[number]) VALUES (' "+ num1 +" ', ' "+ txt1. Text + "', '" + Date + "', '" + nup1. Text + "')";
Try
{

if (txt1. Text==string. Empty)//Determine if there is a flight
{
MessageBox.Show ("Please select a flight!") ");
}
Else
{

if (DateTime.Now < DTP1. Value)//Judgment time
{
SqlCommand cmd = new SqlCommand (SQL, conn);
int num = cmd. ExecuteNonQuery ();
if (num > 0)
{
MessageBox.Show ("Add '" + nup1. Text + "' Zhang success!");
}
Else
{
MessageBox.Show ("Increase failure! ");
}
}
else {
MessageBox.Show ("The time format is wrong! ");
}

}
}
catch (Exception ex)
{

MessageBox.Show ("Exception! "+ex," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Finally
{
Conn. Close ();
}


}

private void But3_click (object sender, EventArgs e)
{
DialogResult result = MessageBox.Show ("OK exit!! "," hint ", Messageboxbuttons.yesno, MessageBoxIcon.Information);
if (result = = Dialogresult.yes)
{
This. Close ();
}
}

Do the project Ah, or should be familiar with all the knowledge! Book to time side hate less!

Study hard and keep up!

C # Window Aviation Summary

Related Article

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.