public void Find()
{
DBHelper db = new DBHelper();
string sql = "select Id,CityName from CityInfo ";
MessageBox.Show(sql);
SqlConnection conn = new SqlConnection(db.str);
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "s");
//增加“全部”到查询数据的前面
DataRow rows = ds.Tables["s"].NewRow();
// rows["Id"] = -1;
rows["CityName"] = "请选择";
ds.Tables["s"].Rows.InsertAt(rows, 0);
comboBox1.DataSource = ds.Tables["s"];
comboBox1.DisplayMember = "CityName";
comboBox1.ValueMember = "Id";
}
public void ine()
{
DBHelper db = new DBHelper();
string sql = "select Id,CityName from CityInfo ";
MessageBox.Show(sql);
SqlConnection conn = new SqlConnection(db.str);
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "s");
//增加“全部”到查询数据的前面
DataRow rows = ds.Tables["s"].NewRow();
//rows["Id"]=-1;
rows["CityName"] = "请选择";
ds.Tables["s"].Rows.InsertAt(rows, 0);
comboBox2.DataSource = ds.Tables["s"];
comboBox2.DisplayMember = "CityName";
comboBox2.ValueMember = "Id";
}
public void findall()
{
DBHelper db = new DBHelper();
int fromCityNum = Convert.ToInt32(comboBox1.SelectedValue);
int toCityNum = Convert.ToInt32(comboBox2.SelectedValue);
string sql = @"select * from AirwaysInfo as A,FlightInfo as F where A.Id = F.AirwaysId
and LeaveCity = '" + fromCityNum + "' and Destination = '" + toCityNum + "'";
SqlConnection conn = new SqlConnection(db.str);
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ds.Tables.Clear();
da.Fill(ds, "ss");
dataGridView1.DataSource = ds.Tables["ss"];
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string no = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//string xue = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string yes = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string qw = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
string ew = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
//string rw = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
string aw = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
textBox1.Text = no;
textBox2.Text = comboBox2.Text;
textBox3.Text = yes;
textBox4.Text = qw;
textBox5.Text = ew;
textBox6.Text = comboBox1.Text;
textBox7.Text = aw;
}
public void ding()
{
DBHelper db = new DBHelper();
SqlConnection conn = new SqlConnection(db.str);
if ((textBox1.Text).Equals(string.Empty))
{
MessageBox.Show("请选择正确的航班!", "提示", MessageBoxButtons.OK);
}
else
{
if (Convert.ToDateTime(dateTimePicker1.Text) < Convert.ToDateTime(DateTime.Now.ToString()))
{
MessageBox.Show("请输入正确日期", "提示", MessageBoxButtons.OK);
}
else
{
if (numericUpDown1.Value > 0)
{
Random r = new Random();
int a = r.Next(10000, 1000000);
string sql = @"insert into OrderInfo(OrderId,FlightNo,LeaveDate,Number) Values
('" + a + "','" + textBox1.Text + "','" + dateTimePicker1.Value.ToString() + "','" + numericUpDown1.Value.ToString() + "')";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int b = cmd.ExecuteNonQuery();
if (b == 1)
{
MessageBox.Show("成功,您的机票编号为:" + a, "提示", MessageBoxButtons.OK);
conn.Close();
}
}
else
{
MessageBox.Show("乘坐人数为0!", "警告", MessageBoxButtons.OK);
}
}
}
}
}
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定退出吗!!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
this.Close();
}
}
要注意细节 事件 方法 属性 等等!!!