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

📄 trasquerydlg.cpp

📁 太原是公交查询系统(未实现中转)实现了数据库的链接
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TrasQueryDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TrasQuery.h"
#include "TrasQueryDlg.h"
#include "Map1.h"
#include "Map2.h"
#include "Map3.h"
#include "Map4.h"
#include "Map5.h"
#include "Map6.h"
#include "Map7.h"
#include "Map9.h"
#include "Map10.h"
#include "adodc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
private:
	CFont  m_font;
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
	m_font.CreatePointFont(150,"华文楷体");
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrasQueryDlg dialog
CTrasQueryDlg::CTrasQueryDlg(CWnd* pParent /*=NULL*/)

	: CDialog(CTrasQueryDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTrasQueryDlg)
	m_lineStr = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	//m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);   //注释已有图标
	m_brush.CreateSolidBrush(RGB(252,172,101));
	m_font.CreatePointFont(200,"华文楷体");
	m_LinQue=FALSE;
	m_StaQue=FALSE;
	m_Edit1=FALSE;
	m_Combo1=FALSE;
	m_Edit2=FALSE;
	m_Combo2=FALSE;
}

void CTrasQueryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTrasQueryDlg)
	DDX_Control(pDX, IDC_ADODC_LINE, m_ado);
	DDX_Text(pDX, IDC_LINE_INPUT, m_lineStr);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTrasQueryDlg, CDialog)
	//{{AFX_MSG_MAP(CTrasQueryDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_LINE_QUERY, OnLineQuery)
	ON_BN_CLICKED(IDR_STATION_QUERY, OnStationQuery)
	ON_COMMAND(IDM_IMPORT_MAP, OnImportMap)
	ON_WM_CTLCOLOR()
	ON_EN_CHANGE(IDC_LINE_INPUT, OnChangeLineInput)
	ON_EN_CHANGE(IDC_STATION_INPUT, OnChangeStationInput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTrasQueryDlg message handlers

BOOL CTrasQueryDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}	

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
//	SetIcon(m_hIcon, TRUE);			// Set big icon
//	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here	
	((CComboBox *)GetDlgItem(IDC_COMBO1))->AddString("请选择");
	((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString("请选择");
	Initconn();	
	   
	    _bstr_t StaSource,linSource;

	    StaSource="select * from 车站表";    	
		linSource="select * from 路线名";
		
		Execute(linSource);
		
		while (!m_pRec->traEOF)
		{  
		   ((CComboBox *)GetDlgItem(IDC_COMBO1))->AddString((_bstr_t)m_pRec->GetCollect("路线号"));	   
		   m_pRec->MoveNext();			
		}
		
		Execute(StaSource);				
		
		while (!m_pRec->traEOF)
		{  
		  ((CComboBox *)GetDlgItem(IDC_COMBO2))->AddString((_bstr_t)m_pRec->GetCollect("车站名"));
		   
		   m_pRec->MoveNext();			
		}
		
		ExitConn();	
	
	((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
	((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTrasQueryDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTrasQueryDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
	//	dc.DrawIcon(x, y, m_hIcon);     //注释原有图标
	}
	else
	{
		CDialog::OnPaint();
	}
    CString str;	
	((CComboBox *)GetDlgItem(IDC_COMBO1))->GetWindowText(str);
	UpdateData(false);
	m_lineStr=str;
}




// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
void CTrasQueryDlg::Initconn()
{
	try
	{
	  m_pCon.CreateInstance(__uuidof(Connection));
	  //m_pRec.CreateInstance(__uuidof(Recordset));

	  m_pCon->ConnectionString="Provider=SQLOLEDB.1;Password=111000;Persist Security Info=True;User ID=sa;Initial Catalog=TrasQuery;Data Source=ADMIN";
	  m_pCon->Open("","","",adConnectUnspecified);
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
	}	
}
bool CTrasQueryDlg::Execute(_bstr_t strSql)
{
	//m_pRec=m_pCon->Execute(strSql, NULL,adCmdText);
		try
	{
		// 是否已经连接数据库
		if(m_pCon == NULL)
			Initconn();
		// Connection对象的Execute方法:(_bstr_t CommandText, 
		// VARIANT * RecordsAffected, long Options ) 
		// 其中CommandText是命令字串,通常是SQL命令。
		// 参数RecordsAffected是操作完成后所影响的行数, 
		// 参数Options表示CommandText的类型:adCmdText-文本命令;adCmdTable-表名
		// adCmdProc-存储过程;adCmdUnknown-未知
		m_pRec=m_pCon->Execute(strSql,NULL,adCmdText);
		return true;
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
		return false;
	}
}

void CTrasQueryDlg::ExitConn()
{
  	 m_pRec->Close();
     m_pCon->Close();
     m_pRec.Release();
	 m_pCon.Release();

}
bool CTrasQueryDlg::OnLineQuery() 
{
	// TODO: Add your control notification handler code here
    m_LinQue=TRUE;
	m_Combo1=TRUE;
    int count=0;	

	count=((CListBox *)GetDlgItem(IDC_LIST1))->GetSelCount();
    
	if(count!=0)
		((CListBox *)GetDlgItem(IDC_LIST1))->ResetContent();

    GetDlgItem(IDC_LINE_STATION)->SetWindowText("该路车所经站点:");
	if(m_Edit1)
	{
		GetDlgItem(IDC_LINE_INPUT)->GetWindowText(m_lineStr); 
		((CComboBox *)GetDlgItem(IDC_COMBO1))->SelectString(-1,m_lineStr);
		m_Combo1=FALSE;
	}
	else if(m_Combo1)
	{
		CString str;	
		((CComboBox *)GetDlgItem(IDC_COMBO1))->GetWindowText(str);
		UpdateData(false);
		m_lineStr=str;
		m_Edit1=FALSE;
		Invalidate();
		
	}
	
	
		
	_bstr_t source1,source2,source3,lineNo,lineBool;
	
	if(m_lineStr!="")
	{		
		Initconn();	
		source1="select * from 车站表,行车表1 where 行车表1.路线号='"+m_lineStr;
		source1+="'and 车站表.车站号=行车表1.车站号";
		source2="select * from 车站表,行车表2 where 行车表2.路线号='"+m_lineStr;

⌨️ 快捷键说明

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