📄 courmanage.cpp
字号:
// CourManage.cpp : implementation file
//
#include "stdafx.h"
#include "StudentCheck.h"
#include "CourManage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCourManage dialog
CCourManage::CCourManage(CWnd* pParent /*=NULL*/)
: CDialog(CCourManage::IDD, pParent)
{
//{{AFX_DATA_INIT(CCourManage)
m_strAct = _T("");
//}}AFX_DATA_INIT
m_CurAdo.InitialDB();
}
CCourManage::~CCourManage()
{
m_CurAdo.ClosedDB();
}
void CCourManage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCourManage)
DDX_Control(pDX, IDC_ACT_LIST, m_lstAct);
DDX_Text(pDX, IDC_ACT_EDIT, m_strAct);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCourManage, CDialog)
//{{AFX_MSG_MAP(CCourManage)
ON_BN_CLICKED(IDC_ACT_ADD, OnActAdd)
ON_BN_CLICKED(IDC_ACT_MOD, OnActMod)
ON_BN_CLICKED(IDC_ACT_DEL, OnActDel)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_LBN_SELCHANGE(IDC_ACT_LIST, OnSelchangeActList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCourManage message handlers
BOOL CCourManage::OnInitDialog()
{
CDialog::OnInitDialog();
//首先,把数据库中的活动名称和ID号读进控件中
ReadToList();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCourManage::ReadToList()
{
//把数据库中的活动名称和ID号读进控件中
_bstr_t vSQL;
CString str1,str2;
int i=0;
sa_ActID.RemoveAll();
sa_ActName.RemoveAll();
m_lstAct.ResetContent();
//执行SELETE语句
vSQL="select CourseID, CourseName from Course order by CourseID";
m_CurAdo.GetRecordSet(vSQL);
_RecordsetPtr m_pRecordset ;
m_pRecordset = m_CurAdo.GetRecordSet(vSQL);
//获取记录集中的数据
while (m_pRecordset->adoEOF == 0)
{
sa_ActID.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("CourseID"));
sa_ActName.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("CourseName"));
m_lstAct.AddString(sa_ActName.GetAt(i));
i++;
m_pRecordset->MoveNext();
}
for(int j=0 ; j< sa_ActID.GetSize() ;j++)
{
m_lstAct.SetItemData(j,atoi(sa_ActID.GetAt(j))) ;
}
}
void CCourManage::OnActAdd()
{
//首先判断文本框里有字符输入,然后把输入的课程名称插入数据库
UpdateData(1);
_bstr_t vSQL;
if (m_strAct.IsEmpty())
{
AfxMessageBox("请输入活动名称!");
return;
}
else
{
vSQL="Insert into Course(CourseID,CourseName) \
select (Max(CourseID)+1),'" + m_strAct + "' from Course";
m_CurAdo.ExecuteSQL(vSQL);
ReadToList(); //更新listbox控件
}
}
void CCourManage::OnActMod()
{
//把文本框中的信息(活动名称)重新写入数据库,执行更新操作
UpdateData(1);
_bstr_t vSQL;
if (m_lstAct.GetCurSel()<0)
{
AfxMessageBox("请先选择,左边框中的活动名称.");
return;
}
if (m_strAct.IsEmpty())
{
AfxMessageBox("请输入活动名称!");
return;
}
else
{
CString str1;
str1.Format("%i",m_lstAct.GetItemData(m_lstAct.GetCurSel()));
vSQL="UPDATE Course set CourseName='"+m_strAct +"' where CourseID= "+str1;
if (m_CurAdo.ExecuteSQL(vSQL))
{
ReadToList(); //更新listBox控件
AfxMessageBox("更新成功",MB_OK);
}
}
}
void CCourManage::OnActDel()
{
_bstr_t vSQL;
CString str;
if (m_lstAct.GetCurSel()<0)
{
AfxMessageBox("请先选择左边的活动项!");
return;
}
if (MessageBox("您确定要删除当前部门吗?", "请确认", MB_YESNO) == IDYES)
{
str.Format("%d",m_lstAct.GetItemData(m_lstAct.GetCurSel()));
vSQL = "DELETE FROM Course Where CourseID=" + str;
if (m_CurAdo.ExecuteSQL(vSQL))
{
AfxMessageBox("删除成功!!!");
ReadToList();
m_strAct="";
UpdateData(0);
}
else
AfxMessageBox("删除失败!!!");
}
}
void CCourManage::OnExit()
{
this->OnOK();
}
void CCourManage::OnSelchangeActList()
{
CString str1;
m_lstAct.GetText(m_lstAct.GetCurSel(),str1);
m_strAct=str1;
UpdateData(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -