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

📄 routesearchview.cpp

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

#include "stdafx.h"
#include "StationManage.h"
#include "RouteSearchView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CRouteSearchView

IMPLEMENT_DYNCREATE(CRouteSearchView, CRecordView)

CRouteSearchView::CRouteSearchView()
	: CRecordView(CRouteSearchView::IDD)
{
	//{{AFX_DATA_INIT(CRouteSearchView)
	m_pSet = NULL;
	m_keyword = _T("");
	//}}AFX_DATA_INIT
}

CRouteSearchView::~CRouteSearchView()
{
	if (((CStationManageApp*)AfxGetApp())->m_RouteSearchViews==1)
	{
		((CStationManageApp*)AfxGetApp())->m_RouteSearchViews=0;
	}
	if (m_pSet)
		delete m_pSet;
}

void CRouteSearchView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRouteSearchView)
	DDX_Control(pDX, IDC_LIST1, m_rslist);
	DDX_Control(pDX, IDC_LIST_ROUTE, m_list_route);
	DDX_Control(pDX, IDC_COMBO_SearchType, m_searchtype);
	DDX_Text(pDX, IDC_EDIT1, m_keyword);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRouteSearchView, CRecordView)
	//{{AFX_MSG_MAP(CRouteSearchView)
	ON_BN_CLICKED(IDC_BUTTON1, OnSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRouteSearchView diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CRouteSearchView message handlers

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

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

	return m_pSet;
}

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

void CRouteSearchView::OnInitialUpdate()
{
	BeginWaitCursor();
	GetRecordset();
	CRecordView::OnInitialUpdate();
	GetDocument()->SetTitle("路线查询");
	GetParent()->SetWindowText("路线查询");
	EndWaitCursor();
	RECT rect;
	m_list_route.GetWindowRect(&rect);
	int listwidth=rect.right-rect.left;
	DWORD dwExtendedStyle=LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE;
	m_list_route.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
	showList(m_pSet,m_list_route);
	m_rslist.SetExtendedStyle(dwExtendedStyle|LVS_EX_FULLROWSELECT);
}

void CRouteSearchView::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 CRouteSearchView::OnSearch() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if (m_keyword=="")
	{ 
		MessageBox("关键字不能为空!","警告",MB_OK||MB_ICONEXCLAMATION);
		return;
	}
	CString str;
	m_searchtype.GetWindowText(str);
	if(str=="路线ID")
	{
		int	id=atoi(m_keyword);		
		CString StrSql;
		StrSql.Format("select * from route where route_id=%d",id);
		CRouteSet rs(m_pSet->m_pDatabase);
		rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
		if (rs.GetRecordCount()!=0)
		{
			showList(&rs,m_rslist);
		}
		else
		{
			MessageBox("没有您要找的路线ID信息!");
		}
		rs.Close();
	}
	else
	{
		CString StrSql;
		StrSql.Format("select * from route where [end]='%s'",m_keyword);
		CRouteSet rs(m_pSet->m_pDatabase);
		rs.Open(AFX_DB_USE_DEFAULT_TYPE,StrSql);
		if (rs.GetRecordCount()!=0)
		{
			showList(&rs,m_rslist);
		}
		else
		{
			MessageBox("没有您要找的站点信息!");
		}
		rs.Close();
	}
}

⌨️ 快捷键说明

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