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

📄 mainfrm.cpp

📁 个人理财系统(管理股票信息)
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "StockSystem.h"

#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(IDM_LICAI, OnLicai)
	ON_WM_CLOSE()
	ON_COMMAND(IDM_DB_SET, OnDbSet)
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_UPDATECONNECTSTR, updatConnectStr)

END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_pframe = NULL;
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
//	
//	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
//		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
//		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
//	{
//		TRACE0("Failed to create toolbar\n");
//		return -1;      // fail to create
//	}
//
//	if (!m_wndStatusBar.Create(this) ||
//		!m_wndStatusBar.SetIndicators(indicators,
//		  sizeof(indicators)/sizeof(UINT)))
//	{
//		TRACE0("Failed to create status bar\n");
//		return -1;      // fail to create
//	}
//
//	// TODO: Delete these three lines if you don't want the toolbar to
//	//  be dockable
//	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
//	EnableDocking(CBRS_ALIGN_ANY);
//	DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	//设置主框架的标题
	cs.style&=~FWS_ADDTOTITLE;
	cs.lpszName = "证券分析管理系统";
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if (m_pframe != NULL)	delete m_pframe;
	CFrameWnd::OnClose();
}

void CMainFrame::OnLicai() 
{
	//读取配置文件
	ReadConfig();
	connectStr.Format("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s",m_password,m_user,m_dbname);
	//进行连接数据库操作 
	CStockSystemApp *pApp = (CStockSystemApp *)AfxGetApp();
	//这里要先判断一下当前是否有用户存在,如果没用户才在的话,就要调用新建用户对话框
	pApp->m_pConnection.InitInstance();
	if (!pApp->m_pConnection.ConnectDb(connectStr))
	{
		MessageBox("连接数据库失败","提示");
		pApp->m_pConnection.m_connect.Release();
		return;
 	}
	//这里要先判断一下当前是否有用户存在,如果没用户才在的话,就要调用新建用户对话框

	
	//创建新页面
	if (!m_pframe)
	{
		m_pframe = new CPersonFrame(this);
		m_pframe->Create(NULL, _T("个人理财中心"), WS_OVERLAPPEDWINDOW ,
		rectDefault, NULL,  MAKEINTRESOURCE(IDR_MENU));
		m_pframe->ShowWindow(SW_SHOWMAXIMIZED);
	}
	else m_pframe->SetForegroundWindow();
}
void CMainFrame::OnDbSet() 
{
	dbconfig = new CDbConfig(this);
	dbconfig->DoModal();	
	delete dbconfig;
}

LONG CMainFrame::updatConnectStr(WPARAM wParam, LPARAM lParam)
{
	return 0;
}

void CMainFrame::ReadConfig()
{
	FILE	*fp_opt;
	int		i,j;	
	char	*p, *value;
	char buf[256];
	char	*temp[] = {
			"  ",
			"dbname",
			"user",
			"password",
			0
	};	
	memset(buf, 0, 256);
	//打开系统信息配置文件
	fp_opt = fopen("dbconf.conf", "r");
	if(fp_opt == NULL)
	{
		MessageBox("打开配置文件失败","提示");
		return;
	}
	while(fgets(buf, 256, fp_opt) != NULL)
	{
		if((buf[0] == '#') || strlen(buf) == 0 )
		{
			continue;
		}
		i=0;
		p = strtok(buf,"=");
		if(p == NULL)
		{
			continue;
		}
		for (j=1; j<4; j++)	
		{
			if (strncmp(p, temp[j],strlen(temp[j]))==0) 
			{
				i = j;
				break;
			}
		}
		value = strtok(0, "=");
		if ((value == NULL) || (!isascii(value[0]))) 
		{
			continue;
		}
		switch (i) 
		{
			case 1:
				m_dbname = value;
				break;
			case 2:
				m_user= value;
				break;
			case 3:
				m_password = value;
				break;
		} 
		memset(buf, 0, 256);
	}	
	fclose(fp_opt);
}

⌨️ 快捷键说明

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