📄 page1.cpp
字号:
fstinfor.Write(pbuffer,strsize);
b=TRUE;
fstinfor.Close();
}
}
if (b==FALSE) AfxMessageBox("没有此记录");
}
this->OnAll();
}
}
}
void CPage1::OnEdit()
{
// TODO: Add your control notification handler code here
int class_num;
CModifyDlg modifydlg;
if (modifydlg.DoModal() == IDOK )
{
if(modifydlg.m_npassword != 111111)
AfxMessageBox(_T("您的修改密码输入不正确"),MB_OKCANCEL,0);
else
{
BOOL b=FALSE;
int buffersizes;
LPTSTR pbuffers;
CFile fstinfor;
if(fstinfor.Open("stinfor.txt",CFile::modeRead))
{
buffersizes=(int)fstinfor.GetLength();
CString stinfor;
CString s1,s2,s3,s4;
int pos_start;
int pos_end;
pbuffers=stinfor.GetBuffer(buffersizes);
fstinfor.Read(pbuffers,buffersizes);
stinfor.ReleaseBuffer();
fstinfor.Close();
class_num=1;
s1.Format("\r\n%d\t%d\t",class_num,modifydlg.m_nxuehao);
s3.Format("%d\t%d\t",class_num,modifydlg.m_nxuehao);
class_num=2;
s2.Format("\r\n%d\t%d\t",class_num,modifydlg.m_nxuehao);
s4.Format("%d\t%d\t",class_num,modifydlg.m_nxuehao);
if(stinfor.Find(s1)!=-1)
{
pos_start=stinfor.Find(s1);
pos_end=stinfor.Find('\n',pos_start+2);
stinfor.Delete(pos_start,pos_end-pos_start-1);
int strsize=stinfor.GetLength();
char* pbuffer=stinfor.GetBuffer(strsize);
fstinfor.Open("stinfor.txt",CFile::modeCreate|CFile::modeWrite);
fstinfor.Write(pbuffer,strsize);
b=TRUE;
fstinfor.Close();
}
else if(stinfor.Find(s2)!=-1)
{
pos_start=stinfor.Find(s2);
pos_end=stinfor.Find('\n',pos_start+2);
stinfor.Delete(pos_start,pos_end-pos_start-1);
int strsize=stinfor.GetLength();
char* pbuffer=stinfor.GetBuffer(strsize);
fstinfor.Open("stinfor.txt",CFile::modeCreate|CFile::modeWrite);
fstinfor.Write(pbuffer,strsize);
b=TRUE;
fstinfor.Close();
}
else
{
pos_start=0;
pos_end=stinfor.Find('\t',2);
if(s3.Compare(stinfor.Left(pos_end+1))==0||s4.Compare(stinfor.Left(pos_end+1))==0)
{
pos_end=stinfor.Find('\n');
stinfor.Delete(0,pos_end+1);
int strsize=stinfor.GetLength();
char* pbuffer=stinfor.GetBuffer(strsize);
fstinfor.Open("stinfor.txt",CFile::modeCreate|CFile::modeWrite);
fstinfor.Write(pbuffer,strsize);
b=TRUE;
fstinfor.Close();
}
}
}
if (b==FALSE) AfxMessageBox("没有这个学号");
else
{
CString s;
if(modifydlg.m_nxuehao<200)
class_num=1;
else
class_num=2;
s.Format("%d\t%d\t%s\t%.f\t%.f\t%.f\t%.f\t%.f\r\n",
class_num,
modifydlg.m_nxuehao,
modifydlg.m_Name,
modifydlg.m_nMaths,
modifydlg.m_nwuli,
modifydlg.m_nhuaxue,
modifydlg.m_nEnglish,
modifydlg.m_nzhengz);
int nstrsize=s.GetLength();
char *newpbuffer=s.GetBuffer(nstrsize);
fstinfor.Open("stinfor.txt",CFile::modeWrite);
fstinfor.SeekToEnd();
fstinfor.Write(newpbuffer,nstrsize);
fstinfor.Close();
}
this->OnAll();
}
}
}
void CPage1::OnFind()
{
// TODO: Add your control notification handler code here
BOOL m_canfind;
CFindDlg findialg;
if (findialg.DoModal()==IDOK)
{
m_canfind=FALSE;
int buffersizes;
m_clist3.DeleteAllItems();
LPTSTR pbuffers;
CFile fstinfor;
if(fstinfor.Open("stinfor.txt",CFile::modeRead))
{
buffersizes=(int)fstinfor.GetLength();
CString stinfor;
pbuffers=stinfor.GetBuffer(buffersizes);
fstinfor.Read(pbuffers,buffersizes);
stinfor.ReleaseBuffer();
m_xuan.GetLBText(m_xuan.GetCurSel(),m_Getstring);
int n=0;
int m=0;
int class_num;
BOOL display;
int ststart=0;
CString temp;
CString s;
float sum_courses=0;
if(m_Getstring=="一班")
class_num=1;
if(m_Getstring=="二班")
class_num=2;
//// m_set.Open();
for(int stend=0;stend<buffersizes;stend++)
{
if(stinfor.GetAt(stend)=='\t'||stinfor.GetAt(stend)=='\n')
{
temp=stinfor.Mid(ststart,(stend-ststart));
switch(m)
{
case 0: if(atoi(temp)==class_num)
display=TRUE;
else
display=FALSE;
break;
case 1: if(display)
{
if((findialg.m_getstring2==">=")&&(atoi(temp)<(int)findialg.m_ntiaojian))
display=FALSE;
if((findialg.m_getstring2=="=")&&(atoi(temp)!=(int)findialg.m_ntiaojian))
display=FALSE;
if((findialg.m_getstring2=="<=")&&(atoi(temp)>(int)findialg.m_ntiaojian))
display=FALSE;
if(display)
{
m_canfind=TRUE;
sum_courses=0;
m_clist3.InsertItem(n,"");
s.Format("%d",atoi(temp));
m_clist3.SetItemText(n,0,s);
}
}
break;
case 2: if(display)
{
m_clist3.SetItemText(n,1,temp);
}
break;
case 7: if(display)
{
s.Format("%.1f",atof(temp));
m_clist3.SetItemText(n,6,s);
sum_courses=sum_courses+(float)atof(temp);
s.Format("%.1f",sum_courses);
m_clist3.SetItemText(n,7,s);
s.Format("%.1f",sum_courses/5);
m_clist3.SetItemText(n,8,s);
n++;
}
break;
default: if(display)
{
s.Format("%.1f",atof(temp));
m_clist3.SetItemText(n,m-1,s);
sum_courses=sum_courses+(float)atof(temp);
}
}
ststart=stend+1;
m=(m+1)%8;
}
}
fstinfor.Close();
if(!m_canfind)
::AfxMessageBox("没有您所要求的结果,请修改查询条件重新查询!");
}
}
}
void CPage1::OnAll()
{
// TODO: Add your control notification handler code here
int buffersizes;
//char * pbuffers;
// char * pbuffert;
m_clist3.DeleteAllItems();
////if(m_set.IsOpen()) m_set.Close();
LPTSTR pbuffers;
CFile fstinfor;
if(fstinfor.Open("stinfor.txt",CFile::modeRead))
{
buffersizes=(int)fstinfor.GetLength();
CString stinfor;
pbuffers=stinfor.GetBuffer(buffersizes);
fstinfor.Read(pbuffers,buffersizes);
stinfor.ReleaseBuffer();
m_xuan.GetLBText(m_xuan.GetCurSel(),m_Getstring);
//// m_set.m_strFilter.Empty();
int n=0;
int m=0;
int class_num;
BOOL display;
int ststart=0;
CString temp;
CString s;
float sum_courses=0;
if(m_Getstring=="一班")
class_num=1;
if(m_Getstring=="二班")
class_num=2;
//// m_set.Open();
for(int stend=0;stend<buffersizes;stend++)
{
if(stinfor.GetAt(stend)=='\t'||stinfor.GetAt(stend)=='\n')
{
temp=stinfor.Mid(ststart,(stend-ststart));
switch(m)
{
case 0: if(atoi(temp)==class_num)
display=TRUE;
else
display=FALSE;
break;
case 1: if(display)
{
sum_courses=0;
m_clist3.InsertItem(n,"");
s.Format("%d",atoi(temp));
m_clist3.SetItemText(n,0,s);
}
break;
case 2: if(display)
{
m_clist3.SetItemText(n,1,temp);
}
break;
case 7: if(display)
{
s.Format("%.1f",atof(temp));
m_clist3.SetItemText(n,6,s);
sum_courses=sum_courses+(float)atof(temp);
s.Format("%.1f",sum_courses);
m_clist3.SetItemText(n,7,s);
s.Format("%.1f",sum_courses/5);
m_clist3.SetItemText(n,8,s);
n++;
}
break;
default: if(display)
{
s.Format("%.1f",atof(temp));
m_clist3.SetItemText(n,m-1,s);
sum_courses=sum_courses+(float)atof(temp);
}
}
ststart=stend+1;
m=(m+1)%8;
}
}
fstinfor.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -