📄 officeinfodlg.cpp
字号:
// Officeinfodlg.cpp : implementation file
//
#include "stdafx.h"
#include "mystudentsys.h"
#include "Officeinfodlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// COfficeinfodlg dialog
COfficeinfodlg::COfficeinfodlg(CWnd* pParent /*=NULL*/)
: CDialog(COfficeinfodlg::IDD, pParent)
{
//{{AFX_DATA_INIT(COfficeinfodlg)
m_officename = _T("");
//}}AFX_DATA_INIT
}
void COfficeinfodlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COfficeinfodlg)
DDX_Text(pDX, IDC_EDIT_officename, m_officename);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COfficeinfodlg, CDialog)
//{{AFX_MSG_MAP(COfficeinfodlg)
ON_BN_CLICKED(IDC_BUTTON_first, OnBUTTONfirst)
ON_BN_CLICKED(IDC_BUTTON_last, OnBUTTONlast)
ON_BN_CLICKED(IDC_BUTTON_next, OnBUTTONnext)
ON_BN_CLICKED(IDC_BUTTON_pre, OnBUTTONpre)
ON_BN_CLICKED(IDC_BUTTON_add, OnBUTTONadd)
ON_BN_CLICKED(IDC_BUTTON_save, OnBUTTONsave)
ON_BN_CLICKED(IDC_BUTTON_del, OnBUTTONdel)
ON_WM_CLOSE()
ON_COMMAND(ID_toolbar_add, Ontoolbaradd)
ON_COMMAND(ID_toolbar_del, Ontoolbardel)
ON_COMMAND(ID_toolbar_first, Ontoolbarfirst)
ON_COMMAND(ID_toolbar_last, Ontoolbarlast)
ON_COMMAND(ID_toolbar_next, Ontoolbarnext)
ON_COMMAND(ID_toolbar_pre, Ontoolbarpre)
ON_COMMAND(ID_toolbar_save, Ontoolbarsave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COfficeinfodlg message handlers
void COfficeinfodlg::OnBUTTONfirst()
{
// TODO: Add your control notification handler code here
if(!myofficeset.IsBOF())
{
myofficeset.MoveFirst();//向前移动一条记录
DisplayRecord();//更新窗口显示
// UpdateData(FALSE);
}
}
BOOL COfficeinfodlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(!m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_SIZE_DYNAMIC)
||!m_ToolBar.LoadToolBar(IDR_TOOLBAR_officeinfo))
{
TRACE0(_T("创建工具条失败\n"));
return FALSE;
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
CString sqlStr;
sqlStr="SELECT * FROM tb_office";//在tb_office数据表里面查询
if(!myofficeset.Open(AFX_DB_USE_DEFAULT_TYPE,sqlStr))//打开数据表
{
AfxMessageBox("tb_office表打开失败!");
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
bool COfficeinfodlg::DisplayRecord()
{
if(myofficeset.IsEOF()&&myofficeset.IsBOF())//判断是否移动到了开头和结尾
{
m_officename="";
}
else
{
if(myofficeset.IsBOF())//移动到了开头,就向后移动
{
myofficeset.MoveNext();
}
else//否则前移
{
if(myofficeset.IsEOF())
{
myofficeset.MovePrev();
}
}
}
m_officename=myofficeset.m_Office;//对应变量赋值
UpdateData(false);//显示更新
return true;
}
void COfficeinfodlg::OnBUTTONlast()
{
// TODO: Add your control notification handler code here
if(!myofficeset.IsEOF())//如果不是结尾,就移动到最后一条记录,然后显示更新
{
myofficeset.MoveLast();
DisplayRecord();//更新显示
}
}
void COfficeinfodlg::OnBUTTONnext()
{
// TODO: Add your control notification handler code here
if(!myofficeset.IsEOF())//如果不是结尾,就移动到下一条记录,然后显示更新
{
myofficeset.MoveNext();
DisplayRecord();//更新显示
}
}
void COfficeinfodlg::OnBUTTONpre()
{
// TODO: Add your control notification handler code here
if(!myofficeset.IsBOF())//如果不是开头,就移动到上一条记录,然后显示更新
{
myofficeset.MovePrev();
DisplayRecord();//更新显示
}
}
void COfficeinfodlg::OnBUTTONadd()
{
// TODO: Add your control notification handler code here
m_officename="";
UpdateData(false);
m_bAdd=true;
}
void COfficeinfodlg::OnBUTTONsave()
{
UpdateData(true);//读入输入的资料
if(m_officename.IsEmpty())
{
//如果名字是空就提示错误
AfxMessageBox("请输入相应的数据!");
return;
}
CString sql;
sql.Format("SELECT * FROM tb_office WHERE office = '%s'",m_officename);
if (myofficeset_find.IsOpen())
myofficeset_find.Close();
if(!myofficeset_find.Open(AFX_DB_USE_DEFAULT_TYPE,sql))
{
AfxMessageBox("tb_office 表打开失败!");
}
if(myofficeset_find.GetRecordCount()!=0)
{
AfxMessageBox("科室名称不能重复,请修改后再输入!");
if(myofficeset_find.IsOpen())
{
myofficeset_find.Close();
}
return;
}
{//如果是添加记录,就调用添加记录的函数处理
myofficeset.AddNew();
}
myofficeset.m_Office=m_officename;//对应变量更新
myofficeset.Update();
myofficeset.Requery();
m_bAdd=false;//设置添加状态为false
DisplayRecord();//更新显示
}
void COfficeinfodlg::OnBUTTONdel()
{
myofficeset.Delete();//删除记录
myofficeset.Requery();
DisplayRecord();//更新显示
}
void COfficeinfodlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(myofficeset.IsOpen())
{
myofficeset.Close();//记录集关闭
// MessageBox("didi");
}
CDialog::OnClose();
}
void COfficeinfodlg::Ontoolbaradd()
{
// TODO: Add your command handler code here
OnBUTTONadd();
}
void COfficeinfodlg::Ontoolbardel()
{
// TODO: Add your command handler code here
OnBUTTONdel();
}
void COfficeinfodlg::Ontoolbarfirst()
{
// TODO: Add your command handler code here
OnBUTTONfirst();
}
void COfficeinfodlg::Ontoolbarlast()
{
// TODO: Add your command handler code here
OnBUTTONlast();
}
void COfficeinfodlg::Ontoolbarnext()
{
// TODO: Add your command handler code here
OnBUTTONnext();
}
void COfficeinfodlg::Ontoolbarpre()
{
// TODO: Add your command handler code here
OnBUTTONpre();
}
void COfficeinfodlg::Ontoolbarsave()
{
// TODO: Add your command handler code here
OnBUTTONsave();
}
void COfficeinfodlg::OnOK()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -