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

📄 systemview.cpp

📁 本软件为车站售票服务,能够提供查询班次,预定座位,取消预定等功能
💻 CPP
字号:
// SystemView.cpp : implementation of the CSystemView class
//

#include "stdafx.h"
#include "System.h"
#include "EnterSystem.h"
#include "SystemDoc.h"
#include "SystemView.h"
#include "EnterRomove.h"
#include "EnterBook.h"
#include "Passenger.h"
#include "Showline.h"
#include "Singleline.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSystemView

IMPLEMENT_DYNCREATE(CSystemView, CListView)

BEGIN_MESSAGE_MAP(CSystemView, CListView)
	//{{AFX_MSG_MAP(CSystemView)
	ON_COMMAND(ID_Remove, OnRemove)
	ON_COMMAND(ID_Inputbusline, OnInputbusline)
	ON_COMMAND(ID_Bookout, OnBookout)
	ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
	ON_COMMAND(ID_DISPLY_BUSLINE, OnDisplyBusline)
	ON_COMMAND(ID_DISPLY_PASSENGER, OnDisplyPassenger)
	ON_COMMAND(SingleLine, OnSingleLine)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSystemView construction/destruction

CSystemView::CSystemView()
{
	// TODO: add construction code here

}

CSystemView::~CSystemView()
{
}

BOOL CSystemView::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);
}

/////////////////////////////////////////////////////////////////////////////
// CSystemView drawing

void CSystemView::OnDraw(CDC* pDC)
{
	CSystemDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

void CSystemView::OnInitialUpdate()
{
	CListView::OnInitialUpdate();
	ShowEnterSystem();
	// TODO: You may populate your ListView with items by directly accessing
	//  its list control through a call to GetListCtrl().
}

/////////////////////////////////////////////////////////////////////////////
// CSystemView printing

BOOL CSystemView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSystemView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSystemView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}
void CSystemView::ShowWinList()
{
	CListCtrl& ListCtrl =GetListCtrl();
	while(ListCtrl.DeleteColumn(0)){};
	ListCtrl.DeleteAllItems();
	ListCtrl.InsertColumn(0,"班次号");
	ListCtrl.SetColumnWidth(0,100);
	ListCtrl.InsertColumn(1,"发车时间");
	ListCtrl.SetColumnWidth(1,100);
	ListCtrl.InsertColumn(2,"终点城市");
	ListCtrl.SetColumnWidth(2,100);
	ListCtrl.InsertColumn(3,"座位总数");
	ListCtrl.SetColumnWidth(3,100);
	ListCtrl.InsertColumn(4,"已售座位");
	ListCtrl.SetColumnWidth(4,100);
}
/////////////////////////////////////////////////////////////////////////////
// CSystemView diagnostics

#ifdef _DEBUG
void CSystemView::AssertValid() const
{
	CListView::AssertValid();
}

void CSystemView::Dump(CDumpContext& dc) const
{
	CListView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CSystemView message handlers

void CSystemView::OnRemove() 
{
    AfxMessageBox("请确定已有乘客订票");
	EnterRomove Dlg;
	CSystemDoc* pDoc = GetDocument();
	if(Dlg.DoModal()==IDOK)
	{
		int i,pos,s,r;
		int index=Dlg.Index;
		for(i=0;i<pDoc->mBuslineArray[index].mPassengerArray.GetSize();i++)
		{
			s=Dlg.m_rName.Compare(pDoc->mBuslineArray[index].mPassengerArray[i].m_Name);
			r=Dlg.m_rID.Compare(pDoc->mBuslineArray[index].mPassengerArray[i].ID);
			if(s==0&&r==0)
			{
				pos=i;
				break;
			}
		}
        pDoc->mBuslineArray[index].mPassengerArray.RemoveAt(pos,1);
	}
}

void CSystemView::OnInputbusline() 
{
		CSystemDoc* pDoc = GetDocument();
		EnterSystem Dlg;
	    if(Dlg.DoModal()==IDOK)
		{
		    Busline busline;
            busline.allseats=Dlg.m_totalseats;
		    busline.goal_city=Dlg.m_goalcity;
            busline.linename=Dlg.m_linename;
		    busline.starttime=Dlg.m_stattime;
			pDoc->mBuslineArray.Add(busline);
			ShowEnterSystem();
		}
}

void CSystemView::OnBookout() 
{
   	AfxMessageBox("请确定已输入班次信息");
	CSystemDoc* pDoc = GetDocument();
	EnterBook Dlg;
	
    if(Dlg.DoModal()==IDOK)
	{   
		int index=Dlg.Index;
		Passenger mpassenger;
		mpassenger.m_Name=Dlg.m_bName;
		mpassenger.ID=Dlg.m_bID;
		mpassenger.seatID=Dlg.m_bseatID;
        pDoc->mBuslineArray[index].mPassengerArray.Add(mpassenger);
	}
 }

void CSystemView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NMLISTVIEW* pNM = (NMLISTVIEW*)pNMHDR;
    if(pNM->iItem >=0)
	{
		CSystemDoc* pDoc = GetDocument();
		int ID=AfxMessageBox("选“Yes”编辑,“No”删除,“Cancel”中止",MB_YESNOCANCEL|MB_ICONQUESTION);
		if(ID==IDYES)
		{
            Busline& busline=pDoc->mBuslineArray[pNM->iItem];
			EnterSystem Dlg;
			Dlg.m_totalseats=busline.allseats;
			Dlg.m_goalcity=busline.goal_city;
			Dlg.m_linename=busline.linename;
			Dlg.m_stattime=busline.starttime;
			if(Dlg.DoModal()==IDOK)
			{
                 busline.allseats=Dlg.m_totalseats;
				 busline.goal_city=Dlg.m_goalcity;
                 busline.linename=Dlg.m_linename;
				 busline.starttime=Dlg.m_stattime;
				 pDoc->mBuslineArray.Add(busline);
				 ShowEnterSystem();
			}
		}
	*pResult = 0;
	}
}
void CSystemView::ShowEnterSystem()
{
	CListCtrl& ListCtrl =GetListCtrl();
	while(ListCtrl.DeleteColumn(0)){};
	ListCtrl.DeleteAllItems();
	ListCtrl.InsertColumn(0,"班次号");
	ListCtrl.SetColumnWidth(0,100);
	ListCtrl.InsertColumn(1,"座位总数");
	ListCtrl.SetColumnWidth(1,100);
	ListCtrl.InsertColumn(2,"终点城市");
	ListCtrl.SetColumnWidth(2,100);
	ListCtrl.InsertColumn(3,"发车时间");
	ListCtrl.SetColumnWidth(3,100);
	int i,j;
	CString str;
	Busline* pBusline=NULL;
    CSystemDoc* pDoc=GetDocument();
	for(i=0;i<pDoc->mBuslineArray.GetSize();i++)
	{
		pBusline=&pDoc->mBuslineArray[i];
        str.Format("%d",pBusline->linename);
		ListCtrl.InsertItem(i,str);
		j=1;
		str.Format("%d",pBusline->allseats);
		ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
		j++;
		str.Format("%s",pBusline->goal_city);
		ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
		j++;
		str.Format("%s",pBusline->starttime);
		ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
	}
}
//本函数没有用处
void CSystemView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	switch(mDisplyID)
	{
	case ID_DISPLY_PASSENGER:
		ShowPassenger();
		break;
	case ID_DISPLY_BUSLINE:
		ShowEnterSystem();
		break;
	}
}
	

void CSystemView::ShowPassenger()
{
	Showline Dlg;
	if(Dlg.DoModal()==IDOK)
	{
		CListCtrl& ListCtrl =GetListCtrl();
	    while(ListCtrl.DeleteColumn(0)){};
	    ListCtrl.DeleteAllItems();
	    ListCtrl.InsertColumn(0,"所乘班次");
	    ListCtrl.SetColumnWidth(0,100);
	    ListCtrl.InsertColumn(1,"姓名");
	    ListCtrl.SetColumnWidth(1,100);
	    ListCtrl.InsertColumn(2,"身份证号");
	    ListCtrl.SetColumnWidth(2,100);
	    ListCtrl.InsertColumn(3,"座位号");
	    ListCtrl.SetColumnWidth(3,100);
	    int i,j;
	    CString str;
	    Busline* pbusline=NULL;
        CSystemDoc* pDoc=GetDocument();
	    int index=Dlg.Index;
		pbusline=&pDoc->mBuslineArray[index];
		Passenger* mpassenger=NULL;
		int s=pbusline->mPassengerArray.GetSize();
		for(i=0;i<s;i++)
		{
            str.Format("%d",pbusline->linename);
		    ListCtrl.InsertItem(i,str);
		    j=1;
			mpassenger=&pbusline->mPassengerArray[i];
		    str.Format("%s",mpassenger->m_Name);
		    ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
            j++;
		    str.Format("%s",mpassenger->ID);
		    ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
		    str.Format("%d",mpassenger->seatID);
		    j++;
		    ListCtrl.SetItem(i,j,LVIF_TEXT,str,0,0,0,NULL);
		}
	
	}
}

void CSystemView::OnDisplyBusline() 
{
    ShowEnterSystem();
}

void CSystemView::OnDisplyPassenger() 
{
    AfxMessageBox("请确定已存在订票乘客");
	mDisplyID=ID_DISPLY_PASSENGER;
	ShowPassenger();
}

void CSystemView::OnSingleLine() 
{
   AfxMessageBox("请确定已存在班次信息");
   Singleline Dlg;
   if(Dlg.DoModal()==IDOK)
   {
		CListCtrl& ListCtrl =GetListCtrl();
	    while(ListCtrl.DeleteColumn(0)){};
	    ListCtrl.DeleteAllItems();
	    ListCtrl.InsertColumn(0,"班次");
	    ListCtrl.SetColumnWidth(0,100);
	    ListCtrl.InsertColumn(1,"剩余票数");
	    ListCtrl.SetColumnWidth(1,100);
	    ListCtrl.InsertColumn(2,"已售座位");
	    ListCtrl.SetColumnWidth(2,200);
	    int seati,j,k;
	    CString str;
	    int index=Dlg.Index;
        CSystemDoc* pDoc=GetDocument();
	    Busline* pbusline=NULL;
		pbusline=&pDoc->mBuslineArray[index];
		Passenger* mpassenger;
		int s=pbusline->mPassengerArray.GetSize();
			for(j=0;j<s;j++)
			{
				    str.Format("%d",pbusline->linename);
		            ListCtrl.InsertItem(j,str);
		            k=1;
			        mpassenger=&pbusline->mPassengerArray[j];
		            int data=pbusline->allseats-s;
					str.Format("%d",data);
		            ListCtrl.SetItem(j,k,LVIF_TEXT,str,0,0,0,NULL);
                    k++;
					seati=mpassenger->seatID;
		            str.Format("已售座位%d号",seati);
		            ListCtrl.SetItem(j,k,LVIF_TEXT,str,0,0,0,NULL);
				
			}



   }
}

⌨️ 快捷键说明

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