📄 studyin.cpp
字号:
// StudyIn.cpp : implementation file
//
#include "stdafx.h"
#include "StuChgManager.h"
#include "StudyIn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CStuChgManagerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CStudyIn dialog
CStudyIn::CStudyIn(CWnd* pParent /*=NULL*/)
: CDialog(CStudyIn::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudyIn)
m_stuincode = _T("");
m_stuinspecility = _T("");
m_stuinclasscify = -1;
//}}AFX_DATA_INIT
}
void CStudyIn::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudyIn)
DDX_Control(pDX, IDC_STUINspeciality, m_ctrlstuinspe);
DDX_Control(pDX, IDC_STUINcode, m_ctrlstuincode);
DDX_Text(pDX, IDC_STUINcode, m_stuincode);
DDX_Text(pDX, IDC_STUINspeciality, m_stuinspecility);
DDX_Radio(pDX, IDC_STUINSPE_CODE, m_stuinclasscify);
DDX_Control(pDX, IDC_DATAGRID6, m_stuingrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudyIn, CDialog)
//{{AFX_MSG_MAP(CStudyIn)
ON_BN_CLICKED(IDC_STUINSPE, OnStuinspe)
ON_BN_CLICKED(IDC_STUINSPESUBMIT, OnStuinspesubmit)
ON_BN_CLICKED(IDC_STUINSPE_CODE, OnStuinspeCode)
ON_BN_CLICKED(IDC_STUINSPE_SPE, OnStuinspeSpe)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStudyIn message handlers
BOOL CStudyIn::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
deleteItem = false; //初始操作失效
queryItem = false;
m_ctrlstuincode.SetWindowText(""); //清空Edit框
m_ctrlstuinspe.SetWindowText("");
m_ctrlstuincode.EnableWindow(false); //编辑框失效
m_ctrlstuinspe.EnableWindow(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStudyIn::OnStuinspe()
{
// TODO: Add your control notification handler code here
deleteItem = true; //删除有效
queryItem = false;
m_ctrlstuincode.SetWindowText(""); //清空
m_ctrlstuinspe.SetWindowText("");
m_ctrlstuincode.EnableWindow(true);//编辑框有效
m_ctrlstuinspe.EnableWindow(true);
m_ctrlstuincode.SetFocus();
}
void CStudyIn::OnStuinspeCode()
{
// TODO: Add your control notification handler code here
deleteItem = false; //按学号查询有效
queryItem = true;
m_ctrlstuincode.SetWindowText(""); //清空
m_ctrlstuinspe.SetWindowText("");
m_ctrlstuincode.EnableWindow(true);
m_ctrlstuinspe.EnableWindow(false);
m_ctrlstuincode.SetFocus();
}
void CStudyIn::OnStuinspeSpe()
{
// TODO: Add your control notification handler code here
deleteItem = false; //按专业查询
queryItem = true;
m_ctrlstuincode.SetWindowText("");
m_ctrlstuinspe.SetWindowText("");
m_ctrlstuinspe.EnableWindow(true);
m_ctrlstuincode.EnableWindow(false);
m_ctrlstuinspe.SetFocus();
}
bool CStudyIn::notspeExist(CString str)
{
CString sql;//查询记录
sql.Format("select * from StudyIn where speID = \'%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;
}
bool CStudyIn::notstuExist(CString str)
{
CString sql;//查询记录
sql.Format("select * from studyin 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;
}
bool CStudyIn::notExist(CString str1,CString str2)
{
CString sql; //查询记录
sql.Format("select * from studyin where stuID = \'%s\' and speID = '%s'",str1,str2);
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 CStudyIn::RefreshInfo()
{
m_ctrlstuincode.SetWindowText("");//请空
m_ctrlstuinspe.SetWindowText("");
m_stuingrid.SetRefDataSource(NULL);
CString sql;
sql = "select stuID as 学生学号,speID as 专业代码,classnum as 班级 from studyin";
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_stuingrid.SetRefDataSource((LPUNKNOWN)theApp.record->DataSource); //将查询结果显示到DataGrid控件
m_stuingrid.Refresh();
}
}
void CStudyIn::OnStuinspesubmit()
{
// TODO: Add your control notification handler code here
UpdateData(true);
CString sql;
if(queryItem) //查询
{
if(m_stuinclasscify == 0) //按学号查询
{
if(m_stuincode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstuincode.SetFocus();
return;
}
if(notstuExist(m_stuincode))
{
MessageBox("此学生不存在!");
m_ctrlstuincode.SetFocus();
return;
}
sql.Format("select * from studyin where stuID = '%s'",m_stuincode);
} //按专业查询
if(m_stuinclasscify == 1)
{
if(m_stuinspecility.GetLength() == 0)
{
MessageBox("专业不能为空!");
m_ctrlstuinspe.SetFocus();
return;
}
if(notspeExist(m_stuinspecility))
{
MessageBox("此专业不存在!");
m_ctrlstuinspe.SetFocus();
return;
}
sql.Format("select * from studyin where speID = '%s'",m_stuinspecility);
}
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_stuingrid.SetRefDataSource((LPUNKNOWN)theApp.record->DataSource); //将查询结果显示到DataGrid控件
m_stuingrid.Refresh();
}
m_ctrlstuincode.SetWindowText("");
m_ctrlstuinspe.SetWindowText("");
MessageBox("成功查询!");
}
if(deleteItem)//删除
{
if(m_stuincode.GetLength() == 0)
{
MessageBox("学号不能为空!");
m_ctrlstuincode.SetFocus();
return;
}
if(m_stuinspecility.GetLength() == 0)
{
MessageBox("专业不能为空!");
m_ctrlstuinspe.SetFocus();
return;
}
if(notExist(m_stuincode,m_stuinspecility))
{
MessageBox("此学生没有修这门课!");
m_ctrlstuincode.SetFocus();
return;
}
CString sql; //执行存储过程spDeleteStudyIn
sql.Format("exec spDeleteStudyIn '%s','%s'",m_stuincode,m_stuinspecility);
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_ctrlstuincode.SetFocus();
}
}
void CStudyIn::OnButton1()
{
// TODO: Add your control notification handler code here
this->RefreshInfo(); //刷新
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -