您好,欢迎来到九壹网。
搜索
您的当前位置:首页C#数据库应用系统(机票预定系统)源代码

C#数据库应用系统(机票预定系统)源代码

来源:九壹网


C#数据库应用系统(机票预定系统)源代码

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Data.SqlClient; using System.Windows.Forms;

namespace TicketOrder {

public partial class Form1 : Form {

public Form1() {

InitializeComponent(); }

string sql = \"\";

string connStr =@\"server=sa\\SQLEXPRESS;database=Ticket;trusted_connection=true\"; SqlDataAdapter da; DataSet ds;

private void Form1_Load(object sender, EventArgs e) {

sql = \"select FlightNO as '航班号',LeaveCity as '出发城市',Destination as '目的城市',LeaveTime as '出发时间' from TicketInfo where 1=1\"; Fill(); }

///

/// 初始化函数 /// private void Fill() {

da = new SqlDataAdapter(sql, connStr); ds = new DataSet(); try {

da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0]; }

catch (Exception ex) {

MessageBox.Show(\"输入信息有误,可能有不能识别的字符!\"+ex.Message); } }

private void button3_Click(object sender, EventArgs e) {

bool isNew = true; while (isNew) {

if (txtChufa.Text != \"\") {

sql += string.Format(\" and LeaveCity like'%{0}%'\ Fill(); }

if (txtMudi.Text != \"\") {

sql += string.Format(\" and Destination like'%{0}%'\ Fill(); }

isNew = false;

sql = \"select FlightNO as '航班号',LeaveCity as '出发城市',Destination as '目的城市',LeaveTime as '出发时间' from TicketInfo where 1=1\"; } }

private void button1_Click(object sender, EventArgs e) {

sql = string.Format(\"insert into OrderInfo(FlightNO,SeatType,Number,LeaveDate) values('{0}','{1}','{2}','{3}')\ SqlConnection conn = new SqlConnection(connStr); int num = 0; try {

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn); num = cmd.ExecuteNonQuery(); if (num != 0)

MessageBox.Show(\"预定成功!\"); else

MessageBox.Show(\"预定失败!\");

}

catch (Exception ex) {

MessageBox.Show(ex.Message); }

finally {

conn.Close(); } }

private void button2_Click(object sender, EventArgs e) {

Application.Exit(); } } }

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务