最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)航班查詢及預(yù)訂功能

 更新時(shí)間:2018年02月23日 10:35:25   作者:格調(diào)c  
這篇文章給大家介紹利用C#完成航班機(jī)票信息查詢,航班機(jī)票預(yù)定等功能。代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

具體代碼如下所示:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace FrmHangBanUser
{
public partial class FrmUser : Form
{
//1.連接字符串
string connString = "Data Source = .;Initial Catalog=Ticket;User ID = sa; Pwd = sa";
//3.創(chuàng)建DataSet對(duì)象
DataSet set = new DataSet();
public FrmUser()
{
InitializeComponent();
}
#region 窗體加載事件
/// <summary>
/// 窗體加載事件?。?
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmUser_Load(object sender, EventArgs e)
{
//FlightInfo();
AirwaysInfo();
CityInfo();
}
#endregion
#region 出發(fā)地
/// <summary>
/// 出發(fā)地
/// </summary>
public void AirwaysInfo()
{
try
{
//2.創(chuàng)建Connection對(duì)象
SqlConnection conn = new SqlConnection(connString);
//4.創(chuàng)建DataAdapter對(duì)象
StringBuilder _sb = new StringBuilder();
_sb.AppendLine(@"SELECT Id,CityName FROM CityInfo");
SqlDataAdapter adapter = new SqlDataAdapter(_sb.ToString(), conn);
//5.填充數(shù)據(jù)集
adapter.Fill(set, "CityUser");
//6.綁定數(shù)據(jù)源到ComboBox控件中
this.cboAirways.DataSource = set.Tables["CityUser"];
this.cboAirways.ValueMember = "Id";
this.cboAirways.DisplayMember = "CityName";
//7.添加行對(duì)象
DataRow row = set.Tables["CityUser"].NewRow();
row["Id"] = -1;
row["CityName"] = "請(qǐng)選擇";
set.Tables["CityUser"].Rows.InsertAt(row, 0);
//8.默認(rèn)選中一行
this.cboAirways.SelectedIndex = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region 非空驗(yàn)證
/// <summary>
/// 非空驗(yàn)證
/// </summary>
public void Check()
{
if(this.cboAirways.SelectedIndex == 0)
{
MessageBox.Show("請(qǐng)輸入你要出發(fā)的城市?。?!","操作提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
}
else if (this.cboMudidi.SelectedIndex == 0)
{
MessageBox.Show("請(qǐng)輸入你的目的地啊啊?。?!", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
}
#endregion
#region 目的地
/// <summary>
/// 目的地
/// </summary>
public void CityInfo()
{
try
{
//2.創(chuàng)建Connection對(duì)象
SqlConnection conn = new SqlConnection(connString);
//4.創(chuàng)建DataAdapter對(duì)象
StringBuilder _sb = new StringBuilder();
_sb.AppendLine(@"SELECT Id,CityName FROM CityInfo");
SqlDataAdapter adapter = new SqlDataAdapter(_sb.ToString(), conn);
//5.填充數(shù)據(jù)集
adapter.Fill(set, "City");
//6.綁定數(shù)據(jù)源到ComboBox控件中
this.cboMudidi.DataSource = set.Tables["City"];
this.cboMudidi.ValueMember = "Id";
this.cboMudidi.DisplayMember = "CityName";
//7.添加行對(duì)象
DataRow row = set.Tables["City"].NewRow();
row["Id"] = -1;
row["CityName"] = "請(qǐng)選擇";
set.Tables["City"].Rows.InsertAt(row, 0);
//8.默認(rèn)選中一行
this.cboMudidi.SelectedIndex = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region 航班信息
/// <summary>
/// 航班信息
/// </summary>
public void FlightInfo()
{
try
{
//2.創(chuàng)建Connection對(duì)象
SqlConnection conn = new SqlConnection(connString);
//4.創(chuàng)建DataAdapter對(duì)象
StringBuilder _sb = new StringBuilder();
_sb.AppendLine(@"SELECT F.FlightNO,A.Airways,F.LeaveTime,F.LandTime,F.Price
FROM FlightInfo AS F INNER JOIN AirwaysInfo AS A ON F.AirwaysId = A.Id");
SqlDataAdapter adapter = new SqlDataAdapter(_sb.ToString(), conn);
//5.填充數(shù)據(jù)集
if (set.Tables["Airways"]!=null)
{
set.Tables["Airways"].Clear();
}
adapter.Fill(set, "Airways");
//6.綁定數(shù)據(jù)源
this.dvgUserInfo.DataSource = set.Tables["Airways"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region 查詢按鈕功能
/// <summary>
/// 查詢按鈕功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnChaXun_Click(object sender, EventArgs e)
{
Check();
Filter();
}
#endregion
#region 按選擇的條件篩選
/// <summary>
/// 按選擇的條件篩選
/// </summary>
public void Filter()
{
try
{
SqlConnection conn=new SqlConnection(connString);
//篩選條件
DataSet ds = new DataSet();
int city = Convert.ToInt32(cboAirways.SelectedValue);
int Destination = Convert.ToInt32(cboMudidi.SelectedValue);
StringBuilder sb = new StringBuilder();
if(city!=-1 && Destination!=-1)
{
sb.AppendLine(@"SELECT F.FlightNO,A.Airways,F.LandTime,F.LeaveTime,F.Price
FROM FlightInfo AS F INNER JOIN AirwaysInfo AS A ON F.AirwaysId = A.Id");
sb.AppendFormat(@"WHERE LeaveCity = {0} AND Destination = {1}", city, Destination);
}
SqlDataAdapter adapter = new SqlDataAdapter(sb.ToString(),conn);
adapter.Fill(ds,"User");
this.dvgUserInfo.DataSource = ds.Tables["User"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
#region 關(guān)閉按鈕功能
/// <summary>
/// 關(guān)閉按鈕功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGuanbi_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("你確定要退出程序嘛~","退出提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Stop);
if(result == DialogResult.OK)
{
Application.Exit(); //退出程序了。。 - - |||
}
}
#endregion
#region 實(shí)現(xiàn)航班選擇功能
/// <summary>
/// 實(shí)現(xiàn)航班選擇功能
/// </summary>
private void dvgUserInfo_MouseClick(object sender, MouseEventArgs e)
{
txtHNo.Text = dvgUserInfo.SelectedRows[0].Cells["FlightNO"].Value.ToString();
txtGongSi.Text = dvgUserInfo.SelectedRows[0].Cells["Airways"].Value.ToString();
this.txtChuFa.Text = this.cboAirways.Text;
this.txtMuDi.Text = this.cboMudidi.Text;
txtShijian.Text = dvgUserInfo.SelectedRows[0].Cells["LeaveTime"].Value.ToString();
txtDaoDa.Text = dvgUserInfo.SelectedRows[0].Cells["LandTime"].Value.ToString();
txtPiaoJia.Text = dvgUserInfo.SelectedRows[0].Cells["Price"].Value.ToString();
}
#endregion
#region 航班預(yù)定功能
/// <summary>
/// 航班預(yù)定功能
/// </summary>
/// <returns></returns>
public bool Insert()
{
Random _dom = new Random();
int no = _dom.Next(100000, 1000000);
SqlConnection conn = null;
string No = this.txtHNo.Text;
DateTime LeaveDate = this.dateTimePicker1.Value;
string Number = this.nuShang.Value.ToString();
try
{
conn = new SqlConnection(connString);
//構(gòu)建插入學(xué)生記錄的SQL的語句
StringBuilder _sbu = new StringBuilder();
_sbu.AppendLine("INSERT INTO OrderInfo(OrderId,FlightNo,LeaveDate,Number)");
_sbu.AppendFormat("VALUES('{0}','{1}','{2}','{3}')", no, No, LeaveDate, Number);
_sbu.AppendFormat("SELECT @@IDENTITY");
//創(chuàng)建Command對(duì)象
SqlCommand command = new SqlCommand(_sbu.ToString(), conn);
//打開連接
conn.Open();
//調(diào)用方法
int result = command.ExecuteNonQuery();
//對(duì)返回值進(jìn)行處理
if (result > 0)
{
MessageBox.Show("恭喜你!預(yù)定成功!訂單編號(hào)為"+no);
return true;
}
else
{
MessageBox.Show("預(yù)定失敗!請(qǐng)重試!");
return false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
finally
{
//關(guān)閉連接
conn.Close();
}
}
#endregion
#region 預(yù)定按鈕
/// <summary>
/// 預(yù)定按鈕!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnYuDing_Click(object sender, EventArgs e)
{
Insert();
}
#endregion
}
}

總結(jié)

以上所述是小編給大家介紹的C#實(shí)現(xiàn)航班查詢及預(yù)訂功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • C#遍歷集合與移除元素的方法

    C#遍歷集合與移除元素的方法

    這篇文章主要介紹了C#遍歷集合與移除元素的方法,結(jié)合實(shí)例形式分析了C#使用for循環(huán)遍歷集合以及add與Remove方法進(jìn)行元素添加與移除的使用技巧,需要的朋友可以參考下
    2016-06-06
  • C#實(shí)現(xiàn)終止正在執(zhí)行的線程

    C#實(shí)現(xiàn)終止正在執(zhí)行的線程

    這篇文章主要介紹了C#實(shí)現(xiàn)終止正在執(zhí)行的線程的方法,針對(duì)臨界資源等容易出現(xiàn)錯(cuò)誤的地方進(jìn)行了分析,并提出了改進(jìn)方案與實(shí)例,需要的朋友可以參考下
    2014-09-09
  • c#判斷正確的ip地址格式示例

    c#判斷正確的ip地址格式示例

    這篇文章主要介紹了c#判斷正確的ip地址格式示例,需要的朋友可以參考下
    2014-02-02
  • C#關(guān)鍵字in、out、ref的作用與區(qū)別

    C#關(guān)鍵字in、out、ref的作用與區(qū)別

    這篇文章介紹了C#關(guān)鍵字in、out、ref的作用與區(qū)別,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • Unity命令行打包WebGL的示例代碼

    Unity命令行打包WebGL的示例代碼

    這篇文章主要介紹了Unity命令行打包WebGL的相關(guān)知識(shí),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • C#開發(fā)Windows UWP系列之3D變換

    C#開發(fā)Windows UWP系列之3D變換

    這篇文章介紹了C#開發(fā)Windows UWP系列之3D變換,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • c#轉(zhuǎn)義字符串中的所有正則特殊字符方法示例

    c#轉(zhuǎn)義字符串中的所有正則特殊字符方法示例

    這篇文章主要介紹了c#轉(zhuǎn)義字符串中的所有正則特殊字符,大家可以參考使用
    2013-12-12
  • C#計(jì)算兩個(gè)文件的相對(duì)目錄算法的實(shí)例代碼

    C#計(jì)算兩個(gè)文件的相對(duì)目錄算法的實(shí)例代碼

    現(xiàn)在已知兩個(gè)文件相對(duì)于網(wǎng)站根目錄的路徑,如何計(jì)算相對(duì)路徑呢,有需要的朋友可以參考一下
    2013-09-09
  • C#實(shí)現(xiàn)簡(jiǎn)單打字游戲

    C#實(shí)現(xiàn)簡(jiǎn)單打字游戲

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)單打字游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • C#導(dǎo)入和導(dǎo)出CSV文件

    C#導(dǎo)入和導(dǎo)出CSV文件

    這篇文章介紹了C#導(dǎo)入和導(dǎo)出CSV文件的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05

最新評(píng)論

古蔺县| 河东区| 常熟市| 叶城县| 建阳市| 隆德县| 枞阳县| 达孜县| 义马市| 安化县| 监利县| 偃师市| 泉州市| 包头市| 元阳县| 忻城县| 塔河县| 博爱县| 博野县| 崇左市| 松原市| 于都县| 忻城县| 哈密市| 河西区| 松桃| 邯郸市| 广饶县| 亳州市| 临邑县| 万载县| 富蕴县| 安康市| 靖州| 左权县| 高安市| 育儿| 仁布县| 云浮市| 张家川| 瑞丽市|