📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "STUGRADE.h"
#include "MainFrm.h"
#include "DlgLogin.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
CMainFrame *pFrame; //!全局变量,这里应用m_pConnection!!!!
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_TOOL_STU, OnToolStu)
ON_COMMAND(ID_TOOL_SYS, OnToolSys)
ON_COMMAND(ID_TOOL_GRADE, OnToolGrade)
//}}AFX_MSG_MAP
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
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::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);
m_ImageList.Create(16,16,ILC_COLOR16|TRUE,2,2);
//m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON_baobao));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON_Open));
m_ImageListFORLIST.Create(16,16,ILC_COLOR16|TRUE,2,2);
m_ImageListFORLIST.Add(::AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageListFORLIST.Add(::AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImageListFORstu.Create(16,16,ILC_COLOR16|TRUE,2,2);
m_ImageListFORstu.Add(::AfxGetApp()->LoadIcon(IDI_ICON_Stu));
m_ImageListFORCent.Create(16,16,ILC_COLOR16|TRUE,2,2);
m_ImageListFORCent.Add(::AfxGetApp()->LoadIcon(IDI_ICON_Cent));
//数据库初始化
CDlgLogin dlg;
dlg.ConSQL=&ConSQL;
againlogin:
if (dlg.DoModal()==IDCANCEL)
exit(0);
// ConSQL = "driver={SQL Server};Server=hfx;DATABASE=StuGrade;UID=sa;PWD=604;";
HRESULT hr;
try{
hr = m_pConnection.CreateInstance(__uuidof( Connection )) ;
if (m_pConnection->State)
m_pConnection->Close();
ASSERT(!FAILED(hr));
if(SUCCEEDED(hr)) {
m_pConnection->ConnectionTimeout=5;
m_pConnection->Open((LPCSTR)ConSQL,"","",adModeUnknown);
// m_pConnection->Open("driver={SQL Server};Server=hfx;DATABASE=StuGrade;UID=sa;PWD=604;","","",adModeUnknown);
// m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stu.mdb","","",adModeUnknown);
}
}
catch(_com_error e)
{
CString errormessage;
CString errMsg = e.ErrorMessage();
if (errMsg.Right(5)=="#3149")
errormessage.Format("数据库连接超时!\r\n请检查用户名和密码!");
else
errormessage.Format("数据库连接超时!\r\n请检查数据库状态!\r\n数据连接错误:%s",e.ErrorMessage());
MessageBox(errormessage,"连接出错",MB_OK|MB_ICONERROR);///显示错误信息
goto againlogin;
}
hr = m_Rs.CreateInstance(__uuidof( Recordset ));
ASSERT(!FAILED(hr));
pFrame = this;
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;
// Set the position of the window to the upper -left corner.
// cs.x =cs. y =0;
//Set the width and height of the window .
// AfxMessageBox("dd");
cs. cx=700;
cs. cy=500;
return CFrameWnd::PreCreateWindow(cs);
// return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnToolGrade()
{
POSITION pos = pDocTemp1->GetFirstDocPosition();
if(pos) //检测有无打开过这个,有的话直接show 没有的话创建
{
CDocument *pDoc = pDocTemp1->GetNextDoc(pos);
pos = pDoc->GetFirstViewPosition();
::BringWindowToTop(pDoc->GetNextView(pos)->GetParentFrame()->m_hWnd);
}
else
pDocTemp1->OpenDocumentFile(NULL);
}
void CMainFrame::OnToolStu()
{
POSITION pos = pDocTemp2->GetFirstDocPosition();
if(pos) //检测有无打开过这个,有的话直接show 没有的话创建
{
CDocument *pDoc = pDocTemp2->GetNextDoc(pos); //直接show
pos = pDoc->GetFirstViewPosition();
::BringWindowToTop(pDoc->GetNextView(pos)->GetParentFrame()->m_hWnd);
}
else
pDocTemp2->OpenDocumentFile(NULL);
}
void CMainFrame::OnToolSys()
{
POSITION pos = pDocTemp3->GetFirstDocPosition();
if(pos)
{
CDocument *pDoc = pDocTemp3->GetNextDoc(pos);
pos = pDoc->GetFirstViewPosition();
::BringWindowToTop(pDoc->GetNextView(pos)->GetParentFrame()->m_hWnd);
}
else
pDocTemp3->OpenDocumentFile(NULL);
}
HRESULT CMainFrame::ExecSQL(CString szSQL)
{
HRESULT hr = m_pConnection->Execute((LPCSTR)szSQL,NULL,adExecuteNoRecords);
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -