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

📄 databaseview.cpp

📁 用C++编写的学生信息管理系统 兼有数据库
💻 CPP
📖 第 1 页 / 共 3 页
字号:

void CDATABASEView::OnSaerch1() 
{
	 CSearch1 dlg;
	 if(dlg.DoModal()==IDOK)
	 {
		 m_pSet->m_strFilter.Format("stuid='%s'",dlg.m_stuid);
	     m_pSet->Requery();
		 UpdateData(FALSE);
		 if(m_pSet->IsEOF())  AfxMessageBox("您输入的学号不存在,查找失败!");
	 }
}

void CDATABASEView::OnSql() 
{
	CInput0 dlg0;
	CInput dlg;
	CPSWset pasSet;
    CString adm_pas;
	while(dlg0.DoModal()==IDOK){
		  pasSet.Open();
	      pasSet.m_strFilter="user='administer'";
	      pasSet.Requery();
		  adm_pas=pasSet.m_pass;
		  if(dlg0.m_pass==adm_pas){
			  if(dlg.DoModal()==IDOK){
				  int nChoice=MessageBox("您的上述操作对数据库存在一定的危险性,如果误操作将可能导致数据丢失甚至本数据库应用程序无法正常运行。确定要执行该操作吗?","安全警告",MB_YESNO|MB_ICONWARNING);
				  if(nChoice==IDNO)     break;
				  char *sqlstr;
                  sqlstr=(char *)malloc(200);
                  UpdateData(TRUE);
                  sqlstr=dlg.m_SQL.GetBuffer(200);
    	          ExeSQL(sqlstr);
				  m_pSet->Requery();
				  AfxMessageBox("如果您输入的SQL语句有效的话,数据库操作执行完毕!");
				  OnRefresh();
			  }
			  pasSet.Close();
			  
			  return;
		  }
		  else AfxMessageBox("密码错误,请重新输入");
		  pasSet.Close();
	}
}

	


void CDATABASEView::ExeSQL(char *Sql)
{
	HENV henv;
	HDBC hdbc;
	RETCODE rc;
	char username[10];
	char password[10];
	char sourcename[30];

	HSTMT FAR *phstmt;
	phstmt=(HSTMT FAR *)malloc(sizeof(HSTMT FAR));
	strcpy(sourcename,"我的数据库0");
	strcpy(username,"");
	strcpy(password,"");
	rc=SQLAllocEnv(&henv);
	if(rc==SQL_SUCCESS)
	{
		rc=SQLAllocConnect(henv,&hdbc);
		
		if(rc==SQL_SUCCESS)
		{
			rc=SQLConnect(hdbc,(UCHAR*)sourcename,SQL_NTS,(UCHAR *)"",SQL_NTS,(UCHAR *)"",SQL_NTS);
			if(rc==SQL_SUCCESS||rc==SQL_SUCCESS_WITH_INFO)
				rc=SQLAllocStmt(hdbc,phstmt);
			else AfxMessageBox("数据库连接错误");
			rc=SQLExecDirect(*phstmt,(UCHAR FAR *)Sql,SQL_NTS);
			SQLDisconnect(hdbc);
		}
		
		SQLFreeConnect(hdbc);
	}
	SQLFreeEnv(henv);
}

void CDATABASEView::OnSearch2() 
{
	
	CHSearch dlg;
	dlg.DoModal();
}

void CDATABASEView::OnShoudong() 
{
	CSd dlg;
	dlg.DoModal();
}

BEGIN_EVENTSINK_MAP(CDATABASEView, CRecordView)
    //{{AFX_EVENTSINK_MAP(CDATABASEView)
	ON_EVENT(CDATABASEView, IDC_MSFLEXGRID, -605 /* MouseDown */, OnMouseDownMsflexgrid, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CDATABASEView::OnMouseDownMsflexgrid(short Button, short Shift, long x, long y) 
{
	/*int row=m_MSFGrid.GetRow();
	CString str=m_MSFGrid.GetTextMatrix(row,1);
	m_pSet->MoveFirst();
	m_pSet->m_strFilter.Format("stuid='%s'",str);
	m_pSet->Requery();
	UpdateData(FALSE);*/

}

HBRUSH CDATABASEView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	return m_Brush;
}

void CDATABASEView::OnIfo() 
{
	CIfo dlg;
	CIfoSet IfoSet;
	CAdd   add_dlg;
	dlg.m_stuid=m_pSet->m_stuid;
	dlg.m_name=m_pSet->m_name;
    IfoSet.Open();
	IfoSet.m_strFilter.Format("stuid='%s'",m_pSet->m_stuid);
	IfoSet.Requery();
	if(IfoSet.IsEOF()){
	    if(add_dlg.DoModal()==IDOK)
			if(dlg.DoModal()==IDOK)
			{
				IfoSet.AddNew();
				IfoSet.SetFieldNull(&(IfoSet.m_stuid),FALSE);
				IfoSet.m_stuid=m_pSet->m_stuid;
	        	IfoSet.m_native=dlg.m_native;
		        IfoSet.m_politic=dlg.m_politic;
	        	IfoSet.m_id=dlg.m_id;
         		IfoSet.m_jlid=dlg.m_jlid;
                IfoSet.m_email=dlg.m_email;
				IfoSet.m_pname=dlg.m_pname;
				IfoSet.m_pname2=dlg.m_pname2;
          		IfoSet.m_ptel=dlg.m_ptel;
				IfoSet.m_address=dlg.m_address;
				IfoSet.m_zipcode=dlg.m_zipcode;
				IfoSet.m_addition=dlg.m_addition;
        		IfoSet.Update();
          		UpdateData(FALSE);
				AfxMessageBox("记录添加成功!");
			}
	}
	
	else
	{
		dlg.m_native=IfoSet.m_native;
		dlg.m_politic=IfoSet.m_politic;
	    dlg.m_id=IfoSet.m_id;
        dlg.m_jlid=IfoSet.m_jlid;
        dlg.m_email=IfoSet.m_email;
		dlg.m_pname=IfoSet.m_pname;
		dlg.m_pname2=IfoSet.m_pname2;
		dlg.m_ptel=IfoSet.m_ptel;
		dlg.m_address=IfoSet.m_address;
		dlg.m_zipcode=IfoSet.m_zipcode;
		dlg.m_addition=IfoSet.m_addition;
	UpdateData(FALSE);
	if(dlg.DoModal()==IDOK)
	{
		IfoSet.Edit();
	    IfoSet.m_native=dlg.m_native;
		IfoSet.m_politic=dlg.m_politic;
	    IfoSet.m_id=dlg.m_id;
        IfoSet.m_jlid=dlg.m_jlid;
        IfoSet.m_email=dlg.m_email;
		IfoSet.m_pname=dlg.m_pname;
		IfoSet.m_pname2=dlg.m_pname2;
        IfoSet.m_ptel=dlg.m_ptel;
		IfoSet.m_address=dlg.m_address;
		IfoSet.m_zipcode=dlg.m_zipcode;
		IfoSet.m_addition=dlg.m_addition;
		IfoSet.Update();
		UpdateData(FALSE);
		AfxMessageBox("记录修改成功!");
	}
	}
	
}


//////////////////////

void CDATABASEView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	pDC->SetMapMode(MM_ANISOTROPIC);
	pDC->SetWindowExt(1440,1440);
	pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),-pDC->GetDeviceCaps(LOGPIXELSY));
	CRecordView::OnPrepareDC(pDC, pInfo);
}


void CDATABASEView::ShowFont(CDC* pDC, int& nPosition,int nPoints)
{
	TEXTMETRIC tm;
	CFont NewFont;
	char psOrigin[100];
	CSize ExtentSize;
	NewFont.CreateFont(-nPoints * 20,0,0,0,FW_BOLD,true,false,false,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"Times New Roman");
	CFont* pOldFont=(CFont*)pDC->SelectObject(&NewFont);
	pDC->GetTextMetrics(&tm);
	TRACE("Points= %d,tmHeight= %d,tmInternalLeading= %d","tmExternalLeading=%d",nPoints,tm.tmHeight,tm.tmInternalLeading,tm.tmExternalLeading);
	wsprintf(psOrigin,"This is %d_point Times New Roman.",nPoints);
	CString str(psOrigin);
	ExtentSize=pDC->GetTextExtent(str);
	pDC->TextOut(0,nPosition,str);
	pDC->SelectObject(pOldFont);
	nPosition-= tm.tmHeight +tm.tmExternalLeading + 50;
}


void CDATABASEView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	int flag=1;
	CAllSet pSet;
	CCodeSet codeSet;
	CKmSet2 kmSet;
	CFont font,*oldfont;
	CPoint point;
	CString ss=_T("学生学期基本信息表");
	int nWidth=pDC->GetDeviceCaps(HORZRES);
	int nHeight=pDC->GetDeviceCaps(VERTRES);
	int ghdf=pDC->GetDeviceCaps(LOGPIXELSY);
	CRect DrawRect(0,0,nWidth,nHeight),rect,tempRect;		
	DrawRect.InflateRect(-100,-50,-100,-100);
	pDC->Rectangle(&DrawRect);		
	font.CreateFont(-MulDiv(32,-pDC->GetDeviceCaps(LOGPIXELSY),72),
					0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
					OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
					VARIABLE_PITCH|FF_SWISS,_T("华文行楷"));
	oldfont=pDC->SelectObject(&font);
	tempRect=DrawRect;
	tempRect.InflateRect(0,-5,0,0);
	pDC->DrawText(ss,&tempRect,DT_CALCRECT|DT_SINGLELINE);	
	rect=tempRect;rect.InflateRect(10,0);
	point=CPoint(DrawRect.left+(DrawRect.Width()-rect.Width())/2,rect.bottom+2);
	pDC->MoveTo(point);
	pDC->LineTo(point.x+rect.Width(),point.y);
	point.Offset(0,2);
	pDC->MoveTo(point);
	pDC->LineTo(point.x+rect.Width(),point.y);
	tempRect.right=DrawRect.right;
	pDC->DrawText(ss,&tempRect,DT_CENTER|DT_TOP|DT_SINGLELINE);	
	pDC->SelectObject(oldfont);
	font.DeleteObject();
	font.CreateFont(-MulDiv(16,-pDC->GetDeviceCaps(LOGPIXELSY),72),
					0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
					OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
					VARIABLE_PITCH|FF_SWISS,_T("黑体"));
	pDC->SelectObject(&font);
	ss=_T("                              华中科技大学 学生管理处");
	rect=DrawRect;
	rect.top=point.y+2900;
	pDC->DrawText(ss,&rect,DT_CALCRECT|DT_SINGLELINE);	
	rect.right=DrawRect.right;
	pDC->DrawText(ss,&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);	
	rect.InflateRect(0,0,0,400);
	rect.top=point.y+3000;
	CTime theTime=CTime::GetCurrentTime();
    pDC->DrawText(theTime.Format("                                     %Y年%m月%d日"),&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);
	
	pDC->SelectObject(oldfont);
	font.DeleteObject();
	font.CreateFont(-MulDiv(22,-pDC->GetDeviceCaps(LOGPIXELSY),72),
					0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
					OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
					VARIABLE_PITCH|FF_SWISS,_T("宋体"));
	pDC->SelectObject(&font);


	codeSet.Open();
	codeSet.m_strFilter.Format("profcode='%s'",m_pSet->m_profcode);
	codeSet.Requery();
    pSet.Open();
	pSet.m_strFilter.Format("xs.stuid='%s' and xs.stuid=xj.stuid and xs.stuid=xx.stuid and xs.stuid=cj.stuid",m_pSet->m_stuid);
	pSet.Requery();
	kmSet.Open();
	kmSet.m_strFilter.Format("profcode='%s' ",m_pSet->m_profcode);
	kmSet.Requery();
	
    
	DrawRect.InflateRect(-50,-225,-50,-2500);
	rect=DrawRect;
    rect.InflateRect(-45,0,-45,0);
	pDC->Rectangle(&DrawRect);
	rect.top=point.y+100;
	ss.Format("基本信息:");
	pDC->DrawText(ss,&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+300;
	ss.Format("学号:%s",m_pSet->m_stuid);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
    ss.Format("姓名:%s    ",m_pSet->m_name);
	pDC->DrawText(ss,&rect,DT_RIGHT|DT_TOP|DT_SINGLELINE);
    rect.top=point.y+450;
	ss.Format("专业:%s",codeSet.m_profname);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	ss.Format("班级:%s       ",pSet.m_class);
	pDC->DrawText(ss,&rect,DT_RIGHT|DT_TOP|DT_SINGLELINE);

	rect.top=point.y+600;
	ss.Format("学籍注册:%s",pSet.m_reg);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	ss.Format("注册类型:%s ",pSet.m_type);
	pDC->DrawText(ss,&rect,DT_RIGHT|DT_TOP|DT_SINGLELINE);
	DrawRect.InflateRect(0,-800,0,1000);
	pDC->Rectangle(&DrawRect);
	rect=DrawRect;
	rect.InflateRect(-45,0,-45,0);
	rect.top=point.y+900;
	ss.Format("选修课情况");
	pDC->DrawText(ss,&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+1100;
	ss.Format("已获得学分:%2.1f",pSet.m_credit);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+1250;
	ss.Format("本期所选选修课:");
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+1400;
	ss.Format("%s      %s",pSet.m_lesson1,pSet.m_lesson2);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+1550;
	ss.Format("%s      %s",pSet.m_lesson3,pSet.m_lesson4);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
    DrawRect.InflateRect(0,-1000,0,1100);
	pDC->Rectangle(&DrawRect);
	rect=DrawRect;
	rect.InflateRect(-45,0,-45,0);
	rect.top=point.y+1900;
	ss.Format("本期各科成绩");
	pDC->DrawText(ss,&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+2050;
	ss.Format("%s  %d         %s  %d",kmSet.m_subject1,pSet.m_score1,kmSet.m_subject2,pSet.m_score2);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+2200;
	ss.Format("%s  %d         %s  %d",kmSet.m_subject3,pSet.m_score3,kmSet.m_subject4,pSet.m_score4);
	pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	rect.top=point.y+2350;
	if(kmSet.m_subject5!=""&&kmSet.m_subject6!=""&&flag){
		ss.Format("%s  %d         %s  %d",kmSet.m_subject5,pSet.m_score5,kmSet.m_subject6,pSet.m_score6);
		pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	}
	else if(kmSet.m_subject5!=""&&flag){
		ss.Format("%s  %d",kmSet.m_subject5,pSet.m_score5);
		pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
		flag=0;
	}

	rect.top=point.y+2500;
	if(kmSet.m_subject7!=""&&kmSet.m_subject8!=""&&flag){
		ss.Format("%s  %d         %s  %d",kmSet.m_subject7,pSet.m_score7,kmSet.m_subject8,pSet.m_score8);
		pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
	}
	else if(kmSet.m_subject7!=""&&flag){
		ss.Format("%s  %d",kmSet.m_subject5,pSet.m_score5);
		pDC->DrawText(ss,&rect,DT_LEFT|DT_TOP|DT_SINGLELINE);
		flag=0;
	}
	rect.top=point.y+2650;
	ss.Format("加权平均分:%3.2f",pSet.m_ave);
	pDC->DrawText(ss,&rect,DT_CENTER|DT_TOP|DT_SINGLELINE);
	



}

⌨️ 快捷键说明

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