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

📄 smdlg.cpp

📁 课程设计的简单Access学生数据库系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SMDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SM.h"
#include "SMDlg.h"
#include "unitdlg.h"
#include "classdlg.h"
#include "studentdlg.h"
#include "student.h"
#include "studentlist.h"
#include "TeachingDlg.h"
#include "teacherlistdlg.h"
#include "subject.h"
#include "subjectlistDlg.h"
#include "ScoreDlg.h"
#include "SearchDlg.h"
#include "CountClassAvgDlg.h"
#include "AvgSubjectDlg.h"
#include "ScoreQuery.h"
#include "AccountDlg.h"
#include "LogDlg.h"
#include "UpdownDlg.h"
#include "logdlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

//##ModelId=40A481F802FD
class CAboutDlg : public CDialog
{
public:
	//##ModelId=40A481F8030D
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	//##ModelId=40A481F8031C
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//##ModelId=40A481F8030D
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

//##ModelId=40A481F8031C
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()

/////////////////////////////////////////////////////////////////////////////
// CSMDlg dialog

//##ModelId=40A481F30271
CSMDlg::CSMDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSMDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSMDlg)
	m_ClassName = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

//##ModelId=40A481F302A1
void CSMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSMDlg)
	DDX_Control(pDX, IDC_LIST, m_List);
	DDX_Control(pDX, IDC_UNITTREE, m_Tree);
	DDX_Text(pDX, IDC_CLASS, m_ClassName);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSMDlg, CDialog)
	//{{AFX_MSG_MAP(CSMDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CANCELMODE()
	ON_WM_CAPTURECHANGED()
	ON_WM_CHAR()
	ON_COMMAND(ID_VIEW_UNIT, OnViewUnit)
	ON_COMMAND(ID_DELETE_UNIT, OnDeleteUnit)
	ON_COMMAND(ID_NEW_CLASS, OnNewClass)
	ON_COMMAND(ID_VIEW_CLASS, OnViewClass)
	ON_COMMAND(ID_EDIT_CLASS, OnEditClass)
	ON_COMMAND(ID_DELETE_CLASS, OnDeleteClass)
	ON_NOTIFY(TVN_SELCHANGED, IDC_UNITTREE, OnSelchangedUnittree)
	ON_NOTIFY(NM_CLICK, IDC_UNITTREE, OnClickUnittree)
	ON_COMMAND(ID_DELETE_STUDENT, OnDeleteStudent)
	ON_COMMAND(ID_NEW_STUDENT, OnNewStudent)
	ON_COMMAND(ID_VIEW_STUDENT, OnViewStudent)
	ON_COMMAND(ID_EDIT_STUDENT, OnEditStudent)
	ON_COMMAND(ID_NEW_UNIT, OnNewUnit)
	ON_COMMAND(ID_EDIT_UNIT, OnEditUnit)
	ON_COMMAND(ID_FIND_CLASS, OnFindClass)
	ON_COMMAND(ID_FIND_STUDENT, OnFindStudent)
	ON_COMMAND(ID_FIND_UNIT, OnFindUnit)
	ON_COMMAND(ID_EXIT, OnExit)
	ON_COMMAND(ID_SUBJECT, OnSubject)
	ON_COMMAND(ID_TEACHER, OnTeacher)
	ON_COMMAND(ID_TEACHING, OnTeaching)
	ON_COMMAND(ID_UPDOWN, OnUpdown)
	ON_COMMAND(ID_ABOUT, OnAbout)
	ON_COMMAND(ID_ACCOUNT, OnAccount)
	ON_COMMAND(ID_AVG_CLASS, OnAvgClass)
	ON_COMMAND(ID_AVG_SUBJECT, OnAvgSubject)
	ON_COMMAND(ID_LOGOUT, OnLogout)
	ON_COMMAND(ID_LOGIN, OnLogin)
	ON_COMMAND(ID_SCORE, OnScore)
	ON_COMMAND(ID_PRINT_SCORE, OnPrintScore)
	ON_NOTIFY(NM_RCLICK, IDC_UNITTREE, OnRclickUnittree)
	ON_COMMAND(ID_EDIT_UNIT, OnViewUnit)
	ON_COMMAND(ID_DELETE_UNIT, OnDeleteUnit)
	ON_COMMAND(ID_VIEW_UNIT, OnViewUnit)
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMDlg message handlers

//##ModelId=40A481F302CE
BOOL CSMDlg::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
	AfxGetModuleState()->m_dwVersion = 0x0601;//使用ACESS2000数据库
	CString dbName;
	dbName.LoadString(IDS_DATABASENAME);
	try
	{
		theDatabase.Open(dbName, false, false) ;
	/*	{
			CDaoTableDef td(&theDatabase);
			td.Open("unit");
			CDaoRecordset rs;
			rs.Open(&td);
			rs.AddNew();
			rs.SetFieldValue("ID",COleVariant(1L));
			rs.SetFieldValue("unit","root");
			rs.SetFieldValue("superior_id",COleVariant(-1L));
			rs.Update();
			rs.Close();
			td.Close();
		}  */
		pUnitClassTree = new UnitClassTree(&m_Tree);
		pList = new StudentList(&m_List);
		pList->Init();
		pUnitClassTree->Load();
		pUnitClassTree->SetSelectUnit(1);
		m_Tree.Expand(m_Tree.GetRootItem(), TVE_EXPAND);
		UnitMenu.LoadMenu(IDR_UNIT_POP_MENU);
		CLogDlg dlg;
		dlg.DoModal();
		
	//	HTREEITEM item = m_Tree.GetParentItem(m_Tree.GetSelectedItem());
	}
	catch(CDaoException *e)
	{
		DisplayDaoException(e);
		DestroyWindow();
	}
	catch(CException *e)
	{
		DisplayException(e);
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

//##ModelId=40A481F302DE
void CSMDlg::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.

//##ModelId=40A481F302EE
void CSMDlg::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.
//##ModelId=40A481F302FD
HCURSOR CSMDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//##ModelId=40A481F3029F
BOOL CSMDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	delete pUnitClassTree;
	delete pList;
	theDatabase.Close();
	return CDialog::DestroyWindow();
}


//##ModelId=40A481F302FF
void CSMDlg::OnCancelMode() 
{
	CDialog::OnCancelMode();
	
}

//##ModelId=40A481F3030D
void CSMDlg::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	
	CDialog::OnCaptureChanged(pWnd);
}

//##ModelId=40A481F3031C
void CSMDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnChar(nChar, nRepCnt, nFlags);
}

//##ModelId=40A481F3033C
void CSMDlg::OnViewUnit() 
{
	// TODO: Add your command handler code here
	CUnitDlg dlg(&(pUnitClassTree->GetSelectUnit()));
	try
	{
		int r = dlg.DoModal();
		if(r)
		{
			pUnitClassTree->ReLoad();
			pUnitClassTree->SetSelectUnit(r);
		}
	}
	catch(CException *e)
	{
		DisplayException(e);
	}
}

//##ModelId=40A481F3033E
void CSMDlg::OnDeleteUnit() 
{
	try
	{
		if(pUnitClassTree->GetSelectUnit().ID==1)
		{
			AfxMessageBox("不能删除学校名称!!");
			return ;
		}
		if(IDOK==AfxMessageBox("将删除所有相关的班级学生成绩记录, 慎重!", MB_OKCANCEL   ))
		{
			long id = pUnitClassTree->GetParent(pUnitClassTree->GetSelectUnit().ID);
			CDaoTableDef td(&theDatabase);
			td.Open(_T("unit"));
			CDaoRecordset RS;
			RS.Open(&td);
			pUnitClassTree->GetSelectUnit().DeleteAssociate(&RS);
			pUnitClassTree->GetSelectUnit().Delete(&RS);
			RS.Close();
			td.Close();
			pUnitClassTree->ReLoad();
			pUnitClassTree->SetSelectUnit(id);
		}
	}
	catch(CException *e)
	{
		DisplayException(e);
	}
}

//##ModelId=40A481F3034B
void CSMDlg::OnNewClass() 
{
	try
	{
		CClassDlg dlg;
		long id;
		if(id=dlg.DoModal())
			pUnitClassTree->NewClass(id);
	}
	catch(CException *e)
	{
		DisplayException(e);
	}
}

//##ModelId=40A481F3035B
void CSMDlg::OnViewClass() 
{
	try
	{
		if(!pUnitClassTree->GetSelectType())//is Unit

⌨️ 快捷键说明

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