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

📄 searchstatisticsview.cpp

📁 一个学生信息管理系统,使用了多中数值算法,有HASH查找,归并排序,堆排序,快速排序,界面也不错
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// QueryDbView.cpp : implementation file
//

#include "stdafx.h"
#include "StudInfoManager.h"
#include "SearchStatisticsView.h"
#include "StudInfoManagerView.h"
#include "MainFrm.h"
#include "math.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSearchStatisticsView

IMPLEMENT_DYNCREATE(CSearchStatisticsView, CFormView)

CSearchStatisticsView::CSearchStatisticsView()
	: CFormView(CSearchStatisticsView::IDD)
{
	//{{AFX_DATA_INIT(CSearchStatisticsView)
	m_uiBoyCount = 0;
	m_uiGirlCount = 0;
	//}}AFX_DATA_INIT
}

CSearchStatisticsView::~CSearchStatisticsView()
{
}

void CSearchStatisticsView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSearchStatisticsView)
	DDX_Control(pDX, IDC_COMBO_SCHCTT, m_comboSchCtt);
	DDX_Control(pDX, IDC_EDITCOURSEAVERAGEMARK, m_edtCourseAverageMark);
	DDX_Control(pDX, IDC_EDITGRADEAVERAGEAGE, m_edtGradeAverageAge);
	DDX_Control(pDX, IDC_EDITPERSONAVERAGEMARK, m_edtPersonAverageMark);
	DDX_Control(pDX, IDC_COMBO_SCHSORT, m_comboSchSort);
	DDX_Text(pDX, IDC_EDITBOYCOUNT, m_uiBoyCount);
	DDX_Text(pDX, IDC_EDITGIRLCOUNT, m_uiGirlCount);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSearchStatisticsView, CFormView)
	//{{AFX_MSG_MAP(CSearchStatisticsView)
	ON_BN_CLICKED(IDC_BTN_SEARCH, OnBtnSearch)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_CBN_EDITCHANGE(IDC_COMBO_SCHCTT, OnEditchangeComboSchctt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSearchStatisticsView diagnostics

#ifdef _DEBUG
void CSearchStatisticsView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSearchStatisticsView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSearchStatisticsView message handlers

BOOL CSearchStatisticsView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}

void CSearchStatisticsView::OnBtnSearch() 
{
	// TODO: Add your control notification handler code here
	CString strSchCtt; //搜索内容
	CString strSchSort;//搜索类别
	CString str;
	UINT uiSelect=m_comboSchSort.GetCurSel();
	bool bIsAgainFlag=false;
	long lCount;

	lCount=m_comboSchCtt.GetCount();
	m_comboSchCtt.GetWindowText(strSchCtt);

	m_pMainFrame->m_wndOutputBar.SetEditText(1,
		"                                        -------------------------------搜索结果-------------------------------\r\n\r\n");

	//搜索是否重复
	for(long i=0;i<lCount;i++)
	{
		m_comboSchCtt.GetLBText(i,str);
		if(str==strSchCtt)
		{
			bIsAgainFlag=true;
			break;
		}
	}

	if(!bIsAgainFlag)
		m_comboSchCtt.InsertString(-1,strSchCtt);

	//根据搜索类别进行相应的搜索
	switch(uiSelect)
	{
	case 0://按学号查找
		this->SearchByStudNum(strSchCtt);
		break;
		
	case 1://按姓名查找
		this->SearchByName(strSchCtt);
		break;
		
	case 2://按性别查找
		this->SearchBySex(strSchCtt);
		break;
		
	case 3://按年级课程查找
		this->SearchByGradeCourse(strSchCtt);
		break;
		
	case 4://按教师查找
		this->SearchByTeacher(strSchCtt);
		break;
		
	case 5://按课程查找
		this->SearchByCourse(strSchCtt);
		break;

	default:
		break;
	}
}

void CSearchStatisticsView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	m_comboSchSort.SetCurSel(0);
	m_comboSchCtt.SetCurSel(0);
	m_pMainFrame=(CMainFrame*)::AfxGetApp()->m_pMainWnd;
	pStudInfo=((CStudInfoManagerView*)m_pMainFrame->GetActiveView())->GetStudInfo();
}

void CSearchStatisticsView::SearchByCourse(CString strSchCtt)
{
	char* pInCourse;
	char pCourseTemp1[10];
	char pCourseTemp2[10];
	UINT i;
	bool bIsFind=false;

	pInCourse=(LPSTR)(LPCTSTR)strSchCtt;
	for(i=0;i<10;i++)
	{
		strcpy(pCourseTemp1,pStudInfo[i].pCourseInfo->pCourse);
		strcpy(pCourseTemp2,pStudInfo[i].pCourseInfo->pNext->pCourse);

		if(!strcmp(strupr(pCourseTemp1),strupr(pInCourse)))
		{
			bIsFind=true;
			PrintStudInfo(pStudInfo[i]);
		}

		if(!strcmp(strupr(pCourseTemp2),strupr(pInCourse)))
		{
			bIsFind=true;
			PrintStudInfo(pStudInfo[i]);
		}
	}

	if(!bIsFind)
		m_pMainFrame->m_wndOutputBar.SetEditText(1,
		"                                        -------------------------------搜索结果-------------------------------\r\n\r\n                                                                没有学生选修该门课程!");
}

void CSearchStatisticsView::SearchByGradeCourse(CString strSchCtt)
{
	UINT i,j;
	CString strGrade;	     //要查找的年级
	char* pCourse[20]={NULL};//该年级课程
	bool bIsFind1,bIsFind2;
	UINT uiCount=0;
	UINT uiPos=0;
	bool bIsFind=false;
	CString str,strFormer;
	
	if(strSchCtt.GetLength()==1)
		strSchCtt="0"+strSchCtt;

	for(i=0;i<10;i++)
	{
		bIsFind1=false;
		bIsFind2=false;

		if(GetGrade(pStudInfo[i].uiStudNum)/10==0)
			strGrade.Format("0%d",GetGrade(pStudInfo[i].uiStudNum));
		else
			strGrade.Format("%d",GetGrade(pStudInfo[i].uiStudNum));

		if(strGrade!=strSchCtt)
			continue;

		//----------该学生符合所输入的年级----------
		bIsFind=true;
		for(j=0;j<20;j++)
			if(pCourse[j]!=NULL)
				if(!strcmp(pStudInfo[i].pCourseInfo->pCourse,pCourse[j]))
				{
					bIsFind1=true;
					break;
				}

		if(!bIsFind1)
		{
			pCourse[uiPos]=pStudInfo[i].pCourseInfo->pCourse;
			uiPos++;
		}

		for(j=0;j<20;j++)
			if(pCourse[j]!=NULL)
				if(!strcmp(pStudInfo[i].pCourseInfo->pNext->pCourse,pCourse[j]))
				{
					bIsFind2=true;
					break;
				}

		if(!bIsFind2)
		{
			pCourse[uiPos]=pStudInfo[i].pCourseInfo->pNext->pCourse;
			uiPos++;
		}
		//------------------------------------------
	}

	if(!bIsFind)
	{
		m_pMainFrame->m_wndOutputBar.SetEditText(1,
		"                                        -------------------------------搜索结果-------------------------------\r\n\r\n                                                                没有学生选修该门课程!");
		return;
	}

	for(i=0;i<uiPos;i++)
	{
		strFormer=m_pMainFrame->m_wndOutputBar.GetEditText(1);
		str.Format("                                                                        %s",
			pCourse[i]);
		str=strFormer+str+"\r\n";
		m_pMainFrame->m_wndOutputBar.SetEditText(1,str);
	}
}

void CSearchStatisticsView::SearchByName(CString strSchCtt)
{
	UINT i;
	char* pInName;
	char pNameTemp[10];
	bool bIsFind=false;

	pInName=(LPSTR)(LPCTSTR)strSchCtt;
	for(i=0;i<10;i++)
	{
		strcpy(pNameTemp,pStudInfo[i].pName);

		if(!strcmp(strupr(pNameTemp),strupr(pInName)))
		{
			bIsFind=true;
			PrintStudInfo(pStudInfo[i]);
		}
	}

	if(!bIsFind)
		m_pMainFrame->m_wndOutputBar.SetEditText(1,
		"                                        -------------------------------搜索结果-------------------------------\r\n\r\n                                                                       查无此人!");
}

void CSearchStatisticsView::SearchBySex(CString strSchCtt)
{
	char* pInSex;
	char pSexTemp[2];
	UINT i;
	bool bIsFind=false;

	pInSex=(LPSTR)(LPCTSTR)strSchCtt;

	if(!strcmp(pInSex,"男") || !strcmp(strupr(pInSex),"M"))
		strcpy(pInSex,"M");
	else
		if(!strcmp(pInSex,"女") || !strcmp(strupr(pInSex),"F"))
			strcpy(pInSex,"F");
		else
		{
			m_pMainFrame->m_wndOutputBar.SetEditText(1,
				"                                        -------------------------------搜索结果-------------------------------\r\n\r\n                                                             好像世界上没有这种性别的人吧!");			
			return;
		}

	for(i=0;i<10;i++)
	{
		strcpy(pSexTemp,pStudInfo[i].pSex);
		if(!strcmp(strupr(pSexTemp),pInSex))
		{
			bIsFind=true;
			PrintStudInfo(pStudInfo[i]);
		}
	}

	if(!bIsFind)
		m_pMainFrame->m_wndOutputBar.SetEditText(1,

⌨️ 快捷键说明

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