首页上一页 1 下一页尾页 1 条记录 1/1页
关于数据库系统开发完全手册资产设备管理系统
发表在C语言图书答疑
2010-09-05
是否精华
是
否
版块置顶:
是
否
在开发资产设备管理系统资产类别时,怎样响应DataGrid控件的单击事件,并且把表格中的数据显示在编辑框中。可是我照你们书上的例子做时,当我单击DataGrid控件时,会出现内存不能读的问题,我数据库也附加了,也初始化了COM环境,也导入了MSADO15.DLL.不知道是什么原因,可当我初始化COM环境后,单击DataGrid控件时,会出现运行时的错误,当我把DataGrid控件的单击事件代码注释起来后,再单击DataGrid控件时,没有反应.
这个问题困扰了我好久了,请你们帮我分析一下到底是什么问题,在此我先谢了.期待你们的好消息.
// Equipment.h : main header file for the EQUIPMENT application
//
#if !defined(AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_)
#define AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
#include "DataManage.h"
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp:
// See Equipment.cpp for the implementation of this class
//
class CEquipmentApp : public CWinApp
{
public:
CDataManage* datamanage;
CEquipmentApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEquipmentApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CEquipmentApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_)
// Equipment.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Equipment.h"
#include "EquipmentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp
BEGIN_MESSAGE_MAP(CEquipmentApp, CWinApp)
//{{AFX_MSG_MAP(CEquipmentApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp construction
CEquipmentApp::CEquipmentApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CEquipmentApp object
CEquipmentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp initialization
BOOL CEquipmentApp::InitInstance()
{
AfxEnableControlContainer();
::CoInitialize(NULL);
AfxOleInit();
datamanage = new CDataManage;
datamanage->ConnectDatabase("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=EquipmentManage;Data Source=.");
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CEquipmentDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CEquipmentApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
return CWinApp::ExitInstance();
}
// DataManage.h: interface for the CDataManage class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_)
#define AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CDataManage
{
public:
CDataManage();
virtual ~CDataManage();
public:
_RecordsetPtr GetRecordset();
bool ExecSql(CString sql);
bool ConnectDatabase(CString constr);
_ConnectionPtr GetConn();
_RecordsetPtr Record1;
protected:
_ConnectionPtr DataConn;
_RecordsetPtr DataRecord;
};
#endif // !defined(AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_)
// DataManage.cpp: implementation of the CDataManage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Equipment.h"
#include "DataManage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDataManage::CDataManage()
{
DataConn.CreateInstance(_uuidof(Connection));
DataRecord.CreateInstance(_uuidof(Recordset));
Record1.CreateInstance(_uuidof(Recordset));
}
CDataManage::~CDataManage()
{
DataConn.Release();
DataRecord.Release();
Record1.Release();
}
_ConnectionPtr CDataManage::GetConn()
{
return DataConn;
}
bool CDataManage::ConnectDatabase(CString constr)
{
DataConn->ConnectionString=_bstr_t (constr);
try
{
DataConn->Open(" "," ", " ",-1);
}
catch(...)
{
return false;
}
return true;
}
bool CDataManage::ExecSql(CString sql)
{
_bstr_t sqltext=sql;
try{
DataConn->Execute(sqltext,NULL,adCmdText);
}
catch(_com_error&e){
AfxMessageBox(e.ErrorMessage(),0,0);
return false;
}
return true;
}
_RecordsetPtr CDataManage::GetRecordset()
{
return (DataRecord);
}
//{{AFX_INCLUDES()
#include "datagrid.h"
#include "adodc.h"
//}}AFX_INCLUDES
#if !defined(AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_)
#define AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EquipKind.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CEquipKind dialog
class CEquipKind : public CDialog
{
// Construction
public:
bool IsRepeated(CString str);
CEquipKind(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CEquipKind)
enum { IDD = IDD_EQUIPKIND_DIALOG };
CEdit kind;
CDataGrid DBgrid1;
CToolBarCtrl toolbar;
CImageList imagelist;
HICON m_hIcon;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEquipKind)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CEquipKind)
virtual void OnOK();
virtual BOOL OnInitDialog();
afx_msg void OnClickDatagrid1();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnButtonrefresh();
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_)
// EquipKind.cpp : implementation file
#include "stdafx.h"
#include "Equipment.h"
#include "EquipKind.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEquipmentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CEquipKind dialog
CEquipKind::CEquipKind(CWnd* pParent /*=NULL*/)
: CDialog(CEquipKind::IDD, pParent)
{
//{{AFX_DATA_INIT(CEquipKind)
// NOTE: the ClassWizard will add member initialization here
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
//}}AFX_DATA_INIT
}
void CEquipKind::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEquipKind)
DDX_Control(pDX, IDC_EDIT1, kind);
DDX_Control(pDX, IDC_DATAGRID1, DBgrid1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEquipKind, CDialog)
//{{AFX_MSG_MAP(CEquipKind)
ON_WM_SHOWWINDOW()
ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEquipKind message handlers
void CEquipKind::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
bool CEquipKind::IsRepeated(CString str)
{
CString sql;
sql.Format("select * from tb_kinds where kinds='%s'",str);
theApp.datamanage->Record1->raw_Close();
theApp.datamanage->Record1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.datamanage->Record1->RecordCount>0)
return true;
return false;
}
BOOL CEquipKind::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetIcon(m_hIcon,TRUE);
toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
toolbar.SetBitmapSize(CSize(32,32));
imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
for(int n=0; n<5;n++)
{
imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
}
toolbar.SetImageList(&imagelist);
TBBUTTON buttons[6];
for(int i=0;i<6;i++)
{
CString str;
int strlength;
CCHAR *temp;
str.LoadString(ID_BUTTONADD+i-1);
strlength=str.GetLength()+1;
temp=str.GetBufferSetLength(strlength);
temp[strlength]='\0';
temp[strlength-1]='\0';
if(i<1)
{
buttons[i].fsStyle=TBSTYLE_SEP;
}
else
{
buttons[i].fsStyle=TBSTYLE_BUTTON;
}
buttons[i].fsState=TBSTATE_ENABLED;
buttons[i].dwData=0;
buttons[i].idCommand=ID_BUTTONADD+i-1;
buttons[i].iBitmap=i-1;
buttons[i].iString=toolbar.AddStrings(temp);
str.ReleaseBuffer();
}
toolbar.AutoSize();
toolbar.AddButtons(6,buttons);
toolbar.ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BEGIN_EVENTSINK_MAP(CEquipKind, CDialog)
//{{AFX_EVENTSINK_MAP(CEquipKind)
ON_EVENT(CEquipKind, IDC_DATAGRID1, -600 /* Click */, OnClickDatagrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CEquipKind::OnClickDatagrid()
{
// TODO: Add your control notification handler code here
CString str;
_variant_t temp;
if ((!theApp.datamanage->GetRecordset()->ADOEOF)&&(!theApp.datamanage->GetRecordset()->BOF))
{
temp = theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)0)->Value;
str = temp.bstrVal;
kind.SetWindowText(str);
}
}
void CEquipKind::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
OnButtonrefresh(); //调用刷新按钮的单击事件
}
void CEquipKind::OnButtonrefresh()
{
// TODO: Add your command handler code here
kind.SetWindowText(""); //清空编辑框文本
DBgrid1.SetRefDataSource(NULL);
theApp.datamanage->GetRecordset()->raw_Close();
theApp.datamanage->GetRecordset()->Open("select kinds as 资产类别 from tb_kinds",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
if(theApp.datamanage->GetRecordset()->RecordCount>0)
DBgrid1.SetRefDataSource(theApp.datamanage->GetRecordset()->DataSource);
}
这个问题困扰了我好久了,请你们帮我分析一下到底是什么问题,在此我先谢了.期待你们的好消息.
// Equipment.h : main header file for the EQUIPMENT application
//
#if !defined(AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_)
#define AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
#include "DataManage.h"
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp:
// See Equipment.cpp for the implementation of this class
//
class CEquipmentApp : public CWinApp
{
public:
CDataManage* datamanage;
CEquipmentApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEquipmentApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CEquipmentApp)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EQUIPMENT_H__8DE7C605_4B34_439F_B904_2975D8A01A58__INCLUDED_)
// Equipment.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Equipment.h"
#include "EquipmentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp
BEGIN_MESSAGE_MAP(CEquipmentApp, CWinApp)
//{{AFX_MSG_MAP(CEquipmentApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp construction
CEquipmentApp::CEquipmentApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CEquipmentApp object
CEquipmentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CEquipmentApp initialization
BOOL CEquipmentApp::InitInstance()
{
AfxEnableControlContainer();
::CoInitialize(NULL);
AfxOleInit();
datamanage = new CDataManage;
datamanage->ConnectDatabase("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=EquipmentManage;Data Source=.");
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CEquipmentDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
int CEquipmentApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
return CWinApp::ExitInstance();
}
// DataManage.h: interface for the CDataManage class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_)
#define AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CDataManage
{
public:
CDataManage();
virtual ~CDataManage();
public:
_RecordsetPtr GetRecordset();
bool ExecSql(CString sql);
bool ConnectDatabase(CString constr);
_ConnectionPtr GetConn();
_RecordsetPtr Record1;
protected:
_ConnectionPtr DataConn;
_RecordsetPtr DataRecord;
};
#endif // !defined(AFX_DATAMANAGE_H__EE6DEDE3_191B_451C_940E_7AC519174199__INCLUDED_)
// DataManage.cpp: implementation of the CDataManage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Equipment.h"
#include "DataManage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDataManage::CDataManage()
{
DataConn.CreateInstance(_uuidof(Connection));
DataRecord.CreateInstance(_uuidof(Recordset));
Record1.CreateInstance(_uuidof(Recordset));
}
CDataManage::~CDataManage()
{
DataConn.Release();
DataRecord.Release();
Record1.Release();
}
_ConnectionPtr CDataManage::GetConn()
{
return DataConn;
}
bool CDataManage::ConnectDatabase(CString constr)
{
DataConn->ConnectionString=_bstr_t (constr);
try
{
DataConn->Open(" "," ", " ",-1);
}
catch(...)
{
return false;
}
return true;
}
bool CDataManage::ExecSql(CString sql)
{
_bstr_t sqltext=sql;
try{
DataConn->Execute(sqltext,NULL,adCmdText);
}
catch(_com_error&e){
AfxMessageBox(e.ErrorMessage(),0,0);
return false;
}
return true;
}
_RecordsetPtr CDataManage::GetRecordset()
{
return (DataRecord);
}
//{{AFX_INCLUDES()
#include "datagrid.h"
#include "adodc.h"
//}}AFX_INCLUDES
#if !defined(AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_)
#define AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EquipKind.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CEquipKind dialog
class CEquipKind : public CDialog
{
// Construction
public:
bool IsRepeated(CString str);
CEquipKind(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CEquipKind)
enum { IDD = IDD_EQUIPKIND_DIALOG };
CEdit kind;
CDataGrid DBgrid1;
CToolBarCtrl toolbar;
CImageList imagelist;
HICON m_hIcon;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEquipKind)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CEquipKind)
virtual void OnOK();
virtual BOOL OnInitDialog();
afx_msg void OnClickDatagrid1();
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnButtonrefresh();
DECLARE_EVENTSINK_MAP()
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EQUIPKIND_H__10EC3F63_AAA2_4B3F_BB94_000E13713588__INCLUDED_)
// EquipKind.cpp : implementation file
#include "stdafx.h"
#include "Equipment.h"
#include "EquipKind.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEquipmentApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CEquipKind dialog
CEquipKind::CEquipKind(CWnd* pParent /*=NULL*/)
: CDialog(CEquipKind::IDD, pParent)
{
//{{AFX_DATA_INIT(CEquipKind)
// NOTE: the ClassWizard will add member initialization here
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINTITLE);
//}}AFX_DATA_INIT
}
void CEquipKind::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEquipKind)
DDX_Control(pDX, IDC_EDIT1, kind);
DDX_Control(pDX, IDC_DATAGRID1, DBgrid1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEquipKind, CDialog)
//{{AFX_MSG_MAP(CEquipKind)
ON_WM_SHOWWINDOW()
ON_COMMAND(ID_BUTTONREFRESH, OnButtonrefresh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEquipKind message handlers
void CEquipKind::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
bool CEquipKind::IsRepeated(CString str)
{
CString sql;
sql.Format("select * from tb_kinds where kinds='%s'",str);
theApp.datamanage->Record1->raw_Close();
theApp.datamanage->Record1->Open((_bstr_t)sql,theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.datamanage->Record1->RecordCount>0)
return true;
return false;
}
BOOL CEquipKind::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
SetIcon(m_hIcon,TRUE);
toolbar.Create(TBSTYLE_FLAT|CCS_TOP|WS_CHILD|WS_VISIBLE|WS_BORDER|CCS_ADJUSTABLE|TBSTYLE_WRAPABLE,CRect(0,0,0,0),this,IDR_TOOLBAR2);
toolbar.SetBitmapSize(CSize(32,32));
imagelist.Create(32,32,ILC_COLOR32|ILC_MASK,0,0);
for(int n=0; n<5;n++)
{
imagelist.Add(theApp.LoadIcon(n+IDI_ICON1));
}
toolbar.SetImageList(&imagelist);
TBBUTTON buttons[6];
for(int i=0;i<6;i++)
{
CString str;
int strlength;
CCHAR *temp;
str.LoadString(ID_BUTTONADD+i-1);
strlength=str.GetLength()+1;
temp=str.GetBufferSetLength(strlength);
temp[strlength]='\0';
temp[strlength-1]='\0';
if(i<1)
{
buttons[i].fsStyle=TBSTYLE_SEP;
}
else
{
buttons[i].fsStyle=TBSTYLE_BUTTON;
}
buttons[i].fsState=TBSTATE_ENABLED;
buttons[i].dwData=0;
buttons[i].idCommand=ID_BUTTONADD+i-1;
buttons[i].iBitmap=i-1;
buttons[i].iString=toolbar.AddStrings(temp);
str.ReleaseBuffer();
}
toolbar.AutoSize();
toolbar.AddButtons(6,buttons);
toolbar.ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BEGIN_EVENTSINK_MAP(CEquipKind, CDialog)
//{{AFX_EVENTSINK_MAP(CEquipKind)
ON_EVENT(CEquipKind, IDC_DATAGRID1, -600 /* Click */, OnClickDatagrid1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CEquipKind::OnClickDatagrid()
{
// TODO: Add your control notification handler code here
CString str;
_variant_t temp;
if ((!theApp.datamanage->GetRecordset()->ADOEOF)&&(!theApp.datamanage->GetRecordset()->BOF))
{
temp = theApp.datamanage->GetRecordset()->GetFields()->GetItem((long)0)->Value;
str = temp.bstrVal;
kind.SetWindowText(str);
}
}
void CEquipKind::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
// TODO: Add your message handler code here
OnButtonrefresh(); //调用刷新按钮的单击事件
}
void CEquipKind::OnButtonrefresh()
{
// TODO: Add your command handler code here
kind.SetWindowText(""); //清空编辑框文本
DBgrid1.SetRefDataSource(NULL);
theApp.datamanage->GetRecordset()->raw_Close();
theApp.datamanage->GetRecordset()->Open("select kinds as 资产类别 from tb_kinds",theApp.datamanage->GetConn().GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
if(theApp.datamanage->GetRecordset()->RecordCount>0)
DBgrid1.SetRefDataSource(theApp.datamanage->GetRecordset()->DataSource);
}