📄 cclasss.cpp
字号:
// CClass.cpp : implementation file
//
#include "stdafx.h"
#include "aoManage.h"
#include "CClassS.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCClassS dialog
CCClassS::CCClassS(CWnd* pParent /*=NULL*/)
: CParentDlg(CCClassS::IDD, pParent)
{
//{{AFX_DATA_INIT(CCClassS)
m_strCode = _T("");
m_strName = _T("");
//}}AFX_DATA_INIT
m_pCClass=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}
void CCClassS::DoDataExchange(CDataExchange* pDX)
{
CParentDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCClassS)
DDX_Text(pDX, IDC_EDIT1, m_strCode);
DDV_MaxChars(pDX, m_strCode, 2);
DDX_Text(pDX, IDC_EDIT2, m_strName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCClassS, CParentDlg)
//{{AFX_MSG_MAP(CCClassS)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCClassS message handlers
BOOL CCClassS::OnInitDialog()
{
CParentDlg::OnInitDialog();
m_pCClass->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from cclass");
if (m_pCClass->FindFirst("code='"+m_strCode+"'"))
{
COleVariant vVal;
m_pCClass->GetFieldValue("name",vVal);
m_strName=(LPCTSTR)vVal.bstrVal;
}
UpdateData(FALSE);
m_strCodeOld=m_strCode;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCClassS::OnButton1()
{
if (MessageBox("确实要修改吗?",NULL,MB_OKCANCEL)==IDCANCEL)
return;
UpdateData(TRUE);
if (!m_strCode.GetLength()||!m_strName.GetLength())
{
MessageBox("分类号和名称不能为空");
return;
}
if (strcmp(m_strCode,m_strCodeOld))
{
if (m_pCClass->FindFirst("code='"+m_strCode+"'"))
{
MessageBox("分类号已存在,请选择另外未注册的");
return;
}
else
m_pCClass->FindFirst("code='"+m_strCodeOld+"'");
}
m_pCClass->Edit();
m_pCClass->SetFieldValue("code",(LPCTSTR)m_strCode);
m_pCClass->SetFieldValue("name",(LPCTSTR)m_strName);
m_pCClass->Update();
MessageBox("已成功修改");
OnOK();
}
void CCClassS::OnButton2()
{
OnCancel();
}
void CCClassS::OnClose()
{
if (m_pCClass->IsOpen())
m_pCClass->Close();
CParentDlg::OnClose();
}
void CCClassS::OnButton5()
{
if (MessageBox("确实要删除吗?","",MB_OKCANCEL)==IDOK)
{
m_pCClass->Delete();
MessageBox("记录已删除");
OnOK();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -