zoukankan      html  css  js  c++  java
  • 航班查询系统

    拖动框架属性  把基本的框架写完 属性的name值改了 txt显示文本

    然后写代码

    链接数据库 

    string lian = "Data Source=.;Initial Catalog=ticke;User ID=sa ";//连接的地址

    SqlConnection conn = new SqlConnection(lian);//连接对象

    Dataset ds = new  Dataset();//独立于数据源的数据集

    string sql = "select * from 表明";//写数据库

    Sqldataadapter addap = new SqlDataadapter(sql,conn);//卡车

    }
    private void chufadi()
    {
    //创建字符串和数据集
    fangfa lian = new fangfa();
    SqlConnection conn = new SqlConnection(lian.str);
    string sql = "Select * from CityInfo";
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    da.Fill(ds,"CityInfo");
    da.Fill(ds, "CityInfo2");


    //向数据集第一行添加数据"请选择"
    DataRow row = ds.Tables["CityInfo"].NewRow();
    row["Id"] = -1;
    row["CityName"] = "请选择";
    ds.Tables["CityInfo"].Rows.InsertAt(row, 0);

    DataRow row1 = ds.Tables["CityInfo2"].NewRow();
    row1["Id"] = -1;
    row1["CityName"] = "请选择";
    ds.Tables["CityInfo2"].Rows.InsertAt(row1, 0);

    //向下拉框填充数据
    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 chaxun()
    {

    fangfa lian = new fangfa();
    SqlConnection conn = new SqlConnection(lian.str);
    int go = Convert.ToInt32(comboBox1.SelectedValue);
    int qu = Convert.ToInt32(comboBox2.SelectedValue);
    string sql = " select f.FlightNo,a.Airways ,f.LeaveTime,f.LandTime,f.Price from AirwaysInfo as a,FlightInfo as f where a.Id=f.AirwaysId and LeaveCity='" + go + "' and Destination='" + qu + "'";
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();
    da.Fill(ds, "aa");
    dataGridView1.DataSource = ds.Tables["aa"];

    }

    private void Form1_Load(object sender, EventArgs e)
    {
    chufadi();

    }

    private void groupBox1_Enter(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
    chaxun();
    }

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {

    string no = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
    string hangban = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
    string chu = Convert.ToString(dataGridView1.SelectedRows[0].Cells[2].Value);
    string mudidi = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
    int piaojia = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[4].Value);
    textBox1.Text = no;
    textBox6.Text = hangban;
    textBox2.Text = comboBox1.Text;
    textBox7.Text = comboBox2.Text;
    textBox3.Text = Convert.ToString(chu);
    textBox8.Text = mudidi;
    textBox4.Text = piaojia.ToString();

    }

    private void textBox5_TextChanged(object sender, EventArgs e)
    {
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
    yuding();
    }
    public void yuding()
    {
    Random rd = new Random();
    string date = textBox3.Text.ToString();

    int num1 = rd.Next(10000, 10000000);//随机数
    fangfa lian = new fangfa();
    SqlConnection conn = new SqlConnection(lian.str);
    conn.Open();
    string sql = "INSERT INTO OrderInfo VALUES ('"+num1+"','"+textBox1.Text+"','"+date+"','"+numericUpDown1.Text+"')";
    try
    {
    string kong = string.Empty;
    if (textBox1.Text != kong)
    {


    dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
    int piaojia = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[4].Value);
    textBox1.Text = no;
    textBox6.Text = hangban;
    textBox2.Text = comboBox1.Text;
    textBox7.Text = comboBox2.Text;
    textBox3.Text = Convert.ToString(chu);
    textBox8.Text = mudidi;
    textBox4.Text = piaojia.ToString();

    }

    private void textBox5_TextChanged(object sender, EventArgs e)
    {
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
    yuding();
    }
    public void yuding()
    {
    Random rd = new Random();
    string date = textBox3.Text.ToString();

    int num1 = rd.Next(10000, 10000000);//随机数
    fangfa lian = new fangfa();
    SqlConnection conn = new SqlConnection(lian.str);
    conn.Open();
    string sql = "INSERT INTO OrderInfo VALUES ('"+num1+"','"+textBox1.Text+"','"+date+"','"+numericUpDown1.Text+"')";
    try
    {
    string kong = string.Empty;
    if (textBox1.Text != kong)
    {

    if (DateTime.Now < dateTimePicker1.Value)
    {
    SqlCommand cmd = new SqlCommand(sql, conn);
    int num = cmd.ExecuteNonQuery();
    if (num > 0)
    {
    MessageBox.Show("增加'" + numericUpDown1.Text + "'张成功!");
    }
    else
    {
    MessageBox.Show("增加失败!");
    }
    }
    else
    {
    MessageBox.Show("增加失败!");
    }
    }
    else
    {
    MessageBox.Show("请选择");
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(sql);
    MessageBox.Show("异常!"+ex, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    finally
    {
    conn.Close();
    }

    }
    }
    }

  • 相关阅读:
    eclipse测试链接sql server2008 数据库
    Java中的日期格式转化
    java.sql.SQLException: Field 'id' doesn't have a default value(用eclipse操作数据库时报了这种奇怪的错误)的原因与解决方法
    Java进程与线程的区别
    Java开发岗位面试题归类
    JavaScript 里,$ 代表什么?/JQuery是什么语言?/html中用link标签引入css时的中 rel="stylesheet"属性?/EL表达式是什么?
    (一)初识EasyTouch
    简单影子制作
    屏幕分辨率
    VuforiaAR 教程
  • 原文地址:https://www.cnblogs.com/BaoWangZe/p/8523800.html
Copyright © 2011-2022 走看看