chadep.cpp
来自「员工管理系统,基本的数据库操作,数据库类的设计,基本的查询等」· C++ 代码 · 共 112 行
CPP
112 行
// Chadep.cpp : implementation file
//
#include "stdafx.h"
#include "数据库.h"
#include "Chadep.h"
#include "depemp.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChadep dialog
CChadep::CChadep(CWnd* pParent /*=NULL*/)
: CDialog(CChadep::IDD, pParent)
{
//{{AFX_DATA_INIT(CChadep)
m_namebumen = _T("");
//}}AFX_DATA_INIT
}
void CChadep::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChadep)
DDX_Text(pDX, IDC_EDIT1, m_namebumen);
DDX_Control(pDX, IDC_ADODC1, m_adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChadep, CDialog)
//{{AFX_MSG_MAP(CChadep)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChadep message handlers
void CChadep::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
m_namebumen.TrimLeft();
m_namebumen.TrimRight();
if(m_namebumen=="")
{
MessageBox("请输入部门名称");
return;
}
_variant_t var;
_RecordsetPtr pRecord;
ADOConn Adoconn;
_bstr_t bSQL;
CString sql;
sql.Format("select * from 部门表 where 部门名称='%s'",m_namebumen);
bSQL=(_bstr_t)sql;
pRecord=Adoconn.GetRecordSet(bSQL);
///////
if(pRecord->adoEOF)
{
MessageBox("sorry! 没有这个部门");
return;
}
/////////////
else
{
CString str1,str2;
int int1;
pRecord->get_Collect(variant_t("部门号"),(_variant_t*)(&var));
if(var.vt!=VT_NULL)
{
depid=var.iVal;
}
pRecord->get_Collect(_variant_t("部门名称"),(_variant_t*)(&var));
if(var.vt!=VT_NULL)
{
str2=(LPCSTR)_bstr_t(var);
}
str1.Format(" %d %s",depid,str2);
MessageBox("有这个部门"+str1);
CString cSource;
cSource.Format( "SELECT 姓名, 地址,部门号 from 员工表 where 部门号=%d", depid);
//设置数据源
m_datagrid.SetCaption(str2);
m_adodc.SetRecordSource(cSource);
m_adodc.Refresh();
//dlg.adodcc.SetRecordSource();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?