zoukankan      html  css  js  c++  java
  • 航班查询及预订系统的主要代码块实现

    【实现查询航班信息的功能】

    /// <summary>
    /// 窗体加载填充数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Flight_Load(object sender, EventArgs e)
    {
    try{
    //查询用的sql语句
    string sql = "select * from CityInfo";
    //查询并填充数据集
    DBHelper db = new DBHelper();
    this.ds = new DataSet();//创建数据集对象
    //创建DataAdapter
    sda = new SqlDataAdapter(sql, db.Connection);
    //填充数据集
    sda.Fill(ds,"CityInfo");
    //请选择实现
    DataRow row = ds.Tables["CityInfo"].NewRow();
    row["Id"] = -1;
    row["CityName"] = "请选择";
    ds.Tables["CityInfo"].Rows.InsertAt(row,0);
    //绑定城市数据
    this.cboCityInfo.DataSource = ds.Tables["CityInfo"];
    this.cboCityInfo.ValueMember = "Id";
    this.cboCityInfo.DisplayMember = "CityName";
    //绑定目的地数据
    DataView dv = new DataView(ds.Tables["CityInfo"]);
    this.cboCitytermini.DataSource = dv;
    this.cboCitytermini.ValueMember = "Id";
    this.cboCitytermini.DisplayMember = "CityName";
    }
    catch(Exception ex){
    MessageBox.Show(ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
    }
    }

    private void button1_Click(object sender, EventArgs e)
    {
    //查询数据并显示
    if (cboCitytermini.Text != "请选择" && cboCitytermini.Text != "请选择")
    {
    int fromid = Convert.ToInt32(cboCityInfo.SelectedValue);
    int toid = Convert.ToInt32(cboCitytermini.SelectedValue);
    FlightSelect(fromid,toid);
    }
    }

    【实现航班选择,分组框,文本框传值】

    /// <summary>
    /// 实现航班选择,文本框,分组框传值
    /// </summary>
    public void FlightDetails()
    {
    //在第二个分组框显示信息
    //拿到当前选中项的航班号
    string Flightnum = Convert.ToString(dgvTicketInfo.SelectedRows[0].Cells[0].Value); //航空公司
    string Airways = Convert.ToString(dgvTicketInfo.SelectedRows[0].Cells[1].Value);
    //出发时间
    string LeaveTime = Convert.ToString(dgvTicketInfo.SelectedRows[0].Cells[2].Value);
    //到达时间
    string LandTime = Convert.ToString(dgvTicketInfo.SelectedRows[0].Cells[3].Value);
    //成人票价
    string Price = Convert.ToString(dgvTicketInfo.SelectedRows[0].Cells[4].Value);
    //出发地
    string formCity = cboCityInfo.Text;
    //目的地
    string toidCity = cboCitytermini.Text;
    //赋值给第二个分组框text文本框各个值
    txtFlightNum.Text = Flightnum.ToString();
    txtAirways.Text = Airways;
    txtLeaveTime.Text = LeaveTime;
    txtLandTime.Text = LandTime;
    txtPrice.Text = Price.ToString();
    txtCityInfo.Text = formCity;
    txtDetination.Text = toidCity;

    }

    【增加预订记录,实现航班预订功能】

    /// <summary>
    /// 增加预订记录,实现航班预订功能
    /// </summary>
    /// <returns></returns>
    public int InsertAt()
    {

    //获取学生数据
    //打开数据库连接
    DBHelper db = new DBHelper();
    Random r = new Random();
    int OrderId = r.Next(1000,1000000);//6位随机数的订单编号

    string FlightNo = Convert.ToString(txtFlightNum.Text);//航班号

    int Number = Convert.ToInt32(numericUpDown1.Value);//预订数量

    DateTime LeaveDate = DtlPicker.Value;//出发日期
    try
    {
    //sql语句
    string sql = "INSERT INTO OrderInfo([OrderId],[FlightNo],[LeaveDate],[Number]) VALUES('" + OrderId + "','" + FlightNo + "','" + LeaveDate + "','" + Number + "')";
    //创建Command对象
    SqlCommand comm = new SqlCommand(sql, db.Connection);
    db.OpenConnection();
    //执行命令
    int result = comm.ExecuteNonQuery();
    if (result > 0)
    {
    return OrderId;
    }
    else
    {
    return -1;
    }
    }
    catch (Exception)
    {
    return -1;
    }
    finally
    {
    //关闭数据库连接
    db.CloseConnection();

    }
    }

    //点击预订按钮,订票
    if (Convert.ToDateTime(DtlPicker.Text) < Convert.ToDateTime(DateTime.Now.ToString()))
    {
    MessageBox.Show("请选择正确的出发日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    else
    {
    if (this.txtFlightNum == null)
    {
    MessageBox.Show("请选择一个航班!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
    else
    {
    int sum = InsertAt();
    MessageBox.Show("预订成功!您的订单编号为:"+sum,"提示",MessageBoxButtons.OK);
    }
    }

  • 相关阅读:
    SVN合并时报错:Merge tracking not allowed with missing subtrees; try restoring these items
    The operation names in the portType match the method names in the SEI or Web service implementation class.
    原生java调用webservice的方法,不用生成客户端代码
    如何快速开发一个支持高效、高并发的分布式ID生成器
    分布式ID生成器解决方案
    高并发分布式系统中生成全局唯一Id汇总
    python接口自动化17-multipart/form-data表单提交
    httprunner学习25-文件上传multipart/form-data
    python测试开发django-72.删除表后如何重新生成表
    python测试开发django-71.自定义标签tag
  • 原文地址:https://www.cnblogs.com/java-123/p/8523673.html
Copyright © 2011-2022 走看看