📄 active.cpp
字号:
// Active.cpp : implementation file
//
#include "stdafx.h"
#include "StudentCheck.h"
#include "Active.h"
#include "StuActive.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CActive dialog
CActive::CActive(CWnd* pParent /*=NULL*/)
: CDialog(CActive::IDD, pParent)
{
//{{AFX_DATA_INIT(CActive)
m_strAct = _T("");
//}}AFX_DATA_INIT
m_CurAdo.InitialDB();
}
CActive::~CActive()
{
m_CurAdo.ClosedDB();
}
void CActive::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CActive)
DDX_Control(pDX, IDC_ACT_LIST, m_lstAct);
DDX_Text(pDX, IDC_ACT_EDIT, m_strAct);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CActive, CDialog)
//{{AFX_MSG_MAP(CActive)
ON_BN_CLICKED(IDC_ACT_ADD, OnActAdd)
ON_BN_CLICKED(IDC_ACT_MOD, OnActMod)
ON_LBN_SELCHANGE(IDC_ACT_LIST, OnSelchangeActList)
ON_BN_CLICKED(IDC_ACT_DEL, OnActDel)
ON_BN_CLICKED(IDC_EXIT, OnExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CActive message handlers
void CActive::OnActAdd()
{
// TODO: Add your control notification handler code here
//首先判断文本框里有字符输入,然后把输入的活动名称插入数据库
UpdateData(1);
_bstr_t vSQL;
if (m_strAct.IsEmpty())
{
AfxMessageBox("请输入活动名称!");
return;
}
else
{
vSQL="Insert into Activity(ActID,ActName) \
select (Max(ActID)+1),'" + m_strAct + "' from Activity";
m_CurAdo.ExecuteSQL(vSQL);
ReadToList(); //更新listbox控件
}
}
void CActive::OnActMod()
{
// TODO: Add your control notification handler code here
//把文本框中的信息(活动名称)重新写入数据库,执行更新操作
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 Activity set ActName='"+m_strAct +"' where ActID= "+str1;
if (m_CurAdo.ExecuteSQL(vSQL))
{
ReadToList(); //更新listBox控件
AfxMessageBox("更新成功",MB_OK);
}
}
}
BOOL CActive::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 CActive::ReadToList()
{
//把数据库中的活动名称和ID号读进控件中
_bstr_t vSQL;
CString str1,str2;
int i=0;
sa_ActID.RemoveAll();
sa_ActName.RemoveAll();
m_lstAct.ResetContent();
//执行SELETE语句
vSQL="select ActID, ActName from Activity order by ActID";
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("ActID"));
sa_ActName.Add((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ActName"));
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 CActive::OnSelchangeActList()
{
CString str1;
m_lstAct.GetText(m_lstAct.GetCurSel(),str1);
m_strAct=str1;
UpdateData(0);
}
void CActive::OnActDel()
{
// TODO: Add your control notification handler code here
_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 Activity Where ActID=" + str;
if (m_CurAdo.ExecuteSQL(vSQL))
{
AfxMessageBox("删除成功!!!");
ReadToList();
m_strAct="";
UpdateData(0);
}
else
AfxMessageBox("删除失败!!!");
}
}
void CActive::OnExit()
{
this->OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -