C#航空查询及预订
关于航空查询及预订项目中出现的问题
namespace Flight
{
public partial class Flight : Form
{
public Flight()
{
InitializeComponent();
}
private void labgo_Click(object sender, EventArgs e)
{
}
public string connstr = "Data Source=.;Initial Catalog=Ticket;Persist Security Info=True;User ID=sa;Password=19981120";
//查询按钮
private void Flight_Load(object sender, EventArgs e)
{
this.goplace();
this.inplace();
// MessageBox.Show("没有要查找的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
//DataRow row = ds.Tables["CityInfo"].NewRow();
//row[0] = -1;
//row[1] = "请选择";
//ds.Tables["CityInfo"].Rows.InsertAt(row, 0);
}
private void cmbgo_SelectedIndexChanged(object sender, EventArgs e)
{
}
//查询显示临时数据
private void bttcha_Click(object sender, EventArgs e)
{
int one = Convert.ToInt32(cmbgo.SelectedValue);//获得航班id
int two = Convert.ToInt32(cmbin.SelectedValue);
SqlConnection conn = new SqlConnection(connstr);
try
{
conn.Open();
//两表联查
string sql = @"select f.FlightNo,a.Airways ,f.LeaveTime,f.LandTime,f.Price
from AirwaysInfo as a,FlightInfo as f
where a.Id=f.AirwaysId and f.LeaveCity = '" + one + "' and f.Destination = '" + two + "' ";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "ang");
dgvone.DataSource = ds.Tables["ang"];
}
catch (Exception ex)
{
MessageBox.Show("异常!" + ex, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
conn.Close();
}
}
//出发地
public void goplace()
{
SqlConnection conn = new SqlConnection(connstr);
string sql = "select * from CityInfo";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "CityInfo");
//dgvone.DataSource = ds.Tables["CityInfo"];
DataRow row = ds.Tables["CityInfo"].NewRow();
row["Id"] = -1;
row["CityName"] = "请选择";
ds.Tables["CityInfo"].Rows.InsertAt(row, 0);
cmbgo.DataSource = ds.Tables["CityInfo"];
cmbgo.DisplayMember = "CityName";
cmbgo.ValueMember = "Id";
}
//目的地
public void inplace()
{
SqlConnection conn = new SqlConnection(connstr);
string sql = "select * from CityInfo";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "CityInfo");
//dgvone.DataSource = ds.Tables["CityInfo"];
DataRow row = ds.Tables["CityInfo"].NewRow();
row["Id"] = -1;
row["CityName"] = "请选择";
ds.Tables["CityInfo"].Rows.InsertAt(row, 0);
cmbin.DataSource = ds.Tables["CityInfo"];
cmbin.DisplayMember = "CityName";
cmbin.ValueMember = "Id";
}
//详细显示查询信息
public void details()
{
string flnum = dgvone.SelectedRows[0].Cells[0].Value.ToString();//定义接受值
string company = dgvone.SelectedRows[0].Cells[1].Value.ToString();
DateTime date = Convert.ToDateTime(dgvone.SelectedRows[0].Cells[2].Value);
string intime = dgvone.SelectedRows[0].Cells[3].Value.ToString();
int flomney = Convert.ToInt32(dgvone.SelectedRows[0].Cells[4].Value);
textflnum.Text = flnum;//将接受值付给控件并显示
textflcob.Text = company;
textflgo.Text = cmbgo.Text;
textflin.Text = cmbin.Text;
textflgotime.Text = Convert.ToString(date);
textflintime.Text = intime;
textflmoney.Text = flomney.ToString();
}
//显示查询信息入口
private void dgvone_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.details();
}
//添加预定航班信息
private void bttyuding_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connstr);
string date = fldtime.Value.ToString();
conn.Open();
Random rd = new Random();
int num1 = rd.Next(10000, 10000000);//随机数
//将预定信息添加到数据库中
string sql = "insert into OrderInfo ([OrderId],[FlightNo],[LeaveDate],[Number])values('" + num1 + "','" + textflnum.Text + "','" + date + "','" + flupdnum.Text + "')";
try
{
if (textflnum.Text == string.Empty)
{
MessageBox.Show("请选择一个航班!");
}
else if(DateTime.Now>=fldtime.Value)
{
MessageBox.Show("请选择一个正确的时间!");
}
else
{
SqlCommand cmd = new SqlCommand(sql, conn);
int num = cmd.ExecuteNonQuery();
if (num > 0)
{
MessageBox.Show("你的订单编号为" + num1 + "\n 预定票数:" + flupdnum.Text + " \n你的航班编号为"+textflnum.Text+"");
}
else
{
MessageBox.Show("增加失败!");
}
}
}
catch (Exception ex)
{
MessageBox.Show(sql);
MessageBox.Show("异常!" + ex, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
conn.Close();
}
}
//关闭退出订票系统
private void bttclose_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定退出吗!!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
this.Close();
}
}
}
}
防止他人恶意篡改窗体运行时的数据 需要将textbox控件的readonly属性改为true
瑕疵是:关于订票时间为当日及以前不可预定 有点违背常理
滴水穿石非一日之功 凿壁借光非一人可为
C#航空查询及预订的更多相关文章
- C#实现航班查询及预订
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- Html5 学习笔记 【PC固定布局】 实战7 机票预订页面
最终实际效果: HTML代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta char ...
- 图解Android - Binder 和 Service
在 Zygote启动过程 一文中我们说道,Zygote一生中最重要的一件事就是生下了 System Server 这个大儿子,System Server 担负着提供系统 Service的重任,在深入了 ...
- HTML系列(二):头部meta元素
有关name: 一.页面关键字 网站关键字:用户通过搜索引擎能搜到该网站的词汇.最好控制在10个以内. 基本语法: <meta name="keywords" content ...
- 世界十大OTA公司盘点
世界十大OTA公司盘点 文/刘照慧(执惠旅游联合创始人,首发百度百家) 全球在线旅游公司(OTA)经过多年发展,已经形成较为成熟的商业模式,各大巨头跑马圈地,格局初现, 这两篇文章就梳理出全球按市值( ...
- Switch分销技术解读
Switch分销技术解读 来源:环球旅讯|2009-03-13 当Switch在海外成熟运作近40年后,该业务终于进入中国市场.但对于中国业者来说,知道Switch的人很少,了解Switch的人更少. ...
- 术语-EDI:EDI
ylbtech-术语-EDI:EDI 电子数据交换(Electronic data interchange,缩写EDI)是指按照同一规定的一套通用标准格式,将标准的经济信息,通过通信网络传输,在贸易伙 ...
- Html5 学习笔记 【PC固定布局】 实战7 风景欣赏 联系我们
风景欣赏最终效果: 关于公司最终效果: 风景欣赏Html代码: <!DOCTYPE html> <html lang="zh-cn"> <head&g ...
- 微信小程序与传统APP十大优劣对比
随着微信公众平台的开放,微信端小程序涌现市场,带来很很多便利和简单的原生操作,询:微信端小程序是否会替代传统的APP应用?两者的优劣如何?我们一起来看看传统APP与微信端小程序十大优劣对比 ...
随机推荐
- DOM模型-属性操作
HTML 元素包括标签名和若干个键值对,这个键值对就称为"属性"(attribute)."属性"本身是一个对象(Attr对象),但是实际上,这个对象极少使用.一 ...
- 09 Javascript的伪数组 arguments
arguments代表的是实参.有个讲究的地方是:arguments只在函数中使用. (1)返回函数实参的个数:arguments.length 例子: fn(2,4); fn(2,4,6); fn( ...
- Redi缓存注意事项
缓存使用的场景 在一个高频访问的应用系统中,每次用户的请求需要去存储中获取数据,会对数据库造成很大的压力.容易导致数据库的奔溃.所以才会出现缓存来分担一部分的数据库的压力. 具体会产生数据库访问压力的 ...
- 了解selenium--(虫师的博客)
Selenium is a portable software-testing framework for web applications. Selenium is composed of seve ...
- Matplotlib快速入门
Matplotlib 可能还有小伙伴不知道Matplotlib是什么,下面是维基百科的介绍. Matplotlib 是Python编程语言的一个绘图库及其数值数学扩展 NumPy.它为利用通用的图形用 ...
- 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心
SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...
- springboot集成mockito与powermock
mockito大家都比较熟悉了,存在或者不存在,都不要紧,mockito让你有一种只要一出手,就知道有没有的感觉.但是它也不是万能的,比如静态方法.私有方法,它就无能为力了.这是为什么呢?当然不是 ...
- 使用CocoaPods创建自己的私有库-iOS组件化第一步
目前iOS组件化常用的解决方案是Pod+路由+持续集成,通常架构设计完成后第一步就是将原来工程里的模块按照架构图分解为一个个独立的pod工程(组件),今天我们就来看看如何创建一个Pod私有库. 新建: ...
- STM32学习的一些实例
第一讲:修炼STM32之乾坤大挪移术—— 如何用DMA神器搬运数据DMA,即直接存储器访问.DMA 传输方式无需 CPU 直接控制传输,通过硬件为 RAM 与 I/O 设备开辟一条直接传送数据的通路, ...
- ZooKeeper入门(四) Zookeeper监视(Watches)
1 简介 Zookeeper 所有的读操作——getData(), getChildren(), 和 exists() 都 可以设置监视(watch),并且这些watch都由写操作来触发:create ...