📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "order.h"
#include "stdio.h"
#include "MainFrm.h"
#include "reservation.h"
#include "ReservationSet.h"
#include "FlightSet.h"
#include "FilterFlight.h"
#include "flight.h"
#include "MotorCarSet.h"
#include "FilterCar.h"
#include "motorcar.h"
#include "hotelSet.h"
#include "FilterHotel.h"
#include "hotel.h"
#include "CustomerSet.h"
#include "AddClient.h"
#include "AddFlight.h"
#include "AddHotel.h"
#include "AddCar.h"
#include "AddReservation.h"
#include "TripCheck.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDD_reservation, Onreservation)
ON_COMMAND(IDD_flight, Onflight)
ON_COMMAND(IDD_car, Oncar)
ON_COMMAND(IDD_hotel, Onhotel)
ON_COMMAND(IDD_AddCustomer, OnAddCustomer)
ON_COMMAND(IDD_AddFlight, OnAddFlight)
ON_COMMAND(IDD_AddHotel, OnAddHotel)
ON_COMMAND(IDD_AddCars, OnAddCars)
ON_COMMAND(IDD_AddReservations, OnAddReservations)
ON_COMMAND(IDD_constrain, Onconstrain)
ON_COMMAND(IDD_complite, Oncomplite)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
void CMainFrame::Onreservation()
{
// TODO: Add your command handler code here
reservation ThisDlg;
CReservationSet pointer;
pointer.Open();
ThisDlg.m_reservationName=pointer.m_custName;
ThisDlg.m_reservationtype=pointer.m_resvType;
ThisDlg.m_reservationkey=pointer.m_resvKey;
ThisDlg.DoModal();
//ThisDlg.
}
void CMainFrame::Onflight()
{
// TODO: Add your command handler code here
FilterFlight ThisDlg;
flight FlightInfo;
FlightSet pointer;
pointer.Open();
pointer.MoveFirst();
ThisDlg.DoModal();
while(!(pointer.IsEOF()))
{
if(pointer.m_flightNum==ThisDlg.m_flightNum)
{
FlightInfo.m_fight=pointer.m_flightNum;
FlightInfo.m_flightseat=pointer.m_numSeats;
FlightInfo.m_flightseatrest=pointer.m_numAvail;
FlightInfo.m_from=pointer.m_FromCity;
FlightInfo.m_toward=pointer.m_ArivCity;
FlightInfo.m_price=pointer.m_price;
FlightInfo.DoModal();
pointer.MoveNext();
}
else
pointer.MoveNext();
}
return;
}
void CMainFrame::Oncar()
{
// TODO: Add your command handler code here
MotorCarSet set;
FilterCar filter;
motorcar info;
set.Open();
set.MoveFirst();
filter.DoModal();
while(!(set.IsEOF()))
{
if(set.m_location==filter.m_FilterCarLocation)
{
info.m_carlocation=set.m_location;
info.m_carprice=set.m_price;
info.m_restcar=set.m_numAvail;
info.m_totalcar=set.m_numCars;
info.DoModal();
set.MoveNext();
}
else
set.MoveNext();
}
return;
}
void CMainFrame::Onhotel()
{
// TODO: Add your command handler code here
FilterHotel filter;
hotel info;
hotelSet set;
set.Open();
set.MoveFirst();
filter.DoModal();
while(!set.IsEOF())
{
if(set.m_location==filter.m_FilterHotelLocation)
{
info.m_HotelLocation=set.m_location;
info.m_HotelPrice=set.m_price;
info.m_HotelRest=set.m_numAvail;
info.m_HotelTotal=set.m_numRooms;
info.DoModal();
set.MoveNext();
}
else
set.MoveNext();
}
return;
}
void CMainFrame::OnAddCustomer()
{
// TODO: Add your command handler code here
CCustomerSet set;
AddClient add;
set.Open();
set.MoveFirst();
add.DoModal();
while(!set.IsEOF())
{
if(set.m_custName==add.m_AddName)
{
AfxMessageBox("该顾客已经在数据库中!");
return;
}
else
set.MoveNext();
}
if(set.IsEOF())
{
CString strSQL;
strSQL.Format("insert into CUSTOMERS values(\'%s\')",
add.m_AddName);
set.m_pDatabase->ExecuteSQL(strSQL);
AfxMessageBox("顾客入库完毕!");
}
}
void CMainFrame::OnAddFlight()
{
// TODO: Add your command handler code here
FlightSet set;
AddFlight add;
set.Open();
set.MoveFirst();
add.DoModal();
while(!set.IsEOF())
{
if(set.m_flightNum==add.m_AddFlightNum)
{
AfxMessageBox("该航班已经在数据库中!");
return;
}
else
set.MoveNext();
}
if(set.IsEOF())
{
CString strSQL;
strSQL.Format("insert into FLIGHTS values(\'%s\',%d,%d,%d,\'%s\',\'%s\')",
add.m_AddFlightNum,add.m_AddFlightPrice,add.m_AddFlightTotalSeat,add.m_AddFlightRestSeat,add.m_AddFlightFrom,add.m_AddFlightArrive);
set.m_pDatabase->ExecuteSQL(strSQL);
AfxMessageBox("航班入库完毕!");
}
}
void CMainFrame::OnAddHotel()
{
// TODO: Add your command handler code here
hotelSet set;
AddHotel add;
set.Open();
set.MoveFirst();
add.DoModal();
while(!set.IsEOF())
{
if(set.m_location==add.m_AddHotelLocation)
{
AfxMessageBox("该旅馆已经在数据库中!");
return;
}
else
set.MoveNext();
}
if(set.IsEOF())
{
CString strSQL;
strSQL.Format("insert into HOTELS values(\'%s\',%d,%d,%d)",
add.m_AddHotelLocation,add.m_AddHotelPrice,add.m_AddHotelTotalRooms,add.m_AddHotelRestRooms);
set.m_pDatabase->ExecuteSQL(strSQL);
AfxMessageBox("旅馆入库完毕!");
}
}
void CMainFrame::OnAddCars()
{
// TODO: Add your command handler code here
MotorCarSet set;
AddCar add;
set.Open();
set.MoveFirst();
add.DoModal();
while(!set.IsEOF())
{
if(set.m_location==add.m_AddCarLocation)
{
AfxMessageBox("该车辆已经在数据库中!");
return;
}
else
set.MoveNext();
}
if(set.IsEOF())
{
CString strSQL;
strSQL.Format("insert into CARS values(\'%s\',%d,%d,%d)",
add.m_AddCarLocation,add.m_AddCarPrice,add.m_AddCarTotal,add.m_AddCarRest);
set.m_pDatabase->ExecuteSQL(strSQL);
AfxMessageBox("车辆入库完毕!");
return;
}
}
void CMainFrame::OnAddReservations()
{
// TODO: Add your command handler code here
int count=0;
CReservationSet set;
CCustomerSet customer;
AddReservation add;
FlightSet flight;
MotorCarSet car;
hotelSet hotel;
CString str;
add.m_RecordCount=0;
customer.Open();
customer.MoveFirst();
set.Open();
set.MoveFirst();
str=set.m_resvKey;
add.m_RecordCount=1;
flight.Open();
flight.MoveFirst();
car.Open();
car.MoveFirst();
hotel.Open();
hotel.MoveFirst();
while(!set.IsEOF())
{
set.MoveNext();
if(set.m_resvKey!=str)
{
str=set.m_resvKey;
add.m_RecordCount++;
}
}
add.DoModal();
while(!(customer.IsEOF()))
{
if(customer.m_custName==add.m_AddCustomer)
{
count++;
break;
}
else
customer.MoveNext();
}
if(count==0)
{
AfxMessageBox("数据库中不存在该用户,请使用入库选项添加顾客!");
return;
}
CString strSQL;
strSQL.Format("insert into RESERVATIONS values(\'%s\',%d,\'%s\')",
add.m_AddCustomer,add.m_AddReservationType,add.m_AddReservationKey);
set.m_pDatabase->ExecuteSQL(strSQL);
if(add.m_AddReservationType==1)
{
while(!flight.IsEOF())
{
if(add.m_AddReservationKey.Left(4)==flight.m_flightNum)
{
long number=flight.m_numAvail;
CString flightNum=flight.m_flightNum;
number--;
strSQL.Format("update FLIGHTS set numAvail=%d where flightNum=\'%s\'",number,flightNum);
flight.m_pDatabase->ExecuteSQL(strSQL);
break;
}
else flight.MoveNext();
}
}
else if(add.m_AddReservationType==2)
{
while(!hotel.IsEOF())
{
if(add.m_AddReservationKey.Left(4)==hotel.m_location)
{
long number=hotel.m_numAvail;
CString location=hotel.m_location;
number--;
strSQL.Format("update HOTELS set numAvail=%d where location=\'%s\'",number,location);
hotel.m_pDatabase->ExecuteSQL(strSQL);
break;
}
else hotel.MoveNext();
}
}
else
{
while(!car.IsEOF())
{
if(add.m_AddReservationKey.Left(4)==car.m_location)
{
long number=car.m_numAvail;
CString location=car.m_location;
number--;
strSQL.Format("update CARS set numAvail=%d where location=\'%s\'",number,location);
car.m_pDatabase->ExecuteSQL(strSQL);
break;
}
else car.MoveNext();
}
}
AfxMessageBox("服务添加完毕!");
}
void CMainFrame::Onconstrain()
{
// TODO: Add your command handler code here
CString strSQL;
long totalflight,totalcar,totalhotel,total;
totalflight=totalcar=totalhotel=total=0;
CString flightNum,hotelNum,carNum;
CReservationSet set;
FlightSet flight;
MotorCarSet car;
hotelSet hotel;
set.Open();
flight.Open();
car.Open();
hotel.Open();
set.MoveFirst();
flight.MoveFirst();
car.MoveFirst();
hotel.MoveFirst();
while(!flight.IsEOF())
{
flightNum=flight.m_flightNum;
while(!set.IsEOF())
{
if((set.m_resvType==1)&&(set.m_resvKey.Left(4)==flightNum))
totalflight++;
set.MoveNext();
}
total=flight.m_numSeats-totalflight;
strSQL.Format("update FLIGHTS set numAvail=%d where flightNum=\'%s\'",total,flightNum);
flight.m_pDatabase->ExecuteSQL(strSQL);
set.MoveFirst();
flight.MoveNext();
}
set.MoveFirst();
while(!hotel.IsEOF())
{
while(!set.IsEOF())
{
if((set.m_resvType==2)&&(set.m_resvKey.Left(4)==hotel.m_location))
totalhotel++;
set.MoveNext();
}
total=hotel.m_numRooms-totalhotel;
strSQL.Format("update HOTELS set numAvail=%d where location=\'%s\'",total,hotel.m_location);
hotel.m_pDatabase->ExecuteSQL(strSQL);
set.MoveFirst();
hotel.MoveNext();
}
set.MoveFirst();
while(!car.IsEOF())
{
while(!set.IsEOF())
{
if((set.m_resvType==3)&&(set.m_resvKey.Left(4)==car.m_location))
totalcar++;
set.MoveNext();
}
total=car.m_numCars-totalcar;
strSQL.Format("update CARS set numAvail=%d where location=\'%s\'",total,car.m_location);
car.m_pDatabase->ExecuteSQL(strSQL);
set.MoveFirst();
car.MoveNext();
}
AfxMessageBox("一致性操作完毕!");
}
void CMainFrame::Oncomplite()
{
// TODO: Add your command handler code here
FlightSet flight;
CReservationSet set;
TripCheck check;
flight.Open();
flight.MoveFirst();
set.Open();
set.MoveFirst();
check.DoModal();
CString name=check.m_name;
CString fit=check.m_from;
if(check.m_from==check.m_toward)
{
AfxMessageBox("请确信您输入了查询路线!");
return;
}
loop1:
while(!set.IsEOF())
{
if(set.m_custName==name&&set.m_resvType==1)
{
while(!flight.IsEOF())
{
if(flight.m_flightNum==set.m_resvKey.Left(4)&&fit==flight.m_FromCity)
{
fit=flight.m_ArivCity;
set.MoveFirst();
flight.MoveFirst();
if(fit!=check.m_toward)
goto loop1;
else
{
AfxMessageBox("该顾客的旅行路线是完整的!");
return;
}
}
else
flight.MoveNext();
}
flight.MoveFirst();
set.MoveNext();
}
else
set.MoveNext();
}
AfxMessageBox("该顾客的旅行路线是不完整的!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -