大综合应用学生学习成绩管理程序刘吉林Word文件下载.docx
《大综合应用学生学习成绩管理程序刘吉林Word文件下载.docx》由会员分享,可在线阅读,更多相关《大综合应用学生学习成绩管理程序刘吉林Word文件下载.docx(25页珍藏版)》请在冰豆网上搜索。
if(!
AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
returnFALSE;
}
CStringsPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
intnPos;
nPos=sPath.ReverseFind('
\\'
);
sPath=sPath.Left(nPos);
nPos=sPath.ReverseFind('
CStringlpszFile=sPath+"
\\mydb.mdb"
;
char*szDesc;
intmlen;
szDesc=newchar[256];
sprintf(szDesc,"
DSN=%s?
DESCRIPTION=TOCsupportsource?
DBQ=%s?
FIL=MicrosoftAccess?
DEFAULTDIR=%s?
?
"
"
mydb"
lpszFile,sPath);
mlen=strlen(szDesc);
for(inti=0;
i<
mlen;
i++)
if(szDesc[i]=='
'
)
szDesc[i]='
\0'
if(FALSE==SQLConfigDataSource(NULL,ODBC_ADD_DSN,"
MicrosoftAccessDriver(*.mdb)\0"
(LPCSTR)szDesc))
AfxMessageBox("
SQLConfigDataSourceFailed"
try
CStringstrConnect;
strConnect.Format("
DSN=mydb;
"
if(!
m_DB.OpenEx(strConnect,CDatabase:
:
useCursorLib))
UnabletoConnecttotheSpecifiedDataSource"
returnFALSE;
catch(CDBException*pE)
pE->
ReportError();
Delete();
returnFALSE;
//////////////////////////////
其中m_DB是定义的一个CDatabase对象,用来指向数据库mymdb。
2)、新建CRecordset数据集类
在项目中,共有四个数据集类,分别是CDRecordset、CBRecordset、CTRecordset、CSinfoRecordset。
它们分别对应学生成绩表、成绩概况表、教师表和学生信息表。
3)、学生成绩模块的代码
BOOLCBaDialog:
OnInitDialog()
{
CDialog:
OnInitDialog();
CDRecordsetm_Set(&
theApp.m_DB);
CBRecordsetm_bSet(&
CTRecordsetm_tSet(&
//////////初始化列表控件ListCtrlx
unsignedi=0;
CODBCFieldInfoInfo;
m_Set.Open();
m_ListCtrlx.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
for(i=0;
i<
m_Set.m_nFields;
i++)
m_Set.GetODBCFieldInfo(i,Info);
m_ListCtrlx.InsertColumn(i,Info.m_strName,LVCFMT_LEFT,80);
m_Set.Close();
//////////初始化列表控件ListCtrlb
m_bSet.Open();
m_ListCtrlb.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_bSet.m_nFields;
m_bSet.GetODBCFieldInfo(i,Info);
m_ListCtrlb.InsertColumn(i,Info.m_strName,LVCFMT_LEFT,80);
m_bSet.Close();
////////////////////////////////////
/////////////初始化列表控件ListCtrll
m_ListCtrll.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ListCtrll.InsertColumn(0,_T("
科目"
),LVCFMT_IMAGE|LVCFMT_LEFT);
m_ListCtrll.InsertColumn(1,"
任课老师"
for(i=0;
2;
m_ListCtrll.SetColumnWidth(i,80);
m_cob.SetCurSel
(1);
this->
Enable(FALSE);
m_Timer=SetTimer(1,2,NULL);
m_bIsAsc=TRUE;
m_bS=TRUE;
returnTRUE;
//returnTRUEunlessyousetthefocustoacontrol
//EXCEPTION:
OCXPropertyPagesshouldreturnFALSE
}
voidCBaDialog:
OnStatr()
//TODO:
Addyourcontrolnotificationhandlercodehere
m_ListCtrlx.DeleteAllItems();
m_ListCtrlb.DeleteAllItems();
m_ListCtrll.DeleteAllItems();
if(m_Set.IsOpen())
if(m_bSet.IsOpen())
m_cob.GetLBText(m_cob.GetCurSel(),m_Getstring);
Select();
if(m_Getstring=="
计本一班"
m_tSet.Open();
if(m_Getstring=="
计本二班"
m_tSet.Open(AFX_DB_USE_DEFAULT_TYPE,"
[NO2TECHER]"
m_nRecordCount=this->
Show();
//初始化“学生成绩详单”,并返回字段数
display();
//初始化“各科成绩概况”
exhibit();
//将teacher表中的记录加载到“任课教师”
m_bS=GetDlgItem(IDC_STATR)->
EnableWindow(true);
Enable(TRUE);
intCBaDialog:
Show()
inti=0;
m_Set.MoveFirst();
do
{
CStrings;
s.Format("
%d"
m_Set.m_column1);
m_ListCtrlx.InsertItem(i,s,0);
m_ListCtrlx.SetItemText(i,1,m_Set.m_column2);
%.1f"
m_Set.m_column3);
m_ListCtrlx.SetItemText(i,2,s);
m_Set.m_column4);
m_ListCtrlx.SetItemText(i,3,s);
m_Set.m_column5);
m_ListCtrlx.SetItemText(i,4,s);
m_Set.m_column6);
m_ListCtrlx.SetItemText(i,5,s);
m_Set.m_column7);
m_ListCtrlx.SetItemText(i,6,s);
m_Set.m_column8);
m_ListCtrlx.SetItemText(i,7,s);
%.2f"
m_Set.m_column9);
m_ListCtrlx.SetItemText(i,8,s);
i++;
m_Set.MoveNext();
}while(!
m_Set.IsEOF());
returni;
voidCBaDialog:
display()
m_bSet.MoveFirst();
CStrings;
m_ListCtrlb.InsertItem(i,m_bSet.m_column1,0);
s.Format("
m_bSet.m_column2);
m_ListCtrlb.SetItemText(i,1,s);
m_bSet.m_column3);
m_ListCtrlb.SetItemText(i,2,s);
m_bSet.m_column4);
m_ListCtrlb.SetItemText(i,3,s);
m_bSet.m_column5);
m_ListCtrlb.SetItemText(i,4,s);
i++;
m_bSet.MoveNext();
}while(!
m_bSet.IsEOF());
exhibit()
m_ListCtrll.InsertItem(i,m_tSet.m_column1,0);
m_ListCtrll.SetItemText(i,1,m_tSet.m_column2);
m_tSet.MoveNext();
}while(!
m_tSet.IsEOF());
m_tSet.Close();
Enable(BOOLp)
BOOLHB;
HB=p;
GetDlgItem(IDC_ADD)->
EnableWindow(HB);
GetDlgItem(IDC_DELECT)->
GetDlgItem(IDC_EDIT)->
GetDlgItem(IDC_FIND)->
GetDlgItem(IDC_ALL)->
CStringCBaDialog:
Select()//班级的选择
{
m_Set.Open();
m_bSet.Open();
else
m_Set.Open(AFX_DB_USE_DEFAULT_TYPE,"
[NO2STUDENT]"
m_bSet.Open(AFX_DB_USE_DEFAULT_TYPE,"
[NO2OBJECT]"
returnm_Getstring;
}
Equal()
for(inti=0;
5;
floatp=0;
if(i==0)
p=m_Set.m_column3;
if(i==1)
p=m_Set.m_column4;
if(i==2)
p=m_Set.m_column5;
if(i==3)
p=m_Set.m_column6;
if(i==4)
p=m_Set.m_column7;
m_bSet.Edit();
if(Selec==FALSE)
m_bSet.m_column2-=p;
m_bSet.m_column3=(float)(m_bSet.m_column2/m_nRecordCount);
if(p>
=60)
m_bSet.m_column4-=1;
=80)
m_bSet.m_column5-=1;
m_bSet.m_column2+=p;
m_bSet.m_column4+=1;
m_bSet.m_column5+=1;
m_bSet.Update();
m_bSet.IsEOF())
break;
Xuan()
OnTimer(UINTnIDEvent)
Addyourmessagehandlercodehereand/orcalldefault
CStringm_string;
m_cob.GetLBText(m_cob.GetCurSel(),m_string);
if(m_Getstring!
=m_string)
GetDlgItem(IDC_STATR)->
EnableWindow(TRUE);
OnTimer(nIDEvent);
OnAdd()
Selec=TRUE;
CAddialogdlg;
/////////////////////////////
m_Set.Close();
m_bSet.Close();
if(m_tSet.IsOpen())
m_tSet.Close();
/////////////////////////////////
if(dlg.DoModal()==IDOK)
m_Set.AddNew();
m_nRecordCount+=1;
m_Set.m_column1=dlg.m_nxue;
m_Set.m_column2=dlg.m_strName;
m_Set.m_column3=dlg.m_fmaths;
m_Set.m_column4=dlg.m_fphysical;
m_Set.m_column5=dlg.m_fchemistry;
m_Set.m_column6=dlg.m_fenglish;
m_Set.m_column7=dlg.m_fpolitic;
m_Set.m_column8=dlg.m_fmaths+dlg.m_fphysical+dlg.m_fchemistry+dlg.m_fenglish+dlg.m_fpolitic;
m_Set.m_column9=(float)(m_Set.m_column8/5);
this->
Equal();
m_Set.Update();
//Update()一定放在Equal()后
m_Set.Requery();
Xuan();
OnDelect()
CDelectDialogdlg;
Selec=FALSE;
if(dlg.DoModal()==IDOK)
m_Set.MoveFirst();
BOOLsel=FALSE;
do
if(m_Set.m_column1!
=dlg.m_nxue)
m_Set.MoveNext();
else
{
m_nRecordCount-=1;
sel=TRUE;
m_bSet.MoveFirst();
this->
m_Set.Delete();
m_Set.Requery();
break;
}
}while(!
if(sel==FALSE)
AfxMessageBox("
没有此记录"
return;
}
else
OnFind()
CFinDialogdlg;
//选择班级
if(dlg.m_Getstring2=="
>
="
m_Set.m_strFilter.Format("
[%s]>
=%.2f"
dlg.m_Getstring1,dlg.m_find);
[%s]=%.2f"
<
[%s]<
m_ListCtrlx.DeleteAllItems();
if(m_Set.IsEOF())
{
没有符合条件的记录"
m_Set.Close();
return;
OnAll()
m_Set.m_strFilter.Empty();
m_Set.Requery();
OnEdit()
Addyourcon