一、建立C#窗体

所需控件:

Label标签

Button 按钮

TextBox 文本框

ComboBox 组合框

DATaGridView 数据显示

DateTimePicker 日期表

NumericUpDown 数字选择

二、建立后台数据库

大概需要四张表

1,航空公司表

2,城市信息表

3,航班信息表

3,订单信息表

三、向comboBox中插入城市信息供用户选择

示例SQL语句:

select CityName from CityInfo

四、让DataGridView显示查询到的数据

示例SQL语句:

int AirId = comboBox1.SelectedIndex ;

int DestinationId = comBox2.SelectedIndex;

select * from FlightInfo as F,AirwaysInfo as A where AirwaysInfo.Id = FlightInfo.AirwaysId and FlightInfo.LeaveCity='" + AirId + "' and FlightInfo.Destination='" + DestinationId + "

将行显示属性 设置为 FullRowSelect

并将每个值显示在各个TextBox 文本框

五、预定订单

获取订单数量,用户选择的航班信息和日期

添加到返回到数据库中,预定成功

全部参考代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookPlane
{
public partial class FIightOrderMSG : Form
{
public FIightOrderMSG()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
FillDataGridView();
}

private void Form1_Load(object sender, EventArgs e)
{
dgvList.AutoGenerateColumns = false;
FindCityInfo();
}

DBHelper db = new DBHelper();
/// <summary>
/// 查询航班出发地
/// </summary>
public void FindCityInfo()
{
string sql = "select * from CityInfo";

try
{
db.conOpen();
SqlCommand comm = new SqlCommand(sql, db.conn);
SqlDataReader reader = comm.ExecuteReader();
cboStart.Items.Add("请选择");
cboStart.Items.IndexOf(0);
cboStart.SelectedIndex = 0;
cboEnd.Items.Add("请选择");
cboEnd.Items.IndexOf(0);
cboEnd.SelectedIndex = 0;
if (reader.HasRows)
{
while (reader.Read())
{
string city = reader["CityName"].ToString();
cboStart.Items.Add(city);
cboEnd.Items.Add(city);
}
reader.Close();
}
else
{
MessageBox.Show("未检测到有效信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception)
{
MessageBox.Show("发生错误!");
}
finally
{
db.conClose();
}
}

/// <summary>
/// 填充DataGridView中的数据
/// </summary>
public void FillDataGridView()
{

//连接数据库
SqlConnection conn = new SqlConnection(db.strCon);
//创建SQL语句
StringBuilder sql = new StringBuilder();
//获取comboBox被选中的下标
int AirId = cboStart.SelectedIndex;
int DestinationId = cboEnd.SelectedIndex;
//创建SQL语句
sql.AppendLine(" select * from FlightInfo,AirwaysInfo");
sql.AppendLine(" where AirwaysInfo.Id = FlightInfo.AirwaysId");
sql.AppendLine(" and FlightInfo.LeaveCity='" + AirId + "' and FlightInfo.Destination='" + DestinationId + "'");
//创建适配器,卡车对象
SqlDataAdapter da = new SqlDataAdapter(sql.ToString(), conn);
DataSet ds = new DataSet();
da.Fill(ds, "air");
dgvList.DataSource = ds.Tables["air"];

//string FlightNo = reader["FlightNo"].ToString();
//string Airways = reader["Airways"].ToString();
//string LeaveTime = reader["LeaveTime"].ToString();
//string LandTime = reader["LandTime"].ToString();
//string Price = reader["Price"].ToString();

}

private void dgvList_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取DataGridView中的值,显示在各个文本框中
txtFlightNo.Text = Convert.ToString(dgvList.SelectedCells[0].Value);
txtFlightCompany.Text = dgvList.SelectedRows[0].Cells[1].Value.ToString();
txtStartTime.Text = dgvList.SelectedRows[0].Cells[2].Value.ToString();
txtEndTime.Text = dgvList.SelectedRows[0].Cells[3].Value.ToString();
txtPrice.Text = dgvList.SelectedRows[0].Cells[4].Value.ToString();
txtStart.Text = cboStart.SelectedItem.ToString();
txtEnd.Text = cboEnd.SelectedItem.ToString();
}

private void btnOrder_Click(object sender, EventArgs e)
{
//产生6位随机数
Random r = new Random();
string random = Convert.ToString(r.Next(100000, 1000000));
string flightNo = txtFlightNo.Text;
int num = Convert.ToInt32(nudOrderNum.Value);
if (txtFlightCompany.Text != string.Empty)
{
if (dtpStart.Value < DateTime.Now)
{
MessageBox.Show("请选择一个有效的时间!", "提示");
}
else
{
SqlConnection conn = new SqlConnection(db.strCon);
DateTime leaveTime = dtpStart.Value;
try
{

//连接数据库
conn.Open();
string sql = @"insert into OrderInfo values('" + random + "','" + flightNo + "','" + leaveTime + "'," + num + ")";
SqlCommand comm = new SqlCommand(sql, conn);
int isReact = comm.ExecuteNonQuery();
if (isReact > 0)
{
MessageBox.Show("预定成功!祝您旅途愉快!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show("发生错误!" + ex);
}
finally
{
conn.Close();
}
}
}
else
{
MessageBox.Show("请选择一个航班!", "提示");
}

}

private void btnClose_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定要关闭吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
this.Close();
}
}
}
}

转载于:https://www.cnblogs.com/chenyang520/p/8529595.html

模拟航班查询及预定系统 编写示例相关推荐

  1. 开发“航班查询及预定”系统

    整体的首页 //创建配适器 SqlDataAdapter sa;//创建临时数据集 DataSet ds;public FrmLogin(){InitializeComponent();}privat ...

  2. 基于android的航班查询飞机票订购系统app

    基于Android的航班查询系统.使用了I/O流读文件.Dom解析xml文件和反射技术实现了航班的始末城市.航班号查询等功能,并采用数据库SQLite存储航班信息数据,用户可以通过手机随时随地查询航班 ...

  3. 计算机毕业设计基于android的航班查询飞机票订购系统app

    基于Android的航班查询系统.使用了I/O流读文件.Dom解析xml文件和反射技术实现了航班的始末城市.航班号查询等功能,并采用数据库SQLite存储航班信息数据,用户可以通过手机随时随地查询航班 ...

  4. 基于Python+django的航班查询与推荐-计算机毕业设计

    项目介绍 随着时代的发展,人们选择出行的方式也有了很多的选择,但是就目前来说飞机和航班是最便捷的出行方式之一,尤其是对于一些旅程比较远的游客来说,选择飞机和航班无疑是最佳的选择,为了能够让乘客更加方便 ...

  5. Myflight航班查询系统

    1.导入命名空间,并且定义连接对象和命令对象 using System.Data.SqlClient; //定义连接对象 SqlConnection conn = null; //定义命令对象 Sql ...

  6. c语言机票座位预定系统_C语言实现飞机订票系统

    问题描述与题目要求 问题描述: 假定某民航有M个航次的班机,每个航次都只到达一个地方.试为该机场售票处设计一个自动订票和退票系统,要求系统具有以下功能: (1) 订票:若该航次余票大于等于乘客订票数, ...

  7. Java 编写航班查询系统 窗体程序 完整源码

    开发环境 开发语言为Java,开发环境Eclipse或者IDEA都可以.数据库采用:MySQL.运行主程序,或者执行打开JAR文件即可以运行本程序. 系统框架 利用JDK自带的SWING框架开发,需要 ...

  8. 编写一个模拟航空客运定票系统的程序

    原文地址:编写一个模拟航空客运定票系统的程序作者:木木女 实习报告 题目:2.7 编写一个模拟航空客运定票系统的程序 班级: 姓名: 学号:完成日期: 一.  需求分析: 1.     程序需要模拟航 ...

  9. 多线程试验。模拟航班售票系统,实现4个售票窗口发售某班次航班的100张机票,一个售票窗口用一个线程表示。要求不能重复发售。

    五一假期要到了,希望大家都都能开开心心 代码 import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; i ...

最新文章

  1. 基于ARM+DSP进行应用开发-经验共享
  2. 二次重建基本完成辣!
  3. 8、mybatis中的sql映射文件详解(3)
  4. 我们为什么要学习3D建模?
  5. 2016年4月计算机组成原理试题答案,2019年4月成人自考计算机组成原理真题及答案解析...
  6. pyecharts显示所有x轴_基于Pyecharts可视化大屏案例一(1)
  7. hsrp+route-map 解决多路由器多isp
  8. python 在线培训费用-Python人工智能在线培训班学费多少钱?
  9. Arduino 各种模块篇 舵机 Modules - Servo
  10. dede 调用四级导航
  11. Reinforcement Learning by David Silver 学记记录
  12. 驻马店远大计算机阳业学院,电力学院
  13. 黑客攻防实战入门读书笔记
  14. C语言基础入门,编程的第一步
  15. mysql中exec语句_SQL语句-exec执行
  16. 三天打鱼两天晒网C++
  17. MySQL基本命令操作
  18. unity的RectTransform
  19. Elliptic Curve
  20. Div高度自适应内容高度之最简处理

热门文章

  1. AutoMapper的介绍与使用(二)
  2. vs2012新建项目产生的问题
  3. flex 有关数据类型强制转
  4. (教学思路 C#之类五)类的分类(静态类、实例类、嵌套类、结构、简单的抽象类、简单的密封类)...
  5. 实用的HTML5的上传图片方法
  6. 多米诺骨牌v.1MEL语言
  7. RUNOOB python练习题8 numpy矩阵的索引及遍历
  8. Toast源码深度分析
  9. 交换机的基本原理配置(一)
  10. 企业网站6个常见的优化漏洞