?? patmandlg.cpp
字號:
// PatManDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HosptialMan.h"
#include "PatManDlg.h"
#include "PatEditDlg.h"
#include "Patient.h"
#include "columns.h"
#include "column.h"
#include "COMDEF.H"
#include "_recordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPatManDlg dialog
CPatManDlg::CPatManDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPatManDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPatManDlg)
m_Name = _T("");
//}}AFX_DATA_INIT
}
void CPatManDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPatManDlg)
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
DDX_Text(pDX, IDC_Name, m_Name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPatManDlg, CDialog)
//{{AFX_MSG_MAP(CPatManDlg)
ON_BN_CLICKED(IDC_SEARCH_BUTTON, OnSearchButton)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_EDIT_BUTTON, OnEditButton)
ON_BN_CLICKED(ID_DELETE_BUTTON, OnDeleteButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPatManDlg message handlers
void CPatManDlg::RefreshData()
{
UpdateData(TRUE);
CString cSql;
cSql = "SELECT Id,Name AS 姓名,IdNum AS 身份證號,Sex AS 性別,Age AS 年齡,";
cSql += "Marry AS 婚姻狀況 FROM Patient";
if(m_Name!="")
cSql += " Where Name Like '%"+m_Name+"%'";
m_Adodc.SetRecordSource((LPCTSTR)(_bstr_t)cSql);
m_Adodc.Refresh();
// 設置列寬度
_variant_t vIndex;
vIndex = long(0);
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(0);
vIndex = long(1); // 姓名
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(80);
vIndex = long(2); // 身份證號
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(120);
vIndex = long(3); // 性別
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(4); // 年齡
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(50);
vIndex = long(5); // 婚姻狀況
m_DataGrid.GetColumns().GetItem(vIndex).SetWidth(120);
}
BOOL CPatManDlg::OnInitDialog()
{
CDialog::OnInitDialog();
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPatManDlg::OnSearchButton()
{
RefreshData();
}
void CPatManDlg::OnAddButton()
{
CPatEditDlg dlg;
dlg.cPId = "";
if(dlg.DoModal()==IDOK)
RefreshData();
}
void CPatManDlg::OnEditButton()
{
if (m_Adodc.GetRecordset().GetEof())
{
MessageBox("請選擇要修改的數據");
return;
}
CPatEditDlg dlg;
dlg.cPId = m_DataGrid.GetItem(0);
dlg.m_Name = m_DataGrid.GetItem(1);
dlg.m_IdNum = m_DataGrid.GetItem(2);
dlg.cSex = m_DataGrid.GetItem(3);
dlg.m_Age = atoi(m_DataGrid.GetItem(4));
dlg.cMarry = m_DataGrid.GetItem(5);
if(dlg.DoModal()==IDOK)
RefreshData();
}
void CPatManDlg::OnDeleteButton()
{
if (m_Adodc.GetRecordset().GetEof())
{
MessageBox("請選擇要刪除的數據");
return;
}
if (MessageBox("是否刪除當前記錄?","請確認", MB_YESNO) == IDYES)
{
CPatient cPt;
cPt.sql_Delete(m_DataGrid.GetItem(0));
RefreshData();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -