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

📄 create.cpp

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

#include "stdafx.h"
#include "BankSystem.h"
#include "Create.h"

#include "BankSystemDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCreate dialog


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


void CCreate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCreate)
	DDX_Control(pDX, IDC_RADIO3, m_conRadio2);
	DDX_Control(pDX, IDC_RADIO1, m_conRadio1);
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	DDX_Text(pDX, IDC_EDIT2, m_strID);
	DDX_Text(pDX, IDC_EDIT3, m_strPassW);
	DDX_Text(pDX, IDC_EDIT4, m_strPassW2);
	DDX_Text(pDX, IDC_EDIT5, m_strAddr);
	DDX_Text(pDX, IDC_EDIT6, m_strMonth);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCreate, CDialog)
	//{{AFX_MSG_MAP(CCreate)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDOK, OnOk)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCreate message handlers

void CCreate::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_RADIO3)->ShowWindow(SW_SHOW); 
	m_conRadio2.SetCheck(0);;
		
	
}

void CCreate::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_RADIO3)->ShowWindow(SW_HIDE); 
	((CButton*)GetDlgItem(IDC_RADIO4))->SetCheck(TRUE);
	OnRadio4();
}

void CCreate::OnOk() 
{
	// TODO: Add your control notification handler code here
    try{
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		m_pRecordset->Open("SELECT * FROM VIEW1",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);

		_variant_t varName,varID,varPassW,varAddr,varType,varKind,varSort,varTime,varMoney,varAcount,varStatus,varLastTime,varDueTime,varOldInterest;
		CString strErr,strSucc,m_strTime,m_strLastTime,m_strDueTime;
		CTime m_begaintime=CTime::GetCurrentTime();
		m_strLastTime=m_strTime=m_begaintime.Format("%y-%m-%d");
		varMoney.lVal=VT_I8;
		float money=10;
		varMoney=money;
		varStatus=_variant_t("正常");
		varAcount=ApplyNewAcount();
		int check1,check2;

		UpdateData(true);
		check1=m_conRadio1.GetCheck();
		check2=m_conRadio2.GetCheck();

		strErr.Empty();
		strSucc.Empty();

		if(check1==1)
			varType="储蓄账户";
		else
			varType="信用卡帐户";
		if(check2==1)
		{
			varKind="定期";
			if(m_strMonth=="")
				strErr+="年限不能为空!\n";
			int month=atoi(m_strMonth);
			CTime nowTime=CTime::GetCurrentTime();
			CTimeSpan timespan(month*30,0,0,0);
			CTime dueTime=nowTime+timespan;
			m_strDueTime=dueTime.Format("%y-%m-%d");
			varOldInterest=m_pRecordset->GetCollect("定期");
			
		}
		else 
		{
			varKind="活期";
			m_strDueTime="--------";
		}
	
	    if(m_strName=="")
			strErr+="姓名不能为空!\n";
		if(m_strID.GetLength()!=18)
			strErr+="身份证18位!\n";
		if(m_strPassW=="")
			strErr+="密码不能为空!\n";
		if(m_strPassW2!=m_strPassW)
			strErr+="两次输入密码不一致!\n";
	    if(m_strAddr=="")
			strErr+="联系方式不能为空!\n";
		
		if(strErr=="")
		{
			varName=m_strName;
			varID=m_strID;
			varPassW=m_strPassW;
			varAddr=m_strAddr;
			varTime=varLastTime=m_strTime;
			varDueTime=m_strDueTime;
			varStatus=_variant_t("正常");

			m_pRecordset->AddNew();
			m_pRecordset->PutCollect("姓名",varName);
			m_pRecordset->PutCollect("身份证",varID);
			m_pRecordset->PutCollect("密码",varPassW);
			m_pRecordset->PutCollect("联系方式",varAddr);
			m_pRecordset->PutCollect("账户类型",varType);
			m_pRecordset->PutCollect("账号",varAcount);
			m_pRecordset->PutCollect("定活",varKind);
			m_pRecordset->PutCollect("开户时间",varTime);
			m_pRecordset->PutCollect("最后结算时间",varLastTime);
			m_pRecordset->PutCollect("到期时间",varDueTime);
			m_pRecordset->PutCollect("金额",varMoney);
			m_pRecordset->PutCollect("状态",varStatus);
			m_pRecordset->PutCollect("固定利息",varOldInterest);
			m_pRecordset->Update();
		}
		if(strErr!="")
			AfxMessageBox(strErr);
		else
		{
			strSucc="注册成功~!\n账号为";
			strSucc+=(LPCSTR)_bstr_t(varAcount);
			AfxMessageBox(strSucc);
		}
		m_pRecordset->Close();
		m_pRecordset=NULL;
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	
}

BOOL CCreate::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CBankSystemApp * pApp = (CBankSystemApp*)AfxGetApp();
	CBankSystemDlg * m_pMain = (CBankSystemDlg*)pApp->m_pMainWnd;
	m_pConnection=m_pMain->m_pConnection;

	m_conRadio1.SetCheck(true);
	m_conRadio2.SetCheck(true);

	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

CString CCreate::ApplyNewAcount()
{
	CString acount;
    _RecordsetPtr m_pRec;
	_variant_t varnum;
	m_pRec.CreateInstance(__uuidof(Recordset));
	m_pRec->Open("SELECT * FROM NewAcount",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	varnum=m_pRec->GetCollect("新账号");
	acount=(LPCSTR)_bstr_t(varnum);
	int num=atoi(acount);
	num++;
	acount.Format("%d",num);
	varnum=acount;
	m_pRec->MoveFirst();
	m_pRec->PutCollect("新账号",varnum);
	m_pRec->Update();
	m_pRec->Close();
	return acount;
}

void CCreate::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT6)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);	
	
}

void CCreate::OnRadio4() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT6)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE);
	GetDlgItem(IDC_STATIC2)->ShowWindow(SW_HIDE);	
	
}

⌨️ 快捷键说明

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