www.pudn.com > vc++.rar > FamilyManDlg.cpp


// FamilyManDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "HrSys.h" 
#include "FamilyManDlg.h" 
#include "COMDEF.H" 
#include "Columns.h" 
#include "Column.h" 
#include "FamilyEditDlg.h" 
#include "_recordset.h" 
#include "Family.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CFamilyManDlg dialog 
 
 
CFamilyManDlg::CFamilyManDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CFamilyManDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CFamilyManDlg) 
	m_EmpName = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CFamilyManDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CFamilyManDlg) 
	DDX_Control(pDX, IDC_ADODC1, m_adodc); 
	DDX_Control(pDX, IDC_DATAGRID1, m_datagrid); 
	DDX_Text(pDX, IDC_EMPNAME_STATIC, m_EmpName); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CFamilyManDlg, CDialog) 
	//{{AFX_MSG_MAP(CFamilyManDlg) 
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton) 
	ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton) 
	ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFamilyManDlg message handlers 
void CFamilyManDlg::Refresh_Data() 
{ 
	CString cEmpId; 
	cEmpId.Format("%d", iEmpId); 
	//设置记录源 
	CString cSource; 
	cSource = "SELECT Id, Name AS 姓名, Sex AS 性别, Age AS 年龄, Relationship AS 关系,"; 
	cSource	+= " WorkingOrg AS 工作单位 FROM Family WHERE Emp_Id=" + cEmpId; 
	m_adodc.SetRecordSource(cSource); 
	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(70); 
	vIndex = long(2); 
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(50); 
	vIndex = long(3); 
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(80); 
	vIndex = long(4); 
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(100); 
	vIndex = long(5); 
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(150); 
} 
 
void CFamilyManDlg::OnAddButton()  
{ 
	// TODO: Add your control notification handler code here 
	CFamilyEditDlg dlg; 
	dlg.cId = ""; 
	dlg.iEmpId = iEmpId; 
	if (dlg.DoModal() == IDOK) 
		Refresh_Data(); 
} 
 
BOOL CFamilyManDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	Refresh_Data(); 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CFamilyManDlg::OnModiButton()  
{ 
	// TODO: Add your control notification handler code here 
	if (m_adodc.GetRecordset().GetEof())  
	{ 
		MessageBox("请选择要修改的记录"); 
		return; 
	} 
	CFamilyEditDlg dlg; 
	dlg.cId = m_datagrid.GetItem(0); //记录编号 
	dlg.iEmpId = iEmpId;  //员工编号 
	dlg.m_Name = m_datagrid.GetItem(1); //姓名 
	dlg.cSex = m_datagrid.GetItem(2); //性别 
	dlg.m_Age = atoi(m_datagrid.GetItem(3)); //年龄 
	dlg.m_Relation = m_datagrid.GetItem(4); //关系 
	dlg.m_Org = m_datagrid.GetItem(5); 
 
	if (dlg.DoModal() == IDOK) 
		Refresh_Data(); 
} 
 
void CFamilyManDlg::OnDelButton()  
{ 
	// TODO: Add your control notification handler code here 
	if (m_adodc.GetRecordset().GetEof())  
	{ 
		MessageBox("请选择要删除的记录"); 
		return; 
	} 
	if (MessageBox("是否删除当前记录","请确定", MB_YESNO) == IDYES) 
	{ 
		CFamily fam; 
		fam.sql_delete(m_datagrid.GetItem(0)); 
		Refresh_Data(); 
	} 
}