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

📄 stmanagerdlg.cpp

📁 此系统为学生管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// stmanagerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "stmanager.h"
#include "stmanagerDlg.h"
#include "DlgStudent.h"//学生类对话框类头文件
#include "clist.h"//链表类头文件
#include "DlgSort.h"//排序对话框头文件
#include "DlgSearch.h"//查找对话框头文件
#include "DlgOutcome.h"//查询结果对话框头文件
#include "DlgStatistic.h"
#include "Splash.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
 clist link;//全局变量链表类对象

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

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

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

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

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

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()

/////////////////////////////////////////////////////////////////////////////
// CStmanagerDlg dialog

CStmanagerDlg::CStmanagerDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStmanagerDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStmanagerDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_index=-1;
}

void CStmanagerDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStmanagerDlg)
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStmanagerDlg, CDialog)
	//{{AFX_MSG_MAP(CStmanagerDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_INput, OnBUTTONINput)
	ON_BN_CLICKED(IDC_BUTTON_sort, OnBUTTONsort)
	ON_BN_CLICKED(IDC_BUTTON_delete, OnBUTTONdelete)
	ON_BN_CLICKED(IDC_BUTTON_deletelist, OnBUTTONdeletelist)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_BN_CLICKED(IDC_BUTTON_readfile, OnBUTTONreadfile)
	ON_BN_CLICKED(IDC_BUTTON_save, OnBUTTONsave)
	ON_BN_CLICKED(IDC_BUTTON_search, OnBUTTONsearch)
	ON_BN_CLICKED(IDC_BUTTON_Amend, OnBUTTONAmend)
	ON_BN_CLICKED(IDC_BUTTON_Statistic, OnBUTTONStatistic)
	ON_WM_CREATE()
	ON_WM_SETCURSOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStmanagerDlg message handlers

BOOL CStmanagerDlg::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
	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);//获得List控件所占范围的大小,	画网格
	CRect  rt;
	m_list.GetClientRect(&rt);
    m_list.SetBkColor(RGB(250,100,160));		//设置背景色
	m_list.SetTextColor(RGB(50,50,10)); 		//设置文本色
	m_list.SetTextBkColor(RGB(150,250,100));//设置文本背景色
	//设置列
	m_list.InsertColumn(0,"姓名",LVCFMT_LEFT,rt.right/7,0);
    m_list.InsertColumn(1,"性别",LVCFMT_LEFT,rt.right/7,1);
    m_list.InsertColumn(2,"学号",LVCFMT_LEFT,rt.right/7,2);
	m_list.InsertColumn(3,"专业",LVCFMT_LEFT,rt.right/7,3);
    m_list.InsertColumn(4,"数学成绩",LVCFMT_LEFT,rt.right/7,4);
    m_list.InsertColumn(5,"Cpp成绩",LVCFMT_LEFT,rt.right/7,5);
    m_list.InsertColumn(6,"英语成绩",LVCFMT_LEFT,rt.right/7,6);

 

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

void CStmanagerDlg::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.

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

//DEL void CStmanagerDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 	m_index=m_list.GetSelectionMark();
//DEL 	*pResult = 0;
//DEL }

void CStmanagerDlg::OnBUTTONINput() //添加节点
{
	// TODO: Add your control notification handler code here
	CDlgStudent add;//用来接收输入框中的学生信息
	if(add.DoModal()==IDCANCEL)//若是点了取消键就返回
		return ;
	int BOOL=0;//用来确定刚想添加的节点是否已经在链表中存在
    cstudent *note=link.head;
    cstudent *temp=NULL;
	char *name=add.m_name.GetBuffer(add.m_name.GetLength());//把CString转换为char*
	char *sex=add.m_sex.GetBuffer(add.m_sex.GetLength());
	char *number=add.m_number.GetBuffer(add.m_number.GetLength());
	char *major=add.m_major.GetBuffer(add.m_major.GetLength());
	while(note!=NULL)//用来检验链表中是否已存在该姓名或该学号的学生
	{    
         if( strcmp(note->getnumber(),number)==0)
		{
			BOOL++;
			AfxMessageBox("该学号的同学已存在");
			break;
		}
		 note=note->next;
    }
	if(BOOL==0)//若值还是0,说明链表里不存在该姓名或学号的同学
	{
		temp=new cstudent(name,sex,number,major,add.m_math,add.m_cpp,add.m_english);//创建学生点,添加到链表中去	
		if(add.m_addhead==0)//判断是加在表头还是表尾
			link.addhead(temp);
		else
			link.addtail(temp);
			if(add.m_addhead==1)
			{	
				int row=m_list.GetItemCount();//得到链表的长度
    			m_list.InsertItem(row,add.m_name);//添加在表尾
				m_list.SetItemText(row,1,add.m_sex);
				m_list.SetItemText(row,2,add.m_number);
				m_list.SetItemText(row,3,add.m_major);
				CString math,cpp,english;
				math.Format("%.1f",add.m_math);//double类型转换cstring
				m_list.SetItemText(row,4,math);
				cpp.Format("%.1f",add.m_cpp);
				m_list.SetItemText(row,5,cpp);
				english.Format("%.1f",add.m_english);
				m_list.SetItemText(row,6,english);
			}
			else
			{
				m_list.InsertItem(0,add.m_name);//自动
				m_list.SetItemText(0,1,add.m_sex);
				m_list.SetItemText(0,2,add.m_number);
				m_list.SetItemText(0,3,add.m_major);
				CString math,cpp,english;
				math.Format("%.1f",add.m_math);//double类型转换cstring
				m_list.SetItemText(0,4,math);
				cpp.Format("%.1f",add.m_cpp);
				m_list.SetItemText(0,5,cpp);
				english.Format("%.1f",add.m_english);
				m_list.SetItemText(0,6,english);
			}
	}
	else
		return;
      
	
}

void CStmanagerDlg::OnBUTTONsort()//排序 
{
	// TODO: Add your control notification handler code here
   if(link.head==NULL)
   {
	   MessageBox("抱歉,没有学生数据,不能排序");
       return;
   }
   CDlgSort sort;

⌨️ 快捷键说明

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