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

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. python发送邮件554DT:SPM已解决

    说明:本例使用163邮箱 一.报错信息 使用SMTP发送邮件遇到以下报错: 554, b'DT:SPM 163 smtp10,DsCowACXeOtmjRRdsY8aCw--.21947S2 1561 ...

  2. Python 爬虫从入门到进阶之路(八)

    在之前的文章中我们介绍了一下 requests 模块,今天我们再来看一下 Python 爬虫中的正则表达的使用和 re 模块. 实际上爬虫一共就四个主要步骤: 明确目标 (要知道你准备在哪个范围或者网 ...

  3. 了解Kubernetes主体架构(二十八)

    前言 Kubernetes的教程一直在编写,目前已经初步完成了以下内容: 1)基础理论 2)使用Minikube部署本地Kubernetes集群 3)使用Kubeadm创建集群 接下来还会逐步完善本教 ...

  4. 18 | 眼前一亮:带你玩转GUI自动化的测试报告

  5. C# 异步转同步 TaskCompletionSource

    本文通过TaskCompletionSource,实现异步转同步 首先有一个异步方法,如下异步任务延时2秒后,返回一个结果 private static async Task<string> ...

  6. SQL高度优化

      受同事dd之托,优化一条boss看的报表SQL.dd写复杂疑难SQL无数,如何写出优雅的SQL自有一番心得体会.能将一条7表含inner join,left join并含有关联子查询的.返回结果集 ...

  7. 设计模式-模块方法模式(TemplateMethod)

    模块方法模式是行为模式之一,它把具有特定步骤算法中的某些必要的处理委让给抽象方法,通过子类继承对抽象方法的不同实现改变整个算法的行为. UML图: 具体代码: /** * 抽象-模块方法模式核心 */ ...

  8. JDK源码分析系列02---ArrayList和LinkList

    ArrayList和LinkList的源码分析 概要 ArrayList和LinkList是常用的存储结构,不看源码先分析字面意思,Array意思是数组,可知其底层是用数组实现的,Link意思是链接, ...

  9. RabbitMQ windows 安装后 此时不应有 \RabbitMQ。

    在安装过程中,如果细心实际上在安装的细节显示starting Service后就已经提示这个问题,实际上就是没有注册到RabbitMQ这个服务. 在研究了很久之后才发现原来是安装路径的问题,原先是安装 ...

  10. Python线程池ThreadPoolExecutor源码分析

    在学习concurrent库时遇到了一些问题,后来搞清楚了,这里记录一下 先看个例子: import time from concurrent.futures import ThreadPoolExe ...