📄 studentdlg.cpp
字号:
if(MessageBox("确定要删除吗?","删除",36)==IDNO)
{
return;
}
_variant_t nTemp;
int i=0,n;
CString CourseName;
CString strSQL,str,str_Course,str_ID,str_IDtemp,strClass;
UpdateData(true);
strSQL="SELECT * ";
strSQL+="FROM 学生";
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL), m_pConnection_Std.GetInterfacePtr(),ADODB::adOpenDynamic,ADODB::adLockOptimistic,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打开数据表时发生异常。错误信息:%s",e.ErrorMessage());
} // 用SQL查询数据库,将数据存放于记录集中
m_pRecordset_Std->MoveFirst();
while (!m_pRecordset_Std->adoEOF)
{
m_pRecordset_Std->MoveNext();
i++;
}
//查看学号是否存在
n=i;
if(n>0)
{
m_pRecordset_Std->MoveFirst();
for(i=0;i<n;i++)
{
nTemp=m_pRecordset_Std->GetCollect("学号");
str=(LPCSTR)_bstr_t(nTemp);
if(m_ID==str)
{
nTemp=m_pRecordset_Std->GetCollect("学生ID");
str_ID=(LPCSTR)_bstr_t(nTemp);
m_pRecordset_Std->Close();
break;
}
else
m_pRecordset_Std->MoveNext();
if (i+1==n)
{
AfxMessageBox("没有这个学号的学生!");
m_pRecordset_Std->Close();
return;
}
}
}
//删除成绩记录
i=m_Course.GetCurSel()+1;
str.Format("%d",i);
n=m_Class.GetCurSel()+1;
strClass.Format("%d",n);
strSQL="SELECT 成绩.学生ID,成绩.课程ID,成绩.平时作业, 成绩.实验报告, 成绩.期中考试, 成绩.期末考试 ";
strSQL+="FROM 成绩 ";
strSQL+="WHERE 成绩.课程ID=";
strSQL+=str;
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL), m_pConnection_Std.GetInterfacePtr(),ADODB::adOpenDynamic,ADODB::adLockOptimistic,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打开数据表时发生异常。错误信息:%s",e.ErrorMessage());
} // 用SQL查询数据库,将数据存放于记录集中
m_pRecordset_Std->MoveFirst();
i=0;
while (!m_pRecordset_Std->adoEOF)
{
m_pRecordset_Std->MoveNext();
i++;
}
n=i;
if(n>0)
{
m_pRecordset_Std->MoveFirst();
for(i=0;i<n;i++)
{
nTemp=m_pRecordset_Std->GetCollect("学生ID");
str_IDtemp=(LPCSTR)_bstr_t(nTemp);
if(str_IDtemp==str_ID)
{
m_pRecordset_Std->Delete(ADODB::adAffectCurrent);
break;
}
else
m_pRecordset_Std->MoveNext();
}
m_pRecordset_Std->Update();
m_pRecordset_Std->Close();
}
MessageBox("删除成功!");
OnSelchangeComboCourse();
UpdateData(false);
}
//修改
void CStudentDlg::OnButtonUpdate()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_ID.GetLength()==0)
{
AfxMessageBox("请输入学号!");
return;
}
CString strSQL,str;
long StuID;
_variant_t nTemp;
int m=0,i=0;
i=m_Class.GetCurSel()+1;
str.Format("%d",i);
strSQL="SELECT 班级.班级ID, 学生.学生ID, 学生.班级ID, 学生.学号, 学生.姓名 ";
strSQL+="FROM 班级 INNER JOIN 学生 ON 班级.班级ID = 学生.班级ID ";
strSQL+="WHERE 班级.班级ID =";
strSQL+=str;
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL), m_pConnection_Std.GetInterfacePtr(),ADODB::adOpenDynamic,ADODB::adLockOptimistic,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打开数据表时发生异常。错误信息:%s",e.ErrorMessage());
} // 用SQL查询数据库,将数据存放于记录集中
m=0;
m_pRecordset_Std->MoveFirst();
while (!m_pRecordset_Std->adoEOF)
{
m_pRecordset_Std->MoveNext();
m++;
}
if(m>0)
{
m_pRecordset_Std->MoveFirst();
for(i=0;i<m;i++)
{
nTemp=m_pRecordset_Std->GetCollect("学号");
str=(LPCSTR)_bstr_t(nTemp);
if(str==m_ID)
break;
else
m_pRecordset_Std->MoveNext();
if (i+1==m)
{
AfxMessageBox("没有这个学号的学生!");
m_pRecordset_Std->Close();
return;
}
}
}
m_pRecordset_Std->PutCollect("学号",_variant_t(m_ID));
m_pRecordset_Std->PutCollect("姓名",_variant_t(m_Name));
nTemp=m_pRecordset_Std->GetCollect("学生ID");
StuID=nTemp;
m_pRecordset_Std->Update();
m_pRecordset_Std->Close();
m=m_Course.GetCurSel()+1;
str.Format("%d",m);
strSQL="SELECT 成绩.学生ID, 成绩.课程ID, 学生.学生ID, 课程.课程ID, 成绩.平时作业, 成绩.实验报告, 成绩.期中考试, 成绩.期末考试,成绩.总评成绩 ";
strSQL+="FROM 学生 INNER JOIN (课程 INNER JOIN 成绩 ON 课程.课程ID = 成绩.课程ID) ON 学生.学生ID = 成绩.学生ID ";
strSQL+="WHERE 课程.课程ID= ";
strSQL+=str;
try
{
m_pRecordset_Std->Open(_bstr_t(strSQL), m_pConnection_Std.GetInterfacePtr(),ADODB::adOpenDynamic,ADODB::adLockOptimistic,ADODB::adCmdText);
}
catch (_com_error e)
{
CString strError;
strError.Format("警告:打开数据表时发生异常。错误信息:%s",e.ErrorMessage());
}
m=0;
m_pRecordset_Std->MoveFirst();
while (!m_pRecordset_Std->adoEOF)
{
m_pRecordset_Std->MoveNext();
m++;
}
if(m>0)
{
long temp_Stu;
m_pRecordset_Std->MoveFirst();
for(i=0;i<m;i++)
{
nTemp=m_pRecordset_Std->GetCollect("学生.学生ID");
temp_Stu=nTemp;
if(temp_Stu==StuID)
break;
else
m_pRecordset_Std->MoveNext();
}
}
m_pRecordset_Std->PutCollect("平时作业",_variant_t(m_Exercise));
m_pRecordset_Std->PutCollect("实验报告",_variant_t(m_Report));
m_pRecordset_Std->PutCollect("期中考试",_variant_t(m_Midterm));
m_pRecordset_Std->PutCollect("期末考试",_variant_t(m_Terminal));
m_pRecordset_Std->PutCollect("总评成绩",_variant_t(m_Mark));
m_pRecordset_Std->Update();
m_pRecordset_Std->Close();
MessageBox("修改成功!");
OnSelchangeComboCourse();
UpdateData(false);
}
//现在时间
void CStudentDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString strTime,str;
time_t timer;
struct tm* t_tm;
time(&timer);
t_tm = localtime(&timer);
str.Format("%d",t_tm->tm_year+1900);
strTime=str;
strTime+="-";
str.Format("%d",t_tm->tm_mon+1);
strTime+=str;
strTime+="-";
str.Format("%d",t_tm->tm_mday);
strTime+=str;
strTime+=" ";
str.Format("%d",t_tm->tm_hour);
strTime+=str;
strTime+=":";
str.Format("%d",t_tm->tm_min);
strTime+=str;
strTime+=":";
str.Format("%d",t_tm->tm_sec);
strTime+=str;
GetDlgItem(IDC_STATIC_TIME)->SetWindowText(strTime);
CDialog::OnTimer(nIDEvent);
}
void CStudentDlg::OnButtonLocate()
{
// TODO: Add your control notification handler code here
CString str;
UpdateData(true);
if(m_ID=="")
{
AfxMessageBox("请输入学号!");
return;
}
for(int i=1;i<50;i++)
{
m_Grid.SetCol(1);
m_Grid.SetRow(i);
str=m_Grid.GetText();
if(str==m_ID)
{
m_Grid.SetTopRow(i);
m_Grid.SetRow(i-1);
m_Grid.SetRowSel(i);
m_Grid.SetBackColorSel(RGB(192,80,0));
break;
}
}
if(i==50)
{
AfxMessageBox("查无此学号!");
return;
}
UpdateData(false);
}
void CStudentDlg::OnClickMsflexgrid()
{
// TODO: Add your control notification handler code here
CString str;
UpdateData(true);
m_Grid.SetCol(1);
m_ID=m_Grid.GetText();
m_Grid.SetCol(2);
m_Name=m_Grid.GetText();
m_Grid.SetCol(3);
str=m_Grid.GetText();
m_Exercise=atof(str);
m_Grid.SetCol(4);
str=m_Grid.GetText();
m_Report=atof(str);
m_Grid.SetCol(5);
str=m_Grid.GetText();
m_Midterm=atof(str);
m_Grid.SetCol(6);
str=m_Grid.GetText();
m_Terminal=atof(str);
m_Grid.SetCol(7);
str=m_Grid.GetText();
m_Mark=atof(str);
m_Grid.SetColSel(1);
m_Grid.SetBackColorSel(RGB(192,80,0));
UpdateData(false);
}
void CStudentDlg::OnChangeEditExercise()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
Student2 * pStudent2;
pStudent2=new Student2;
CString id, name;
float exercise, report, midterm, terminal;
if (GetDlgItem(IDC_EDIT_EXERCISE)->GetWindowTextLength()==0)
GetDlgItem(IDC_EDIT_EXERCISE)->SetWindowText("0");
UpdateData(true);
id=m_ID,name=m_Name;
exercise=m_Exercise,report=m_Report,midterm=m_Midterm,terminal=m_Terminal;
pStudent2->SetStudent(id,name,exercise,report,midterm,terminal);
m_Mark=pStudent2->CalcMark();
UpdateData(false);
// TODO: Add your control notification handler code here
}
void CStudentDlg::OnChangeEditMidterm()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
Student2 * pStudent2;
pStudent2=new Student2;
CString id, name;
float exercise, report, midterm, terminal;
if (GetDlgItem(IDC_EDIT_MIDTERM)->GetWindowTextLength()==0)
GetDlgItem(IDC_EDIT_MIDTERM)->SetWindowText("0");
UpdateData(true);
id=m_ID,name=m_Name;
exercise=m_Exercise,report=m_Report,midterm=m_Midterm,terminal=m_Terminal;
pStudent2->SetStudent(id,name,exercise,report,midterm,terminal);
m_Mark=pStudent2->CalcMark();
UpdateData(false);
// TODO: Add your control notification handler code here
}
void CStudentDlg::OnChangeEditReport()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
Student2 * pStudent2;
pStudent2=new Student2;
CString id, name;
float exercise, report, midterm, terminal;
if (GetDlgItem(IDC_EDIT_REPORT)->GetWindowTextLength()==0)
GetDlgItem(IDC_EDIT_REPORT)->SetWindowText("0");
UpdateData(true);
id=m_ID,name=m_Name;
exercise=m_Exercise,report=m_Report,midterm=m_Midterm,terminal=m_Terminal;
pStudent2->SetStudent(id,name,exercise,report,midterm,terminal);
m_Mark=pStudent2->CalcMark();
UpdateData(false);
// TODO: Add your control notification handler code here
}
void CStudentDlg::OnChangeEditTerminal()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
Student2 * pStudent2;
pStudent2=new Student2;
CString id, name;
float exercise, report, midterm, terminal;
if (GetDlgItem(IDC_EDIT_TERMINAL)->GetWindowTextLength()==0)
GetDlgItem(IDC_EDIT_TERMINAL)->SetWindowText("0");
UpdateData(true);
id=m_ID,name=m_Name;
exercise=m_Exercise,report=m_Report,midterm=m_Midterm,terminal=m_Terminal;
pStudent2->SetStudent(id,name,exercise,report,midterm,terminal);
m_Mark=pStudent2->CalcMark();
UpdateData(false);
// TODO: Add your control notification handler code here
}
//颜色
HBRUSH CStudentDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
COLORREF m_Color;
m_Color=RGB(255,0,0);
if(nCtlColor==CTLCOLOR_EDIT)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(m_Color);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CStudentDlg::OnButtonUserman()
{
// TODO: Add your control notification handler code here
CUserManagement DlgUser;
DlgUser.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -