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

📄 atmdlg.cpp

📁 一个模仿ATM提款机的MFC程序
💻 CPP
字号:
// ATMDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ATM.h"
#include "ATMDlg.h"
#include "GasUser.h"
#include "WaterUser.h"
#include "TelephoneUser.h"
#include "NewAccount.h"
#include "Ref.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
	CEnterPaswd enterpaswdlg;
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()

/////////////////////////////////////////////////////////////////////////////
// CATMDlg dialog

CATMDlg::CATMDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CATMDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CATMDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CATMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CATMDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}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_CHECK, OnCheck)
	ON_BN_CLICKED(IDC_WITHDRAW, OnWithdraw)
	ON_BN_CLICKED(IDC_CHANGEPASWD, OnChangepaswd)
	ON_BN_CLICKED(IDC_TRANSFER, OnTransfer)
	ON_BN_CLICKED(IDC_SURROGATE, OnSurrogate)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_FORACCOUNT, OnForaccount)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// 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
	ifstream fin("活期帐户.txt");//,ios::nocreate);
	if (fin.is_open())
	{
			
		while (!fin.eof())
		{
			CString acntNum;
			char strNo[19],strpwd[7];
			
			fin >> strNo;
			acntNum = strNo;
			CString  paswrd;
			fin>>strpwd;
			paswrd=strpwd;
			double balan;
			fin>>balan;
			if(fin.eof())
				break;
			CurrentAcnt *p=new CurrentAcnt(acntNum,paswrd);

			p->reloadbalance(balan);
		}
						
		fin.close();
		
	}
//	remove("活期帐户.txt");

		ifstream finP("电话用户.txt");//,ios::nocreate);
	if (finP.is_open())
	{
			
		while (!finP.eof())
		{
			CString phno;
			char strNo[19];
			finP >> strNo;
			phno = strNo;						
			double co;
			finP>>co;
			if(finP.eof())
				break;
			CPhoneuser *p=new CPhoneuser(phno,co);

		}
						
		finP.close();
		
	}

	
	ifstream finG("煤气用户.txt");//,ios::nocreate);
	if (finG.is_open())
	{
		
		while (!finG.eof())
		{
			CString phno;
			char strNo[19];
			finG >> strNo;
			phno = strNo;						
			double co;
			finG>>co;
			if(finG.eof())
				break;
			CGasuser *p=new CGasuser(phno,co);
			
		}
		
		finG.close();
		
	}
	//水费用户
	ifstream finW("水费用户.txt");//,ios::nocreate);
	if (finW.is_open())
	{
		
		while (!finW.eof())
		{
			CString phno;
			char strNo[19];
			finW >> strNo;
			phno = strNo;						
			double co;
			finW>>co;
			if(finW.eof())
				break;
			WaterUser *p=new WaterUser(phno,co);
			
		}
		
		finW.close();
		
	}
	
	ifstream finT("电话费用户.txt");//,ios::nocreate);
	if (finT.is_open())
	{
		
		while (!finT.eof())
		{
			CString phno;
			char strNo[19];
			finT>> strNo;
			phno = strNo;						
			double co;
			finT>>co;
			if(finT.eof())
				break;
			TelephoneUser *p=new TelephoneUser(phno,co);
			
		}
		
		finT.close();
		
	}
	




//	remove("电话用户.txt");

	ifstream finE("外行帐户.txt");//,ios::nocreate);
	if (finE.is_open())
	{
			
		while (!finE.eof())
		{
			CString acntNum;
			char strNo[19],strpwd[7];
			
			finE >> strNo;
			acntNum = strNo;
			CString  paswrd;
			finE>>strpwd;
			paswrd=strpwd;
			double balan;
			finE>>balan;
			if(finE.eof())
				break;
			Exaccount *p=new Exaccount(acntNum,paswrd);
			p->reloadbalance(balan);
		}
						
		finE.close();
		
	}
//	remove("外行帐户.txt");
	
	enterpaswdlg.DoModal();
	SetTimer(0,15000,NULL);   //设置计时器,15秒无操作发出提示
	
	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::OnCheck() 
{
	// TODO: Add your control notification handler code here
	KillTimer(0);
	CCheckchoose checkchoosedlg;
	if(checkchoosedlg.DoModal()==IDOK)
	{	
	   
		if(CurrentAcnt *pCyrntAcnt=CurrentAcnt::searchAccount(enterpaswdlg.m_password))//搜寻检测用户密码
		{
			CCheck check;
		    check.m_Balance=pCyrntAcnt->AcntBalan();
			check.m_Availbal=check.m_Balance-1;
			pCyrntAcnt->reloadbalance(check.m_Balance-pCyrntAcnt->GetCheckFee(0));	//收费依据属地跟属行而定					
			check.DoModal();
		}
		else 
		{
         CPassworderror passerrordlg;  //密码错误
         passerrordlg.DoModal();
		 enterpaswdlg.m_password="";  //重输密码
		 enterpaswdlg.DoModal();
		}
	}
		
}

void CATMDlg::OnWithdraw() 
{
	// TODO: Add your control notification handler code here
	KillTimer(0);
	CWithdraw withdrawdlg;
	withdrawdlg.DoModal();	
}



void CATMDlg::OnChangepaswd() 
{
	// TODO: Add your control notification handler code here
	KillTimer(0);
	CChanegpass change1dlg;
	
	if(change1dlg.DoModal()==IDOK)
	{    
		CChangepassword2 change2dlg;
		if(change2dlg.DoModal()==IDOK)
		{
			if(change1dlg.m_newpassword1==change2dlg.m_newpassword2&&change1dlg.m_newpassword1!="")//两次输入的密码比较及非空检验
			{
				if(CurrentAcnt *pCyrntAcnt=CurrentAcnt::searchAccount(enterpaswdlg.m_password)) //搜寻检测用户密码
				{
					pCyrntAcnt->changePassword(change1dlg.m_newpassword1);
					enterpaswdlg.m_password=change1dlg.m_newpassword1;
					CChangesuccess successdlg;      //修改成功
					successdlg.DoModal();
					Ref ref;
					ref.Refresh(pCyrntAcnt->GetacntNo(),pCyrntAcnt->GetBalance(),0,"修改密码");
				}
		        else 
				{
                   CPassworderror passerrordlg;   //密码错误
                   passerrordlg.DoModal();
		           enterpaswdlg.m_password="";    //重输密码
		           enterpaswdlg.DoModal();
				}
			}
			else                                
			{
				if(change1dlg.m_newpassword1=="")//密码为空
				{
					CSuggest suggestdlg;
					suggestdlg.m_suggest="密码不能为空";
					suggestdlg.DoModal();
				}
				else                        //两次密码不一样
				{	CDifpass difpassdlg;    
					difpassdlg.DoModal();
				}
			
			}
		}     
	}
	
}

void CATMDlg::OnTransfer() 
{
	// TODO: Add your control notification handler code here
KillTimer(0);
CTransfer transferdlg;
CSuggest suggestdlg;
int id=transferdlg.DoModal();
switch(id)
{
case IDOK:   //转本行帐户
	{
		CAccountno1 accountno1dlg;
		if(accountno1dlg.DoModal()==IDOK)
		{
			CAccountno2 accountno2dlg;
			if(accountno2dlg.DoModal()==IDOK)
			{
				if(accountno1dlg.m_accountno1==accountno2dlg.m_accountno2) //比较两次输入的帐号
				{
					CTranamount tranamountdlg;
					if(tranamountdlg.DoModal()==IDOK)
					{
						if(CurrentAcnt *pCyrntAcnt=CurrentAcnt::searchAccount(enterpaswdlg.m_password)) //搜寻检测用户密码
						{
							if(CurrentAcnt *ptTranacnt=CurrentAcnt::searchtranAccount(accountno1dlg.m_accountno1))//搜索检测转帐帐号
							{
								if(pCyrntAcnt->GetacntNo()==ptTranacnt->GetacntNo())  //不能给自己转帐
								{
									CTranmis tranmisdlg;
									tranmisdlg.DoModal();
								}
								else
								{
								    double remain=pCyrntAcnt->AcntBalan();
									double tranremain=ptTranacnt->AcntBalan();
									double amount=tranamountdlg.m_tranamount;
									if(amount>remain)   //余额不足
									{
										suggestdlg.m_suggest="余额不足";
										suggestdlg.DoModal();
									}
									else  //交易成功
									{
										remain-=amount;
										tranremain+=amount;
										pCyrntAcnt->reloadbalance(remain);
										ptTranacnt->reloadbalance(tranremain);
										CPrint3 print3dlg;
										print3dlg.DoModal();
										Ref ref;
										ref.Refresh(pCyrntAcnt->GetacntNo(),remain,amount,"转账");
									}
								}
							}
							else       //无此帐号
							{
								suggestdlg.m_suggest="帐号不存在";
							    suggestdlg.DoModal();
							}
						}
						else
						{
							CPassworderror passerrordlg;   //密码错误
                            passerrordlg.DoModal();
		                    enterpaswdlg.m_password="";    //重输密码
		                    enterpaswdlg.DoModal();
						}
					}
				}
				else   //两次帐号异
				{
					suggestdlg.m_suggest="您两次输入的帐号不一样";
					suggestdlg.DoModal();
				}
			}  
		}
	}break;
case IDC_OUT:   //转他行卡,和转本行操作差不多
	{	
	  CText textdlg;
	  if(textdlg.DoModal()==IDOK)
	  {
		CAccountno1 accountno1dlg;
		if(accountno1dlg.DoModal()==IDOK)
		{
			CAccountno2 accountno2dlg;
			if(accountno2dlg.DoModal()==IDOK)
			{
				if(accountno1dlg.m_accountno1==accountno2dlg.m_accountno2) //比较两次输入的帐号
				{
					CTranamount tranamountdlg;
					if(tranamountdlg.DoModal()==IDOK)
					{
						if(CurrentAcnt *pCyrntAcnt=CurrentAcnt::searchAccount(enterpaswdlg.m_password)) //搜寻检测用户密码
						{
							if(Exaccount *ptTranexacnt=Exaccount::searchtranAccount(accountno1dlg.m_accountno1))//搜索检测转帐帐号
							{								
								double remain=pCyrntAcnt->AcntBalan();
								double tranremain=ptTranexacnt->AcntBalan();
								double amount=tranamountdlg.m_tranamount;
								if(amount>50000)
								{
									suggestdlg.m_suggest="每天转帐限额五万元";
									suggestdlg.DoModal();
								}
								else
								{
									if(amount>remain)   //余额不足
									{
										suggestdlg.m_suggest="余额不足";
										suggestdlg.DoModal();
									}
									else  //交易成功
									{
										remain-=amount;
										tranremain+=amount;
										pCyrntAcnt->reloadbalance(remain-5);//5元手续费
										ptTranexacnt->reloadbalance(tranremain);
										CPrint3 print3dlg;
										print3dlg.DoModal();
										Ref ref;
										ref.Refresh(pCyrntAcnt->GetacntNo(),remain,amount,"转账");
										
									}
								}
								
							}
							else       //无此帐号
							{
								suggestdlg.m_suggest="帐号不存在";
							    suggestdlg.DoModal();
							}
						}
						else
						{
							CPassworderror passerrordlg;   //密码错误
                            passerrordlg.DoModal();
		                    enterpaswdlg.m_password="";    //重输密码
		                    enterpaswdlg.DoModal();
						}
					}
				}
				else   //两次帐号异
				{
					suggestdlg.m_suggest="您两次输入的帐号不一样";
					suggestdlg.DoModal();
				}
			}
		}
	  }
	}break;
default:break;		
}
}

void CATMDlg::OnSurrogate()  //代理业务
{
	// TODO: Add your control notification handler code here
	KillTimer(0);
	CSurrogate surrogatedlg;
	CSuggest suggestdlg;
	if(surrogatedlg.DoModal()==IDOK)
	{
	}



}

void CATMDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	CurrentAcnt::storageC();	
	CPhoneuser::storageP();
	Exaccount::storageE();
	CDialog::OnCancel();
	CEnd endlg;
	endlg.DoModal();
}

BOOL CATMDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	switch(pMsg->message)
	{
	case WM_KEYUP:SetTimer(0,15000,NULL);break;  //设置计时器,15秒无操作发出提示
	case WM_KEYDOWN:KillTimer(0);break;          //键盘操作,取消计时器
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

void CATMDlg::OnTimer(UINT nIDEvent)		
{
	// TODO: Add your message handler code here and/or call default
	Beep(1000,500);								//定时器
	KillTimer(0);
	CAlarm alarmdlg;
	alarmdlg.DoModal();
	
	CDialog::OnTimer(nIDEvent);
}



void CATMDlg::OnForaccount() 
{
	// TODO: Add your control notification handler code here
		NewAccount dlg;
		dlg.DoModal();
		CDialog::OnOK();
}

⌨️ 快捷键说明

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