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

📄 saleticketview.cpp

📁 汽车站售票管理系统,源代码完整无错
💻 CPP
字号:
// SaleTicketView.cpp : implementation file
//

#include "stdafx.h"
#include "StationManage.h"
#include "SaleTicketView.h"

#include "DayPlanSet.h"
#include "RouteSet.h"
#include "SeattypeSet.h"
#include "busset.h"
#include "RouteSendInfoSet.h"
#include "BustypeSet.h"





#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSaleTicketView

IMPLEMENT_DYNCREATE(CSaleTicketView, CRecordView)

CSaleTicketView::CSaleTicketView()
	: CRecordView(CSaleTicketView::IDD)
{
	//{{AFX_DATA_INIT(CSaleTicketView)
	m_pSet = NULL;
	m_end = _T("");
	m_price = 0.0f;
	m_route = _T("");
	m_seattype = _T("");
	m_leftseat = _T("");
	m_fctime = _T("");
	m_fcdate1 = _T("");
	m_fcTime = 0;
	//}}AFX_DATA_INIT
}

CSaleTicketView::~CSaleTicketView()
{
	if (!((CStationManageApp*)AfxGetApp())->m_SaleTicketViewscontrol)
	{
		((CStationManageApp*)AfxGetApp())->m_SaleTicketViews=0;
	}
	if (m_pSet)
		delete m_pSet;
}

void CSaleTicketView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSaleTicketView)
	DDX_Control(pDX, IDC_DATETIMEPICKER1, m_datetimectrl);
	DDX_Control(pDX, IDC_LEFT_TICKET, m_leftticket_list);
	DDX_Control(pDX, IDC_BUTTON_search_lefticket, m_leftticket_bcontrol);
	DDX_Text(pDX, IDC_END, m_end);
	DDX_Text(pDX, IDC_PRICE, m_price);
	DDX_Text(pDX, IDC_ROUTE, m_route);
	DDX_Text(pDX, IDC_SEATTYPE, m_seattype);
	DDX_Text(pDX, IDC_LEFTSEAT, m_leftseat);
	DDX_Text(pDX, IDC_FCTIME, m_fctime);
	DDX_Text(pDX, IDC_FCDATE1, m_fcdate1);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_fcTime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSaleTicketView, CRecordView)
	//{{AFX_MSG_MAP(CSaleTicketView)
	ON_BN_CLICKED(IDC_BUTTON_search_lefticket, OnBUTTONsearchlefticket)
	ON_NOTIFY(NM_CLICK, IDC_LEFT_TICKET, OnClickLeftTicket)
	ON_BN_CLICKED(IDC_BUTTON_sale, OnBUTTONsale)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSaleTicketView diagnostics

#ifdef _DEBUG
void CSaleTicketView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CSaleTicketView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSaleTicketView message handlers

CRecordset* CSaleTicketView::OnGetRecordset()
{
	if (m_pSet != NULL)
		return m_pSet;

	m_pSet = new CTicketSet(NULL);
	m_pSet->Open();

	return m_pSet;
}

CTicketSet* CSaleTicketView::GetRecordset()
{
	CTicketSet* pData = (CTicketSet*) OnGetRecordset();
	ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CTicketSet)));
	return pData;
}

void CSaleTicketView::OnInitialUpdate()
{
	CDayPlanSet* m_pDayPlanSet=new CDayPlanSet(NULL);
	CRouteSet* m_pRouteSet=new CRouteSet(NULL);
	CSeattypeSet* m_pSeatType=new CSeattypeSet(NULL);
	CBusset* m_pBusSet=new CBusset(NULL);
	RefreshData();
	static int haveColumn=0;
	BeginWaitCursor();
	GetRecordset();
	CRecordView::OnInitialUpdate();
	GetDocument()->SetTitle("前台售票");
	GetParent()->SetWindowText("前台售票");
	EndWaitCursor();
	RECT rect;
	m_leftticket_list.GetWindowRect(&rect);
	int listwidth=rect.right-rect.left;
	DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
	m_leftticket_list.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
	showList(m_pDayPlanSet,m_leftticket_list);
	if (m_pDayPlanSet->GetRecordCount()!=0)
	{
		int routeid=(atoi)(m_leftticket_list.GetItemText(m_leftticket_list.GetTopIndex(),2));
		int busid=atoi(m_leftticket_list.GetItemText(m_leftticket_list.GetTopIndex(),3));
		int type=m_pBusSet->SearchBusIndex(busid)->m_seattype;
		m_fctime=m_leftticket_list.GetItemText(m_leftticket_list.GetTopIndex(),7);
		m_fcdate1=m_leftticket_list.GetItemText(m_leftticket_list.GetTopIndex(),1);
		m_leftseat=m_leftticket_list.GetItemText(m_leftticket_list.GetTopIndex(),6);
		m_price=(float)(m_pRouteSet->SearchById(routeid)->m_price);
		m_route=m_pRouteSet->SearchById(routeid)->m_route;
		m_seattype=m_pSeatType->SearchSeatType(type)->m_type;
		UpdateData(FALSE);
	}	
}

void CSaleTicketView::RefreshData()
{
	CRouteSendInfoSet* m_pRSendInfoSet=new CRouteSendInfoSet(NULL);
	CDayPlanSet* m_pDayPlanSet=new CDayPlanSet(NULL);
	CBusset* m_pBusSet=new CBusset(NULL);
	CSeattypeSet* m_pSeatType=new CSeattypeSet(NULL);
	CBustypeSet* m_pBusTypeSet=new CBustypeSet(NULL);
	CTime curtime=CTime::GetCurrentTime();
	CTimeSpan fc_data_distance(0,0,0,0);
	CTimeSpan fc_data_d(1,0,0,0);
	int nYear,nMonth,nDay,nHour_start,nMintue_start,nSecond_start,nHour_stop,nMintue_stop,nSecond_stop;
	int have_year,have_month,have_day,have_hour,have_mintue,have_second;
	int id=0;
	nYear=curtime.GetYear();
	nMonth=curtime.GetMonth();
	nDay=curtime.GetDay();
	CString strValue;
	if (!m_pRSendInfoSet->IsOpen())
		m_pRSendInfoSet->Open();
	m_pRSendInfoSet->MoveFirst();
	if (!m_pBusSet->IsOpen())
		m_pBusSet->Open();
	if (!m_pDayPlanSet->IsOpen())
		m_pDayPlanSet->Open();
	if (m_pDayPlanSet->GetRecordCount()!=0)
	{
		CString fcdatetime;
		int year,month,day,hour,mintue,second,deletecount=0;
		m_pDayPlanSet->MoveFirst();
		while(!m_pDayPlanSet->IsEOF())
		{
			sscanf(m_pDayPlanSet->m_plan_date,"%d-%d-%d",&year,&month,&day);
			sscanf(m_pDayPlanSet->m_fc_time,"%d:%d:%d",&hour,&mintue,&second);
			CTime detime(year,month,day,hour,mintue,second);
			if (detime<curtime)
			{
				deletecount++;
				m_pDayPlanSet->Delete();
				m_pDayPlanSet->MoveNext();
			}
			else
				break;
		}
		if (deletecount>0)
		{
			m_pDayPlanSet->MoveFirst();
			while(!m_pDayPlanSet->IsEOF())
			{
				m_pDayPlanSet->Edit();
				m_pDayPlanSet->m_ID=m_pDayPlanSet->m_ID-deletecount;
				m_pDayPlanSet->Update();
				m_pDayPlanSet->MoveNext();
			}
			m_pDayPlanSet->Requery();
		}
		m_pDayPlanSet->MoveLast();
	}
	int totalDays=0;
	if (m_pDayPlanSet->GetRecordCount()!=0)
	{
		id=m_pDayPlanSet->m_ID;
		sscanf(m_pDayPlanSet->m_plan_date,"%d-%d-%d",&have_year,&have_month,&have_day);
		sscanf(m_pDayPlanSet->m_fc_time,"%d:%d:%d",&have_hour,&have_mintue,&have_second);
		CTime have_datetime(have_year,have_month,have_day,curtime.GetHour(),curtime.GetMinute(),curtime.GetSecond());
		totalDays=((CTimeSpan)(have_datetime-curtime)).GetDays()+1;
		fc_data_distance+=fc_data_d;
	}
	else
	{
		have_year=nYear;
		have_month=nMonth;
		have_day=nDay;		
	}
	if (!m_pSeatType->IsOpen())
	{
		m_pSeatType->Open();
	}
	if (!m_pBusTypeSet->IsOpen())
	{
		m_pBusTypeSet->Open();
	}
	for(int j=7-totalDays;j>0;j--)
	{		
		while (!m_pRSendInfoSet->IsEOF())
		{
			sscanf(m_pRSendInfoSet->m_start_time,"%d:%d:%d",&nHour_start,&nMintue_start,&nSecond_start);
			sscanf(m_pRSendInfoSet->m_stop_time,"%d:%d:%d",&nHour_stop,&nMintue_stop,&nSecond_stop);
			CTime curdate(have_year,have_month,have_day,nHour_start,nMintue_start,nSecond_start);
			//CTime starttime(0,0,0,nHour_start,nMintue_start,nSecond_start);
			CTime stoptime(have_year,have_month,have_day,nHour_stop,nMintue_stop,nSecond_stop);
			int totalminute=((CTimeSpan)(curdate-stoptime)).GetTotalMinutes();
			CTime priortime(have_year,have_month,have_day,nHour_start,nMintue_start,nSecond_start);
			curdate+=fc_data_distance;
			priortime+=fc_data_distance;
			CTimeSpan fc_distance(0,(int)m_pRSendInfoSet->m_send_frequency/60,(int)m_pRSendInfoSet->m_send_frequency%60,0);
			CString curdatestr=curdate.Format("%Y-%m-%d");
			CString fc_time;		
			if (totalminute<0)
				totalminute+=24*60;	
			if (!m_pDayPlanSet->IsOpen())
				m_pDayPlanSet->Open();
			for (int i=0;i*m_pRSendInfoSet->m_send_frequency<totalminute;i++)
			{			
				if(m_pDayPlanSet->CanUpdate())
				{
					fc_time=priortime.Format("%H:%M:%S");
					m_pDayPlanSet->AddNew();
					id++;
					m_pDayPlanSet->m_ID=id;
					m_pDayPlanSet->SetFieldNull(&(m_pDayPlanSet->m_route_id),FALSE);
					m_pDayPlanSet->m_plan_date=curdatestr;
					m_pDayPlanSet->m_route_id=m_pRSendInfoSet->m_route_id;
					m_pBusSet=m_pBusSet->SearchBusIndex(m_pRSendInfoSet->m_route_id);
					m_pDayPlanSet->m_bus_id=m_pBusSet->m_busID;
					m_pDayPlanSet->m_bus_number=m_pBusSet->m_busnumber;
					m_pDayPlanSet->m_bus_type=m_pBusSet->m_bustype;
					m_pDayPlanSet->m_seat_left=m_pBusTypeSet->SearchByBusType(m_pBusSet->m_bustype)->m_seat_total;
					m_pDayPlanSet->m_fc_time=fc_time;
					m_pDayPlanSet->m_run_state=0;
					m_pDayPlanSet->Update();					
				}
				priortime+=fc_distance;
			}
			m_pRSendInfoSet->MoveNext();			
		}
		fc_data_distance+=fc_data_d;
		m_pRSendInfoSet->MoveFirst();
	}	
	m_pDayPlanSet->m_strSort="ID";
	m_pDayPlanSet->MoveFirst();
	if (m_pDayPlanSet->m_ID!=1)
	{
		int id=m_pDayPlanSet->m_ID;
		CString str;
		str.Format("update dayplan set ID=ID-%d",id-1);
		m_pDayPlanSet->m_pDatabase->ExecuteSQL(str);
	}	
	m_pDayPlanSet->Requery();
}

void CSaleTicketView::showList(CRecordset* m_pSet,CListCtrl &m_list)
{
	m_list.DeleteAllItems();
	while(m_list.DeleteColumn(0));	
	try
	{
		if (!m_pSet->IsOpen())
		{
			m_pSet->Open();
		}					
		m_pSet->MoveFirst();
		int nFiledCount_route = m_pSet->GetODBCFieldCount();
		CODBCFieldInfo fieldinfo;
		for(int n=0;n<nFiledCount_route;n++)
		{
			m_pSet->GetODBCFieldInfo(n,fieldinfo);
			int nWidth=m_list.GetStringWidth(fieldinfo.m_strName);
			m_list.InsertColumn(n,fieldinfo.m_strName,LVCFMT_LEFT,nWidth+50);
		}
		CString strValue;
		m_pSet->MoveFirst();
		int nCount=0;
		m_list.DeleteAllItems();
		while(!m_pSet->IsEOF())
		{
			m_list.InsertItem(nCount,strValue);
			for (int j=0;j<nFiledCount_route;j++)
			{
				m_pSet->GetFieldValue(j,strValue);
				m_list.SetItemText(nCount,j,strValue);
			}
			m_pSet->MoveNext();
			nCount++;
		}
	}
	catch (CDBException* e)
	{
		e->ReportError();
		EndWaitCursor();
		return;
	}
}

void CSaleTicketView::OnBUTTONsearchlefticket() 
{
	// TODO: Add your control notification handler code here
	int year,month,day;
	CString m_fcdate="";
	UpdateData();
	CDayPlanSet* m_pdaySet=new CDayPlanSet(NULL);
	CRouteSet* m_routeSet=new CRouteSet(NULL);
	m_datetimectrl.GetTime(m_fcTime);
	int routeId=1;
	if (m_end=="")
	{
		MessageBox("请输入终点站!","警告",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
	if (!m_routeSet->IsOpen())
	{
		m_routeSet->Open();
	}
	if (!m_pdaySet->IsOpen())
	{
		m_pdaySet->Open();
	}
	CString strSQL;
	year=m_fcTime.GetYear();
	month=m_fcTime.GetMonth();
	day=m_fcTime.GetDay();
	m_fcdate=m_fcTime.Format("%Y-%m-%d");
	strSQL.Format("select * from route where [end]='%s'",m_end);
	CRouteSet rs(m_routeSet->m_pDatabase);
	rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	if (rs.GetRecordCount()!=0)
	{
		rs.MoveFirst();
		routeId=rs.m_route_id;		
	}
	CDayPlanSet rs1(m_pdaySet->m_pDatabase);
	strSQL.Format("select * from dayplan where route_id=%d "/*and plan_date='%s'*/,routeId/*,m_fcdate*/);
	rs1.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	showList(&rs1,m_leftticket_list);
}

void CSaleTicketView::OnClickLeftTicket(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CRouteSet* m_pRouteSet=new CRouteSet(NULL);
	CSeattypeSet* m_pSeatTypeSet=new CSeattypeSet(NULL);
	NM_LISTVIEW*   pNMListView  =  (NM_LISTVIEW*)pNMHDR;  
    CurrentItem=pNMListView->iItem;
	int routeid=(atoi)(m_leftticket_list.GetItemText(CurrentItem,2));
	/*
	if (!m_pRouteSet->IsOpen())
	{
	m_pRouteSet->Open();
}*/
	m_fctime=m_leftticket_list.GetItemText(CurrentItem,7);
	m_fcdate1=m_leftticket_list.GetItemText(CurrentItem,1);
	m_leftseat=m_leftticket_list.GetItemText(CurrentItem,6);
	m_price=(float)m_pRouteSet->SearchById(routeid)->m_price;
	m_route=m_pRouteSet->SearchById(routeid)->m_route;
	UpdateData(FALSE);
	//*pResult = 0;
}


void CSaleTicketView::OnBUTTONsale() 
{
	// TODO: Add your control notification handler code here
	CDayPlanSet* m_pdayplanSet=new CDayPlanSet(NULL);
	CRouteSet* m_pRouteSet=new CRouteSet(NULL);
	CSeattypeSet* m_pSeatTypeSet=new CSeattypeSet(NULL);
	CBusset* m_pBusSet=new CBusset(NULL);
	CBustypeSet* m_pBusTypeSet=new CBustypeSet(NULL);
	int curticketid=1;
	if (!m_pSet->IsOpen())
	{
		m_pSet->Open();
	}	
	if (m_pSet->GetRecordCount()!=0)
	{
		m_pSet->MoveLast();
		curticketid=m_pSet->m_ticket_id;
	}
	if (!m_pBusTypeSet->IsOpen())
	{
		m_pBusTypeSet->Open();
	}
	int routeid=(atoi)(m_leftticket_list.GetItemText(CurrentItem,2));
	int busid=atoi(m_leftticket_list.GetItemText(CurrentItem,3));
	int bustype=m_pBusSet->SearchBusIndex(busid)->m_bustype;
	m_pSet->AddNew();
	m_pSet->m_ticket_id=curticketid+1;
	m_pSet->m_ticket_type=1;
	m_pSet->m_date=m_fcdate1;
	m_pSet->m_time=m_fctime;
	m_pSet->m_route=routeid;
	m_pSet->m_start=m_pRouteSet->SearchById(routeid)->m_start;
	m_pSet->m_end=m_pRouteSet->SearchById(routeid)->m_end;
	m_pSet->m_price=m_pRouteSet->SearchById(routeid)->m_price;
	m_pSet->m_fprice=m_pRouteSet->SearchById(routeid)->m_price;	
	m_pSet->m_seat_type=m_pBusSet->SearchBusIndex(busid)->m_seattype;
	m_pSet->m_busID=m_pBusSet->SearchBusIndex(busid)->m_busID;
	m_pSet->m_busnumber=m_pBusSet->SearchBusIndex(busid)->m_busnumber;
	//m_pSet->m_discount=
	//m_pSet->m_conductor=
	m_pSet->m_saled=1;	
	if (!m_pdayplanSet->IsOpen())
	{
		m_pdayplanSet->Open();
	}
	int id=atoi(m_leftticket_list.GetItemText(CurrentItem,0));
	m_pdayplanSet=m_pdayplanSet->SearchById(id);
	m_pdayplanSet->Edit();
	m_pdayplanSet->m_seat_left-=1;
	m_pSet->m_seat=m_pBusTypeSet->SearchByBusType(bustype)->m_seat_total-m_pdayplanSet->m_seat_left;
	m_pSet->Update();
	m_pSet->Requery();
	m_pdayplanSet->Update();
	m_pdayplanSet->Requery();
	MessageBox("买票成功!");
}

⌨️ 快捷键说明

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