📄 ticketsalingdoc.cpp
字号:
// TicketSalingDoc.cpp : implementation of the CTicketSalingDoc class
//
#include "stdafx.h"
#include "TicketSaling.h"
#include "TicketSalingDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingDoc
IMPLEMENT_DYNCREATE(CTicketSalingDoc, CDocument)
BEGIN_MESSAGE_MAP(CTicketSalingDoc, CDocument)
//{{AFX_MSG_MAP(CTicketSalingDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingDoc construction/destruction
CTicketSalingDoc::CTicketSalingDoc()
{
// TODO: add one-time construction code here
}
CTicketSalingDoc::~CTicketSalingDoc()
{
}
BOOL CTicketSalingDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
CTime t=CTime::GetCurrentTime();
CTimeSpan OneDay(1,0,0,0);
char buff[256];
char *city[]={"北京","沈阳","大连","营口","抚顺","丹东","阜新","通化","长春","哈尔滨"};
CTime StartTime[]={
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),19,0,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),7,30,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),7,30,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),7,10,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),7,20,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),8,0,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),8,30,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),8,30,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),9,0,0),
CTime(t.GetYear(),t.GetMonth(),t.GetDay(),9,30,0),
};
int seats[10]={60,60,72,72,60,60,24,24,60,60};
int price[10]={120,30,40,40,30,20,25,25,80,150};
for(int j=0;j<3;j++)
{
for(int i=0;i<10;i++)
{
wsprintf(buff,"%4d%02d%02d%02d",t.GetYear(),t.GetMonth(),t.GetDay()+j,i+1);
CObject *pObj=(CObject *)new CBusInfo(buff,StartTime[i],city[i],seats[i],0,price[i]);
StartTime[i]=StartTime[i]+OneDay;
AddItem(pObj);
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingDoc serialization
void CTicketSalingDoc::Serialize(CArchive& ar)
{
int count;
CString strFlag="TicketSaling";;
CObject *pObj;
CObject *obj;
CTraveler *pTraveler;
CBusInfo *pBusInfo;
POSITION pos;
if (ar.IsStoring())
{
count=m_List.GetCount();
ar<<strFlag;
ar<<count;
pos=m_List.GetHeadPosition(); // TODO: add storing code here
while(pos)
{
pObj=(CObject *)m_List.GetNext(pos);
ar<<pObj;
}
}
else
{
ar>>strFlag;
ar>>count;
for(int i =0;i<count;i++)
{
ar>>pObj;
if(pObj->IsKindOf(RUNTIME_CLASS(CTraveler)))
{
pTraveler=(CTraveler*)pObj;
pos=m_List.GetHeadPosition();
while(pos)
{
obj=(CObject*) m_List.GetNext(pos);
if(obj->IsKindOf(RUNTIME_CLASS(CBusInfo)))
{
pBusInfo=(CBusInfo*)obj;
if(pBusInfo->m_strBusID==pTraveler->m_strBusID)
{
pTraveler->m_pBusInfo=pBusInfo;
break;
}
}
}
}
m_List.AddTail(pObj);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingDoc diagnostics
#ifdef _DEBUG
void CTicketSalingDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CTicketSalingDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingDoc commands
void CTicketSalingDoc::DeleteContents()
{
POSITION pos1,pos2;
CObject *pObj;
int count=m_List.GetCount();
pos1=m_List.GetHeadPosition(); // TODO: add storing code here
while(pos1)
{
pos2=pos1;
pObj=(CObject *)m_List.GetNext(pos1);
m_List.RemoveAt(pos2);
delete pObj;
}
CDocument::DeleteContents();
}
void CTicketSalingDoc::AddItem(CObject *pObj)
{
m_List.AddTail(pObj);
SetModifiedFlag();
}
int CTicketSalingDoc::DeleteItem(CBusInfo *pBusInfo)
{
POSITION current,last;
CObject *pObj;
CBusInfo *pcurBusInfo;
current=m_List.GetHeadPosition(); // TODO: add storing code here
int res=0;
while(current)
{
last=current;
pObj=(CObject *)m_List.GetNext(current);
if(pObj->IsKindOf(RUNTIME_CLASS(CBusInfo)))
{
pcurBusInfo=(CBusInfo *)pObj;
if(pcurBusInfo->m_strBusID==pBusInfo->m_strBusID)
{
m_List.RemoveAt(last);
SetModifiedFlag();
delete pObj;
res++;
}
}
}
return res;
}
int CTicketSalingDoc::DeleteItem(CTraveler *pTraveler)
{
POSITION current,last;
CObject *pObj;
CTraveler *pcurTraveler;
current=m_List.GetHeadPosition(); // TODO: add storing code here
int res=0;
while(current)
{
last=current;
pObj=(CObject *)m_List.GetNext(current);
if(pObj->IsKindOf(RUNTIME_CLASS(CTraveler)))
{
pcurTraveler=(CTraveler *)pObj;
if(pcurTraveler->m_TravelID == pTraveler->m_TravelID
&& pcurTraveler->m_strBusID == pTraveler->m_strBusID)
{
m_List.RemoveAt(last);
delete pObj;
SetModifiedFlag();
res++;
break;
}
}
}
return res;
}
int CTicketSalingDoc::FindSeat(CBusInfo *pBusInfo)
{
POSITION pos;
CObject *pObj;
int *bitmap;
bitmap=new int[pBusInfo->m_nSeat];
for(int i=0;i<pBusInfo->m_nSeat;i++)
bitmap[i]=0;
CTraveler *pTraveler;
pos=m_List.GetHeadPosition(); // TODO: add storing code here
while(pos)
{
pObj=(CObject *)m_List.GetNext(pos);
if(pObj->IsKindOf(RUNTIME_CLASS(CTraveler)))
{
pTraveler=(CTraveler *)pObj;
if(pTraveler->m_strBusID == pBusInfo->m_strBusID)
bitmap[pTraveler->m_nSeat-1]=1;
}
}
int res=-1;
for(int j=0;j<pBusInfo->m_nSeat;j++)
if(!bitmap[j])
{
res=j+1;
break;
}
return res;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -