📄 fina.cpp
字号:
for(i=0;i<6;i++)
{
fStudentScoreSaving[i]=String2Float(cStudentScoreSaving[i]);
/*?????*/ wsprintf(str,"%d",(int)fStudentScoreSaving[i]);/*???????????????*/
}
//deal with adding student
if((lstrcmp(cStudentNameSaving,"姓 名")!=0)&&bIsFaceAddItem)
{
hDataFile=_lopen("fina.hui",OF_WRITE);
if(hDataFile==HFILE_ERROR)
return 0;
/* i=GetClassItemNum(hParentItem);
j=GetStudentItemNum(i,hChildItem);
*/
i=GetClassItemNum(hParentItem);
j=iStudentNumber[i];//total amount of student in one class
lstrcpy(classroom[i].student[j].cStudentName,cStudentNameSaving);
for(k=0;k<6;k++)
{
classroom[i].student[j].fScore[k]=fStudentScoreSaving[k];
lstrcpy(classroom[i].student[j].cStudentNum,cStudentNumSaving);
}
if(_llseek(hDataFile,i*sizeof(struct classinfo)+6*sizeof(struct subjectinfo)+sizeof(str)+j*sizeof(struct studentinfo)+3,0)==HFILE_ERROR)
{
MessageBox(hwnd,"Error Seek","Student Add",MB_OK);
}
if(_lwrite(hDataFile,(LPSTR)&classroom[i].student[j],sizeof(struct studentinfo))==HFILE_ERROR)
{
MessageBox(hwnd,"Error Write Student Info","Warning...",MB_OK);
}
// i=GetStudentItemNum(i,hChildItem);
// wsprintf(str,"%d",iStudentNumber[GetClassItemNum(hParentItem)]);
// MessageBox(NULL,str,"2",MB_OK);
if(_lclose(hDataFile)==HFILE_ERROR)
{
MessageBox(hwnd,"Error Close File Adding Student","Warning...",MB_OK);
}
bIsFaceAddItem=0;
hFaceOnItem[i][j]=AddOneItem(hTree,hClassItem[i],TVI_FIRST,classroom[i].student[j].cStudentName,idFaceOn);
// ReflashTreeWnd();
}
else if(lstrcmp(cStudentNameSaving,"姓 名")!=0)//deal with changing of the content of any student item
{
hDataFile=_lopen("Fina.hui",OF_WRITE);
if(hDataFile==HFILE_ERROR)
{
MessageBox(hwnd,"Error Open Fina.hui","Warning...",MB_OK);
return 0;
}
i=GetClassItemNum(hParentItem);
j=GetStudentItemNum(i,hChildItem);
lstrcpy(classroom[i].student[j].cStudentName,cStudentNameSaving);
lstrcpy(classroom[i].student[j].cStudentNum,cStudentNumSaving);
for(k=0;k<6;k++)
{
classroom[i].student[j].fScore[k]=fStudentScoreSaving[k];
}
if(_llseek(hDataFile,i*sizeof(struct classinfo)+6*sizeof(struct subjectinfo)+sizeof(str)+j*sizeof(struct studentinfo)+3,0)==HFILE_ERROR)
{
MessageBox(hwnd,"Error Seek Changing Student","Warning...",MB_OK);
}
if(_lwrite(hDataFile,(LPSTR)&classroom[i].student[j],sizeof(struct studentinfo))==HFILE_ERROR)
{
MessageBox(hwnd,"Error Write Student Info","Warning...",MB_OK);
}
if(_lclose(hDataFile)==HFILE_ERROR)
{
MessageBox(hwnd,"Error Close File Changing Info Of Student","Warning...",MB_OK);
}
// ReflashTreeWnd();
}
else
{
}
}
return 1;
}
void SetClassInfoWndContent(int iClassItemNum)
{
int k;
SetWindowText(hgClassNameWnd,classroom[iClassItemNum].cClassName);
for(k=0;k<6;k++)
{
SetWindowText(hgSubjectNameWnd[k],classroom[iClassItemNum].classsubject[k].cSubjectName);
wsprintf(cTmpBuff,"%d",(int)classroom[iClassItemNum].classsubject[k].fSubjectScore);
SetWindowText(hgSubjectScoreWnd[k],cTmpBuff);
}
}
void SetStudentInfoWndContent(int iClassItemNum,int iStudentItemNum)//parameters are array pos
{
int k;
float fTotalScoreInfoValue;
float fFinaScoreInfoValue;
float fScoreInfoValue;
float fTotalSubjectScoreInfoValue;
char str[21];
SetWindowText(hgStudentNameWnd,classroom[iClassItemNum].student[iStudentItemNum].cStudentName);
SetWindowText(hgStudentNumWnd,classroom[iClassItemNum].student[iStudentItemNum].cStudentNum);
for(k=0;k<6;k++)
{
SetWindowText(hgStudentSubjectWnd[k],classroom[iClassItemNum].classsubject[k].cSubjectName);
// wsprintf(str,"%d",(int)classroom[iClassItemNum].student[iStudentItemNum].fScore[k]);
// MessageBox(NULL,str,"1",MB_OK);
wsprintf(cTmpBuff,"%d",(int)classroom[iClassItemNum].student[iStudentItemNum].fScore[k]);
SetWindowText(hgStudentScoreWnd[k],cTmpBuff);
fTotalScoreInfoValue=fTotalScoreInfoValue+classroom[iClassItemNum].student[iStudentItemNum].fScore[k];
fScoreInfoValue=fScoreInfoValue+classroom[iClassItemNum].student[iStudentItemNum].fScore[k]*classroom[iClassItemNum].classsubject[k].fSubjectScore;
}
for(k=0;k<6;k++)
{
fTotalSubjectScoreInfoValue=fTotalSubjectScoreInfoValue+classroom[iClassItemNum].classsubject[k].fSubjectScore;
}
fFinaScoreInfoValue=fScoreInfoValue/fTotalSubjectScoreInfoValue;
wsprintf(str,"%d",(int)fTotalScoreInfoValue);
SetWindowText(hgStudentTotalScoreWnd,str);
wsprintf(str,"%d",(int)fFinaScoreInfoValue);
SetWindowText(hgStudentFinaScoreWnd,str);
}
int GetClassItemNum(HTREEITEM hChildItem)
{
int i;
for(i=0;i<20;i++)
{
if(hChildItem==hClassItem[i])
{
break;
}
}
return i;//arrary pos
}
int GetStudentItemNum(int iParentNum,HTREEITEM hChildItem)
{
int i;
// char str[10];
// for(i=0;i<20;i++)
// {
// for(j=0;j<50;j++)
// if(hChildItem==hFaceOnItem[i][j])
// {
// break;
// }
// }
// wsprintf(str,"%d",j);
// MessageBox(NULL,str,"getClassItemNum",MB_OK);
// if(hChildItem==hFaceOnItem[0][0])
// return 0;
for(i=0;i<50;i++)
{
if(hChildItem==hFaceOnItem[iParentNum][i])
{
break;
}
}
return i;//arrary pos
}
float String2Float(char cString[21])
{
char cDot='.';
BOOL bIsDot=0;
int iTmpNum=1;
float fResult;
// char str[20];
// char *pStr;
for(iTmpCount=0;iTmpCount<21;iTmpCount++)
{
if(cString[iTmpCount]=='\0')
break;
}
for(iTmpCount1=0;iTmpCount1<iTmpCount-1;iTmpCount1++)
{
if(cString[iTmpCount1]==cDot)
{
bIsDot=1;
break;
}
}
if(!bIsDot)
iTmpCount1++;
for(iTmpCount2=0;iTmpCount2<iTmpCount1;iTmpCount2++)
{
for(iTmpCount3=0;iTmpCount3<iTmpCount1-iTmpCount2-1;iTmpCount3++)
{
iTmpNum=iTmpNum*10;
}
fResult=fResult+(cString[iTmpCount2]-'0')*iTmpNum;
iTmpNum=1;
}
if(!bIsDot)
{
for(iTmpCount2=0;iTmpCount2<iTmpCount-iTmpCount1-1;iTmpCount2++)
{
for(iTmpCount3=0;iTmpCount3<iTmpCount2+1;iTmpCount3++)
{
iTmpNum=iTmpNum*10;
}
fResult=fResult+(cString[iTmpCount1+iTmpCount2]-'0')/iTmpNum;
iTmpNum=1;
}
}
bIsDot=0;
/*
pPos=strchr(cString,cDot);*/
// wsprintf(str,"%[precision]s",fResult);
// pStr=Float2String(fResult);
// str=Float2String(fResult);
// MessageBox(hwnd,str,"info",MB_OK);
return fResult;
}
/*
char * Float2String(float fFloat)
{
char *pResult;
// pResult[0]=fFloat+'0';
// pResult[1]='\0';
double dZs;
double dZs;
int iZs;
xs=modf(fFloat,&zs);
pResult="hello world";
return pResult;
}*/
BOOL ReflashTreeWnd()
{
int i,j;
iClassNumber=0;
for(i=0;i<20;i++)
{
iStudentNumber[i]=0;
hFaceAddItem[i]=NULL;
}
hDataFile=_lopen("fina.hui",OF_READ);
if(hDataFile==HFILE_ERROR)
{
MessageBox(hwnd,"Error Reading Fina.hui","Warning...",MB_OK);
return 0;
}
if(_llseek(hDataFile,0,0)==HFILE_ERROR)
{
MessageBox(hwnd,"Error Seek Reading Fina.hui","Warning...",MB_OK);
return 0;
}
for(i=0;i<20;i++)
{
if(hClassItem[i]!=0)
{
/* for(j=0;j<50;j++)
{
if(hFaceOnItem[j]!=0)
{
DelOneItem(hTree,hFaceOnItem[i][j]);
}
}
*/ DelOneItem(hTree,hClassItem[i]);
// MessageBox(hwnd,"success","notice",MB_OK);
}
}
for(i=0;i<20;i++)
{
_lread(hDataFile,&classroom[i],sizeof(struct classinfo));
if(lstrcmp(classroom[i].cClassName,"")==0||lstrcmp(classroom[i].cClassName,"班 名")==0)
break;
iClassNumber++;
lstrcpy(cTmpBuff,classroom[i].cClassName);
hClassItem[i]=AddOneItem(hTree,hRootItem,TVI_FIRST,cTmpBuff,idClass);
for(j=0;j<50;j++)
{
if(lstrcmp(classroom[i].student[j].cStudentName,"")==0||lstrcmp(classroom[i].student[j].cStudentName,"姓 名")==0)
break;
iStudentNumber[i]++;
lstrcpy(cTmpBuff,classroom[i].student[j].cStudentName);
hFaceOnItem[i][j]=AddOneItem(hTree,hClassItem[i],TVI_FIRST,cTmpBuff,idFaceOn);
}
LoadString(hInst,IDS_FACEADD,cTmpBuff,sizeof(cTmpBuff));
hFaceAddItem[i]=AddOneItem(hTree,hClassItem[i],TVI_LAST,cTmpBuff,idFaceAdd);
}
// for(i=0;i<20;i++)
// {
// wsprintf(cTmpBuff,"%d",(int)hFaceAddItem[0]);
// MessageBox(NULL,cTmpBuff,"info",MB_OK);
// }
_lclose(hDataFile);
return 1;
}
BOOL UpdateInfoData(void)
{
int i,j;
iClassNumber=0;
hDataFile=_lopen("fina.hui",OF_READ);
if(hDataFile==HFILE_ERROR)
return 0;
for(i=0;i<20;i++)
{
_lread(hDataFile,&classroom[i],sizeof(struct classinfo));
if(!lstrcmp(classroom[i].cClassName,""))
break;
iClassNumber++;
// lstrcpy(cTmpBuff,classroom[i].cClassName);
// hClassItem[i]=AddOneItem(hTree,hRootItem,TVI_FIRST,cTmpBuff,idClass);
for(j=0;j<50;j++)
{
if(!lstrcmp(classroom[i].student[j].cStudentName,""))
break;
iStudentNumber[j]++;
// lstrcpy(cTmpBuff,classroom[i].student[j].cStudentName);
// hFaceOnItem[i][j]=AddOneItem(hTree,hClassItem[i],TVI_FIRST,cTmpBuff,idFaceOn);
}
// LoadString(hInst,IDS_FACEADD,cTmpBuff,sizeof(cTmpBuff));
// hFaceAddItem=AddOneItem(hTree,hClassItem[i],TVI_FIRST,cTmpBuff,idFaceAdd);
}
_lclose(hDataFile);
return 1;
}
BOOL CALLBACK CreateStudentInfoWnd(HWND hParentWnd,HDC hParentDC)
{
int i;
SetBkMode(hParentDC,TRANSPARENT);
SetTextColor(hParentDC,RGB(0,0,0));
TextOut(hParentDC,3,5,"学生姓名",lstrlen("学生姓名"));
hgStudentNameWnd=CreateWindowEx(0L,
"edit",
"姓 名",
WS_CHILD|WS_VISIBLE|ES_LEFT,
73,5,90,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
TextOut(hParentDC,170,5,"学号",lstrlen("学号"));
hgStudentNumWnd=CreateWindowEx(0L,
"edit",
"学 号",
WS_VISIBLE|WS_CHILD|ES_LEFT,
205,5,80,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
TextOut(hParentDC,65,35,"学科名称",lstrlen("学科名称"));
TextOut(hParentDC,230,35,"成绩",lstrlen("成绩"));
for(i=0;i<6;i++)
{
hgStudentSubjectWnd[i]=CreateWindowEx(0L,
"edit",
"课 程",
WS_VISIBLE|WS_CHILD|ES_RIGHT|ES_READONLY,
15,35+(i+1)*25,170,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
hgStudentScoreWnd[i]=CreateWindowEx(0L,
"edit",
"0",
WS_CHILD|WS_VISIBLE|ES_CENTER,
225,35+(i+1)*25,40,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
}
TextOut(hParentDC,15,210,"总分",lstrlen("总分"));
hgStudentTotalScoreWnd=CreateWindowEx(0L,
"edit",
"0",
WS_VISIBLE|WS_CHILD|ES_CENTER|ES_READONLY,
55,210,50,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
TextOut(hParentDC,120,210,"综合测评成绩",lstrlen("综合测评成绩"));
hgStudentFinaScoreWnd=CreateWindowEx(0L,
"edit",
"0",
WS_VISIBLE|WS_CHILD|ES_CENTER|ES_READONLY,
225,210,40,15,
hParentWnd,
(HMENU)NULL,
hInst,
NULL);
return 1;
}
void ReflashStudentItem(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -