📄 salesearchview.cpp
字号:
// SaleSearchView.cpp : implementation file
//
#include "stdafx.h"
#include "StationManage.h"
#include "SaleSearchView.h"
#include "SeattypeSet.h"
#include "RouteSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSaleSearchView
IMPLEMENT_DYNCREATE(CSaleSearchView, CRecordView)
CSaleSearchView::CSaleSearchView()
: CRecordView(CSaleSearchView::IDD)
{
//{{AFX_DATA_INIT(CSaleSearchView)
m_pSet = NULL;
m_start_time = _T("");
m_end_time = _T("");
m_fctime = _T("");
m_price = 0.0f;
m_route = _T("");
m_seatnum = 0;
m_seattype = _T("");
m_ticketid = 0;
//}}AFX_DATA_INIT
}
CSaleSearchView::~CSaleSearchView()
{
if (((CStationManageApp*)AfxGetApp())->m_SaleSearchViews==1)
{
((CStationManageApp*)AfxGetApp())->m_SaleSearchViews=0;
}
if (m_pSet)
delete m_pSet;
}
void CSaleSearchView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSaleSearchView)
DDX_Control(pDX, IDC_LIST_SALE, m_list_sale);
DDX_Text(pDX, IDC_EDIT1, m_start_time);
DDX_Text(pDX, IDC_EDIT3, m_end_time);
DDX_Text(pDX, IDC_FC_TIME, m_fctime);
DDX_Text(pDX, IDC_PRICE, m_price);
DDX_Text(pDX, IDC_ROUTE, m_route);
DDX_Text(pDX, IDC_SEAT_NUM, m_seatnum);
DDX_Text(pDX, IDC_SEAT_TYPE, m_seattype);
DDX_Text(pDX, IDC_TICKET_ID, m_ticketid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSaleSearchView, CRecordView)
//{{AFX_MSG_MAP(CSaleSearchView)
ON_NOTIFY(NM_CLICK, IDC_LIST_SALE, OnClickListSale)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSaleSearchView diagnostics
#ifdef _DEBUG
void CSaleSearchView::AssertValid() const
{
CRecordView::AssertValid();
}
void CSaleSearchView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSaleSearchView message handlers
CRecordset* CSaleSearchView::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CTicketSet(NULL);
m_pSet->Open();
return m_pSet;
}
CTicketSet* CSaleSearchView::GetRecordset()
{
CTicketSet* pData = (CTicketSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CTicketSet)));
return pData;
}
void CSaleSearchView::OnInitialUpdate()
{
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
GetDocument()->SetTitle("售票查询");
GetParent()->SetWindowText("售票查询");
EndWaitCursor();
RECT rect;
m_list_sale.GetWindowRect(&rect);
int listwidth=rect.right-rect.left;
DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
m_list_sale.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
showList(m_pSet,m_list_sale);
if (m_pSet->GetRecordCount()!=0)
{
m_ticketid=atoi(m_list_sale.GetItemText(m_list_sale.GetTopIndex(),0));
m_fctime=m_list_sale.GetItemText(m_list_sale.GetTopIndex(),2);
m_price=atof(m_list_sale.GetItemText(m_list_sale.GetTopIndex(),6));
int routeid=atoi(m_list_sale.GetItemText(m_list_sale.GetTopIndex(),3));
CRouteSet routeset(NULL);
m_route=routeset.SearchById(routeid)->m_route;
m_seatnum=atoi(m_list_sale.GetItemText(m_list_sale.GetTopIndex(),8));
int type=atoi(m_list_sale.GetItemText(m_list_sale.GetTopIndex(),9));
routeset.Close();
CSeattypeSet seattype(NULL);
m_seattype=seattype.SearchSeatType(type)->m_type;
seattype.Close();
UpdateData(FALSE);
}
}
void CSaleSearchView::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 CSaleSearchView::OnClickListSale(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
CurrentItem=pNMListView->iItem;
m_ticketid=atoi(m_list_sale.GetItemText(CurrentItem,0));
m_fctime=m_list_sale.GetItemText(CurrentItem,2);
m_price=atof(m_list_sale.GetItemText(CurrentItem,6));
int routeid=atoi(m_list_sale.GetItemText(CurrentItem,3));
CRouteSet routeset(NULL);
m_route=routeset.SearchById(routeid)->m_route;
m_seatnum=atoi(m_list_sale.GetItemText(CurrentItem,8));
routeset.Close();
int type=atoi(m_list_sale.GetItemText(CurrentItem,9));
CSeattypeSet seattype(NULL);
m_seattype=seattype.SearchSeatType(type)->m_type;
seattype.Close();
UpdateData(FALSE);
*pResult = 0;
}
void CSaleSearchView::OnButtonSearch()
{
// TODO: Add your control notification handler code here
UpdateData();
int id1,id2;
if (m_start_time==""||m_end_time=="")
{
MessageBox("时间不能为空!","警告",MB_OK||MB_ICONEXCLAMATION);
return;
}
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
m_pSet->m_strSort="ticket_id";
m_pSet->Requery();
CString StrSql;
StrSql.Format("select * from ticket where date='%s'",m_start_time);
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
if (rs.GetRecordCount()!=0)
{
rs.MoveFirst();
id1=rs.m_ticket_id;
}
StrSql.Format("select * from ticket where date='%s'",m_end_time);
CTicketSet rs1(m_pSet->m_pDatabase);
rs1.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
if (rs1.GetRecordCount()!=0)
{
rs1.MoveLast();
id2=rs1.m_ticket_id;
}
m_pSet->Close();
StrSql.Format("select * from ticket where ticket_id>=%d and ticket_id<=%d",id1,id2);
m_pSet->Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
showList(m_pSet,m_list_sale);
rs.Close();
rs1.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -