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

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

reread(); } else {

MessageBox.Show(\退票失败!\ } }

catch (Exception ex) {

MessageBox.Show(ex.Message); } } //管理员增加车票

private void btnluru_Click(object sender, EventArgs e) {

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

MessageBox.Show(this, \ 请输入车次 !MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入出发地 !MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入出发时间!MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入目的地 !MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入到达时间 !MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

27

\\Information:\\\Information:\

\\Information:\

\\Information:\

\\Information:\

return; }

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

MessageBox.Show(this, \ 请输入车票数量 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入车票价格! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; } try {

string strSql = \车票信息表 values ('\ + txtcheci.Text + \ + txtstartzhan.Text + \ + txtsfshijian.Text + \ + txtendzhan.Text + \ + txtdaodashijian.Text + \ + txtyingzuoshu.Text + \

+ txtyingzuopiaojia.Text + \ //连接字符串

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

ID=sa;Password=123456\

//执行语句

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

MessageBox.Show(\添加成功!\ return; } else {

MessageBox.Show(\添加失败!\ } }

catch (Exception ex) {

MessageBox.Show(ex.Message); } }

28

//公用执行函数ExecuteNonQuery

public int ExecuteNonQuery(string sql, string conStr) {

using (SqlConnection con = new SqlConnection(conStr)) {

con.Open();

SqlCommand cmd = new SqlCommand(sql, con); return cmd.ExecuteNonQuery(); } } //查看订单

private void mytrian_Load(object sender, EventArgs e) {

this.车票预订表TableAdapter.Fill(this.火车票管理系统DataSet2我的火车票.车票预订表);

SqlConnection conn = new SqlConnection();

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

ID=sa;Password=123456\

conn.Open();

String cmdStr = \车票预订表 where 用户号= '\ SqlCommand sqlCom = new SqlCommand(cmdStr, conn); SqlDataAdapter myadap = new SqlDataAdapter(); myadap.SelectCommand = sqlCom; DataSet myset = new DataSet(); myadap.Fill(myset, \车票预订表\

this.dataGridView1.DataSource = myset.Tables[\车票预订表\

}

//用户修改密码

public partial class updatemima : Form {

public updatemima() {

InitializeComponent(); }

private bool check() {

string str = this.txtzhanghao.Text;

SqlConnection conn = new SqlConnection();

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

ID=sa;Password=123456\

conn.Open();

String commstring = \密码 from 用户表 where 用户号='\ SqlCommand change_comm = new SqlCommand(commstring, conn); SqlDataReader reader = change_comm.ExecuteReader();

29

if (reader.Read() == true) {

if (reader[\密码\ {

MessageBox.Show(this, \ 您输入的原密码不正确 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

reader.Close(); conn.Close(); return false; } else {

reader.Close(); conn.Close(); return true; } } else {

MessageBox.Show(this, \ 不存在您输入的登录帐号 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

reader.Close(); conn.Close(); return false; } }

private void change_code() {

string str1 = this.txtxinmima.Text;

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

ID=sa;Password=123456\

SqlConnection conn1 = new SqlConnection(connstring1); conn1.Open();

string commstring1 = \用户表 set 密码='\ SqlCommand comm1 = new SqlCommand(commstring1, conn1); comm1.ExecuteNonQuery(); conn1.Close();

MessageBox.Show(\登录密码修改成功!\提示\ }

private void btnconfim_Click(object sender, EventArgs e) {

bool str;

if (txtzhanghao.Text == string.Empty)

30

{

MessageBox.Show(this, \ 请输登录帐号 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输原登录密码 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请输入新登录密码 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

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

MessageBox.Show(this, \ 请再次输入新登录密码 ! \\Information:\

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return; }

str = check(); if (str == false) {

return; } else {

if (this.txtxinmima.Text != this.txtxinmimaagain.Text) {

MessageBox.Show(this, \ 您两次输入的心密码不一致 ! \\

Information:\

} else {

change_code(); } } } //查看用户信息

private void userxinxi_Load(object sender, EventArgs e)

31