zoukankan      html  css  js  c++  java
  • 航班查询及预订

          时光老人会带着我们一起成长,也见证我们努力的成果,分享我的成果~~~~~

    前提:数据库是自己做的

    第一步:搭建框架

      

    第二步:Load的事件中绑定下拉框

       1.为了看着方便我定义  //下拉框的绑定出发地

     1   public void One() 
     2         {
     3             string str = Main.str;
     4             SqlConnection con = new SqlConnection(str);
     5             string sql = "select Id, CityName from CityInfo";
     6             SqlDataAdapter da = new SqlDataAdapter(sql, con);
     7             DataSet ds = new DataSet();
     8             try
     9             {
    10                 da.Fill(ds, "StuIn");
    11 
    12                 //01.形成行对象
    13                 DataTable table=ds.Tables[0];
    14                 DataRow dr = table.NewRow();
    15                 //02.给该行的列赋值
    16                 dr[0] = -1;
    17                 dr[1]="-----请选择------";
    18                 //03.让航对象和tabel产生关系
    19                 table.Rows.InsertAt(dr,0);
    20 
    21                 Cbmone.DataSource = ds.Tables[0];
    22                 //绑定数据源 下拉框名字
    23                 Cbmone.DisplayMember = "CityName";
    24               
    25                 
    26                 //下拉框的隐藏值
    27                 Cbmone.ValueMember = "Id";
    28                
    29                
    30             }
    31             catch (Exception)
    32             {
    33                 MessageBox.Show("网络异常");
    34             }
    35             finally
    36             {
    37                 con.Close();
    38             }
    39         }

      2.为了看着方便我定义  //下拉框的绑定目的地

     1  public void two() 
     2         {
     3              string str = Main.str;
     4             SqlConnection con = new SqlConnection(str);
     5             string sql = "select Id, CityName from CityInfo";
     6             SqlDataAdapter da = new SqlDataAdapter(sql, con);
     7             DataSet ds = new DataSet();
     8             try
     9             {
    10                 da.Fill(ds, "StuIn");
    11 
    12                 //01.形成行对象
    13                 DataTable table = ds.Tables[0];
    14                 DataRow dr = table.NewRow();
    15                 //02.给该行的列赋值
    16                 dr[0] = -1;
    17                 dr[1] = "-----请选择------";
    18                 //03.让航对象和tabel产生关系
    19                 table.Rows.InsertAt(dr, 0);
    20 
    21                 comtwo.DataSource = ds.Tables["StuIn"];
    22                 //绑定数据源 下拉框名字
    23                 comtwo.DisplayMember = "CityName";
    24                 
    25                 //下拉框的隐藏值
    26              
    27                 comtwo.ValueMember = "Id";
    28             }
    29             catch (Exception)
    30             {
    31                 MessageBox.Show("网络异常");
    32             }
    33             finally
    34             {
    35                 con.Close();
    36             }
    37         }

      3.在Load的事件中调用

    1  private void Flight_Load(object sender, EventArgs e)
    2         {
    3             
    4             //下拉框的绑定出发地
    5             One();
    6             //下拉框的绑定目的地
    7             two();
    8            
    9         }

    显示图:

    第三步:点击查询按钮进行查询数据

     1  //加载灰色的数据库的信息
     2  private void btselect_Click(object sender, EventArgs e)
     3         {
             //是下拉框的隐藏值
    4 int start = Convert.ToInt32(Cbmone.SelectedValue); 5 int end = Convert.ToInt32(comtwo.SelectedValue); 6 string str = Main.str; 7 SqlConnection con = new SqlConnection(str); 8 string sql = "select FlightNO,Airways,LeaveTime, LandTime, Price from AirwaysInfo,FlightInfo where AirwaysInfo.Id=FlightInfo.AirwaysId and LeaveCity="+start+" and Destination="+end+""; 9 SqlDataAdapter da = new SqlDataAdapter(sql,con); 10 DataSet ds = new DataSet(); 11 try 12 13 { 14 da.Fill(ds, "StuInOf"); 15 Gvlist.DataSource = ds.Tables["StuInOf"]; 16 //绑定数据源 下拉框名字 17 18 } 19 catch (Exception) 20 { 21 MessageBox.Show("网络异常"); 22 } 23 finally 24 { 25 con.Close(); 26 } 27 28 }

    显示图:

    第四步:点击事件,在航班预订中显示信息

     1   private void Gvlist_CellClick(object sender, DataGridViewCellEventArgs e)
     2         {
     3              //航班号(重点)
     4             tbflightNumber.Text = Gvlist.SelectedRows[0].Cells[0].Value.ToString();
     5             //航空公司
     6             tbariway.Text = Gvlist.SelectedRows[0].Cells[1].Value.ToString();
     7             //出发时间
     8             tbTime.Text = Gvlist.SelectedRows[0].Cells[2].Value.ToString();
     9             //到达时间
    10             tbday.Text = Gvlist.SelectedRows[0].Cells[3].Value.ToString();
    11             //成人票
    12             tbprice.Text = Gvlist.SelectedRows[0].Cells[4].Value.ToString();
    13             //出发地
    14             tbplace.Text = Cbmone.Text;  
    15             //目的地
    16             tbplacee.Text = comtwo.Text; 
    17         }

    显示图:

    小理解:

    第五步:预订=====在点击按钮中

     1      //预定票
     2   private void btorder_Click(object sender, EventArgs e)
     3         {
     4         int start = Convert.ToInt32(Cbmone.SelectedValue);
     5             int end = Convert.ToInt32(comtwo.SelectedValue);
     6             //int AirwaysId = Convert.ToInt32(AirwaysId);
     7             string str = Main.str;
     8             SqlConnection con = new SqlConnection(str);
     9             int num = Convert.ToInt32(NUDcount.Text);
    10             //随机数
    11             Random OrderId = new Random();
    12             string num2 = OrderId.Next(100000, 999999).ToString();
    13             //航班号
    14             string FlightNo = tbflightNumber.Text;
    15             //出发时间
    16             string LeaveDate = tbTime.Text;
    17             int Number = num;
    18             string sql = "insert into OrderInfo values('" + num2 + "','" + FlightNo + "','" + LeaveDate + "'," + Number + ")";
    19             SqlCommand cmd = new SqlCommand(sql, con);
    20             try
    21             {
    22                 con.Open();
    23                 int count = Convert.ToInt32(cmd.ExecuteNonQuery());
    24                 if (count > 0)
    25                 {
    26                     MessageBox.Show("预定成功!订单号为" + num2, "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
    27 
    28                 }
    29                 else
    30                 {
    31                     MessageBox.Show("预定失败");
    32 
    33                 }
    34             }
    35             catch (Exception)
    36             {
    37 
    38                 MessageBox.Show("异常");
    39             }
    40             finally
    41             {
    42                 con.Close();
    43             }
    44            
    45         }

    显示图:

        

    第六步:在点击关闭按钮时退出整个的窗体

    1   private void btclose_Click(object sender, EventArgs e)
    2         {
    3             Application.Exit();
    4         }

              我的成果,希望和大家分享,有错的地方,请多指教!!!!!

  • 相关阅读:
    总结ASP.NET C#中经常用到的13个JS脚本代码
    C# 处理 JSON 常用的帮助类
    C# 中移动文件到指定位置
    C# 常用时间戳处理方法
    c#批量上传图片到服务器示例分享
    C# 通过URL获取图片并显示在PictureBox上的方法
    QT中Qtableview视图表格中点击表头进行排序
    qt QTableWidget&&QTableView 导出数据到excel
    51nod 1242 斐波那契数列的第N项
    矩阵快速幂
  • 原文地址:https://www.cnblogs.com/yejiaojiao/p/5015023.html
Copyright © 2011-2022 走看看