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

📄 adminmodify.cpp

📁 一个简单的银行管理程序 VC++实现
💻 CPP
字号:
// AdminModify.cpp : implementation file
//

#include "stdafx.h"
#include "banksystem.h"
#include "AdminModify.h"

#include "BankSystemDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAdminModify dialog


CAdminModify::CAdminModify(CWnd* pParent /*=NULL*/)
	: CDialog(CAdminModify::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAdminModify)
	m_strUser = _T("");
	m_strPassW = _T("");
	m_strName = _T("");
	m_strID = _T("");
	m_strAddr = _T("");
	//}}AFX_DATA_INIT
}


void CAdminModify::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAdminModify)
	DDX_Control(pDX, IDC_COMBO, m_combo);
	DDX_Text(pDX, IDC_EDIT1, m_strUser);
	DDX_Text(pDX, IDC_EDIT2, m_strPassW);
	DDX_Text(pDX, IDC_EDIT3, m_strName);
	DDX_Text(pDX, IDC_EDIT4, m_strID);
	DDX_Text(pDX, IDC_EDIT5, m_strAddr);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAdminModify, CDialog)
	//{{AFX_MSG_MAP(CAdminModify)
	ON_BN_CLICKED(IDC_BUTTON1, OnSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAdminModify message handlers

void CAdminModify::OnSearch() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);

	if(m_strUser.IsEmpty())
	{
		AfxMessageBox("账号不能为空!");
		return;
	}

	_RecordsetPtr   m_pRec;
	_ConnectionPtr  m_pCon;

	CBankSystemApp *App = (CBankSystemApp*)AfxGetApp();
	CBankSystemDlg *m_pMain = (CBankSystemDlg*)App->m_pMainWnd;

	CString  strSQL;
	strSQL = "SELECT * FROM Admin where 账号=";
	strSQL+= m_strUser;

	_variant_t  varName,varPassW,varID,varAddr;
	CString     m_strPower;

	m_pCon = m_pMain->m_pConnection;
	m_pRec.CreateInstance(__uuidof(Recordset));
	m_pRec->Open(_variant_t(strSQL),m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	
	if(m_pRec->adoEOF)
	{
		AfxMessageBox("没有此账号!");
		return;
	}
	
	m_strUser  = (LPCSTR)_bstr_t(m_pRec->GetCollect("账号"));
	m_strPassW = (LPCSTR)_bstr_t(m_pRec->GetCollect("密码"));
	m_strName  = (LPCSTR)_bstr_t(m_pRec->GetCollect("姓名"));
	m_strID    = (LPCSTR)_bstr_t(m_pRec->GetCollect("身份证"));
	m_strAddr  = (LPCSTR)_bstr_t(m_pRec->GetCollect("联系方式"));
	m_strPower = (LPCSTR)_bstr_t(m_pRec->GetCollect("权限"));

	if(m_strPower=="1")
		m_combo.SetCurSel(0);
	else 
		m_combo.SetCurSel(1);

	UpdateData(false);

	m_pRec->Update();
	m_pRec->Close();

	GetDlgItem(IDOK)->EnableWindow(true);
	GetDlgItem(IDC_EDIT2)->EnableWindow(true);
	GetDlgItem(IDC_EDIT3)->EnableWindow(true);
	GetDlgItem(IDC_EDIT4)->EnableWindow(true);
	GetDlgItem(IDC_EDIT5)->EnableWindow(true);	

	
}

void CAdminModify::OnOK() 
{
	// TODO: Add extra validation here

    UpdateData(true);

	if(m_strUser.IsEmpty()||m_strID.IsEmpty()||m_strName.IsEmpty()||m_strAddr.IsEmpty()||m_strPassW.IsEmpty())
	{
		AfxMessageBox("请填写详细信息!");
		return;
	}

	_RecordsetPtr   m_pRec;
	_ConnectionPtr  m_pCon;

	CBankSystemApp *App = (CBankSystemApp*)AfxGetApp();
	CBankSystemDlg *m_pMain = (CBankSystemDlg*)App->m_pMainWnd;

	CString  strSQL;
	strSQL = "SELECT * FROM Admin where 账号=";
	strSQL+= m_strUser;

	_variant_t  varName,varPassW,varID,varAddr,varPower;
	CString     m_strPower;

	m_pCon = m_pMain->m_pConnection;
	m_pRec.CreateInstance(__uuidof(Recordset));
	m_pRec->Open(_variant_t(strSQL),m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	
	if(m_pRec->adoEOF)
	{
		AfxMessageBox("没有此账号!");
		return;
	}

	varName  = m_strName;
	varPassW = m_strPassW;
	varID    = m_strID;
	varAddr  = m_strAddr;
	if(m_combo.GetCurSel()==0)
		varPower = "1";
	else 
		varPower = "2";
	
	m_pRec->PutCollect("密码",varPassW);
	m_pRec->PutCollect("姓名",varName);
	m_pRec->PutCollect("身份证",varID);
	m_pRec->PutCollect("联系方式",varAddr);
	m_pRec->PutCollect("权限",varPower);



	m_pRec->Update();
	m_pRec->Close();

	GetDlgItem(IDOK)->EnableWindow(false);
	GetDlgItem(IDC_EDIT2)->EnableWindow(false);
	GetDlgItem(IDC_EDIT3)->EnableWindow(false);
	GetDlgItem(IDC_EDIT4)->EnableWindow(false);
	GetDlgItem(IDC_EDIT5)->EnableWindow(false);	
	
//	CDialog::OnOK();
}

BOOL CAdminModify::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_EDIT2)->EnableWindow(false);
	GetDlgItem(IDC_EDIT3)->EnableWindow(false);
	GetDlgItem(IDC_EDIT4)->EnableWindow(false);
	GetDlgItem(IDC_EDIT5)->EnableWindow(false);	

	
	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 + -