?? employdlg.cpp
字號:
// EmployDlg.cpp : implementation file
//
#include "stdafx.h"
#include "salarly.h"
#include "EmployDlg.h"
#include "EmploySet.h"
#include "EmployOdlg.h"
#include "DelectEmployDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEmployDlg dialog
CEmployDlg::CEmployDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEmployDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEmployDlg)
m_strAddress = _T("");
m_strDepartment = _T("");
m_strID = _T("");
m_strJob = _T("");
m_strName = _T("");
m_strQuery = _T("");
m_strSex = _T("");
m_strTel = _T("");
m_Birthday = 0;
//}}AFX_DATA_INIT
}
void CEmployDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEmployDlg)
DDX_Control(pDX, IDC_LIST1, m_List1);
DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
DDX_Text(pDX, IDC_DEPARTMENT, m_strDepartment);
DDX_Text(pDX, IDC_ID, m_strID);
DDX_Text(pDX, IDC_JOB, m_strJob);
DDX_Text(pDX, IDC_NAME, m_strName);
DDX_Text(pDX, IDC_QUERY, m_strQuery);
DDX_Text(pDX, IDC_SEX, m_strSex);
DDX_Text(pDX, IDC_TEL, m_strTel);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_Birthday);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEmployDlg, CDialog)
//{{AFX_MSG_MAP(CEmployDlg)
ON_BN_CLICKED(IDC_BUTTON_SHOW, OnButtonShow)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
ON_BN_CLICKED(IDC_BUTTON_DELET, OnButtonDelet)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEmployDlg message handlers
BOOL CEmployDlg::OnInitDialog() //初始化List控件
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_List1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);//設(shè)置List網(wǎng)格
m_List1.InsertColumn(0,_T("員工號"),LVCFMT_IMAGE|LVCFMT_LEFT);
m_List1.InsertColumn(1,_T("姓名"));
m_List1.InsertColumn(2,_T("部門"));
m_List1.InsertColumn(3,_T("性別"));
m_List1.InsertColumn(4,_T("職務(wù)"));
m_List1.InsertColumn(5,_T("電話"));
m_List1.InsertColumn(6,_T("生日"));
m_List1.InsertColumn(7,_T("住址"));
int j;
for(j=0; j <=7; j++)
{
m_List1.SetColumnWidth(j, 80);
}
m_List1.SetColumnWidth(2, 50);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEmployDlg::OnButtonShow()
{
// TODO: Add your control notification handler code here
m_List1.DeleteAllItems(); //清除LIST控件的當(dāng)前顯示
int i=0;
CEmploySet m_Set;
m_Set.Open(); //打開記錄集
m_Set.MoveFirst(); //移到數(shù)據(jù)表中的第一條記錄
do
{ //把數(shù)據(jù)表中的內(nèi)容顯示到LIST控件中
CString s;
m_List1.InsertItem(i,m_Set.m_ID,0);
m_List1.SetItemText(i,1,m_Set.m_name);
m_List1.SetItemText(i,2,m_Set.m_department);
m_List1.SetItemText(i,3,m_Set.m_sex);
m_List1.SetItemText(i,4,m_Set.m_job);
m_List1.SetItemText(i,5,m_Set.m_tel);
m_List1.SetItemText(i,6,m_Set.m_birthday.Format("%Y-%#m-%#d"));
m_List1.SetItemText(i,7,m_Set.m_address);
i++;
m_Set.MoveNext();
} while(!m_Set.IsEOF());
m_Set.Close();
}
void CEmployDlg::OnButtonQuery() //員工信息的查詢功能
{
// TODO: Add your control notification handler code here
CEmploySet cSet;
UpdateData(); //更新數(shù)據(jù)
CString str;
m_strQuery.TrimLeft (); //從給定的查詢編號中刪除首部的空格及控制字符
if(m_strQuery.IsEmpty ()) //查詢的編輯控為空時
{
MessageBox("要查詢的員工號不能為空!"); //彈出系統(tǒng)消息對話框
return;
}
str=m_strQuery;
cSet.m_strFilter.Format("ID='%s'",str);
//指定查詢條件
cSet.Open();
if(!cSet.IsEOF()) //如果打開記錄集有記錄
{
m_strDepartment=cSet.m_department; //使數(shù)據(jù)表中的數(shù)據(jù) 和對話框中的要求一一對應(yīng)
m_strName=cSet.m_name;
m_strSex=cSet.m_sex;
m_strTel=cSet.m_tel;
m_strAddress=cSet.m_address;
m_Birthday=cSet.m_birthday;
m_strJob=cSet.m_job;
m_strID=cSet.m_ID;
UpdateData(FALSE); //自動更新表單中控件顯示的內(nèi)容
}
else
MessageBox("查詢的員工記錄不存在!"); //否則彈出系統(tǒng)消息對話框
if(cSet.IsOpen())cSet.Close(); //如果記錄集打開則關(guān)閉
}
void CEmployDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
CEmployOdlg dlg;
CEmploySet pSet;
if(dlg.DoModal()==IDOK){ //單擊"確定",彈出添加員工信息的對話框
pSet.Open(); //打開記錄集
pSet.AddNew(); //添加新記錄
//使對話框中的信息和數(shù)據(jù)表中的一一對應(yīng),添加都數(shù)據(jù)表中
pSet.m_department =dlg.m_strDepartment;
pSet.m_ID =dlg.m_strID;
pSet.m_name =dlg.m_strName;
pSet.m_sex =dlg.m_strSex;
pSet.m_job =dlg.m_strJob;
pSet.m_birthday =dlg.m_Birthday;
pSet.m_tel =dlg.m_strTel;
pSet.m_address =dlg.m_strAddress;
pSet.Update(); //數(shù)據(jù)表的更新
MessageBox("添加成功!"); //彈出系統(tǒng)消息對話框
pSet.Requery(); //更新數(shù)據(jù)庫中的數(shù)據(jù)
}
}
void CEmployDlg::OnButtonEdit() //員工信息的修改功能
{
// TODO: Add your control notification handler code here
CEmploySet pSet;
UpdateData(); //讀取控件中的數(shù)據(jù)
CString str;
m_strQuery.TrimLeft (); //從給定的查詢結(jié)果中刪除首部的空格及控制字符
if(m_strQuery.IsEmpty ()) //判斷查詢的員工號的結(jié)果是否為空
{
MessageBox("要修改的員工號不能為空!");
return;
}
str=m_strQuery;
pSet.m_strFilter.Format("ID='%s'",m_strID); //格式化
pSet.Open(); //打開數(shù)據(jù)表
pSet.Edit(); //編輯數(shù)據(jù)表中的內(nèi)容
//使數(shù)據(jù)表中內(nèi)容和對話框中的內(nèi)容一一對應(yīng)
pSet.m_department=m_strDepartment;
pSet.m_ID= m_strID;
pSet.m_name=m_strName;
pSet.m_sex= m_strSex;
pSet.m_job=m_strJob;
pSet.m_birthday= m_Birthday;
pSet.m_tel= m_strTel;
pSet.m_address= m_strAddress;
pSet.Update();
UpdateData(FALSE); //把數(shù)據(jù)表中的內(nèi)容顯示到控件中
MessageBox("修改成功");
pSet.Requery(); //數(shù)據(jù)表更新
pSet.Close(); //關(guān)閉數(shù)據(jù)表
if(pSet.IsOpen())pSet.Close(); //關(guān)閉數(shù)據(jù)表
}
void CEmployDlg::OnButtonDelet() //員工信息的刪除功能,跳轉(zhuǎn)到刪除對話框
{
// TODO: Add your control notification handler code here
CDelectEmployDlg dlg;
dlg.DoModal();
}
void CEmployDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -