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

📄 personframe.cpp

📁 个人理财系统(管理股票信息)
💻 CPP
字号:
// PersonFrame.cpp : implementation file
//

#include "stdafx.h"
#include "stocksystem.h"
#include "PersonFrame.h"


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

/////////////////////////////////////////////////////////////////////////////
// CPersonFrame

IMPLEMENT_DYNCREATE(CPersonFrame, CFrameWnd)

CPersonFrame::CPersonFrame()
{
}
CPersonFrame::CPersonFrame(CMainFrame *the_main)
{
	paint_times			= 1;			//
	m_pmain_frame		= the_main;		//
	
}

CPersonFrame::~CPersonFrame()
{
	m_pmain_frame->m_pframe = NULL;
	CStockSystemApp *pApp	= (CStockSystemApp *)AfxGetApp();
	//情况vector,这样下次登陆的时候用户列表就不会多出来 
	pApp->UserInfoVect.clear();
}

BEGIN_MESSAGE_MAP(CPersonFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CPersonFrame)
	ON_COMMAND(IDM_LOGIN, OnLogin)
	ON_COMMAND(IDM_AMEND_ACCOUNT, OnAmendAccount)
	ON_COMMAND(IDM_AMEND_PWD, OnAmendPwd)
	ON_COMMAND(IDM_BUY_STOCK, OnBuyStock)
	ON_COMMAND(IDM_GIVE_STOCK, OnGiveStock)
	ON_COMMAND(IDM_LIUSHUIZHANG, OnLiushuizhang)
	ON_COMMAND(IDM_MAKE_STOCK, OnMakeStock)
	ON_COMMAND(IDM_SELL_STOCK, OnSellStock)
	ON_COMMAND(IDM_ADD_ACCOUNT, OnAddAccount)
	ON_COMMAND(IDM_DEL_ACCOUNT, OnDelAccount)
	ON_COMMAND(IDM_CLOSE_ACCOUNT, OnCloseAccount)
	ON_COMMAND(IDM_DEL_INFO, OnDelInfo)
	ON_COMMAND(IDM_DEAL_DETAIL, OnDealDetail)
	ON_COMMAND(IDM_MELON_CUTTING, OnMelonCutting)
	ON_COMMAND(IDM_EXIT_LICAI, OnExitLicai)
	ON_COMMAND(IDM_PARAMETER_SET, OnParameterSet)
	ON_COMMAND(IDM_INVEST_ANALYSIS, OnInvestAnalysis)
	ON_COMMAND(IDT_MARKET_REFURBISH, OnMarketRefurbish)
	ON_COMMAND(IDM_ADD_MONEY, OnAddMoney)
	ON_COMMAND(IDM_LAYOFF_MONEY, OnLayoffMoney)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_SHOWINPUTPWDDLG, showInputPwdDlg)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPersonFrame message handlers

void CPersonFrame::OnLogin() 
{
	CString				currentuser;
	UserInfo			user_info;
	CStockSystemApp *pApp		= (CStockSystemApp *)AfxGetApp();
	CAccountTreeView *theTree	= (CAccountTreeView *)m_splitterwnd.GetPane(0,0);
	theTree->GetCurrentUser(currentuser);
	int len = pApp->UserInfoVect.size();
  	//判断用户是否已经登陆了
	for (int i=0; i<len; i++)
	{
		user_info = pApp->UserInfoVect[i];
		if (user_info.username == currentuser)
		{
			//如果用户已经登陆了,返回
			if (user_info.loginstate == "1")
			{
				return;
			}
			//跳出输入密码的提示框
			else
			{
				m_pinput_pwd = new CInputPwd(this);
				m_pinput_pwd->SetDlgTitle(currentuser);
				m_pinput_pwd->DoModal();	
				delete m_pinput_pwd;
			}
		}
	}	
}
/************************************************************************/
/* 修改帐户                                                             */
/************************************************************************/
void CPersonFrame::OnAmendAccount() 
{
	// TODO: Add your command handler code here
	if (IsCurrentAccountLogin())
	{
		amend_account.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}
/************************************************************************/
/* 修改密码                                                             */
/************************************************************************/
void CPersonFrame::OnAmendPwd() 
{
	if (IsCurrentAccountLogin())
	{
		amend_pwd.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}	
}
/************************************************************************/
/* 买入股票                                                             */
/************************************************************************/
void CPersonFrame::OnBuyStock() 
{
	if (IsCurrentAccountLogin())
	{
		buy_stock.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
 	}
}
/************************************************************************/
/* 送股                                                                 */
/************************************************************************/
void CPersonFrame::OnGiveStock() 
{
	if (IsCurrentAccountLogin())
	{
		give_stock.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}	
}
/************************************************************************/
/* 流水账                                                               */
/************************************************************************/
void CPersonFrame::OnLiushuizhang() 
{
	if (IsCurrentAccountLogin())
	{
		liushuizhang.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}	
}
/************************************************************************/
/* 配股                                                                 */
/************************************************************************/
void CPersonFrame::OnMakeStock() 
{
	if (IsCurrentAccountLogin())
	{
		make_stock.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}
/************************************************************************/
/* 卖出股票                                                             */
/************************************************************************/
void CPersonFrame::OnSellStock() 
{
	if (IsCurrentAccountLogin())
	{
		sell_stock.DoModal();	
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
	
}
/************************************************************************/
/* 新建帐户                                                             */
/************************************************************************/
void CPersonFrame::OnAddAccount() 
{
	// TODO: Add your command handler code here
	addaccount.DoModal();
}
/************************************************************************/
/* 删除帐户                                                             */
/************************************************************************/
void CPersonFrame::OnDelAccount() 
{
	CString				msg;
	CString				currentuser;
	
	CStockSystemApp *pApp	= (CStockSystemApp *)AfxGetApp();
	CAccountTreeView *theTree	= (CAccountTreeView *)m_splitterwnd.GetPane(0,0);
	theTree->GetCurrentUser(currentuser);
	msg.Format("确认要删除[%s]账户吗?",currentuser);
	//判断用户是否要删除
	if ( IDYES == MessageBox(msg, "提示", MB_ICONEXCLAMATION | MB_YESNO) )
	{
		//删除结构体中的相应用户信息
		vector<UserInfo>::iterator it;
		it = pApp->UserInfoVect.begin();
		while (it != pApp->UserInfoVect.end())
		{
			if (it->username == currentuser) {
				pApp->UserInfoVect.erase(it);
				break;
			}
			it++;
		}
		//进行删除操作
		if (!pApp->m_pConnection.DlelteAccount(currentuser))
		{
			MessageBox("删除失败","提示");
		}		
		//删除树控件上对应的用户名
		CString				bufstr = "删除账户";
		this->m_splitterwnd.GetPane(0,0)->SendMessage(WM_UPDATETREE, \
				(WPARAM)&bufstr, 0);						
	}
}
/************************************************************************/
/*关闭帐户                                                              */
/************************************************************************/
void CPersonFrame::OnCloseAccount() 
{
	//发送消息给树控件,改变图标的样子
	CString str = "关闭帐户";
	this->m_splitterwnd.GetPane(0,0)->SendMessage(WM_UPDATETREE, \
 					(WPARAM)&str, NULL);
	//设置要关闭账户的登陆状态为0 ,表示未登陆
	CString				currentuser;
	UserInfo			user_info;
	CStockSystemApp *pApp		= (CStockSystemApp *)AfxGetApp();
	CAccountTreeView *theTree	= (CAccountTreeView *)m_splitterwnd.GetPane(0,0);
	theTree->GetCurrentUser(currentuser);
	int len = pApp->UserInfoVect.size();
	for (int i=0; i<len; i++)
	{
		user_info = pApp->UserInfoVect[i];
		if (user_info.username == currentuser)
		{
			//设置为 0 
			pApp->UserInfoVect[i].loginstate = "0";
		}
	}
}
/************************************************************************/
/*删除记录                                                              */
/************************************************************************/
void CPersonFrame::OnDelInfo() 
{
	MessageBox("删除记录");
}
/************************************************************************/
/* 交易明细                                                             */
/************************************************************************/
void CPersonFrame::OnDealDetail() 
{
	if (IsCurrentAccountLogin())
	{	
		dealdetail.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}
/************************************************************************/
/* 股票分红                                                             */
/************************************************************************/
void CPersonFrame::OnMelonCutting() 
{
	if (IsCurrentAccountLogin())
	{
		melon_cutting.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}

}
/************************************************************************/
/* 追加资金                                                             */
/************************************************************************/
void CPersonFrame::OnAddMoney() 
{
	if (IsCurrentAccountLogin())
	{
		addmoney.DoModal();	
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}
/************************************************************************/
/* 划出资金                                                             */
/************************************************************************/
void CPersonFrame::OnLayoffMoney() 
{
	if (IsCurrentAccountLogin())
	{
		layoutmoney.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}

BOOL CPersonFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{	
	//分割窗口
	m_splitterwnd.CreateStatic(this, 1, 2);
	m_splitterwnd.CreateView(0,0, RUNTIME_CLASS(CAccountTreeView), CSize(120, 300),pContext);
	m_splitterwnd.CreateView(0,1, RUNTIME_CLASS(CMyListView), CSize(0, 60), pContext);
	//创建工具栏
	m_tool_bar.Create(this);
	m_tool_bar.LoadToolBar(IDR_TOOLBAR);
	m_tool_bar.ShowWindow(SW_SHOW);
    m_tool_bar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
	//导入用户列表
	GetUserInfo();
	return TRUE;
}
/************************************************************************/
/* 退出个人理财                                                         */
/************************************************************************/
void CPersonFrame::OnExitLicai() 
{
//	CFrameWnd::OnClose();
}
/************************************************************************/
/* 参数设置                                                             */
/************************************************************************/
void CPersonFrame::OnParameterSet() 
{
	parameter_set.DoModal();
}
/************************************************************************/
/* 投资分析                                                             */
/************************************************************************/
void CPersonFrame::OnInvestAnalysis() 
{
	if (IsCurrentAccountLogin())
	{
		invest_analysis.DoModal();
	}
	else
	{
		MessageBox("帐户还未登录,不能进行操作","错误");
		return;
	}
}

LONG CPersonFrame::showInputPwdDlg(WPARAM wParam, LPARAM lParam)
{
	m_pinput_pwd = new CInputPwd(this);
//	CInputPwd m_pinput_pwd(this);
	CString *pstr = (CString *)wParam;
	m_pinput_pwd->SetDlgTitle(*pstr);
 	m_pinput_pwd->DoModal();	
	delete m_pinput_pwd;
	return 0;
}

void CPersonFrame::GetUserInfo()
{
	UserInfo        userinfo;
	CString			command;
	int				i;	
	command = "select * from tb_account";
	CStockSystemApp *pApp	= (CStockSystemApp *)AfxGetApp();
	int state = pApp->m_pConnection.GetRecordSet(command, record);
 	//数据库里面没有用户
 	if(state == 2)
 	{
 		MessageBox("没有用户,是否创建用户","提示");
 		//跳出创建用户窗口
 		addaccount.DoModal();
 	}
 	else if (state == 0) {
		MessageBox("SQL语句执行错误","提示");
	}
	//读取数据库信息,并在树型空间中列出用户类表
	else
	{
		i = 0;
		while (!record.IsEof())
		{
			record.GetValue("name", userinfo.username);
			record.GetValue("password", userinfo.userpwd);
			record.GetValue("deal_type", userinfo.dealtype);
			record.GetValue("balance", userinfo.balance);
		//	record.GetValue("remark", userinfo.remark);
			userinfo.loginstate = "0";					// 0 表示未登录 
			pApp->UserInfoVect.push_back(userinfo);
			record.MoveNext();
		}
		int len = pApp->UserInfoVect.size();
		//一个循环,把所有的用户发给树形控件
		for (i = 0; i < len; i++)
		{
			userinfo = pApp->UserInfoVect[i];
			this->m_splitterwnd.GetPane(0,0)->SendMessage(WM_UPDATETREE, \
				(WPARAM)&userinfo.username, NULL);
		}
		//currentuser = pApp->UserInfoVect[0].username;
	}
}
//判断但前用户是否登陆,1为登陆了,0表示未登陆
int CPersonFrame::IsCurrentAccountLogin()
{
	CStockSystemApp *pApp	= (CStockSystemApp *)AfxGetApp();	
	CAccountTreeView *theTree	= (CAccountTreeView *)m_splitterwnd.GetPane(0,0);
	theTree->GetCurrentUser(currentuser);
	int len = pApp->UserInfoVect.size();
	for (int i=0; i<len; i++)
	{		
		pApp->UserInfoVect[i];
		if (pApp->UserInfoVect[i].username == currentuser)
		{
			//表示当前用户已经登陆,可以进行修改账户操作
			if (pApp->UserInfoVect[i].loginstate == "1")
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
	}
	return 1;
}

void CPersonFrame::OnMarketRefurbish() 
{

}

⌨️ 快捷键说明

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