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

📄 ticketsalingview.cpp

📁 售票程序计算机科学与工程学院 孙学波
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TicketSalingView.cpp : implementation of the CTicketSalingView class
//

#include "stdafx.h"
#include "TicketSaling.h"

#include "TicketSalingDoc.h"
#include "TicketSalingView.h"
#include "BuyTicketDlg.h"
#include "ReturnTicketDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTicketSalingView

IMPLEMENT_DYNCREATE(CTicketSalingView, CFormView)

BEGIN_MESSAGE_MAP(CTicketSalingView, CFormView)
	//{{AFX_MSG_MAP(CTicketSalingView)
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
	ON_COMMAND(ID_SALETICKET, OnSaleticket)
	ON_COMMAND(ID_DELETE_TICKET, OnDeleteTicket)
	ON_COMMAND(ID_NEWDAY, OnAddNewDay)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTicketSalingView construction/destruction

CTicketSalingView::CTicketSalingView()
	: CFormView(CTicketSalingView::IDD)
{
	//{{AFX_DATA_INIT(CTicketSalingView)
	//}}AFX_DATA_INIT
	// TODO: add construction code here
	mLeftMargin=300;
	mRightMargin=300;
	mTopMargin=600;
	mBottomMargin=300;

}

CTicketSalingView::~CTicketSalingView()
{
}

void CTicketSalingView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTicketSalingView)
	DDX_Control(pDX, IDC_STATIC_TITLE, m_Title);
	DDX_Control(pDX, IDC_LIST2, m_listTraveler);
	DDX_Control(pDX, IDC_TREE1, m_treeBusInfo);
	//}}AFX_DATA_MAP
}

BOOL CTicketSalingView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
   	return CFormView::PreCreateWindow(cs);
}

void CTicketSalingView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

    CTicketSalingDoc *pDoc=(CTicketSalingDoc *)GetDocument();
	CObject *pObj;
	CBusInfo *pBusInfo;
	POSITION pos=pDoc->m_List.GetHeadPosition();
    HTREEITEM hCurrent,hItem[3];
	char buff[256];
    CTime today=CTime::GetCurrentTime(),*pTime;
	char strDate[20];
	
	//设置列表框架
	while (m_listTraveler.DeleteColumn(0)); 

	m_listTraveler.InsertColumn(0,"序号",LVCFMT_LEFT,40);  
 	m_listTraveler.InsertColumn(1,"车次",LVCFMT_LEFT,80);  
	m_listTraveler.InsertColumn(2,"去向",LVCFMT_LEFT,40);  
	m_listTraveler.InsertColumn(3,"座号",LVCFMT_LEFT,60);  
	m_listTraveler.InsertColumn(4,"发车时间",LVCFMT_LEFT,120);  
	m_listTraveler.InsertColumn(5,"票价",LVCFMT_LEFT,100);  
	m_listTraveler.InsertColumn(6,"身份证号",LVCFMT_LEFT,120);  
	m_listTraveler.InsertColumn(7,"姓名",LVCFMT_LEFT,80);  
	m_listTraveler.InsertColumn(8,"购票时间",LVCFMT_LEFT,110);  
	
	m_listTraveler.DeleteAllItems(); 

    //树初始化
	m_treeBusInfo.DeleteAllItems(); 
	for(int i=0;i<3;i++)
	{
		wsprintf(strDate,"%4d年%02d月%02d日",today.GetYear(),today.GetMonth(),today.GetDay());

		
		hItem[i]=m_treeBusInfo.InsertItem(strDate);  
        
		pTime=new CTime(today);
		
		m_treeBusInfo.SetItemData(hItem[i],(DWORD)pTime);
		
		today+=CTimeSpan(1,0,0,0);
	}
	today=CTime::GetCurrentTime();
		
	while(pos)
	{ 
		pObj=(CObject *)pDoc->m_List.GetNext(pos);
		if(pObj->IsKindOf(RUNTIME_CLASS(CBusInfo)))
		{
			pBusInfo=(CBusInfo*)pObj;
			int index=pBusInfo->m_StartTime.GetDay()-today.GetDay();
			if(index>=0 && index < 3)
			{
				wsprintf(buff,"%6s %02d点%02d分",
					pBusInfo->m_Destination,
					pBusInfo->m_StartTime.GetHour(),
					pBusInfo->m_StartTime.GetMinute());

				hCurrent=m_treeBusInfo.InsertItem(buff,hItem[index]);  
				m_treeBusInfo.SetItemData(hCurrent,(DWORD)pObj);
			}
		}
	}
    m_treeBusInfo.Expand(hItem[0],TVE_EXPAND); 
}

void CTicketSalingView::FillListData(CTime today)
{
	CTraveler *pTraveler;
	CObject * pObj;
	POSITION pos;
	CTicketSalingDoc *pDoc=(CTicketSalingDoc *)GetDocument();
	pos=pDoc->m_List.GetHeadPosition();
    int index=0;
	CTime t;
    char buff[256];
	m_listTraveler.DeleteAllItems(); 
	while(pos)
	{ 
		pObj=(CObject *)pDoc->m_List.GetNext(pos);
		if(pObj->IsKindOf(RUNTIME_CLASS(CTraveler)))
		{
			pTraveler=(CTraveler *)pObj;
			CTime st=pTraveler->m_pBusInfo->m_StartTime;  
			if(st.GetYear()==today.GetYear() &&  st.GetMonth()==today.GetMonth() && st.GetDay()==today.GetDay())
			{
				wsprintf(buff,"%4d",index+1);
				m_listTraveler.InsertItem(index,buff);
				m_listTraveler.SetItemText(index,1,pTraveler->m_strBusID);
				m_listTraveler.SetItemText(index,2,pTraveler->m_pBusInfo->m_Destination);
				
				wsprintf(buff,"%4d",pTraveler->m_nSeat);
				m_listTraveler.SetItemText(index,3,buff);
				
				t=pTraveler->m_pBusInfo->m_StartTime;
				wsprintf(buff,"%4d-%02d-%02d %02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute());
				m_listTraveler.SetItemText(index,4,buff);
				
				wsprintf(buff,"%d.00", pTraveler->m_pBusInfo->m_nPrice);
				m_listTraveler.SetItemText(index,5,buff);
				
				m_listTraveler.SetItemText(index,6,pTraveler->m_TravelID);
				m_listTraveler.SetItemText(index,7,pTraveler->m_Name);

				t=pTraveler->m_DateTime;
				wsprintf(buff,"%4d-%02d-%02d %02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute());
				m_listTraveler.SetItemText(index,8,buff);

				m_listTraveler.SetItemData(index,(DWORD)pTraveler);
				index++;
			}
		}
	}
}

void CTicketSalingView::FillListData(CBusInfo *pBusInfo)
{
	CTraveler *pTraveler;
	POSITION pos;
	CObject * pObj;
	CTicketSalingDoc *pDoc=(CTicketSalingDoc *)GetDocument();
	pos=pDoc->m_List.GetHeadPosition();
    int index=0;
    char buff[256];
	CTime t;
	m_listTraveler.DeleteAllItems(); 
	while(pos)
	{ 
		pObj=(CObject *)pDoc->m_List.GetNext(pos);
		if(pObj->IsKindOf(RUNTIME_CLASS(CTraveler)))
		{
			pTraveler=(CTraveler *)pObj;
			if(pTraveler->m_pBusInfo==pBusInfo)
			{
				wsprintf(buff,"%4d",index+1);
				m_listTraveler.InsertItem(index,buff);
				m_listTraveler.SetItemText(index,1,pTraveler->m_strBusID);
				m_listTraveler.SetItemText(index,2,pTraveler->m_pBusInfo->m_Destination);
				
				wsprintf(buff,"%4d",pTraveler->m_nSeat);
				m_listTraveler.SetItemText(index,3,buff);
				
				t=pTraveler->m_pBusInfo->m_StartTime;
				wsprintf(buff,"%4d-%02d-%02d %02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute());
				m_listTraveler.SetItemText(index,4,buff);
				
				wsprintf(buff,"%d.00", pTraveler->m_pBusInfo->m_nPrice);
				m_listTraveler.SetItemText(index,5,buff);
				
				m_listTraveler.SetItemText(index,6,pTraveler->m_TravelID);
				m_listTraveler.SetItemText(index,7,pTraveler->m_Name);

				t=pTraveler->m_DateTime;
				wsprintf(buff,"%4d-%02d-%02d %02d:%02d", t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute());
				m_listTraveler.SetItemText(index,8,buff);

				m_listTraveler.SetItemData(index,(DWORD)pTraveler);
				index++;
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////////
// CTicketSalingView printing

BOOL CTicketSalingView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	first=1;
	return DoPreparePrinting(pInfo);
}

void CTicketSalingView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	//计算表格页数,设置页号
	
	UINT uToPage=pInfo->GetToPage(); 
	UINT uFromPage=pInfo->GetFromPage();

}

void CTicketSalingView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: add cleanup after printing
	first=1;
}

void CTicketSalingView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{  
	//打印当前页,即页号为pInfo->m_nCurPage的页。
	char *buff[9]={"序号","车次","去向","座号","发车时间","票价","身份证号","姓名","购票时间"};
	int w[10]={2,4,2,3,6,5,6,4,6,0};
	int nWidth=pInfo->m_rectDraw.Width()-mLeftMargin-mRightMargin;
	TEXTMETRIC textmetric;            //fetch the basic information about a physical font. 
	pDC->GetTextMetrics(&textmetric);
	if(first)
	{
		nLinesPerPage=(pInfo->m_rectDraw.bottom-mTopMargin-mBottomMargin)/(2*textmetric.tmHeight)-1;
		nTotalLines=m_listTraveler.GetItemCount();  //计算表格行数 
		nPages=nTotalLines/nLinesPerPage;           //计算表格页数

⌨️ 快捷键说明

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