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

📄 doubledlg.cpp

📁 一个简单的学生学籍管理工具。vc编写。 有喜欢的可以批评指正^_^
💻 CPP
字号:
// doubledlg.cpp : implementation file
//

#include "stdafx.h"
#include "studentwin.h"
#include "doubledlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// Cdoubledlg dialog


Cdoubledlg::Cdoubledlg(CWnd* pParent /*=NULL*/)
	: CDialog(Cdoubledlg::IDD, pParent)
{
m_pGridCtrl=NULL;
pDoc=NULL;
open=false;
timer3=false;
dlgtype=1;
couter=0;
cursor=0;
findcouter=0;
rect=CRect(0,0,0,0);
m_nTimer=1;
m_ntimer3=3;
	//{{AFX_DATA_INIT(Cdoubledlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void Cdoubledlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cdoubledlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cdoubledlg, CDialog)
	//{{AFX_MSG_MAP(Cdoubledlg)
	ON_WM_CLOSE()
	ON_WM_KILLFOCUS()
	ON_WM_TIMER()
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cdoubledlg message handlers

BOOL Cdoubledlg::OnInitDialog() 
{
	m_nTimer = SetTimer(1, 20, 0);
//	SetCapture();
MoveWindow(-400,70,400,500);
	GetWindowRect(&rect);
//	ClientToScreen(&rect);
//ScreenToClient(&rect);
		if (m_pGridCtrl == NULL)
	{
		// 创建 Gridctrl 对象
		m_pGridCtrl = new CGridCtrl;
		if (!m_pGridCtrl) return false;

		// 创建 Gridctrl 窗口
		CRect rect;
		GetClientRect(rect);
		m_pGridCtrl->Create(rect, this, 600);
	// 填充数据
		m_pGridCtrl->SetEditable(false);
		m_pGridCtrl->EnableDragAndDrop(TRUE);
if(dlgtype==3)
{
try {
			m_pGridCtrl->SetRowCount(couter+2);
			m_pGridCtrl->SetColumnCount(13);
			m_pGridCtrl->SetFixedRowCount(2);
			m_pGridCtrl->SetFixedColumnCount(1);

		}
		catch (CMemoryException* e)
		{
			e->ReportError();
			e->Delete();
			return false;
		}
		// 填充每格数据
		for (int row = 0; row < m_pGridCtrl->GetRowCount(); row++)
			for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)
			{ 
				GV_ITEM Item;
				Item.mask = GVIF_TEXT|GVIF_FORMAT;
				Item.row = row;
				Item.col = col;
				if (row>=1&&row <2) {
					Item.nFormat = DT_CENTER|DT_WORDBREAK;
					switch(col)
					{
					case 1:
						Item.szText.Format(_T("当前纪录(=>)"));break;
					  case 2:
						Item.szText.Format(_T("学号"));break;
					  case 3:
						Item.szText.Format(_T("姓名"));break;
					  case 4:
				Item.szText.Format(_T("课程1"));break;
			         case 5:
						   Item.szText.Format(_T("分数1"));break;
					   case 6:Item.szText.Format(_T("课程2"));break;
					   case 7:Item.szText.Format(_T("分数2"));break;
                        case 8:Item.szText.Format(_T("课程3"));break;
					   case 9:Item.szText.Format(_T("分数3"));break;
					   case 10:Item.szText.Format(_T("课程4"));break;  
					   case 11:Item.szText.Format(_T("分数4"));break;
					   case 12: Item.szText.Format(_T("总成绩"));break;  
					   
					}
				
				} else if (col < 1) {
					Item.nFormat = DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
				//Item.nFormat = DT_LEFT|DT_WORDBREAK;
				if(row>=2&&row<couter+3)
					Item.szText.Format(_T("%d"),row-1);
			
				} else {
					Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
				
				}
						m_pGridCtrl->SetItem(&Item);

		}
		//	}
		m_pGridCtrl->AutoSize();
		//m_pGridCtrl->AutoSizeRows();

//m_pGridCtrl->SetRowHeight(0, 3*m_pGridCtrl->GetRowHeight(0)/2);

//for(int l=0;l<m_pGridCtrl->GetColumnCount();l++)
//{
m_pGridCtrl->SetColumnWidth(0,30);
//m_pGridCtrl->SetRowHeight(l,50);
//}
//m_pGridCtrl->SetColumnWidth(1,40);
m_pGridCtrl->SetFixedCellCombine(0,0,1,0);

m_pGridCtrl->SetFixedCellCombine(0,1,0,11);
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;	
Item.row=0;
Item.col=1;
Item.nFormat = DT_LEFT|DT_WORDBREAK;
    Item.szText.Format(_T("学生信息一览表"));
	m_pGridCtrl->SetItem(&Item);
m_pGridCtrl->SetRowHeight(0, 4*m_pGridCtrl->GetRowHeight(0)/2);
/////////////////////////////////
//m_pGridCtrl->SetRowCount(couter+2);
GV_ITEM Item1;
Item1.mask = GVIF_TEXT|GVIF_FORMAT;
Item1.row = cursor+1;
Item1.col = 1;
Item1.nFormat = DT_CENTER|DT_WORDBREAK;  
Item1.szText.Format("=>");
m_pGridCtrl->SetItem(&Item1);
pDoc->curpos=pDoc->m_dataList.GetHeadPosition();
Cstudent*pstudent;
for(int l=0;l<m_pGridCtrl->GetRowCount();l++)
{
//m_pGridCtrl->SetColumnWidth(l,60);
m_pGridCtrl->SetRowHeight(l,25);

}
for ( row = 2; row < m_pGridCtrl->GetRowCount(); row++)
{
	pstudent=pDoc->m_dataList.GetAt(pDoc->curpos);
		for (int col = 2; col < m_pGridCtrl->GetColumnCount(); col++)
			{ 

Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
CString str;	

				Item.nFormat = DT_CENTER|DT_WORDBREAK;  
					switch(col)
					{
					
					  case 2:
						 str.Format("%d",pstudent->id);
						Item.szText.Format(str);break;
					  case 3:
					str=pstudent->name;
						Item.szText.Format(str);break;
					  case 4:
		 				 Item.szText.Format(pstudent->lesson[0].name);break;
		
					   case 6:
						 Item.szText.Format(pstudent->lesson[1].name);break;

					   case 7:
						 str.Format("%d",pstudent->lesson[1].fen);
						  Item.szText.Format(str);break;
					   case 5:
						str.Format("%d",pstudent->lesson[0].fen);
						 Item.szText.Format(str);break;
                        case 8:
						Item.szText.Format(pstudent->lesson[2].name);break;

					   case 9:
str.Format("%d",pstudent->lesson[2].fen);
						  Item.szText.Format(str);break;
						 
					   case 10:
		 Item.szText.Format(pstudent->lesson[3].name);
						   break;
					   case 11:
str.Format("%d",pstudent->lesson[3].fen);
						 Item.szText.Format(str);
						 break;
					   case 12:
str.Format("%d",pstudent->lesson[3].fen+pstudent->lesson[2].fen+pstudent->lesson[1].fen+pstudent->lesson[0].fen);
			Item.szText.Format(str);
						 break;		   
 					}
		m_pGridCtrl->SetItem(&Item);
}	
pDoc->m_dataList.GetNext(pDoc->curpos);
if(pDoc->curpos==NULL)
break;
	}

}else{
		try {
			if(dlgtype==1)
			m_pGridCtrl->SetRowCount(couter+2);
			m_pGridCtrl->SetColumnCount(16);
			m_pGridCtrl->SetFixedRowCount(2);
			m_pGridCtrl->SetFixedColumnCount(1);

		}
		catch (CMemoryException* e)
		{
			e->ReportError();
			e->Delete();
			return false;
		}
		// 填充每格数据
		for (int row = 0; row < m_pGridCtrl->GetRowCount(); row++)
			for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)
			{ 
				GV_ITEM Item;
				Item.mask = GVIF_TEXT|GVIF_FORMAT;
				Item.row = row;
				Item.col = col;
				if (row>=1&&row <2) {
					Item.nFormat = DT_CENTER|DT_WORDBREAK;
					switch(col)
					{
					case 1:
						Item.szText.Format(_T("当前纪录(=>)"));break;
					  case 2:
						Item.szText.Format(_T("学号"));break;
					  case 3:
						Item.szText.Format(_T("姓名"));break;
					  case 4:
						  Item.szText.Format(_T("性别"));break;
					   case 5:
						   Item.szText.Format(_T("出生日期"));break;
					   case 6:
						   Item.szText.Format(_T("家庭地址"));break;
					   case 7:
						   Item.szText.Format(_T("电话号码"));break;
                        case 8:
						  Item.szText.Format(_T("课程1"));break;
					   case 9:
						   Item.szText.Format(_T("分数1"));break;
					   case 10:
						   Item.szText.Format(_T("课程2"));break;
					   case 11:
						   Item.szText.Format(_T("分数2"));break;
                         case 12:
						  Item.szText.Format(_T("课程3"));break;
					   case 13:
						   Item.szText.Format(_T("分数3"));break;
					   case 14:
						   Item.szText.Format(_T("课程4"));break;
					   case 15:
						   Item.szText.Format(_T("分数4"));break;


					}
				
				} else if (col < 1) {
					Item.nFormat = DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
				//Item.nFormat = DT_LEFT|DT_WORDBREAK;

					if(row>=2&&row<couter+3)
					Item.szText.Format(_T("%d"),row-1);
					else 
					{
					
					}
				} else {
					Item.nFormat = DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
				
				}
						m_pGridCtrl->SetItem(&Item);

		}
		//	}
		m_pGridCtrl->AutoSize();
		//m_pGridCtrl->AutoSizeRows();

//m_pGridCtrl->SetRowHeight(0, 3*m_pGridCtrl->GetRowHeight(0)/2);
	//}
//for(int l=0;l<m_pGridCtrl->GetColumnCount();l++)
//{
m_pGridCtrl->SetColumnWidth(0,30);
//m_pGridCtrl->SetRowHeight(l,50);
//}
//m_pGridCtrl->SetColumnWidth(1,40);
m_pGridCtrl->SetFixedCellCombine(0,0,1,0);

m_pGridCtrl->SetFixedCellCombine(0,1,0,14);
GV_ITEM Item;
Item.mask = GVIF_TEXT|GVIF_FORMAT;	
Item.row=0;
Item.col=1;
Item.nFormat = DT_LEFT|DT_WORDBREAK;
    Item.szText.Format(_T("学生信息一览表"));
	m_pGridCtrl->SetItem(&Item);
m_pGridCtrl->SetRowHeight(0, 4*m_pGridCtrl->GetRowHeight(0)/2);
/////////////////////////////////

//Item.mask = GVIF_TEXT|GVIF_FORMAT;
if(dlgtype==1)
{
m_pGridCtrl->SetRowCount(couter+2);
Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = cursor+1;
Item.col = 1;
Item.nFormat = DT_CENTER|DT_WORDBREAK;  
Item.szText.Format("=>");
m_pGridCtrl->SetItem(&Item);
pDoc->curpos=pDoc->m_dataList.GetHeadPosition();
Cstudent*pstudent;
for(int l=0;l<m_pGridCtrl->GetRowCount();l++)
{
//m_pGridCtrl->SetColumnWidth(l,60);
m_pGridCtrl->SetRowHeight(l,25);
}
for (int row = 2; row < m_pGridCtrl->GetRowCount(); row++)
{
	pstudent=pDoc->m_dataList.GetAt(pDoc->curpos);

		for (int col = 2; col < m_pGridCtrl->GetColumnCount(); col++)
			{ 

Item.mask = GVIF_TEXT|GVIF_FORMAT;
Item.row = row;
Item.col = col;
CString str;	

				Item.nFormat = DT_CENTER|DT_WORDBREAK;  

					switch(col)
					{
					

					  case 2:
						 str.Format("%d",pstudent->id);
						Item.szText.Format(str);break;
					  case 3:
					str=pstudent->name;
						Item.szText.Format(str);break;
					  case 4:
						  if(pstudent->sex==0)
							  str="女士";
						  else
							  if(pstudent->sex==1)
							  str="先生";
						  Item.szText.Format(str);break;
					   case 6:
						   Item.szText.Format(pstudent->addr);break;
					   case 7:
						  str.Format("%d",pstudent->tel);
						  Item.szText.Format(str);break;
					   case 5:
						   str.Format("%d/%d/%d",pstudent->year,pstudent->yue+1,pstudent->date+1);
						  Item.szText.Format(str);break;
                        case 8:
						 Item.szText.Format(pstudent->lesson[0].name);break;
					   case 9:
str.Format("%d",pstudent->lesson[0].fen);
						 Item.szText.Format(str);break;
						 MessageBox(str);
					   case 10:
						 Item.szText.Format(pstudent->lesson[1].name);break;
					   case 11:
str.Format("%d",pstudent->lesson[1].fen);
						  Item.szText.Format(str);break;
                         case 12:
						Item.szText.Format(pstudent->lesson[2].name);break;
					   case 13:
str.Format("%d",pstudent->lesson[2].fen);
						  Item.szText.Format(str);break;
					   case 14:
						 Item.szText.Format(pstudent->lesson[3].name);
						   break;
					   case 15:
str.Format("%d",pstudent->lesson[3].fen);
						 Item.szText.Format(str);
						   break;
					}

		m_pGridCtrl->SetItem(&Item);
	
}

pDoc->m_dataList.GetNext(pDoc->curpos);
if(pDoc->curpos==NULL)
break;
	}

}
else{	
m_pGridCtrl->SetRowCount(findcouter+2);
Cstudent*pstudent;
GV_ITEM Item;
m_pGridCtrl->AutoSizeColumns();
for(int l=0;l<m_pGridCtrl->GetRowCount();l++)
{
m_pGridCtrl->SetRowHeight(l,20);
}
CString str1;
Item.row=2;
for(int k=0;k<findcouter;k++)
{
	pstudent=pDoc->m_dataList.GetAt(p[k]);
	
  		for (int col = 0; col < m_pGridCtrl->GetColumnCount(); col++)
		{
Item.mask = GVIF_TEXT|GVIF_FORMAT;		
Item.col = col;
CString str;	
Item.nFormat = DT_CENTER|DT_WORDBREAK;
				switch(col)
					{
				case 0:
str.Format("%d",k+1);
m_pGridCtrl->SetColumnWidth(0,40);
Item.szText.Format(str);break;
				case 1:
						Item.szText.Format("=>");break;
					  case 2:
						 str.Format("%d",pstudent->id);
						Item.szText.Format(str);break;
					  case 3:
					str=pstudent->name;
						Item.szText.Format(str);break;
					  case 4:
						  if(pstudent->sex==0)
							  str="女士";
						  else
							  if(pstudent->sex==1)
							  str="先生";
						  Item.szText.Format(str);break;
					   case 6:
						   Item.szText.Format(pstudent->addr);break;
					   case 7:
						  str.Format("%d",pstudent->tel);
						  Item.szText.Format(str);break;
					   case 5:
						   str.Format("%d/%d/%d",pstudent->year,pstudent->yue+1,pstudent->date+1);
						  Item.szText.Format(str);break;
                        case 8:
						 Item.szText.Format(pstudent->lesson[0].name);break;
					   case 9:

str1.Format("%d",pstudent->lesson[0].fen);
						 Item.szText.Format(str1);break;
					   case 10:
						 Item.szText.Format(pstudent->lesson[1].name);break;
					   case 11:
str.Format("%d",pstudent->lesson[1].fen);
						  Item.szText.Format(str);break;
                         case 12:
						Item.szText.Format(pstudent->lesson[2].name);break;
					   case 13:
str.Format("%d",pstudent->lesson[2].fen);
						  Item.szText.Format(str);break;
					   case 14:
						 Item.szText.Format(pstudent->lesson[3].name);
						   break;
					   case 15:
str.Format("%d",pstudent->lesson[3].fen);
						 Item.szText.Format(str);
						   break;
					}
				m_pGridCtrl->SetItem(&Item);
}	
Item.row++;
}
}	
}
}
////////////////////////////////////////////////

	CDialog::OnInitDialog();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Cdoubledlg::entergrid()
{

}

void Cdoubledlg::OnClose() 
{

	// TODO: Add your message handler code here and/or call default
	pDoc->curpos=pDoc->m_dataList.GetHeadPosition();
	CDialog::OnClose();
}

void Cdoubledlg::OnKillFocus(CWnd* pNewWnd) 
{

	CDialog::OnKillFocus(pNewWnd);	
	
}

void Cdoubledlg::OnTimer(UINT nIDEvent) 
{
	

	if(rect.left>=0)
	{
	//ReleaseCapture();
KillTimer(m_nTimer);
	}
	else{
rect.left+=40;
rect.right+=40;
MoveWindow(&rect);
	}

	CDialog::OnTimer(nIDEvent);
}

void Cdoubledlg::OnLButtonDown(UINT nFlags, CPoint point) 
{

if(point.x<=500&&point.y>=70&&point.y<=570)
{
//ReleaseCapture();
}
	CDialog::OnLButtonDown(nFlags, point);
}

void Cdoubledlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

}

void Cdoubledlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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