📄 student.cpp
字号:
m_ctrlsex.EnableWindow(false);
m_ctrlstucode.EnableWindow(true);
m_ctrlstuid.EnableWindow(false);
m_ctrlstuiyear.EnableWindow(false);
m_ctrlstuname.EnableWindow(false);
m_ctrlstuspe.EnableWindow(false);
m_ctrlstucountry.EnableWindow(false);
m_ctrlstunewspe.EnableWindow(false);
m_ctrlstuclassnum.EnableWindow(false);
m_ctrlisforign.EnableWindow(false);
m_ctrlzhusu.EnableWindow(false);
m_ctrlpenkun.EnableWindow(false);
m_ctrlstucode.SetFocus();
}
bool CStudent::isRepeated(CString str)
{
CString sql; //查询信息
sql.Format("select * from Student where Stucode = \'%s\'",str);
theApp.record1->raw_Close(); //关闭当前数集
theApp.record1->CursorLocation = adUseClient;
theApp.record1->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (theApp.record1->RecordCount > 0)
return true;
return false;
}
bool CStudent::notExist(CString str)
{
CString sql; //查询信息
sql.Format("select * from student where stuID = \'%s\'",str);
theApp.record1->raw_Close(); //关闭当前数据集they are the one
theApp.record1->CursorLocation = adUseClient;
theApp.record1->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if(theApp.record1->RecordCount == 0)
return true;
return false;
}
void CStudent::OnStusubmit()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(deleteItem) //删除学生信息,使用存储过程spDeleteStudent
{
if(m_stucode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstucode.SetFocus();
return;
}
if(notExist(m_stucode))
{
MessageBox("此学生不存在!");
m_ctrlstucode.SetFocus();
return;
}
CString sql;
sql.Format("execute spDeleteStudent \'%s\'",m_stucode);
theApp.record->raw_Close();
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
RefreshInfo(); //刷新
MessageBox("删除成功!");
m_ctrlstucode.SetFocus();
}
if(queryItem) //查询
{
if(m_stucode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstucode.SetFocus();
return;
}
if(notExist(m_stucode))
{
MessageBox("此学生不存在!");
m_ctrlstucode.SetFocus();
return;
}
CString sql;//视图StuInfo查询
sql.Format("select * from StuInfo where StuID =\'%s\'",m_stucode);
theApp.record->raw_Close();
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
if(theApp.record->RecordCount > 0) //非空集合
{
m_stugrid.SetRefDataSource((LPUNKNOWN)theApp.record->DataSource); //将查询结果显示到DataGrid控件
m_stugrid.Refresh();
}
m_ctrlstucode.SetFocus();
}
if(insertItem)//插入
{
if(m_stucode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstucode.SetFocus();
return;
}
if(m_stuname.GetLength() == 0)
{
MessageBox("姓名不能为空!");
m_ctrlstuname.SetFocus();
return;
}
if(m_sex.GetLength() == 0)
{
MessageBox("性别不能为空!");
m_ctrlsex.SetFocus();
return;
}
if(m_stuspe.GetLength() == 0)
{
MessageBox("所学专业不能为空!");
m_ctrlstuspe.SetFocus();
return;
}
if(m_isforign)
if(m_stucountry.GetLength() == 0)
{
MessageBox("国籍不能为空!");
m_ctrlstucountry.SetFocus();
return;
}
if(m_stuid.GetLength() == 0)
{
MessageBox("身份证号不能为空!");
m_ctrlstuid.SetFocus();
return;
}
if(m_stuiyear < 1000)
{
MessageBox("入学年份太小!");
m_ctrlstuiyear.SetFocus();
return;
}
if(m_penkun)
penkun = "是";
else
penkun = "否";
if(m_zhusu)
zhusu = "是";
else
zhusu = "否";
if(m_isforign)
isForeign = "是";
else
isForeign = "否";
CString sql; //执行存储过程spInSertStudent
sql.Format("exec spInSertStudent '%s','%s','%s','%s','%d','%s','%s','%d','%s','%s','%s','%s'",m_stucode,m_stuspe,m_stuname,m_sex,m_stuiyear,isForeign,m_stucountry,m_stuclassnumber,m_cashid,m_stuid,penkun,zhusu);
theApp.record->raw_Close();
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
RefreshInfo();//刷新
MessageBox("插入数据!");
m_ctrlstucode.SetFocus();
}
if(modifyItem)//修改
{
if(m_stucode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstucode.SetFocus();
return;
}
if(m_stuname.GetLength() == 0)
{
MessageBox("姓名不能为空!");
m_ctrlstuname.SetFocus();
return;
}
if(m_sex.GetLength() == 0)
{
MessageBox("性别不能为空!");
m_ctrlsex.SetFocus();
return;
}
if(m_stuspe.GetLength() == 0)
{
MessageBox("所学专业不能为空!");
m_ctrlstuspe.SetFocus();
return;
}
if(m_stuid.GetLength() == 0)
{
MessageBox("身份证号不能为空!");
m_ctrlstuid.SetFocus();
return;
}
if(m_stuiyear < 1000)
{
MessageBox("入学年份太小!");
m_ctrlstuiyear.SetFocus();
return;
}
if(m_stuclassnumber < 0)
{
MessageBox("班级不能为负!");
m_ctrlstuclassnum.SetFocus();
return;
}
if(m_isforign)
if(m_stucountry.GetLength() == 0)
{
MessageBox("国籍不能为空!");
m_ctrlstucountry.SetFocus();
return;
}
if(notExist(m_stucode))
{
MessageBox("不存在此学生!");
m_ctrlstucode.SetFocus();
return;
}
if(m_penkun)
penkun = "是";
else
penkun = "否";
if(m_zhusu)
zhusu = "是";
else
zhusu = "否";
if(m_isforign)
isForeign = "是";
else
isForeign = "否";
CString sql; //执行存储过程spUpdateStudent
// sql.Format("Update Student set stuname= '%s',iyear ='%d',sex ='%s',speID ='%s',classnum ='%d',idcard = '%s',cashcardid = '%s',zhusu ='%s',penkun ='%s' where StuID = '%s'",m_stuname,m_stuiyear,m_sex,m_stuspe,m_stunumber,m_stuid,m_cashid,zhusu,penkun,m_stucode);
sql.Format("exec spUpdateStudent '%s','%s','%s','%s','%s','%d','%s','%s','%d','%s','%s','%s','%s'",m_stucode,m_stunewspe,m_stuspe,m_stuname,m_sex,m_stuiyear,isForeign,m_stucountry,m_stuclassnumber,m_cashid,m_stuid,penkun,zhusu);
theApp.record->raw_Close();
theApp.record->CursorLocation = adUseClient;
try //捕捉异常
{
theApp.record->Open((_bstr_t)sql,theApp.connection.GetInterfacePtr(),adOpenKeyset,adLockPessimistic,adCmdText);
}
catch(_com_error & e)
{
AfxMessageBox(e.Description());
return; //捕捉到异常后就不在继续执行
}
RefreshInfo();//刷新
MessageBox("更改成功!");
m_ctrlstucode.SetFocus();
}
}
void CStudent::OnStunew()
{
// TODO: Add your control notification handler code here
RefreshInfo(); //刷新
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -