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

📄 peopledlg.cpp

📁 家庭财务管理系统毕业论文,含源码。基于ACCESS数据库的运用。用了VC++ 6.0 ADO。
💻 CPP
字号:
// PeopleDlg.cpp : implementation file
//

#include "stdafx.h"
#include "HomeRes.h"
#include "PeopleDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPeopleDlg dialog


CPeopleDlg::CPeopleDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPeopleDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPeopleDlg)
	m_strPeopleName = _T("");
	//}}AFX_DATA_INIT
}


void CPeopleDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPeopleDlg)
	DDX_Control(pDX, IDC_COMBO2, m_cobModel);
	DDX_Control(pDX, IDC_COMBO_PEOPLE, m_cobPeople);
	DDX_CBString(pDX, IDC_COMBO_PEOPLE, m_strPeopleName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPeopleDlg, CDialog)
	//{{AFX_MSG_MAP(CPeopleDlg)
	ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPeopleDlg message handlers

BOOL CPeopleDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	Load();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CPeopleDlg::OnOK() 
{
	UpdateData(TRUE);
	CString str;
	m_cobPeople.GetWindowText(str);
	int i = m_cobPeople.FindStringExact(-1,str);
	if(i != -1)
	{
		m_cobPeople.SetCurSel(i);
		AfxMessageBox("要新增的用户名重复了!");
		return;
	}
	if(str == "")
	{
		AfxMessageBox("请写入用户名!");
		return;
	}
	m_cobModel.GetWindowText(str);
	if(str == "")
	{
		AfxMessageBox("请选择用户类型!");
		return;
	}
	else
	{
		_RecordsetPtr	m_pRecordset;
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		try
		{
			m_pRecordset->Open("SELECT * FROM Handler",                // 查询DemoTable表中所有字段
				theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
				adOpenDynamic,
				adLockOptimistic,
				adCmdText);
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}  

		CString strModel;
		m_cobModel.GetWindowText(strModel);
		
		//添加新记录
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("Handler",_variant_t(m_strPeopleName));
		m_pRecordset->PutCollect("Model",_variant_t(strModel));
		m_pRecordset->Update();

		m_pRecordset->Close();
		m_pRecordset = NULL;

		Load();
	}

//	CDialog::OnOK();
}

void CPeopleDlg::Load()
{
	m_cobPeople.ResetContent();//清除控件中的所有字符串条目
	_RecordsetPtr	pHandlerRecordset;
	pHandlerRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		pHandlerRecordset->Open("SELECT * FROM Handler",                // 查询DemoTable表中所有字段
		theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
		adOpenDynamic,
		adLockOptimistic,
		adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}  
				
	_variant_t var;
	CString strName;
	while(!pHandlerRecordset->adoEOF)
	{
		var = pHandlerRecordset->GetCollect("Handler");
		if(var.vt != VT_NULL)
			strName = (LPCSTR)_bstr_t(var);
		m_cobPeople.AddString(strName);	
		pHandlerRecordset->MoveNext();
	}
	pHandlerRecordset->Close();
	pHandlerRecordset.Release();
	pHandlerRecordset = NULL;
}

void CPeopleDlg::OnButtonDel() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString str;
	m_cobPeople.GetWindowText(str);
	if(str != "" && AfxMessageBox("是否删除?",MB_YESNO) == IDYES)
	{
		CString strSql;
		strSql.Format("delete from Handler where Handler='%s'",str);
		_variant_t RecordsAffected;
		theApp.m_pConnection->Execute(_bstr_t(strSql),&RecordsAffected,adCmdText);
		Load();
	}
}

⌨️ 快捷键说明

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