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

📄 regionsempviewdlg.cpp

📁 A HR database application.
💻 CPP
字号:
// RegionsEmpViewDlg.cpp : implementation file
//

#include "stdafx.h"
#include "HRDB.h"
#include "RegionsEmpViewDlg.h"

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

//引入全局变量userName,passWord
extern CString   userName;
extern CString   passWord;

/////////////////////////////////////////////////////////////////////////////
// CRegionsEmpViewDlg dialog


CRegionsEmpViewDlg::CRegionsEmpViewDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRegionsEmpViewDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRegionsEmpViewDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CRegionsEmpViewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRegionsEmpViewDlg)
	DDX_Control(pDX, IDC_ADODC1, m_Adodc);
	DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRegionsEmpViewDlg, CDialog)
	//{{AFX_MSG_MAP(CRegionsEmpViewDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRegionsEmpViewDlg message handlers

BOOL CRegionsEmpViewDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	try
	{
		//初始化ADODC数据源
		m_Adodc.SetConnectionString("Provider=MSDASQL.1; Password=" + passWord +
			"; Persist Security Info=True; User ID=" + userName + "; Data Source=hr; Initial Catalog=hr");
		m_Adodc.SetRecordSource("SELECT \
									e.employee_id, \
									e.first_name, \
									e.last_name, \
									e.email, \
									e.phone_number, \
									e.hire_date, \
									e.job_id, \
									e.salary, \
									e.commission_pct, \
									e.manager_id, \
									d.department_name, \
									l.location_id, \
									c.country_name, \
									r.region_name \
								  FROM \
									employees e, \
									departments d, \
									locations l, \
									countries c, \
									regions r \
								  WHERE e.department_id = d.department_id \
							        AND d.location_id = l.location_id \
                                    AND l.country_id = c.country_id \
                                    AND c.region_id = r.region_id \
                                  ORDER BY r.region_id");
		m_Adodc.Refresh(); //important

		//将DATAGRID绑定到ADODC控件
		LPUNKNOWN pcursor = m_Adodc.GetDSCCursor();
		m_DataGrid.SetRefDataSource(pcursor);
	}
	catch (...) //捕获任何类型的异常
	{
		AfxMessageBox("无权查询!");
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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