📄 ticketview.cpp
字号:
// TicketView.cpp : implementation of the CTicketView class
//
#include "stdafx.h"
#include "Ticket.h"
#include "TicketDoc.h"
#include "TicketView.h"
#include "DlgAddBus.h"
#include "DlgFindBus.h"
#include "DlgSellTic.h"
#include "DlgReturnTic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTicketView
IMPLEMENT_DYNCREATE(CTicketView, CListView)
BEGIN_MESSAGE_MAP(CTicketView, CListView)
//{{AFX_MSG_MAP(CTicketView)
ON_COMMAND(ID_CREATE_BUS, OnCreateBus)
ON_COMMAND(ID_SELL_TIC, OnSellTic)
ON_COMMAND(ID_RETURN_TIC, OnReturnTic)
ON_COMMAND(ID_VIEW_BUSLIST, OnViewBuslist)
ON_COMMAND(ID_VIEW_BUS, OnViewBus)
ON_COMMAND(ID_VIEW_PASSENGER, OnViewPassenger)
ON_UPDATE_COMMAND_UI(ID_VIEW_BUSLIST, OnUpdateViewBuslist)
ON_UPDATE_COMMAND_UI(ID_VIEW_BUS, OnUpdateViewBus)
ON_UPDATE_COMMAND_UI(ID_VIEW_PASSENGER, OnUpdateViewPassenger)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTicketView construction/destruction
CTicketView::CTicketView()
{
// TODO: add construction code here
}
CTicketView::~CTicketView()
{
}
BOOL CTicketView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style|=LVS_SHOWSELALWAYS|LVS_REPORT;
return CListView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTicketView drawing
void CTicketView::OnDraw(CDC* pDC)
{
CTicketDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CTicketView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
// TODO: You may populate your ListView with items by directly accessing
// its list control through a call to GetListCtrl().
OnViewBuslist();
}
/////////////////////////////////////////////////////////////////////////////
// CTicketView printing
BOOL CTicketView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTicketView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTicketView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTicketView diagnostics
#ifdef _DEBUG
void CTicketView::AssertValid() const
{
CListView::AssertValid();
}
void CTicketView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
CTicketDoc* CTicketView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTicketDoc)));
return (CTicketDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTicketView message handlers
void CTicketView::OnCreateBus()
{
// TODO: Add your command handler code here
CDlgAddBus dlg;
if(dlg.DoModal()==2)
return;
CBusManager& BM=GetDocument()->m_BusManager;
CTime time=dlg.m_Time[dlg.m_Date];
if(!BM.AddBus(dlg.m_BusNumber,dlg.m_City,time.GetYear(),time.GetMonth(),time.GetDay(),dlg.m_Hour,dlg.m_Minute,dlg.m_SeatTotal))
AfxMessageBox("创建失败或该班次已存在!");
}
void CTicketView::OnSellTic()
{
// TODO: Add your command handler code here
CDlgFindBus dlg0;
if(dlg0.DoModal()==2)
return;
CBusManager& BM=GetDocument()->m_BusManager;
CTime time=dlg0.m_Time[dlg0.m_Date];
CBus* pBus=BM.FindBus(dlg0.m_BusNumber,time.GetYear(),time.GetMonth(),time.GetDay(),dlg0.m_Hour,dlg0.m_Minute);
if(!pBus){
AfxMessageBox("没有找到符合条件的车次!");
return;
}
CDlgSellTic dlg1;
dlg1.m_pBus=pBus;
if(dlg1.DoModal()==2)
return;
if(!pBus->AddPassenger(dlg1.m_IDCard,dlg1.m_Name,dlg1.m_Seat))
AfxMessageBox("该票已售出!");
}
void CTicketView::OnReturnTic()
{
// TODO: Add your command handler code here
CDlgFindBus dlg0;
if(dlg0.DoModal()==2)
return;
CBusManager& BM=GetDocument()->m_BusManager;
CTime time=dlg0.m_Time[dlg0.m_Date];
CBus* pBus=BM.FindBus(dlg0.m_BusNumber,time.GetYear(),time.GetMonth(),time.GetDay(),dlg0.m_Hour,dlg0.m_Minute);
if(!pBus){
AfxMessageBox("没有找到符合条件的车次!");
return;
}
CDlgReturnTic dlg1;
dlg1.m_pBus=pBus;
if(dlg1.DoModal()==2)
return;
if(!pBus->DeletePassenger(dlg1.m_Seat))
AfxMessageBox("该票还未售出!");
}
void CTicketView::OnViewBuslist()
{
// TODO: Add your command handler code here
CBusManager& BM=GetDocument()->m_BusManager;
m_ShowID=ID_VIEW_BUSLIST;
GetDocument()->m_BusManager.ViewBusList(this);
}
void CTicketView::OnViewBus()
{
// TODO: Add your command handler code here
CDlgFindBus dlg;
if(dlg.DoModal()==2)
return;
CBusManager& BM=GetDocument()->m_BusManager;
CTime time=dlg.m_Time[dlg.m_Date];
CBus* pBus=BM.FindBus(dlg.m_BusNumber,time.GetYear(),time.GetMonth(),time.GetDay(),dlg.m_Hour,dlg.m_Minute);
if(!pBus){
AfxMessageBox("没有找到符合条件的车次!");
return;
}
m_ShowID=ID_VIEW_BUS;
GetDocument()->m_BusManager.ViewBus(this,pBus);
}
void CTicketView::OnViewPassenger()
{
// TODO: Add your command handler code here
CDlgFindBus dlg;
if(dlg.DoModal()==2)
return;
CBusManager& BM=GetDocument()->m_BusManager;
CTime time=dlg.m_Time[dlg.m_Date];
CBus* pBus=BM.FindBus(dlg.m_BusNumber,time.GetYear(),time.GetMonth(),time.GetDay(),dlg.m_Hour,dlg.m_Minute);
if(!pBus){
AfxMessageBox("没有找到符合条件的车次!");
return;
}
m_ShowID=ID_VIEW_PASSENGER;
GetDocument()->m_BusManager.ViewPassenger(this,pBus);
}
void CTicketView::OnUpdateViewBuslist(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_ShowID==ID_VIEW_BUSLIST)
pCmdUI->SetRadio(true);
else
pCmdUI->SetRadio(false);
}
void CTicketView::OnUpdateViewBus(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_ShowID==ID_VIEW_BUS)
pCmdUI->SetRadio(true);
else
pCmdUI->SetRadio(false);
}
void CTicketView::OnUpdateViewPassenger(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_ShowID==ID_VIEW_PASSENGER)
pCmdUI->SetRadio(true);
else
pCmdUI->SetRadio(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -