?? aviationbsdlg.cpp
字號:
// AviationBSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AviationBS.h"
#include "AviationBSDlg.h"
#include "SetLine.h"
#include <fstream.h>
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include "BookingDlg.h"
#include "Refund.h"
#include "QueueDlg.h"
#ifndef SYSLINE_H
#define SYSLINE_H
#include "SysLine.h"
#endif
#ifndef USEDLINE_H
#define USEDLINE_H
#include "UsedLine.h"
#endif
#include "Client.h"
#include "Queue.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern SysLine sysLine;
extern UsedLine usedLine;
extern CClient client;
extern Queue queue;
extern int Index[8];
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAviationBSDlg dialog
CAviationBSDlg::CAviationBSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAviationBSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAviationBSDlg)
m_FlyDate = COleDateTime::GetCurrentTime();
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAviationBSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAviationBSDlg)
DDX_Control(pDX, IDC_COMBO2, m_LineCtrl);
DDX_Control(pDX, IDC_FLIGHINFOLIST, m_FlightListCtrl);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_FlyDate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAviationBSDlg, CDialog)
//{{AFX_MSG_MAP(CAviationBSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ABOUTBUTTON, OnAboutbutton)
ON_BN_CLICKED(IDC_SETLINEBUTTON, OnSetlinebutton)
ON_BN_CLICKED(IDC_FIND, OnFind)
ON_BN_CLICKED(IDC_BOOKINGBUT, OnBooking)
ON_BN_CLICKED(IDC_REFUND, OnRefund)
ON_BN_CLICKED(IDC_ONQUEUE, OnQueue)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAviationBSDlg message handlers
BOOL CAviationBSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//設(shè)置航班的列表框的屬性
m_FlightListCtrl.SetExtendedStyle(m_FlightListCtrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT |
LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES);
//設(shè)置航班的列表框的第一行
TCHAR ListHead[9][13] = {_T("目的地"),_T("航班號"), _T("飛機(jī)型號"),_T("起飛日期"),_T("起飛時間"),_T("頭等艙剩余數(shù)"),
_T("頭等艙票價"),_T("經(jīng)濟(jì)艙剩余數(shù)"),_T("經(jīng)濟(jì)艙票價")};
LV_COLUMN lvcolumn;
CRect rect;
m_FlightListCtrl.GetWindowRect(&rect);
for(int i=0;i<9;i++)
{
lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = ListHead[i];
lvcolumn.iSubItem = i;
lvcolumn.iOrder = i;
if(i<3||i==4) lvcolumn.cx = rect.Width()*2/21;
else if(i==3)lvcolumn.cx = rect.Width()*2/20.5;
else lvcolumn.cx = rect.Width()*2/15.3;
m_FlightListCtrl.InsertColumn(i, &lvcolumn);
}
/////////////////////////////////////////////////////////////////////////////////
//創(chuàng)建數(shù)據(jù)庫文件夾
if(CreateDirectory("DataBase",NULL))
CreateDirectory("DataBase",NULL);
//讀取SystemData.dat文件,把保存在里面的sysLine的關(guān)于系統(tǒng)航線信息讀出來
fstream file("DataBase/SystemData.dat",ios::binary | ios::in);
if(!file){MessageBox("Read file failed!");return false;}
file.seekp(0,ios::beg);
long beg=file.tellp();
file.seekp(0,ios::end);
long end=file.tellp();
if(beg!=end)
{
SysLine temp;
file.seekp(0,ios::beg);
file.read((char *)& temp,sizeof(SysLine));
sysLine=temp;
}
file.close();
//在查詢框中的"目的地"下拉列表中加入已安排航班的航線
CString str;
for(i=0;i<sysLine.LineSz;i++)
{
str.Format(_T("%s"),sysLine.lineArray[sysLine.flightArray[i].lineindex].destination);
str=str.Left(10);
str.Remove(' ');
m_LineCtrl.AddString(str);
}
//用戶航線usedLine信息的讀取與創(chuàng)建,usedLine 包含了七天之內(nèi)的所有航班息(所在航線,售票情況)
fstream file1("DataBase/UsedLine.dat",ios::binary | ios::in);
if(!file1){MessageBox("Read file failed!");return false;}
file1.seekp(0,ios::beg);
beg=file1.tellp();
file1.seekp(0,ios::end);
end=file1.tellp();
if(beg!=end)
{
UsedLine temp1;
file1.seekp(0,ios::beg);
file1.read((char *)& temp1,long(sizeof(UsedLine)));
usedLine=temp1;
}
file1.close();
usedLine.Create(); //第一次啟動時的創(chuàng)建系統(tǒng),以及更新航線信息
client.OnCreate(); //創(chuàng)建及更新客戶信息
queue.OnCreate();
/////////////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CAviationBSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CAviationBSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAviationBSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAviationBSDlg::OnAboutbutton()
{
// TODO: Add your control notification handler code here
CAboutDlg adlg;
adlg.DoModal();
}
void CAviationBSDlg::OnSetlinebutton()
{
// TODO: Add your control notification handler code here
SetLine setLine;
setLine.DoModal();
//在查詢框中的"目的地"下拉列表中加入已安排航班的航線,更新航線
CString str;
int size=m_LineCtrl.GetCount();
for (int i=0;i<size;i++)//刪除舊的
{
m_LineCtrl.DeleteString(0);
}
for(i=0;i<sysLine.LineSz;i++)
{
str.Format(_T("%s"),sysLine.lineArray[sysLine.flightArray[i].lineindex].destination);
str=str.Left(10);
str.Remove(' ');
m_LineCtrl.AddString(str);
}
}
void CAviationBSDlg::OnOK()
{
// TODO: Add extra validation here
fstream file("DataBase/SystemData.dat",ios::out | ios::binary); //SystemData.dat的保存
if(!file)MessageBox("Write file failed!");
else
{
file.seekp(0,ios::beg);
file.write((char*)&sysLine,long(sizeof(SysLine)));
}
file.close();
fstream file1("DataBase/UsedLine.dat",ios::out | ios::binary); //UsedLine.dat的保存
if(!file1)MessageBox("Write file failed!");
else
{
file1.seekp(0,ios::beg);
file1.write((char*)& usedLine,long(sizeof(UsedLine)));
}
file1.close();
client.Save();
queue.Save();
CDialog::OnOK();
}
void CAviationBSDlg::OnFind()
{
UpdateData();
if(m_FlightListCtrl.GetItemCount( )>0)m_FlightListCtrl.DeleteAllItems();
int index=m_LineCtrl.GetCurSel();
if(CB_ERR == index){MessageBox("請選擇目的地!");return;}
if(m_FlyDate>=usedLine.GetNextNDay(7))
{MessageBox("對不起,本系統(tǒng)只能查詢七天以內(nèi)的航班信息!謝謝合作!");return;}
else if(m_FlyDate<usedLine.GetNextNDay(0))
{MessageBox("對不起,你查詢的日期已過期!");return;}
COleDateTime Time=COleDateTime::GetCurrentTime();
//刪除今天已過期的航班
for(int i=usedLine.flightArray[index].front;
usedLine.flightArray[index].length()!=0&&usedLine.flightArray[index].flight[i].FlyTime<=Time;)
{
usedLine.flightArray[index].deQueue();
i=usedLine.flightArray[index].front;
}
//查詢合適的航班
int Findex=0;
for( i=usedLine.flightArray[index].front;i!=(usedLine.flightArray[index].rear+1)%31;i=(i+1)%31)
{
if(usedLine.CompareDate(m_FlyDate,usedLine.flightArray[index].flight[i].FlyTime)==0
&&usedLine.flightArray[index].flight[i].FlyTime>Time)
{
Index[Findex]=i; //用一個數(shù)組存放航班的下標(biāo)
CString str;
LV_ITEM ListItem={0};
ListItem.mask=LVIF_TEXT;
ListItem.iItem=Findex;
ListItem.iSubItem=0;
str.Format(_T("%s"),usedLine.lineArray[index].destination);
str=str.Left(10);
str.Remove(' ');
ListItem.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
if (m_FlightListCtrl.InsertItem(&ListItem) != -1)
{
LV_ITEM FlightInfo = {0};
for(int j=1;j<9;j++)
{
FlightInfo.mask=LVIF_TEXT;
FlightInfo.iItem=Findex;
FlightInfo.iSubItem =j;
switch(j)
{
case 1: {
str.Format(_T("%s"),usedLine.flightArray[index].flight[i].PlaneNum);
str=str.Left(6);
str.Remove(' ');
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 2: {
str.Format(_T("%s"),usedLine.flightArray[index].flight[i].PlaneType);
str=str.Left(6);
str.Remove(' ');
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 3:{
str.Format("%d-%d-%d",
usedLine.flightArray[index].flight[i].FlyTime.GetYear(),
usedLine.flightArray[index].flight[i].FlyTime.GetMonth(),
usedLine.flightArray[index].flight[i].FlyTime.GetDay());
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 4: {
str.Format("%d:%d:%d",
usedLine.flightArray[index].flight[i].FlyTime.GetHour(),
usedLine.flightArray[index].flight[i].FlyTime.GetMinute(),
usedLine.flightArray[index].flight[i].FlyTime.GetSecond());
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 5: {str.Format("%d",usedLine.flightArray[index].flight[i].FirCFreeNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
case 6: {str.Format("%.1f",usedLine.flightArray[index].flight[i].FirCP);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
case 7: {str.Format("%d",usedLine.flightArray[index].flight[i].TouCFreeNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
case 8: {str.Format("%.1f",usedLine.flightArray[index].flight[i].TouCP);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
}
m_FlightListCtrl.SetItem(&FlightInfo);
}
}
Findex++;
}
if(usedLine.CompareDate(m_FlyDate,usedLine.flightArray[index].flight[i].FlyTime)<0)break;
}
if(m_FlightListCtrl.GetItemCount()==0)MessageBox("對不起,今天的航班都已經(jīng)起飛,請更換日期或航線查詢,謝謝!");
}
void CAviationBSDlg::OnBooking()
{
// TODO: Add your control notification handler code here
UpdateData();
COleDateTime now=COleDateTime::GetCurrentTime();
int LineIndex=m_LineCtrl.GetCurSel(); //選中航線的下標(biāo)
int index=m_FlightListCtrl.GetSelectionMark();
if(-1==index){MessageBox("請選擇你要訂票的航班,謝謝!");return;}
else
{
int FlightIndex=Index[index];
if(now>=usedLine.flightArray[LineIndex].flight[FlightIndex].FlyTime)
{MessageBox("抱歉,你所選的航班已經(jīng)起飛!請選擇其它航班,謝謝!");return;}
Index[6]=LineIndex; //通過m_index數(shù)組將所選的航線及即航班傳給訂票對話框
Index[7]=FlightIndex;
if(usedLine.flightArray[LineIndex].flight[FlightIndex].FirCFreeNum==0&&
usedLine.flightArray[LineIndex].flight[FlightIndex].TouCFreeNum==0)
{
int temp=MessageBox("你所選擇的航班已滿員,是否愿意填寫候補(bǔ)表格,一有空位將馬上通知你!",
NULL,MB_ICONQUESTION|MB_OKCANCEL);
if(IDOK==temp) //候補(bǔ)隊列
{
CQueueDlg Dlg;
Dlg.DoModal();
}
}
else //進(jìn)行訂票
{
CBookingDlg Dlg;
Dlg.DoModal();
m_FlightListCtrl.DeleteAllItems();
}
}
}
void CAviationBSDlg::OnRefund()
{
// TODO: Add your control notification handler code here
CRefund Dlg;
Dlg.DoModal();
if(m_FlightListCtrl.GetItemCount( )>0)m_FlightListCtrl.DeleteAllItems();
}
void CAviationBSDlg::OnQueue()
{
// TODO: Add your control notification handler code here
UpdateData();
int LineIndex=m_LineCtrl.GetCurSel(); //選中航線的下標(biāo)
int index=m_FlightListCtrl.GetSelectionMark();
if(-1==index){MessageBox("請選擇你要訂票的航班,謝謝!");return;}
else
{
if(m_FlightListCtrl.GetItemCount( )>0)m_FlightListCtrl.DeleteAllItems();
int FlightIndex=Index[index];
Index[6]=LineIndex; //通過m_index數(shù)組將所選的航線及即航班傳給訂票對話框
Index[7]=FlightIndex;
CQueueDlg Dlg;
Dlg.DoModal();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -