// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "test.h" #include "MainFrm.h" #include "LoginDlg.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(ID_LOGIN_IN, OnLoginIn) ON_UPDATE_COMMAND_UI(ID_Reader, OnUpdateReader) ON_UPDATE_COMMAND_UI(ID_LEND_OUT, OnUpdateLendOut) ON_UPDATE_COMMAND_UI(ID_LOGIN_OUT, OnUpdateLoginOut) ON_UPDATE_COMMAND_UI(ID_BOOK_MAINTAIN, OnUpdateBookMaintain) ON_UPDATE_COMMAND_UI(ID_RETRUN_BACK, OnUpdateRetrunBack) ON_UPDATE_COMMAND_UI(ID_USER_MAINTAIN, OnUpdateUserMaintain) ON_UPDATE_COMMAND_UI(ID_LOGIN_IN, OnUpdateLoginIn) ON_COMMAND(ID_LOGIN_OUT, OnLoginOut) ON_COMMAND(ID_BOOK_MAINTAIN, OnBookMaintain) ON_COMMAND(ID_USER_MAINTAIN, OnUserMaintain) ON_COMMAND(ID_LEND_OUT, OnLendOut) ON_COMMAND(ID_RETRUN_BACK, OnRetrunBack) ON_COMMAND(ID_Reader, OnReader) ON_COMMAND(ID_ReaderQry, OnReaderQry) //}}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 m_log = false; } 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; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs 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::OnLoginIn() { // TODO: Add your command handler code here CLoginDlg Dlg; //对话框对象 Dlg.DoModal(); if( Dlg.m_bLogin == true ) //单击了"登录"按钮 { m_log=Dlg.m_bLogin; //确定登录状态 m_name=Dlg.m_name; m_password=Dlg.m_password; m_which=Dlg.m_which; } } void CMainFrame::OnUpdateReader(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CString str="管理员"; int len=str.GetLength(); if(m_which.Left(len)!="管理员") pCmdUI->Enable(m_log); //非管理员则更新菜单状态可用 else pCmdUI->Enable(false); //更新菜单状态不可用 } void CMainFrame::OnUpdateLendOut(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CString str="管理员"; int len=str.GetLength(); if(m_which.Left(len)!="管理员") pCmdUI->Enable(false); //非管理员则更新菜单状态不可用 else pCmdUI->Enable(true); //菜单命令可用 } void CMainFrame::OnUpdateLoginOut(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(m_log); //更新菜单状态 } void CMainFrame::OnUpdateBookMaintain(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CString str="管理员"; int len=str.GetLength(); if(m_which.Left(len)!="管理员") pCmdUI->Enable(false); //非管理员则更新菜单状态不可用 else pCmdUI->Enable(true); //更新菜单状态可用 } void CMainFrame::OnUpdateRetrunBack(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CString str="管理员"; int len=str.GetLength(); if(m_which.Left(len)!="管理员") pCmdUI->Enable(false); //非管理员则更新菜单状态不可用 else pCmdUI->Enable(true); //更新菜单状态可用 } void CMainFrame::OnUpdateUserMaintain(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CString str="管理员"; int len=str.GetLength(); if(m_which.Left(len)!="管理员") pCmdUI->Enable(false); //非管理员则更新菜单状态不可用 else pCmdUI->Enable(true); } void CMainFrame::OnUpdateLoginIn(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(!m_log); //登录后则更新"登录"命令不可用 } void CMainFrame::OnLoginOut() { // TODO: Add your command handler code here m_which="error"; m_log=false; //退出后,则m_log为false } void CMainFrame::OnBookMaintain() { // TODO: Add your command handler code here CbookDlg dlg; dlg.DoModal(); //弹出对话框 } void CMainFrame::OnUserMaintain() { // TODO: Add your command handler code here CReaderDlg dlg; dlg.DoModal(); //显示对话框 } void CMainFrame::OnLendOut() { // TODO: Add your command handler code here CBookReadDlg dlg; dlg.DoModal(); //显示对话框 } void CMainFrame::OnRetrunBack() { // TODO: Add your command handler code here CBookRDlg dlg; dlg.DoModal(); //显示对话框 } void CMainFrame::OnReader() { // TODO: Add your command handler code here CUserInfoDlg dlg; dlg.DoModal(); } void CMainFrame::OnReaderQry() { // TODO: Add your command handler code here CQryDlg dlg; dlg.DoModal(); //显示对话框 }