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

📄 performance6dlg.cpp

📁 文件包含了很多VC实例
💻 CPP
字号:
// performance6Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "performance6.h"
#include "performance6Dlg.h"

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CPerformance6Dlg dialog

CPerformance6Dlg::CPerformance6Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPerformance6Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPerformance6Dlg)
	m_listEdit = _T("高三(1)班");
	m_nChinese = 0;
	m_nEnglish = 0;
	m_nMath = 0;
	m_strName = _T("");
	m_nPosition = 0;
	m_strStuinfo = _T("");
	m_nTotalPoints = 0;
	m_day = 0;
	m_SelectDay = 0 ;
	m_bSex = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPerformance6Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPerformance6Dlg)
	DDX_CBString(pDX, IDC_COMBO_CLASSGRADE, m_listEdit);
	DDX_Text(pDX, IDC_EDIT_CHINESE, m_nChinese);
	DDV_MinMaxInt(pDX, m_nChinese, 0, 100);
	DDX_Text(pDX, IDC_EDIT_ENGLISH, m_nEnglish);
	DDV_MinMaxInt(pDX, m_nEnglish, 0, 100);
	DDX_Text(pDX, IDC_EDIT_MATH, m_nMath);
	DDV_MinMaxInt(pDX, m_nMath, 0, 100);
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDV_MaxChars(pDX, m_strName, 10);
	DDX_Text(pDX, IDC_EDIT_POSITION, m_nPosition);
	DDX_Text(pDX, IDC_EDIT_STUINFO, m_strStuinfo);
	DDX_Text(pDX, IDC_EDIT_TOTALPOINTS, m_nTotalPoints);
	DDV_MinMaxInt(pDX, m_nTotalPoints, 0, 300);
	DDX_MonthCalCtrl(pDX, IDC_MONTHCALENDAR1, m_day);
	DDX_Radio(pDX, IDC_RADIO1, m_bSex);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPerformance6Dlg, CDialog)
	//{{AFX_MSG_MAP(CPerformance6Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOK, OnReg)
	ON_NOTIFY(MCN_SELECT, IDC_MONTHCALENDAR1, OnSelectMonthcalendar1)
	ON_BN_CLICKED(IDC_BUTTON2, OnDel)
	ON_BN_CLICKED(IDC_BUTTON1, OnEditInfo)
	ON_BN_CLICKED(IDC_BUTTON3, OnSort)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPerformance6Dlg message handlers

BOOL CPerformance6Dlg::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);
		}
	}
	CTime CurrentTime=CTime::GetCurrentTime(); 
	m_day = CurrentTime;
	m_SelectDay = m_day;
	UpdateData(FALSE);
	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CPerformance6Dlg::OnReg() 
{
	bool hasStudent = false ;
	UpdateData(TRUE);
	CStudentInfo temp(m_strName,m_bSex,m_listEdit,
		m_nChinese,m_nMath,m_nEnglish,m_SelectDay);
	for( int i = 0 ; i < vecStudents.size() ; i++ )
	{
		if(vecStudents[i].GetName() == m_strName)
		{
			hasStudent = true ;
		}
	}
	if(!hasStudent)
	{
		int sortNO = 1 ;
		for( i = 0 ; i < vecStudents.size() ; i++ )
		{
			if(vecStudents[i].getTotal()>temp.getTotal())
			{
				sortNO++ ;
			}
		}
		vecStudents.push_back(temp);
		m_nTotalPoints = m_nChinese + m_nMath + m_nEnglish;
		m_nPosition = sortNO ;
		m_strStuinfo = pack(vecStudents);
		m_day = m_SelectDay;
		UpdateData(FALSE);
	}
}

CString CPerformance6Dlg::pack(std::vector<CStudentInfo>& vec)
{
	CString str = "" ;
	str = "  姓名    性别  班级    语文  数学  英语  总分  名次  登记日期  " ;
	CString temp;
	
	for( int i = 0 ; i < vec.size() ; i++ )
	{
		str += "\r\n  ";
		str += vec[i].GetName();
		if(vec[i].GetSex())
		{
			temp = "  女  ";
		}
		else
		{
			temp = "  男  ";
		}
		str += temp + "  " ;
		str += vec[i].GetClassGrade() ;
		temp.Format("  %d    %d    %d    %d",vec[i].GetChinese(),vec[i].GetMath(),vec[i].GetEnglish(),vec[i].getTotal());
		str += temp ;
		int sortNO = 1 ;
		for( int j = 0 ; j < vecStudents.size() ; j++ )
		{
			if(vec[j].getTotal()>vec[i].getTotal())
			{
				sortNO++ ;
			}
		}
		temp.Format("  第%d名  ",sortNO);
		str += temp ;
		temp.Format("  %d年%d月%d日",vec[i].GetTime().GetYear(),vec[i].GetTime().GetMonth(),vec[i].GetTime().GetDay());
	    str += temp ;
	}
	return str ;
}

void CPerformance6Dlg::OnSelectMonthcalendar1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CTime a;
    CMonthCalCtrl* mCtrl = (CMonthCalCtrl*)GetDlgItem(IDC_MONTHCALENDAR1);
	mCtrl->GetCurSel(a);
	CTime b(2011,12,23,0,0,0);
	CTime c(2008,1,1,0,0,0);
	m_SelectDay = a - ( b - c );
//	CString str;
//	str.Format("  %d年%d月%d日",m_SelectDay.GetYear(),m_SelectDay.GetMonth(),m_SelectDay.GetDay());
//	MessageBox(str);
	*pResult = 0;
}

void CPerformance6Dlg::OnDel() 
{
	UpdateData(TRUE);
	bool hasThisStudent = false ;
	std::vector<CStudentInfo>::iterator iter ;
	for( iter = vecStudents.begin(); iter != vecStudents.end() ; )
	{
		if(m_strName == iter->GetName())
		{
			hasThisStudent = true ;
			vecStudents.erase(iter);
		}
		else
		{
			iter++;
		}
	}
	if(!hasThisStudent)
	{
		MessageBox(CString("没有找到")+m_strName);
	}
	m_strStuinfo = pack(vecStudents);
	m_day = m_SelectDay;
	UpdateData(FALSE);
}

void CPerformance6Dlg::OnEditInfo() 
{
	UpdateData(TRUE);
	bool hasThisStudent = false ;
	std::vector<CStudentInfo>::iterator iter ;
	for( iter = vecStudents.begin(); iter != vecStudents.end() ; )
	{
		if(m_strName == iter->GetName())
		{
			hasThisStudent = true ;
			m_strName = iter->GetName();
			m_bSex = iter->GetSex();
			m_listEdit = iter->GetClassGrade();
			m_nChinese = iter->GetChinese();
			m_nMath = iter->GetMath();
			m_nEnglish = iter->GetEnglish();
			m_nTotalPoints = m_nChinese+m_nMath+m_nEnglish;	
			m_nPosition = 0 ;
			vecStudents.erase(iter);
		}
		else
		{
			iter++ ;
		}
	}
	if(!hasThisStudent)
	{
		MessageBox(CString("没有找到")+m_strName);
	}
	m_strStuinfo = pack(vecStudents);
	m_day = m_SelectDay;
	UpdateData(FALSE);
}

void CPerformance6Dlg::OnSort() 
{
	CStudentInfo temp ;
	int i,j ;
	for( i = 1 ; i < vecStudents.size() ; i++ )
	{
		if( vecStudents[i].getTotal() > vecStudents[i-1].getTotal() )
		{
			temp = vecStudents[i];
			for( j = i-1 ; temp.getTotal() > vecStudents[j].getTotal() ; j-- )
			{
				vecStudents[j+1] = vecStudents[j];
			}
			vecStudents[j+1] = temp ;
		}
	}
	m_strStuinfo = pack(vecStudents);
	m_day = m_SelectDay;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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