📄 deptdlg.cpp
字号:
// DeptDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HosptialMan.h"
#include "DeptDlg.h"
#include "BaseType.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDeptDlg dialog
CDeptDlg::CDeptDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDeptDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDeptDlg)
m_DeptName = _T("");
//}}AFX_DATA_INIT
}
void CDeptDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDeptDlg)
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Control(pDX, IDC_DATALIST1, m_DataList);
DDX_Text(pDX, IDC_DEPTNAME_EDIT, m_DeptName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDeptDlg, CDialog)
//{{AFX_MSG_MAP(CDeptDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_EDIT_BUTTON, OnEditButton)
ON_BN_CLICKED(IDC_DELT_BUTTON, OnDeltButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDeptDlg message handlers
void CDeptDlg::OnAddButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//判断科室名称是否为空
if (m_DeptName == "")
{
MessageBox("请输入科室名称");
return;
}
CBaseType cBT;
cBT.SetTypeName(m_DeptName);
// 判断是否有相同的名称
if(cBT.HaveTypeName("1"))
{
MessageBox("已经存在此科室名称!");
return;
}
cBT.SetTypeId(1); //设置TypeId=1,表示插入科室数据
cBT.sql_Insert(); //调用sql_insert()函数,插入记录
m_Adodc.Refresh(); //更新科室列表框
}
void CDeptDlg::OnEditButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
//判断是否选择了要修改的科室
if (m_DataList.GetText() == "")
{
MessageBox("请选择要修改的科室名称");
return;
}
//判断科室名称是否为空
if (m_DeptName == "")
{
MessageBox("请输入科室名称");
return;
}
// 如果不同则查看数据库是否已经存在新的科室名称
if(cDNameOld!=m_DeptName)
{
CBaseType cBT;
cBT.SetTypeName(m_DeptName);
if(cBT.HaveTypeName("1"))
MessageBox("新的科室名称已经存在!");
else
{
cBT.sql_Update(cDId);
m_Adodc.Refresh();
}
}
}
BEGIN_EVENTSINK_MAP(CDeptDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CDeptDlg)
ON_EVENT(CDeptDlg, IDC_DATALIST1, -600 /* Click */, OnClickDatalist1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CDeptDlg::OnClickDatalist1()
{
// 点击科室信息后将科室名称放入编辑框中
m_DeptName = m_DataList.GetText();
cDId = m_DataList.GetBoundText(); //读取科室编号
cDNameOld = m_DataList.GetText(); //读取科室名称
UpdateData(FALSE); //更新显示
}
void CDeptDlg::OnDeltButton()
{
// 删除科室信息
if (cDId=="")
{
MessageBox("请选择要删除的数据");
return;
}
if (MessageBox("是否删除当前记录?","请确认", MB_YESNO) == IDYES)
{
CBaseType cBT;
cBT.sql_Delete(cDId);
m_Adodc.Refresh();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -