📄 form3.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Enterprise
{
public partial class Form3 : Form
{
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
OleDbConnection oleCon;
public Form3()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
oleCon.Open();
string people_num = this.textBox1.Text.ToString();
string people_lei = this.textBox2.Text.ToString();
string people_name = this.textBox3.Text.ToString();
string people_sex = this.textBox4.Text.ToString();
string people_adress = this.textBox5.Text.ToString();
string insertstr = "INSERT INTO Plane(people_num,people_lei,people_name,people_sex,people_adress) VALUES ('";
insertstr += people_num + "','";
insertstr += people_lei + "','";
insertstr += people_name + "','";
insertstr += people_sex + "','";
insertstr += people_adress + "')";
OleDbCommand insertcmd = new OleDbCommand(insertstr, oleCon);
insertcmd.ExecuteNonQuery();
MessageBox.Show("机票订单信息已成功添加!");
oleCon.Close();
}
private void Form3_Load(object sender, EventArgs e)
{
string strPath = Application.StartupPath + "\\Data.mdb";
string connstr = conn + strPath;
oleCon = new OleDbConnection(connstr);
}
private void button3_Click(object sender, EventArgs e)
{
try
{
if (this.comboBox1.SelectedItem.ToString() == "全部信息")
{
oleCon.Open();
string command = "select people_num as 证件号码,people_lei as 证件类型,people_name as 旅客姓名,people_sex as 旅客性别,people_adress as 送票地址 from Plane";
OleDbDataAdapter da = new OleDbDataAdapter(command, oleCon);
DataSet ds = new DataSet();
da.Fill(ds, "people");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "people";
oleCon.Close();
}
else if (this.comboBox1.SelectedItem.ToString() == "按照证件号码")
{
oleCon.Open();
string num = this.textBox6.Text.ToString();
string command = "select people_num as 证件号码,people_lei as 证件类型,people_name as 旅客姓名,people_sex as 旅客性别,people_adress as 送票地址 from Plane where people_num=" + "'" + num + "'";
OleDbDataAdapter da = new OleDbDataAdapter(command, oleCon);
DataSet ds = new DataSet();
da.Fill(ds, "people");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "people";
oleCon.Close();
}
else
{
oleCon.Open();
string name = this.textBox7.Text.ToString();
string command = "select people_num as 证件号码,people_lei as 证件类型,people_name as 旅客姓名,people_sex as 旅客性别,people_adress as 送票地址 from Plane where people_name=" + "'" + name + "'";
OleDbDataAdapter da = new OleDbDataAdapter(command, oleCon);
DataSet ds = new DataSet();
da.Fill(ds, "people");
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = "people";
oleCon.Close();
}
}
catch (OleDbException ex)
{
throw ex;
}
finally
{
if (oleCon.State == ConnectionState.Open)
{
oleCon.Close();
}
}
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
private void button6_Click(object sender, EventArgs e)
{
oleCon.Open();
string num = this.textBox8.Text.ToString();
string command = "select people_num as 证件号码,people_lei as 证件类型,people_name as 旅客姓名,people_sex as 旅客性别,people_adress as 送票地址 from Plane where people_num=" + "'" + num + "'";
OleDbDataAdapter da = new OleDbDataAdapter(command, oleCon);
DataSet ds = new DataSet();
da.Fill(ds, "people");
this.dataGridView2.DataSource = ds;
this.dataGridView2.DataMember = "people";
oleCon.Close();
}
private void button7_Click(object sender, EventArgs e)
{
oleCon.Open();
string people_num = this.textBox9.Text.ToString();
string people_lei = this.textBox10.Text.ToString();
string people_name = this.textBox11.Text.ToString();
string people_sex = this.textBox12.Text.ToString();
string people_adress = this.textBox13.Text.ToString();
string insertstr = "UPDATE Plane SET ";
insertstr += "people_num='" + people_num + "',";
insertstr += "people_name='" + people_name + "',";
insertstr += "people_lei='" + people_lei + "',";
insertstr += "people_sex='" + people_sex + "',";
insertstr += "people_adress='" + people_adress + "'";
insertstr += " where people_num=" + "'" + people_num + "'";
OleDbCommand insertcmd = new OleDbCommand(insertstr, oleCon);
insertcmd.ExecuteNonQuery();
MessageBox.Show("该机票订单信息已成功添加!");
oleCon.Close();
}
private void button8_Click(object sender, EventArgs e)
{
this.Close();
}
private void button9_Click(object sender, EventArgs e)
{
oleCon.Open();
string num = this.textBox14.Text.ToString();
string command = "select people_num as 证件号码,people_lei as 证件类型,people_name as 旅客姓名,people_sex as 旅客性别,people_adress as 送票地址 from Plane where people_num=" + "'" + num + "'";
OleDbDataAdapter da = new OleDbDataAdapter(command, oleCon);
DataSet ds = new DataSet();
da.Fill(ds, "people");
this.dataGridView3.DataSource = ds;
this.dataGridView3.DataMember = "people";
oleCon.Close();
}
private void button10_Click(object sender, EventArgs e)
{
string num = this.textBox14.Text.ToString();
oleCon.Open();
string command = "delete * from Plane where people_num=" + "'" + num + "'";
OleDbCommand myCommand = new OleDbCommand(command, oleCon);
myCommand.ExecuteNonQuery();
oleCon.Close();
MessageBox.Show("该机票订单信息已经成功删除!");
}
private void button11_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -