📄 backticketview.cpp
字号:
// BackTicketView.cpp : implementation file
//
#include "stdafx.h"
#include "StationManage.h"
#include "BackTicketView.h"
#include "SeattypeSet.h"
#include "busset.h"
#include "DayPlanSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBackTicketView
IMPLEMENT_DYNCREATE(CBackTicketView, CRecordView)
CBackTicketView::CBackTicketView()
: CRecordView(CBackTicketView::IDD)
{
//{{AFX_DATA_INIT(CBackTicketView)
m_pSet = NULL;
m_end = _T("");
m_fctime = _T("");
m_keyword = _T("");
m_price = 0.0f;
m_seatnum = 0;
m_seattype = _T("");
m_ticket_id = 0;
//}}AFX_DATA_INIT
}
CBackTicketView::~CBackTicketView()
{
if (!((CStationManageApp*)AfxGetApp())->m_BackTicketViewscontrol)
{
((CStationManageApp*)AfxGetApp())->m_BackTicketViews=0;
}
if (m_pSet)
delete m_pSet;
}
void CBackTicketView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBackTicketView)
DDX_Control(pDX, IDC_TICKET_LIST, m_ticket_list);
DDX_Control(pDX, IDC_COMBO_TYPE, m_search_type);
DDX_Text(pDX, IDC_END, m_end);
DDX_Text(pDX, IDC_FCTIME, m_fctime);
DDX_Text(pDX, IDC_KEYWORD, m_keyword);
DDX_Text(pDX, IDC_PRICE, m_price);
DDX_Text(pDX, IDC_SEATNUM, m_seatnum);
DDX_Text(pDX, IDC_SEATTYPE, m_seattype);
DDX_Text(pDX, IDC_TICKETID, m_ticket_id);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBackTicketView, CRecordView)
//{{AFX_MSG_MAP(CBackTicketView)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
ON_BN_CLICKED(IDC_BUTTON_BACK, OnButtonBack)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBackTicketView diagnostics
#ifdef _DEBUG
void CBackTicketView::AssertValid() const
{
CRecordView::AssertValid();
}
void CBackTicketView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBackTicketView message handlers
CRecordset* CBackTicketView::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CTicketSet(NULL);
m_pSet->Open();
return m_pSet;
}
CTicketSet* CBackTicketView::GetRecordset()
{
CTicketSet* pData = (CTicketSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CTicketSet)));
return pData;
}
void CBackTicketView::OnInitialUpdate()
{
CSeattypeSet* m_pSeatType=new CSeattypeSet(NULL);
CBusset* m_pBusSet=new CBusset(NULL);
// RefreshData();
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
GetDocument()->SetTitle("退票");
GetParent()->SetWindowText("退票");
EndWaitCursor();
RECT rect;
m_ticket_list.GetWindowRect(&rect);
int listwidth=rect.right-rect.left;
DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
m_ticket_list.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
if (m_pSet->GetRecordCount()!=0)
{
showList(m_pSet,m_ticket_list);
int routeid=(atoi)(m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),2));
int busid=atoi(m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),3));
int type=m_pBusSet->SearchBusIndex(busid)->m_seattype;
m_ticket_id=atoi(m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),0));
CString date=m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),1);
CString time=m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),2);
m_fctime=date+" "+time;
m_end=m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),5);
m_seatnum=atoi(m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),8));
m_price=atof(m_ticket_list.GetItemText(m_ticket_list.GetTopIndex(),6));
m_seattype=m_pSeatType->SearchSeatType(type)->m_type;
UpdateData(FALSE);
}
else
{
MessageBox("没有售票记录!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
}
void CBackTicketView::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 CBackTicketView::OnButtonSearch()
{
// TODO: Add your control notification handler code here
UpdateData();
if (m_search_type.GetDroppedState())
{
MessageBox("请选择查找方式!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
if (m_keyword=="")
{
MessageBox("请输入关键字!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
CString str;
m_search_type.GetWindowText(str);
CString strSQL;
if (str=="票号")
{
strSQL.Format("select * from ticket where ticket_id=%d",GetDlgItemInt(IDC_KEYWORD));
}
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (rs.GetRecordCount()!=0)
{
showList(&rs,m_ticket_list);
}
else
{
MessageBox("没有该票号的记录!","警告",MB_OK|MB_ICONEXCLAMATION);
return;
}
rs.Close();
}
void CBackTicketView::OnButtonBack()
{
// TODO: Add your control notification handler code here
CDayPlanSet *m_pDayplanSet=new CDayPlanSet(NULL);
UpdateData();
CString strSQL;
strSQL.Format("select * from ticket where ticket_id=%d",m_ticket_id);
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if (rs.GetRecordCount()!=0)
{
CString date=rs.m_date;
CString time=rs.m_time;
strSQL.Format("select * from dayplan where plan_date='%s' and fc_time='%s'",date,time);
m_pDayplanSet->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
m_pDayplanSet->Edit();
m_pDayplanSet->m_seat_left++;
m_pDayplanSet->Update();
m_pDayplanSet->Requery();
m_pDayplanSet->Close();
rs.Delete();
MessageBox("成功退票!");
}
rs.Close();
showList(m_pSet,m_ticket_list);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -