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

📄 datamanagerlastdlg.cpp

📁 纯C++语言编写的小型的学生管理系统 用二叉树实现学生相关属性包括姓名,年龄,房间号的保存,使显示按学号降序排列,并能够保存成文件.
💻 CPP
字号:
// DataManagerLastDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DataManagerLast.h"
#include "DataManagerLastDlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CDataManagerLastDlg dialog

CDataManagerLastDlg::CDataManagerLastDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDataManagerLastDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDataManagerLastDlg)
	m_name = _T("");
	m_phone = _T("");
	m_post = _T("");
	m_searchname = _T("");
	m_address = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_count = 1;
	m_addflag = 0;
	m_modifyflag = 0;

	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDataManagerLastDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDataManagerLastDlg)
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_Text(pDX, IDC_PHONE, m_phone);
	DDX_Text(pDX, IDC_POST, m_post);
	DDX_Text(pDX, IDC_SEARCHNAME, m_searchname);
	DDX_Text(pDX, IDC_ADDRESS, m_address);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDataManagerLastDlg, CDialog)
	//{{AFX_MSG_MAP(CDataManagerLastDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_FIRSTPAGE, OnFirstpage)
	ON_BN_CLICKED(IDC_PRIORPAGE, OnPriorpage)
	ON_BN_CLICKED(IDC_NEXTPAGE, OnNextpage)
	ON_BN_CLICKED(IDC_LASTPAGE, OnLastpage)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	ON_BN_CLICKED(IDC_MODIFY, OnModify)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDataManagerLastDlg message handlers

BOOL CDataManagerLastDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	
	GetDlgItem(IDC_NAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_PHONE)->EnableWindow(FALSE);
	GetDlgItem(IDC_POST)->EnableWindow(FALSE);
	GetDlgItem(IDC_ADDRESS)->EnableWindow(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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.

void CDataManagerLastDlg::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.
HCURSOR CDataManagerLastDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDataManagerLastDlg::OnFirstpage() 
{
	DuLinkList p;

	p = (DuLinkList)malloc(sizeof(DuLNode));
	p = m_controller.Get_DuLFirst();
	m_name = p->data->name;
	m_phone = p->data->phone;
	m_post = p->data->postcode;
	m_address = p->data->address;

	m_count = 1;
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here
}

void CDataManagerLastDlg::OnPriorpage() 
{
	DuLinkList p;
	p = (DuLinkList)malloc(sizeof(DuLNode));
	p = m_controller.ListPrior_Dul(m_count);
	m_name = p->data->name;
	m_phone = p->data->phone;
	m_post = p->data->postcode;
	m_address = p->data->address;

	m_count--;
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here
	
}

void CDataManagerLastDlg::OnNextpage() 
{
	DuLinkList p;

	p = (DuLinkList)malloc(sizeof(DuLNode));
	p = m_controller.ListNext_Dul(m_count);
	m_name = p->data->name;
	m_phone = p->data->phone;
	m_post = p->data->postcode;
	m_address = p->data->address;

	m_count++;
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here
}

void CDataManagerLastDlg::OnLastpage() 
{
	DuLinkList p;

	p = (DuLinkList)malloc(sizeof(DuLNode));
	p = m_controller.Get_DuLLast();
	m_name = p->data->name;
	m_phone = p->data->phone;
	m_post = p->data->postcode;
	m_address = p->data->address;

	m_count = m_controller.ListLength_Dul();
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here
	
}

void CDataManagerLastDlg::OnAdd() 
{
	m_addflag = 1 - m_addflag;

	if(1 == m_addflag)
	{
		m_name = _T("");
		m_phone = _T("");
		m_post = _T("");
		m_address = _T("");

		GetDlgItem(IDC_NAME)->EnableWindow(TRUE);//改变编辑框的编辑属性
		GetDlgItem(IDC_PHONE)->EnableWindow(TRUE);
		GetDlgItem(IDC_POST)->EnableWindow(TRUE);
		GetDlgItem(IDC_ADDRESS)->EnableWindow(TRUE);

		UpdateData(FALSE);
	}

	if(0 == m_addflag)
	{
		UpdateData();

		if(m_name == _T("") || m_phone == _T("") || m_post == _T("") ||
			m_address == _T(""))
		{
			AfxMessageBox("请完整输入相关信息");
			m_addflag = 1 - m_addflag;
		}

		else
		{

			Person e;
			e = (Person)malloc(sizeof(personentity));

			strcpy(e->address, m_address.GetBuffer(50));
			strcpy(e->name, m_name.GetBuffer(50));
			strcpy(e->postcode, m_post.GetBuffer(50));
			strcpy(e->phone, m_phone.GetBuffer(50));

			m_controller.ListInsert_DuL(m_count, e);
			m_count++;

			AfxMessageBox("已经成功输入");

			GetDlgItem(IDC_NAME)->EnableWindow(FALSE);
			GetDlgItem(IDC_PHONE)->EnableWindow(FALSE);
			GetDlgItem(IDC_POST)->EnableWindow(FALSE);
			GetDlgItem(IDC_ADDRESS)->EnableWindow(FALSE);
		}
	}
	// TODO: Add your control notification handler code here	
}

void CDataManagerLastDlg::OnDel() 
{
	if(m_controller.ListDelete_DuL(m_count))
	{
		AfxMessageBox("删除成功");
		m_count++;
	}
	UpdateData(FALSE);
	
	// TODO: Add your control notification handler code here
}

void CDataManagerLastDlg::OnModify() 
{
	m_modifyflag = 1 - m_modifyflag;

	if(1 == m_modifyflag)
	{
		GetDlgItem(IDC_NAME)->EnableWindow(TRUE);
		GetDlgItem(IDC_PHONE)->EnableWindow(TRUE);
		GetDlgItem(IDC_POST)->EnableWindow(TRUE);
		GetDlgItem(IDC_ADDRESS)->EnableWindow(TRUE);
	}

	if(0 == m_modifyflag)
	{
		UpdateData();//保存原来编辑框的信息

		if(m_name == _T("") || m_phone == _T("") || m_post == _T("") ||
			m_address == _T(""))
		{
			AfxMessageBox("请完整输入相关信息");
			m_modifyflag = 1 - m_modifyflag;
		}
		else
		{
			Person e;
			e = (Person)malloc(sizeof(personentity));

			strcpy(e->address, m_address.GetBuffer(50));
			strcpy(e->name, m_name.GetBuffer(50));
			strcpy(e->postcode, m_post.GetBuffer(50));
			strcpy(e->phone, m_phone.GetBuffer(50));

			m_controller.ListModify_Dul(m_count-1, e);

			AfxMessageBox("修改成功");

			GetDlgItem(IDC_NAME)->EnableWindow(FALSE);
			GetDlgItem(IDC_PHONE)->EnableWindow(FALSE);
			GetDlgItem(IDC_POST)->EnableWindow(FALSE);
			GetDlgItem(IDC_ADDRESS)->EnableWindow(FALSE);
		}

	}
	UpdateData(FALSE);
	// TODO: Add your control notification handler code here	
}


void CDataManagerLastDlg::OnSearch() 
{
	DuLinkList p;
	p = (DuLinkList)malloc(sizeof(DuLNode));

	UpdateData();
	if(_T("") == m_searchname )
	{
		AfxMessageBox("请输入搜索信息");
	}
	else
	{
		p = m_controller.ListFind_Dul(m_searchname.GetBuffer(50));
		if(!p)
		{
			  AfxMessageBox("can't find this name");
		}
		else
		{
			m_name = p->data->name;
			m_phone = p->data->phone;
			m_post = p->data->postcode;
			m_address = p->data->address;
			UpdateData(FALSE);
		}
	}
	// TODO: Add your control notification handler code here
}

⌨️ 快捷键说明

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