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

📄 05050707dlg.cpp

📁 数据库程序设计ADO完成,简简单单学会MFC+ADO,VC++6V. 0
💻 CPP
字号:
// 05050707Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "05050707.h"
#include "05050707Dlg.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
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy05050707Dlg dialog

CMy05050707Dlg::CMy05050707Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy05050707Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy05050707Dlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy05050707Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy05050707Dlg)
	DDX_Control(pDX, IDC_CHECI, m_checi);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_LIST2, m_roadlist);
	DDX_Control(pDX, IDC_ROAD, m_road);
	DDX_Control(pDX, IDC_STATICend, m_staticend);
	DDX_Control(pDX, IDC_STATICstart, m_staticstart);
	DDX_Control(pDX, IDC_START, m_start);
	DDX_Control(pDX, IDC_END, m_end);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy05050707Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy05050707Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOK, OnQUERTY)
	ON_BN_CLICKED(IDC_RADIOROAD, OnRadioroad)
	ON_BN_CLICKED(IDC_RADIOPOINT, OnRadiopoint)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy05050707Dlg message handlers

BOOL CMy05050707Dlg::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	
	m_roadlist.InsertColumn(0,"车次");
	m_roadlist.InsertColumn(1,"经过站点");
	m_roadlist.SetColumnWidth(0,60); 
	m_roadlist.SetColumnWidth(1,1500); 
	m_roadlist.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
	//初始化结束
	m_roadlist.DeleteAllItems();
	
	m_list.InsertColumn(0,"车次");
	m_list.InsertColumn(1,"起始站点到目的地途经站点");
	m_list.SetColumnWidth(0,60); 
	m_list.SetColumnWidth(1,1500);
	m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP);
	//初始化结束
	m_list.DeleteAllItems();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy05050707Dlg::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 CMy05050707Dlg::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
	{
		CPaintDC dc(this);
        CRect rect;
        GetClientRect(&rect);//得到窗体的大小
        CDC dcMem; 
        dcMem.CreateCompatibleDC(&dc); 
        CBitmap bmpBackground;
        bmpBackground.LoadBitmap(IDB_BITMAP1);//加载背景图片
        BITMAP bitMap;
        bmpBackground.GetBitmap(&bitMap);
        CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
        dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);//画窗体
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy05050707Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMy05050707Dlg::OnQUERTY() 
{
	// TODO: Add your control notification handler code here


	m_roadlist.DeleteAllItems();
	m_list.DeleteAllItems();
	
	int a=IsDlgButtonChecked(IDC_RADIOROAD);
	int b=IsDlgButtonChecked(IDC_RADIOPOINT);
	if (a==0&&b==0)
	{
		AfxMessageBox("请选择查询方式");
	}
	else
	{
	
		
		if (a==1)
		{
			int resulta=0;
			CString road;
			GetDlgItemText(IDC_ROAD,road);
			CoInitialize(NULL);
			_ConnectionPtr pconnect(__uuidof(Connection));
			_RecordsetPtr record(__uuidof(Recordset));
			_CommandPtr comd(__uuidof(Command));
			pconnect->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=BUS";
			pconnect->Open("","","",NULL);
			comd->put_ActiveConnection(_variant_t((IDispatch *)pconnect));
			//标准SQL语句
			/*"select * from BUS WHERE NUMBER='road'"*/
			CString cmda="";
			cmda="select * from BUS where NUMBER='";
			cmda+=road;cmda+="'";
			
			comd->CommandText=_bstr_t(cmda);//得到SQL语句
			record=comd->Execute(NULL,NULL,adCmdText);
			if(!record->end)
			{
				resulta=1;
				m_roadlist.InsertItem(0,road);
				m_roadlist.SetItemText(0,1,(_bstr_t)record->GetCollect("STATION"));
			}
			if (resulta==1)
				AfxMessageBox("查询结束");
			else
				AfxMessageBox("查询结束,结果为空,请确认车次是否正确");
			
			record->Close();
			pconnect->Close();
			comd.Release();
			record.Release();
			pconnect.Release();
			CoUninitialize();
		}
		if (b==1)
		{
			int resultb=0;
			CString roadstart;	CString roadend;
			GetDlgItemText(IDC_START,roadstart);
			GetDlgItemText(IDC_END,roadend);
			CoInitialize(NULL);
			_ConnectionPtr pconnect(__uuidof(Connection));
			_RecordsetPtr record(__uuidof(Recordset));
			_CommandPtr comd(__uuidof(Command));
			pconnect->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=BUS";
			pconnect->Open("","","",NULL);
			comd->put_ActiveConnection(_variant_t((IDispatch *)pconnect));
			//标准SQL语句
			/*select number from BUS
			where  STATION LIKE '%公交总公司%'and 
                 number in (select number from BUS WHERE STATION LIKE '%南京车站%')*/
			CString cmdb="";
			cmdb="select * from BUS WHERE STATION LIKE ";
			cmdb+="'%";cmdb+=roadstart;cmdb+="%'";cmdb+="and number in (select number from BUS WHERE STATION LIKE ";
			cmdb+="'%";cmdb+=roadend;cmdb+="%')";
			comd->CommandText=_bstr_t(cmdb);//"select * from BUS WHERE STATION LIKE '% %'";
			
			record=comd->Execute(NULL,NULL,adCmdText);
			while(!record->end)
			{
				resultb=1;
				m_list.InsertItem(0,(_bstr_t)record->GetCollect("NUMBER"));
				m_list.SetItemText(0,1,(_bstr_t)record->GetCollect("STATION"));
				record->MoveNext();
			}
			if (resultb==1)
				AfxMessageBox("查询结束");
			else
				AfxMessageBox("查询结束,结果为空,请确认站点是否正确");
			record->Close();
			pconnect->Close();
			comd.Release();
			record.Release();
			pconnect.Release();
			CoUninitialize();
			
		}
	}
}

void CMy05050707Dlg::OnRadioroad() 
{
	// TODO: Add your control notification handler code here
	m_start.EnableWindow(false);
	m_end.EnableWindow(false);
	m_staticend.EnableWindow(false);
	m_staticstart.EnableWindow(false);
	m_list.EnableWindow(false);
	m_roadlist.EnableWindow(true);
	m_road.EnableWindow(true);
	m_checi.EnableWindow(true);
}

void CMy05050707Dlg::OnRadiopoint() 
{
	// TODO: Add your control notification handler code here
	m_road.EnableWindow(false);
	m_start.EnableWindow(true);
	m_end.EnableWindow(true);
	m_roadlist.EnableWindow(false);
	m_staticend.EnableWindow(true);
	m_staticstart.EnableWindow(true);
	m_list.EnableWindow(true);
	m_checi.EnableWindow(false);
	
}

⌨️ 快捷键说明

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