航班查询系统

拖动框架属性  把基本的框架写完 属性的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();
}

}
}
}

 

转载于:https://www.cnblogs.com/BaoWangZe/p/8523800.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值