关于航空查询及预订项目中出现的问题

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#航空查询及预订的更多相关文章

  1. C#实现航班查询及预订

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  2. Html5 学习笔记 【PC固定布局】 实战7 机票预订页面

    最终实际效果: HTML代码: <!DOCTYPE html> <html lang="zh-cn"> <head> <meta char ...

  3. 图解Android - Binder 和 Service

    在 Zygote启动过程 一文中我们说道,Zygote一生中最重要的一件事就是生下了 System Server 这个大儿子,System Server 担负着提供系统 Service的重任,在深入了 ...

  4. HTML系列(二):头部meta元素

    有关name: 一.页面关键字 网站关键字:用户通过搜索引擎能搜到该网站的词汇.最好控制在10个以内. 基本语法: <meta name="keywords" content ...

  5. 世界十大OTA公司盘点

    世界十大OTA公司盘点 文/刘照慧(执惠旅游联合创始人,首发百度百家) 全球在线旅游公司(OTA)经过多年发展,已经形成较为成熟的商业模式,各大巨头跑马圈地,格局初现, 这两篇文章就梳理出全球按市值( ...

  6. Switch分销技术解读

    Switch分销技术解读 来源:环球旅讯|2009-03-13 当Switch在海外成熟运作近40年后,该业务终于进入中国市场.但对于中国业者来说,知道Switch的人很少,了解Switch的人更少. ...

  7. 术语-EDI:EDI

    ylbtech-术语-EDI:EDI 电子数据交换(Electronic data interchange,缩写EDI)是指按照同一规定的一套通用标准格式,将标准的经济信息,通过通信网络传输,在贸易伙 ...

  8. Html5 学习笔记 【PC固定布局】 实战7 风景欣赏 联系我们

    风景欣赏最终效果: 关于公司最终效果: 风景欣赏Html代码: <!DOCTYPE html> <html lang="zh-cn"> <head&g ...

  9. 微信小程序与传统APP十大优劣对比

    随着微信公众平台的开放,微信端小程序涌现市场,带来很很多便利和简单的原生操作,询:微信端小程序是否会替代传统的APP应用?两者的优劣如何?我们一起来看看传统APP与微信端小程序十大优劣对比       ...

随机推荐

  1. Swagger API文档集中化注册管理

    接口文档是前后端开发对接时很重要的一个组件.手动编写接口文档既费时,又存在文档不能随代码及时更新的问题,因此产生了像swagger这样的自动生成接口文档的框架.swagger文档一般是随项目代码生成与 ...

  2. Zookeeper详解-API(六)

    ZooKeeper有一个绑定Java和C的官方API.Zookeeper社区为大多数语言(.NET,python等)提供非官方API.使用ZooKeeper API,应用程序可以连接,交互,操作数据, ...

  3. 基于 Roslyn 实现动态编译

    基于 Roslyn 实现动态编译 Intro 之前做的一个数据库小工具可以支持根据 Model 代码文件生成创建表的 sql 语句,原来是基于 CodeDom 实现的,最近改成使用基于 Roslyn ...

  4. docker无法启动

    docker无法启动 docker启动时报错Error starting daemon: SELinux is not supported with the overlay2 graph driver ...

  5. python3的类

    python3的类: python是一门面向对象的编程语言,学习python下的类,,能帮助自己形成一个基本的面向对象的概念.关于类和实例的理解,一个易懂的栗子就是动物类,我们把动物看做一个类,而狗啊 ...

  6. js深入(四)万脸懵圈的this指向

    作为一个js菜鸡的我而言,在之前讲到过那么多的js链式查找机制,比如说原型链,作用域链等等,想当然的把这个机制带入到了this指向上边,结果就是这个this指向指的我万脸懵逼(标题换字了,担心被河蟹) ...

  7. SQL中的LIKE语句的用法

    SQL中的LIKE语句的用法 内容 在SQL结构化查询语言中,LIKE语句有着至关重要的作用.LIKE语句的语法格式是:select * from 表名 where 字段名 like 对应值(子串), ...

  8. flask模板语言 jinja2 以及render_template 深度用法

    是时候开始写个前端了,Flask中默认的模板语言是Jinja2 现在我们来一步一步的学习一下 Jinja2 捎带手把 render_template 中留下的疑问解决一下 首先我们要在后端定义几个字符 ...

  9. kuangbin专题 专题一 简单搜索 非常可乐 HDU - 1495

    题目链接:https://vjudge.net/problem/HDU-1495 题意:有两个空杯(分别是N升和M升)和一罐满的可乐S升,S = N + M,三个容器可以互相倾倒,如果A倒入B,只有两 ...

  10. C语言学习书籍推荐《学习使用C指针(影印版)(英文本)》下载

    <学习使用C指针(影印版)(英文本)>作者通过<学习使用C指针(影印版)(英文本)>中的内存模型为你展示了如何在数组.字符串.结构和函数中使用指针.虽然难以掌握,但是指针为C语 ...