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

📄 bank_impl.cpp

📁 用interbus作为中间件的工具模拟银行自动取款机ATM.
💻 CPP
字号:
// **********************************************************************
//
// Copyright (c) 2000
// Intervision Software Co., Ltd.
// Haidian District, Beijing.
//
// All Rights Reserved
//
// **********************************************************************

#include "StdAfx.h"

#include <STAR/CORBA.h>
#include "bank_impl.h"

#include <stdlib.h>
#include <errno.h>


#ifdef HAVE_FSTREAM
#   include <fstream>
#else
#   include <fstream.h>
#endif

#ifdef HAVE_STD_IOSTREAM
using namespace std;
#endif


//
// Interface declare ::BankAccount
//
BankAccount_impl::BankAccount_impl()
 //   : poa_(PortableServer::POA::_duplicate(poa))
{
	m_pDlg = NULL;
}

BankAccount_impl::~BankAccount_impl()
{
}


//
// Operation declare log
 //
CORBA::Boolean
BankAccount_impl::log(const char* id)
	throw(CORBA::SystemException)
{
	CString strRcv;
	CString strTemp;
	//帐号验证
	strRcv = id;
	strTemp = m_pDlg->getFieldValue(strRcv, "ID");
	if(!strRcv.Compare((LPCSTR)strTemp))
	{
		strTemp.Format("帐号:%s,开始操作", strRcv);
		m_pDlg->addListMsg(strTemp);
		m_strID = strRcv;
		return TRUE;
	}
	else
	{
		strTemp.Format("无效帐号:%s", strRcv);
		m_pDlg->addListMsg(strTemp);
		return FALSE;
	}
	
}

//
// Operation declare authentificate
//
CORBA::Boolean
BankAccount_impl::authentificate(const char* password)
	throw(CORBA::SystemException)
{
	CString strRcv;
	CString strTemp;
	//密码验证
	strRcv = password;
	strTemp = m_pDlg->getFieldValue(m_strID, "PAW");
	if(!strRcv.Compare((LPCSTR)strTemp))
	{
		strTemp.Format("帐号:%s,通过密码验证",m_strID);
		m_pDlg->addListMsg(strTemp);
		return TRUE;
	}
	else
	{
		strTemp.Format("帐号:%s,没有通过密码验证",m_strID);
		m_pDlg->addListMsg(strTemp);
		return FALSE;
	}	
}

//
// Operation declare requery
//
CORBA::Double 
BankAccount_impl::requery()
	throw(CORBA::SystemException)
{
	return atof(m_pDlg->getFieldValue(m_strID, "SUM"));
}

//
// Operation declare authentificate
//
CORBA::Boolean 
BankAccount_impl::withdraw(CORBA::Short nMoney)
	throw(CORBA::SystemException)
{
	CString strTemp;
	//取钱
	strTemp = m_pDlg->getFieldValue(m_strID, "SUM");
	if(nMoney <= atof((LPCSTR)strTemp))
	{
		//从帐户中减去
		if(m_pDlg->updateSUM(m_strID, atof((LPCSTR)strTemp) - nMoney))
		{
			//取钱成功
			return TRUE;
		}
		else
		{
			//数据库操作不成功
			return FALSE;
		}
	}
	else
	{
		//余额不足
		return FALSE;
	}	
}


//
// Operation declare deposit
//
CORBA::Boolean 
BankAccount_impl::deposit(CORBA::Short nMoney)
	throw(CORBA::SystemException)
{
	CString strTemp;
	strTemp = m_pDlg->getFieldValue(m_strID, "SUM");
	//在帐户中加上
	if(m_pDlg->updateSUM(m_strID, atof((LPCSTR)strTemp) + nMoney))
	{
		return TRUE;
	}
	else
	{
		//数据库操作不成功
		return FALSE;		
	}
}

//
// Operation declare deposit
//
CORBA::Boolean 
BankAccount_impl::alterPAW(const char* strPAW)
	throw(CORBA::SystemException)
{
	CString strRcv;
	//修改密码
	strRcv = strRcv.Mid(strRcv.Find(" ")+1);
	if(m_pDlg->updatePAW(m_strID, strRcv))
	{
		return TRUE;
	}
	else
	{
		//数据库操作不成功
		return FALSE;		
	}
	
}

//
// Operation declare leave
//
CORBA::Boolean 
BankAccount_impl::leave()
	throw(CORBA::SystemException)
{
	CString strTemp;

	strTemp.Format("帐号:%s,结束操作",m_strID);
	m_pDlg->addListMsg(strTemp);
	return TRUE;
}

//将对话框的指针传进来
void 
BankAccount_impl::setDlg(CBankServerDlg* pDlg)
{
	m_pDlg = pDlg;
}



⌨️ 快捷键说明

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