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

📄 productdlg.cpp

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

#include "stdafx.h"
#include "HomeRes.h"
#include "ProductDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CProductDlg dialog


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


void CProductDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProductDlg)
	DDX_Control(pDX, IDC_COMBO1, m_cobType);
	DDX_CBString(pDX, IDC_COMBO1, m_strType);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// CProductDlg message handlers

void CProductDlg::Load()
{
	m_cobType.ResetContent();//清除控件中的所有字符串条目
	_RecordsetPtr	pHandlerRecordset;
	pHandlerRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		pHandlerRecordset->Open("SELECT * FROM Type",                // 查询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("Type");
		if(var.vt != VT_NULL)
			strName = (LPCSTR)_bstr_t(var);
		m_cobType.AddString(strName);	
		pHandlerRecordset->MoveNext();
	}
	pHandlerRecordset->Close();
	pHandlerRecordset.Release();
	pHandlerRecordset = NULL;
}

BOOL CProductDlg::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 CProductDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	CString str;
	m_cobType.GetWindowText(str);
	int i = m_cobType.FindStringExact(-1,str);
	if(i != -1)
	{
		m_cobType.SetCurSel(i);
		AfxMessageBox("要新增的消费类型,重复了!");
		return;
	}
	if(str == "")
	{
		AfxMessageBox("请写入消费类型!");
		return;
	}
	else
	{
		_RecordsetPtr	m_pRecordset;
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		try
		{
			m_pRecordset->Open("SELECT * FROM Type",                // 查询DemoTable表中所有字段
				theApp.m_pConnection.GetInterfacePtr(),	 // 获取库接库的IDispatch指针
				adOpenDynamic,
				adLockOptimistic,
				adCmdText);
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}  

		CString strType;
		m_cobType.GetWindowText(strType);
		
		//添加新记录
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("Type",_variant_t(strType));
		m_pRecordset->Update();

		m_pRecordset->Close();
		m_pRecordset = NULL;

		Load();
	}
//	CDialog::OnOK();
}

void CProductDlg::OnButtonDel() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString str;
	m_cobType.GetWindowText(str);
	if(str != "" && AfxMessageBox("是否删除?",MB_YESNO) == IDYES)
	{
		CString strSql;
		strSql.Format("delete from Type where Type='%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 + -