📄 shoupiaotongji.cpp
字号:
// ShouPiaoTongJi.cpp : implementation file
//
#include "stdafx.h"
#include "StationManage.h"
#include "ShouPiaoTongJi.h"
#include "DayPlanSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShouPiaoTongJi
IMPLEMENT_DYNCREATE(CShouPiaoTongJi, CRecordView)
CShouPiaoTongJi::CShouPiaoTongJi()
: CRecordView(CShouPiaoTongJi::IDD)
{
//{{AFX_DATA_INIT(CShouPiaoTongJi)
m_pSet = NULL;
m_keywords = _T("");
//}}AFX_DATA_INIT
}
CShouPiaoTongJi::~CShouPiaoTongJi()
{
if (!((CStationManageApp*)AfxGetApp())->m_ShouPiaoTongJiViewscontrol)
{
((CStationManageApp*)AfxGetApp())->m_ShouPiaoTongJiViews=0;
}
if (m_pSet)
delete m_pSet;
}
void CShouPiaoTongJi::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShouPiaoTongJi)
DDX_Control(pDX, IDC_RESULTLIST, m_resultlist);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_COMBO, m_researchtype);
DDX_Text(pDX, IDC_KEYWORDS, m_keywords);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShouPiaoTongJi, CRecordView)
//{{AFX_MSG_MAP(CShouPiaoTongJi)
ON_BN_CLICKED(IDC_RESEARCH, OnResearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShouPiaoTongJi diagnostics
#ifdef _DEBUG
void CShouPiaoTongJi::AssertValid() const
{
CRecordView::AssertValid();
}
void CShouPiaoTongJi::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CShouPiaoTongJi message handlers
CRecordset* CShouPiaoTongJi::OnGetRecordset()
{
if (m_pSet != NULL)
return m_pSet;
m_pSet = new CTicketSet(NULL);
m_pSet->Open();
return m_pSet;
}
CTicketSet* CShouPiaoTongJi::GetRecordset()
{
CTicketSet* pData = (CTicketSet*) OnGetRecordset();
ASSERT(pData == NULL || pData->IsKindOf(RUNTIME_CLASS(CTicketSet)));
return pData;
}
void CShouPiaoTongJi::OnInitialUpdate()
{
CDayPlanSet* m_pDayPlanSet=new CDayPlanSet(NULL);
BeginWaitCursor();
GetRecordset();
CRecordView::OnInitialUpdate();
GetDocument()->SetTitle("售票统计");
GetParent()->SetWindowText("售票统计");
EndWaitCursor();
RECT rect;
m_list.GetWindowRect(&rect);
int listwidth=rect.right-rect.left;
DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
m_list.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
showList(m_pDayPlanSet,m_list);
}
void CShouPiaoTongJi::OnResearch()
{
// TODO: Add your control notification handler code here
UpdateData();
if (m_keywords=="")
{
MessageBox("关键字不能为空!","警告",MB_OK||MB_ICONEXCLAMATION);
return;
}
CString str;
m_researchtype.GetWindowText(str);
if(str=="票号")
{
int id=atoi(m_keywords);
CString StrSql;
StrSql.Format("select * from ticket where ticket_id='%d'",id);
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
if (rs.GetRecordCount()!=0)
{
showList(&rs,m_resultlist);
}
rs.Close();
}
else
{
if (str=="车次")
{
int id=atoi(m_keywords);
CString StrSql;
StrSql.Format("select * from ticket where busID='%d'",id);
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
if (rs.GetRecordCount()!=0)
{
showList(&rs,m_resultlist);
}
rs.Close();
}
else
{
CString StrSql;
StrSql.Format("select * from ticket where date='%s'",m_keywords);
CTicketSet rs(m_pSet->m_pDatabase);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
if (rs.GetRecordCount()!=0)
{
showList(&rs,m_resultlist);
}
rs.Close();
}
}
}
void CShouPiaoTongJi::showList(CRecordset *m_pSet, CListCtrl &m_list)
{
if (m_list.GetColumn(0,NULL))
{
while(m_list.DeleteColumn(0));
}
try
{
if (!m_pSet->IsOpen())
{
m_pSet->Open();
}
m_list.DeleteAllItems();
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -