📄 atmdlg.cpp
字号:
// ATMDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ATM.h"
#include "ATMDlg.h"
#include "AuthentificateDlg.h"
#include "OperationDlg.h"
#include <STAR/CORBA.h>
#include "..\bank.h"
#include <stdlib.h>
#include <STAR/STARPolicies.h>
#include <STAR/Properties.h>
#include <STAR/MsgLog.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////////////////
TCHAR* CATMDlg::error_table[] =
{
"连接服务器不成功",
"无效帐号", // IDENTIFICATION
"密码错误", // AUTHENTIFICATION
"无法查询", // STATUS
"余额不足", // RETRIEVE
"修改密码不成功", // DELE
};
CString CATMDlg::sWelcome = "欢迎您使用**银行ATM自动取款机!~!";
CString CATMDlg::sLeave = "感谢你对本银行的支持,\r\n欢迎下次光临!";
CString CATMDlg::sGetCard = "请取走卡......";
/////////////////////////////////////////////////////////////////////////////
// CATMDlg dialog
CATMDlg::CATMDlg(CWnd* pParent /*=NULL*/)
: CDialog(CATMDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CATMDlg)
m_strID = _T("");
m_strInfo = sWelcome;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bGet = TRUE;
m_pBankAccount = NULL;
}
void CATMDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CATMDlg)
DDX_Control(pDX, IDCANCEL, m_ctlCancel);
DDX_Control(pDX, IDC_LOG, m_ctlLog);
DDX_Control(pDX, IDC_EDIT_ID, m_ctlID);
DDX_Text(pDX, IDC_EDIT_ID, m_strID);
DDX_Text(pDX, IDC_EDIT_INFO, m_strInfo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CATMDlg, CDialog)
//{{AFX_MSG_MAP(CATMDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_LOG, OnLog)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////
int CATMDlg::commonproc(CORBA::ORB_ptr orb, int argc, char* argv[])
{
//
// 从文件BankAccountobj.ref中获取服务对象hello的引用
//
CORBA::Object_var obj = orb -> string_to_object("relfile:/..\\BankAccountobj.ref");
if(CORBA::is_nil(obj))
{
AfxMessageBox("1 Cannot read object reference from file bBankAccountobj.ref");
return -1;
}
BankAccount_var bankAccount = BankAccount::_narrow(obj);
assert(!CORBA::is_nil(bankAccount));
m_pBankAccount= bankAccount;
//
// 调用服务对象bankAccount中的服务方法log(),进行测试
//
/*
const char* str = "123456789";
AfxMessageBox("Remote call !!");
if(bankAccount->log(str))
AfxMessageBox("Remote call successful !!");
*/
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CATMDlg message handlers
BOOL CATMDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CATMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CATMDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CATMDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CATMDlg::OnLog()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//////////////////////////////////////////////////////////////////////////
//初始化
int state = 0;
CORBA::ORB_var orb;
try
{
//
// 初始化ORB
int argc =0;
char** argv =NULL;
//
orb = CORBA::ORB_init(argc, argv);
//
// 调用客户方通用过程
//
state = commonproc(orb, argc, argv);
}
catch(const CORBA::Exception& ex)
{
AfxMessageBox("orb error!");
state = -1;
return;
}
//////////////////////////////////////////////////////////////////////////
try
{
if(!m_pBankAccount->log((LPCSTR)m_strID))
{
m_sError = _T( "Invalid ID" );
AfxMessageBox("无效帐号!");
m_strID = _T("");
UpdateData(FALSE);
return;
}
}
catch(const CORBA::Exception& ex)
{
AfxMessageBox("连接服务器失败!");
state = -1;
return;
}
ShowWindow(SW_HIDE);
pAuthentificateDlg = new CAuthentificateDlg(this);
m_bGet = TRUE;
if(pAuthentificateDlg->DoModal() == IDOK)
{
if(4 == pAuthentificateDlg->m_nTimes)
{
m_bGet = FALSE;
}
delete pAuthentificateDlg;
pOperationDlg = new COperationDlg(this);
if(m_bGet)
{
pOperationDlg->DoModal();
}
}
else
{
delete pAuthentificateDlg;
}
m_pBankAccount->leave();
//销毁orb
if(!CORBA::is_nil(orb))
{
try
{
orb -> destroy();
}
catch(const CORBA::Exception& ex)
{
AfxMessageBox("ORB destroy error!");
}
}
//显示“欢迎下次光临”
m_strInfo = sLeave;
m_strID = _T("");
m_ctlID.EnableWindow(FALSE);
m_ctlLog.EnableWindow(FALSE);
m_ctlCancel.EnableWindow(FALSE);
UpdateData(FALSE);
ShowWindow(SW_SHOW);
SetTimer(1, 3000, NULL);
return;
}
void CATMDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//显示“请取走你的卡”
if(1 == nIDEvent)
{
if(m_bGet)
{
m_strInfo = sGetCard;
UpdateData(FALSE);
KillTimer(1);
SetTimer(2, 6000 ,NULL);
}
else
{
m_strInfo = sWelcome;
m_ctlID.EnableWindow(TRUE);
m_ctlLog.EnableWindow(TRUE);
m_ctlCancel.EnableWindow(TRUE);
UpdateData(FALSE);
KillTimer(1);
}
}
//恢复到插卡界面
if(2 == nIDEvent)
{
m_strInfo = sWelcome;
m_ctlID.EnableWindow(TRUE);
m_ctlLog.EnableWindow(TRUE);
m_ctlCancel.EnableWindow(TRUE);
UpdateData(FALSE);
KillTimer(2);
}
CDialog::OnTimer(nIDEvent);
}
BOOL CATMDlg::authentificate(CString password)
{
if(m_pBankAccount->authentificate((LPCSTR)password))
{
return TRUE;
}
else
{
return FALSE;
}
}
double CATMDlg::requery()
{
return m_pBankAccount->requery();
}
BOOL CATMDlg::withdraw(UINT nMoney)
{
return m_pBankAccount->withdraw(nMoney);
}
BOOL CATMDlg::deposit(UINT nMoney)
{
return m_pBankAccount->deposit(nMoney);
}
BOOL CATMDlg::alterPAW(CString strPAW)
{
return m_pBankAccount->alterPAW((LPCSTR)strPAW);
}
void CATMDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -