⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ticketsalingview.cpp

📁 售票程序计算机科学与工程学院 孙学波
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if (nTotalLines%nLinesPerPage)
			nPages++;
		if (nPages==0)
			nPages=1;
		pInfo->SetMinPage(1);						//设置开始页号
		pInfo->SetMaxPage(nPages);					//设置结束页号
		first=0;
	}

	int y=mTopMargin;
   	for(int i=0;i<=nLinesPerPage+1;i++)
	{
		pDC->MoveTo(mLeftMargin,y);
		pDC->LineTo(pInfo->m_rectDraw.right-mRightMargin,y);
		y+=2*textmetric.tmHeight;
	}

	
	int n=9;
	int x=mLeftMargin;
	y-=2*textmetric.tmHeight;
	for(i=0;i<=n;i++)
	{
		pDC->MoveTo(x,mTopMargin );
		pDC->LineTo(x,y);
		if(i<n-1)
		x+=w[i]*nWidth/38;
		else
		x=pInfo->m_rectDraw.right-mRightMargin;
	}
	
	CRect mTitleRect(mLeftMargin,200,nWidth,700);
	CFont mTitleFont;
	mTitleFont.CreateFont(200,100,0,0,0,0,0,0,0,0,0,0,0,"楷体"); 
	CFont mTextFont;
	mTextFont.CreateFont(100,50,0,0,0,0,0,0,0,0,0,0,0,"楷体"); 

	CFont *pOldFont=pDC->SelectObject(&mTitleFont); 

	pDC->DrawText("班车售票情况",&mTitleRect,DT_CENTER|DT_VCENTER);
	

	pDC->SelectObject(&mTextFont);
	for(x=mLeftMargin+10,i=0;i<n;i++)	//打印表头
	{
		pDC->TextOut(x,mTopMargin+20,buff[i]);
		x+=w[i]*nWidth/38;
	}
	
	y=mTopMargin+20+2*textmetric.tmHeight;
	int r=(pInfo->m_nCurPage-1)*nLinesPerPage;
	char sbuff[100];
	while(y < pInfo->m_rectDraw.bottom-mBottomMargin-2*textmetric.tmHeight)
	{
		x=mLeftMargin+10;
		for(i=0;i<n && r<m_listTraveler.GetItemCount();i++)	//打印表头
		{
			m_listTraveler.GetItemText(r,i,sbuff,90);
			pDC->TextOut(x,y,sbuff);
			x+=w[i]*nWidth/38;
		}
		r++;
		y+=2*textmetric.tmHeight;
	}

	pDC->SelectObject(pOldFont); 
	pDC->TextOut(500,500,buff[0]); 
}

/////////////////////////////////////////////////////////////////////////////
// CTicketSalingView diagnostics

#ifdef _DEBUG
void CTicketSalingView::AssertValid() const
{
	CFormView::AssertValid();
}

void CTicketSalingView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CTicketSalingDoc* CTicketSalingView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTicketSalingDoc)));
	return (CTicketSalingDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTicketSalingView message handlers

void CTicketSalingView::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here

	HTREEITEM hItem=m_treeBusInfo.GetSelectedItem();  
	HTREEITEM hParentItem=m_treeBusInfo.GetParentItem(hItem); 
    DWORD data=m_treeBusInfo.GetItemData(hItem);
	if(hParentItem==NULL)
	{
	   CTime * ptr=(CTime *)data;
	   FillListData(*ptr);
	   SetTitle(ptr);
	}
	else
	{
	   CBusInfo *ptr=(CBusInfo *)data;
	   FillListData(ptr);
	   SetTitle(ptr);
	}
    m_treeBusInfo.Expand(hItem,TVE_TOGGLE); 
	*pResult = 0;
}
void CTicketSalingView::SetTitle(CBusInfo *pBusInfo)
{
	char buff[256];
    wsprintf(buff," %4d年%02d月%02d日发往:%6s 的第 %6s 次班车售票情况 发车时间:%02d点%02d分 现有客票:%02d 张。",
		pBusInfo->m_StartTime.GetYear(),
		pBusInfo->m_StartTime.GetMonth(),
		pBusInfo->m_StartTime.GetDay(),
		pBusInfo->m_Destination,
		pBusInfo->m_strBusID,
		pBusInfo->m_StartTime.GetHour(),
		pBusInfo->m_StartTime.GetMinute(),
		pBusInfo->m_nSeat-pBusInfo->m_nSeatSaled);
	m_Title.SetWindowText(buff);  
}
void CTicketSalingView::SetTitle(CTime *pTime)
{
	char buff[256];
    wsprintf(buff," %4d年%02d月%02d日发往各站的售票情况",
		pTime->GetYear(),
		pTime->GetMonth(),
		pTime->GetDay());
	m_Title.SetWindowText(buff);  
}

void CTicketSalingView::OnSaleticket() 
{
	HTREEITEM hItem=m_treeBusInfo.GetSelectedItem();
	
	if(hItem)
	{
		HTREEITEM hParentItem=m_treeBusInfo.GetParentItem(hItem); 

		if (hParentItem)
		{
			DWORD data=m_treeBusInfo.GetItemData(hItem);
			CObject *pObj=(CObject *)m_treeBusInfo.GetItemData(hItem);
			if(pObj && pObj->IsKindOf(RUNTIME_CLASS(CBusInfo)))
			{
				CTicketSalingDoc *pDoc=(CTicketSalingDoc *)GetDocument();
				int nSeat=pDoc->FindSeat((CBusInfo*)pObj);
				if(nSeat==-1)
					::AfxMessageBox("对不起,本次车票已全部售完!欢迎下次光临!",0,0);  
				else
				{
					CBuyTicketDlg *pDlg;
					pDlg=new CBuyTicketDlg((CBusInfo*)pObj,nSeat);
					if(pDlg->DoModal()==IDOK)
					{
						pDlg->m_pTraveler->m_pBusInfo->m_nSeatSaled++;            //增加已售票数 
						SetTitle( pDlg->m_pTraveler->m_pBusInfo);
						pDoc->AddItem(pDlg->m_pTraveler);
						FillListData((CBusInfo*)pObj); 
					}
				}
			}
			else
			::AfxMessageBox("请选择好欲购置的车次,再进行购票!",0,0);  
		}
		else
			::AfxMessageBox("请选择好欲购置的车次,再进行购票!",0,0);  
	}
}

void CTicketSalingView::OnDeleteTicket() 
{
	CTicketSalingDoc *pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	HTREEITEM hItem	=m_treeBusInfo.GetSelectedItem();
	if (hItem)
	{
		HTREEITEM hParentItem=m_treeBusInfo.GetParentItem(hItem); 
		if (hParentItem)
		{
			CBusInfo *pBusInfo=(CBusInfo *)m_treeBusInfo.GetItemData(hItem);	int nItemSelected = m_listTraveler.GetSelectedCount();

			int nTicketDeleted=0;
			POSITION currentpos,pos=m_listTraveler.GetFirstSelectedItemPosition();
			while(pos)
			{
				currentpos=pos;
				int i=m_listTraveler.GetNextSelectedItem(pos);

				CTraveler* pTraveler=(CTraveler*) m_listTraveler.GetItemData(i);
				CReturnTicketDlg *pDlg=new CReturnTicketDlg(pTraveler);
				if(pDlg->DoModal()==IDOK)
				{
					m_listTraveler.DeleteItem(i);
					pDoc->DeleteItem(pTraveler);
					nTicketDeleted++;
				}
			}
			if(nTicketDeleted)
			{
			    pBusInfo->m_nSeatSaled-= nTicketDeleted;
			    SetTitle(pBusInfo);
			}
		}
		else
		::AfxMessageBox("请选择好欲退的车票,再进行购票!",0,0);  
	}
}


void CTicketSalingView::OnAddNewDay() 
{
	HTREEITEM hItem	=m_treeBusInfo.GetSelectedItem(),hCurrent;
	HTREEITEM hParentItem=m_treeBusInfo.GetParentItem(hItem); 
	HTREEITEM hChildItem=m_treeBusInfo.GetChildItem(hItem); 
	CBusInfo * pBusInfo;
    CTicketSalingDoc *pDoc=GetDocument();
	if (hItem && !hChildItem && !hParentItem)
	{

		CTime *pTime=(CTime *)m_treeBusInfo.GetItemData(hItem);	
		CTime t=*pTime;

		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 i=0;i<10;i++)
		{
			wsprintf(buff,"%4d%02d%02d%02d",t.GetYear(),t.GetMonth(),t.GetDay(),i+1);
 			CObject *pObj=(CObject *)new CBusInfo(buff,StartTime[i],city[i],seats[i],0,price[i]);
			StartTime[i]=StartTime[i];	
			pDoc->AddItem(pObj); 

			pBusInfo=(CBusInfo*)pObj;

			wsprintf(buff,"%6s %02d点%02d分",
			pBusInfo->m_Destination,
			pBusInfo->m_StartTime.GetHour(),
			pBusInfo->m_StartTime.GetMinute());
			hCurrent=m_treeBusInfo.InsertItem(buff,hItem);  
			m_treeBusInfo.SetItemData(hCurrent,(DWORD)pObj);
		}	
    	m_treeBusInfo.UpdateWindow(); 
	}
	else
	::AfxMessageBox("请选择好欲添加的日期再添加数据!",0,0);  
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -