📄 personneldlg.cpp
字号:
// PersonnelDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SalaryManagement.h"
#include "PersonnelDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPersonnelDlg dialog
BOOL CPersonnelDlg::OnInitDialog(){ //重载初始化对话框的虚函数
//初始化职员信息列表
CListCtrl *pList=(CListCtrl *)GetDlgItem(IDC_INFORMATION_LIST); //建立一个指向 职员信息列表 的CListCtrl指针
pList->InsertColumn(0,"职工号"); //第0列
pList->InsertColumn(1,"姓名"); //第1列
pList->InsertColumn(2,"职位"); //第2列
pList->InsertColumn(3,"所在部门"); //第3列
//设置列表的宽度和风格
pList->SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT); //设置列表的风格 有网格线 全行选中
RECT ListRect; //得到列表控件的空间
pList->GetWindowRect(&ListRect);
int breadth=ListRect.right-ListRect.left; //得到列表控件的宽度
pList->SetColumnWidth(0,breadth/4-1); //设置每一列的宽度
pList->SetColumnWidth(1,breadth/4-1);
pList->SetColumnWidth(2,breadth/4-1);
pList->SetColumnWidth(3,breadth/4-1);
//初始化职员列表信息
//DisplayPersonnelList(); //显示职员列表信息
CDialog::OnInitDialog(); //调用CDialong基类中的初始话对话框的函数
return TRUE;
}
void CPersonnelDlg::DisplayPersonnelList(){ //显示职员列表
CListCtrl *pList=(CListCtrl *)GetDlgItem(IDC_INFORMATION_LIST); //建立一个指向 职员信息列表 的CListCtrl指针
CString SQL; //要查询的SQL语句
//判断是对哪个部门进行操作
if(pDepartment->GetDepartmentName()=="A部门")
SQL="select * from ADepartEmployee"; //专门操作数据库中A部门的表
else if(pDepartment->GetDepartmentName()=="B部门")
SQL="select * from BDepartEmployee"; //专门操作数据库中B部门的表
else if(pDepartment->GetDepartmentName()=="C部门")
SQL="select * from CDepartEmployee"; //专门操作数据库中C部门的表
database.GetRecordset(SQL); //进行查询
pList->DeleteAllItems(); //删除所有的 item 重新列出 item
int row=0; //row代表第几行
while(database.m_pRecordset->adoEOF==0){ //列出职员信息列表中的数据
pList->InsertItem(row,""); //插入一行
pList->SetItemText(row,0,(LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("职员号"))); //职员号
pList->SetItemText(row,1,(LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("姓名"))); //姓名
pList->SetItemText(row,2,(LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("职位"))); //职位
pList->SetItemText(row,3,(LPCTSTR)(_bstr_t)(database.m_pRecordset->GetCollect("所在部门"))); //所在部门
row++; //下一行
database.m_pRecordset->MoveNext(); //下一条记录
}
//初始化经理信息
m_manager=pDepartment->GetManager();
m_managername=m_manager.GetEmployeeName(); //得到了部门经理的名字
UpdateData(FALSE);
}
CPersonnelDlg::CPersonnelDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPersonnelDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPersonnelDlg)
m_managername = _T("");
//}}AFX_DATA_INIT
}
void CPersonnelDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPersonnelDlg)
DDX_Control(pDX, IDC_PERSONNEL_DEPARTMENT_COMBO, m_optdepartment);
DDX_Control(pDX, IDC_INFORMATION_LIST, m_information);
DDX_Text(pDX, IDC_PERSONNEL_MANAGER_EDIT, m_managername);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPersonnelDlg, CDialog)
//{{AFX_MSG_MAP(CPersonnelDlg)
ON_BN_CLICKED(IDC_PERSONNEL_ADD_BUTTON, OnPersonnelAddButton)
ON_BN_CLICKED(IDC_PERSONNEL_EXIT_BUTTON, OnPersonnelExitButton)
ON_CBN_CLOSEUP(IDC_PERSONNEL_DEPARTMENT_COMBO, OnCloseupPersonnelDepartmentCombo)
ON_BN_CLICKED(IDC_PERSONNEL_DELETE_BUTTON, OnPersonnelDeleteButton)
ON_NOTIFY(NM_CLICK, IDC_INFORMATION_LIST, OnClickInformationList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPersonnelDlg message handlers
void CPersonnelDlg::OnPersonnelAddButton(){ //添加新职员
if(pDepartment->GetDepartmentName()=="Root"){
MessageBox("请先选择部门");
return;
}
CPersonnelAddDlg dlg; //打开添加新职员的对话框
if(dlg.DoModal()==IDOK){ //模式对话框
DisplayPersonnelList(); //显示职员列表
}
}
void CPersonnelDlg::OnPersonnelExitButton(){ //退出此对话框
EndDialog(IDCANCEL);
}
void CPersonnelDlg::OnCloseupPersonnelDepartmentCombo(){ //选择了要操作的部门
CString departmentname; //选择的部门的名字
m_optdepartment.GetWindowText(departmentname);
if(departmentname=="A部门"){
pDepartment=&A_Department; //对A部门进行操作
DEPART="A";
}
else if(departmentname=="B部门"){
pDepartment=&B_Department; //对B部门进行操作
DEPART="B";
}
else if(departmentname=="C部门"){
pDepartment=&C_Department; //对C部门进行操作
DEPART="C";
}
else{
MessageBox("请先选择要操作的部门");
return;
}
pDepartment->InitDepartment(); //初始化部门的信息
DisplayPersonnelList(); //显示所选择的部门的职员列表
}
void CPersonnelDlg::OnPersonnelDeleteButton(){ //删除职员
CString SQL; //建立要进行执行的SQL语句
SQL="delete * from "+DEPART+"DepartEmployee where 职员号='"+m_id+"'";
database.ExecuteSQL(SQL); //删除DepartEmployee表中的数据
SQL="delete * from "+DEPART+"Year"+pDepartment->GetYear()+" where 职员号='"+m_id+"'";
database.ExecuteSQL(SQL); //删除XYearxxxx表中的数据
pDepartment->InitDepartment(); //重新得到数据
DisplayPersonnelList(); //显示职员列表
pDepartment->UpdateEmployeeNumber(pDepartment->GetEmployeeNumber()-1); //更新部门的职员数(-1)
}
void CPersonnelDlg::OnClickInformationList(NMHDR* pNMHDR, LRESULT* pResult){ //点击了列表框
CListCtrl *pList=(CListCtrl *)GetDlgItem(IDC_INFORMATION_LIST); //建立一个控制列表控件资源的指针
UpdateData(TRUE);
int i=pList->GetSelectionMark();
m_id=pList->GetItemText(i,0); //职员号
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -