用C#做火车订票管理系统课程设计 下载本文

内容发布更新时间 : 2024/5/19 17:54:14星期一 下面是文章的全部内容请认真阅读。

图4-15用户修改密码

4.3管理员模块

管理员可以注册用户账号,拥有用户所拥有的所有模块,包括列车信息查询,购票,退票,查看用户信息,查看订单,修改登录密码。并且管理员还有自己特定的账号,具体增加车票的权限。管理员运行界面如图4-16所示。

图4-16管理员运行界面

管理员输入车票车次,出发地和出发时间等相关信息,单击增加车票,弹出如图4-17界面。

22

图4-17管理员增加车票

单击确定,车票添加成功。用户就可以买这班火车票。

23

5 设计代码

//登录

private void btnLogin_Click(object sender, EventArgs e) {

cApp.m_User.m_User = txtName.Text; cApp.m_User.m_Type = txtidentity.Text; string userName = txtName.Text; string password = txtPassword.Text; string type = txtidentity.Text;

if (txtName.Text == \ {

MessageBox.Show(\登录账号或密码,身份不能为空!\\警告\MessageBoxButtons.OK,

MessageBoxIcon.Warning);

} else

if (txtidentity.Text == \用户\ { {

SqlConnection conn = new SqlConnection();

conn.ConnectionString = \火车票管理系

统;User ID=sa;Password=123456\

conn.Open();

string cmdStr = \用户表 where 用户号='\密码='\

password + \定义查询语句

SqlCommand sqlCom = new SqlCommand(cmdStr, conn);//定义查询命令 SqlDataReader sdr = sqlCom.ExecuteReader(); if (sdr.HasRows) {

this.Hide();

user U_user = new user(); U_user.Show(); } else {

MessageBox.Show(\登录账号或密码错误!\\错误\MessageBoxButtons.OK,

MessageBoxIcon.Error);

}

conn.Close(); } }

24

else {

SqlConnection conn = new SqlConnection();

conn.ConnectionString = \

Catalog=火车票管理系统;User ID=sa;Password=123456\

conn.Open();

string cmdStr = \管理员表 where 管理号='\

userName + \密码='\定义查询语句

SqlCommand sqlCom = new SqlCommand(cmdStr, conn);//定义查询命令 SqlDataReader sdr = sqlCom.ExecuteReader(); if (sdr.HasRows) {

this.Hide();

manager M_manager = new manager(); M_manager.Show(); } else {

MessageBox.Show(\登录账号或密码错误!\错误\

MessageBoxButtons.OK, MessageBoxIcon.Error);

}

conn.Close(); } } //用户购票

private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) {

if (txtusername.Text == string.Empty) {

MessageBox.Show(this, \ 请输入乘客姓名 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

if (txtshenfen.Text == string.Empty) {

MessageBox.Show(this, \ 请输入乘客身份证号 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

int a = dataGridView1.CurrentRow.Index; try {

25

string strSql = \车票预订表(出发日,用户号,姓名,身份证号,车次,出发地,出发时间,

目的地,到达时间,车票价格) values ( '\+ cApp.m_User.m_User + \txtusername.Text + \dataGridView1.Rows[a].Cells[1].Value + \+ dataGridView1.Rows[a].Cells[3].Value

+\

//连接字符串

string conn = \Source=2013-20141011IV;Initial Catalog=火车票管理系统;User

ID=sa;Password=123456\

//执行语句

if (ExecuteNonQuery(strSql, conn) > 0) {

success s = new success(); s.Show(); this.Hide(); } else {

MessageBox.Show(\预订失败!\ } }

catch (Exception ex) {

MessageBox.Show(ex.Message); } } //用户退票

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {

int a = dataGridView1.CurrentRow.Index; try { string

strSql

=

\

from

车票预订表 +

\

and

where 份

姓名= 证

'\='\

+ +

dataGridView1.Rows[a].Cells[0].Value + \

//连接字符串

string conn = \Source=2013-20141011IV;Initial Catalog=火车票管理系统;User

ID=sa;Password=123456\

//执行语句

if (ExecuteNonQuery(strSql, conn) > 0) {

MessageBox.Show(\退票成功\提示!\

dataGridView1.Rows[a].Cells[1].Value + \and 车次='\+ dataGridView1.Rows[a].Cells[3].Value

26