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

📄 sheetcountdlg.cpp

📁 我上载了那么多怎么都说已经有上载的啦
💻 CPP
字号:
// SheetCountDlg.cpp : implementation file
//

#include "stdafx.h"
#include "gpmis.h"
#include "SheetCountDlg.h"
#include "global.h"
#include "student.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSheetCountDlg dialog
#define NUM1_COLUMNS	4
static _TCHAR *_gszLabel1[NUM1_COLUMNS] =
{
    _T("指导教师"), _T("总数"), _T("本科生"), _T("二学位")
};
static int _gnFmt1[NUM1_COLUMNS] = 
{
	LVCFMT_LEFT, LVCFMT_CENTER , LVCFMT_CENTER , LVCFMT_CENTER 
};
static int _gnWidth1[NUM1_COLUMNS] = 
{
	70, 54, 54, 54
};

#define NUM2_COLUMNS	4
static _TCHAR *_gszLabel2[NUM2_COLUMNS] =
{
    _T("班级"), _T("总数"), _T("男生"), _T("女生")
};
static int _gnFmt2[NUM2_COLUMNS] = 
{
	LVCFMT_LEFT, LVCFMT_CENTER , LVCFMT_CENTER, LVCFMT_CENTER
};
static int _gnWidth2[NUM2_COLUMNS] = 
{
	80, 50, 50, 50
};


CSheetCountDlg::CSheetCountDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSheetCountDlg::IDD, pParent)
{
	m_pSheetView = (CSheetView*)pParent;

	//{{AFX_DATA_INIT(CSheetCountDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CSheetCountDlg::~CSheetCountDlg()
{
	while(!m_teacherList.IsEmpty())
	{
		StudentData* pData = (StudentData*)m_teacherList.RemoveHead();
		delete pData;
	}
	while(!m_classList.IsEmpty())
	{
		ClassData* pData = (ClassData*)m_classList.RemoveHead();
		delete pData;
	}
}

void CSheetCountDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSheetCountDlg)
	DDX_Control(pDX, IDC_TEACHER_LIST, m_lvwTeacher);
	DDX_Control(pDX, IDC_CLASS_LIST, m_lvwClass);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSheetCountDlg, CDialog)
	//{{AFX_MSG_MAP(CSheetCountDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSheetCountDlg message handlers
StudentData* CSheetCountDlg::FindSData(CString sTeacher)
{
	POSITION pos = m_teacherList.GetHeadPosition();
	while( pos )
	{
		StudentData* pData = (StudentData*)m_teacherList.GetNext(pos);
		if( pData && sTeacher == pData->sTeacher )
		{
			return pData;
		}
	}
	return NULL;
}

ClassData* CSheetCountDlg::FindCData(CString sClass)
{
	POSITION pos = m_classList.GetHeadPosition();
	while( pos )
	{
		ClassData* pData = (ClassData*)m_classList.GetNext(pos);
		if( pData && sClass == pData->sClass )
		{
			return pData;
		}
	}
	return NULL;
}

BOOL CSheetCountDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	SetIcon(hIcon, TRUE);	// Set big icon
	SetIcon(hIcon, FALSE);// Set small icon
	
	// TODO: Add extra initialization here
	CStudentList& studentList = CGlobal::GetInstance().m_studentList;
	POSITION pos = studentList.GetHeadPosition();
	CString key;
	StudentData *pSData = NULL; 
	ClassData *pCData = NULL; 
	int i = 0;
	while( pos )
	{
		CStudent* pStudent = studentList.GetNext(pos);
		if( pStudent )
		{
			pSData = FindSData(pStudent->GetTeacher());
			if( pSData )
			{
				pSData->nSum++;
				if( pStudent->GetClass().Find("二") >0 )
					pSData->nSecondD++;
				else 
					pSData->nUnderG++;
			}
			else
			{
				pSData = new StudentData;
				strcpy( pSData->sTeacher, pStudent->GetTeacher());
				pSData->nSum = 1;
				pSData->nSecondD = 0;
				pSData->nUnderG = 0;
				if( pStudent->GetClass().Find("二") >0 )
					pSData->nSecondD++;
				else 
					pSData->nUnderG++;
				m_teacherList.AddTail(pSData);

			}
			pCData = FindCData(pStudent->GetClass());
			if( pCData )
			{
				pCData->nSum++;
				if( pStudent->GetSex().Find("女") >=0 )
					pCData->nFemale++;
				else 
					pCData->nMale++;
			}
			else
			{
				pCData = new ClassData;
				strcpy( pCData->sClass, pStudent->GetClass());
				pCData->nSum = 1;
				pCData->nFemale = 0;
				pCData->nMale = 0;
				if( pStudent->GetSex().Find("女") >=0 )
					pCData->nFemale++;
				else 
					pCData->nMale++;
				m_classList.AddTail(pCData);

			}

			i++;
			
		}
	}

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

void CSheetCountDlg::DrawLabel()
{
	int i;
	LV_COLUMN lvc;

	// delete columns
	int sum = NUM1_COLUMNS;
	_TCHAR **szLabel = _gszLabel1;
	int *nWidth = _gnWidth1;
	int *nFmt = _gnFmt1;
	for(i = 0; i<sum; i++)
	{
		m_lvwTeacher.DeleteColumn(0);
	}
	// insert columns
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	for(i = 0; i<sum; i++)
	{
		lvc.iSubItem = i;
		lvc.pszText = szLabel[i];
		lvc.cx = nWidth[i];
		lvc.fmt = nFmt[i];
		m_lvwTeacher.InsertColumn(i,&lvc);
	}

	m_lvwTeacher.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
	m_lvwTeacher.EnableToolTips(TRUE);

	// delete columns
	sum = NUM2_COLUMNS;
	szLabel = _gszLabel2;
	nWidth = _gnWidth2;
	nFmt = _gnFmt2;
	for(i = 0; i<sum; i++)
	{
		m_lvwClass.DeleteColumn(0);
	}
	// insert columns
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

	for(i = 0; i<sum; i++)
	{
		lvc.iSubItem = i;
		lvc.pszText = szLabel[i];
		lvc.cx = nWidth[i];
		lvc.fmt = nFmt[i];
		m_lvwClass.InsertColumn(i,&lvc);
	}

	m_lvwClass.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
	m_lvwClass.EnableToolTips(TRUE);

}

void CSheetCountDlg::DrawList()
{
	LV_ITEM lvi;
	int i = 0;
	char cNum[100];

	// delete list items
	m_lvwTeacher.DeleteAllItems();
	m_lvwClass.DeleteAllItems();

	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvi.iSubItem = 0;
	lvi.iImage = 0;
	lvi.stateMask = LVIS_STATEIMAGEMASK;
	lvi.state = INDEXTOSTATEIMAGEMASK(1);

	for (POSITION pos = m_teacherList.GetHeadPosition(); pos != NULL; )
	{
		StudentData* pData = (StudentData*)m_teacherList.GetNext(pos);
		if( pData )
		{
			sprintf(cNum,"%s",pData->sTeacher);
			lvi.iItem = i;
			lvi.pszText = (LPTSTR)cNum;
			m_lvwTeacher.InsertItem(&lvi);

			CString strTemp;
			strTemp.Format("%d",pData->nSum);
			m_lvwTeacher.SetItemText(i, 1, strTemp);
			strTemp.Format("%d",pData->nUnderG);
			m_lvwTeacher.SetItemText(i, 2, strTemp);
			strTemp.Format("%d",pData->nSecondD);
			m_lvwTeacher.SetItemText(i, 3, strTemp);

			i++;
		}
	}

	i = 0;
	for ( pos = m_classList.GetHeadPosition(); pos != NULL; )
	{
		ClassData* pData = (ClassData*)	m_classList.GetNext(pos);
		if( pData )
		{
			sprintf(cNum,"%s",pData->sClass);
			lvi.iItem = i;
			lvi.pszText = (LPTSTR)cNum;
			m_lvwClass.InsertItem(&lvi);

			CString strTemp;
			strTemp.Format("%d",pData->nSum);
			m_lvwClass.SetItemText(i, 1, strTemp);
			strTemp.Format("%d",pData->nMale);
			m_lvwClass.SetItemText(i, 2, strTemp);
			strTemp.Format("%d",pData->nFemale);
			m_lvwClass.SetItemText(i, 3, strTemp);

			i++;
		}
	}
}


⌨️ 快捷键说明

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