⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 employeedlg.cpp

📁 在VC6.0下开发的员工管理系统源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// employeeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "employee.h"
#include "employeeDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

//文件名称:employeeDlg.cpp
//创建者:徐钢
//创建时间:2007-06-11
//最后修改时间:2007-06-24
//功能: 实现对对话框界面的事件的处理
//与其他文件的依赖关系:包含 AEmployee.h 头文件

#include "AEmployee.h"   //包含 AEmployee.h 头文件

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

int CEmployeeDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	//ShellExecute(m_hWnd,NULL, "http://www.longze1986.cn",NULL,NULL, SW_SHOWMAXIMIZED);
	return 0;
}

/////////////////////////////////////////////////////////////////////////////
// CEmployeeDlg dialog

CEmployeeDlg::CEmployeeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEmployeeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEmployeeDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CEmployeeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEmployeeDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_LIST1, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEmployeeDlg, CDialog)
	//{{AFX_MSG_MAP(CEmployeeDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButtonOpen)
	ON_BN_CLICKED(IDC_BUTTON2, OnButtonSave)
	ON_BN_CLICKED(IDC_BUTTON3, OnButtonSaveAs)
	ON_BN_CLICKED(IDC_BUTTON4, OnButtonSort)
	ON_BN_CLICKED(IDC_BUTTON5, OnButtonSearch)
	ON_BN_CLICKED(IDC_BUTTON7, OnButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON8, OnButtonChange)
	ON_BN_CLICKED(IDC_BUTTON9, OnButtonDelete)
	ON_BN_CLICKED(IDC_BUTTON6, OnButtonClose)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickListMain)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEmployeeDlg message handlers

BOOL CEmployeeDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	m_imagelist.Create(16,16,ILC_MASK,0,4);
	HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
	m_imagelist.Add(hIcon);

	// 初始化网格控件
	m_list.SetImageList(&m_imagelist,LVSIL_SMALL);  // 将图标导入网格控件
	m_list.InsertColumn(0,"姓名");   // 设置标题栏
	m_list.InsertColumn(1,"部门");
	m_list.InsertColumn(2,"开始工作时间");
	m_list.InsertColumn(3,"职务");
	m_list.InsertColumn(4,"年龄");
	m_list.InsertColumn(5,"性别");
	m_list.InsertColumn(6,"生日");
	m_list.InsertColumn(7,"学历");
	m_list.InsertColumn(8,"住址");
	m_list.InsertColumn(9,"电话");
	m_list.InsertColumn(10,"工资");
	m_list.SetColumnWidth(0,80);  // 设置标题栏的宽度
	m_list.SetColumnWidth(1,80);
	m_list.SetColumnWidth(2,120);
	m_list.SetColumnWidth(3,80);
	m_list.SetColumnWidth(4,80);
	m_list.SetColumnWidth(5,80);
	m_list.SetColumnWidth(6,80);
	m_list.SetColumnWidth(7,80);
	m_list.SetColumnWidth(8,160);
	m_list.SetColumnWidth(9,80);
	m_list.SetColumnWidth(10,80);
	m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);

	//设置下拉列表框的初始值
	CComboBox* pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO1);
	pComboBox->SetCurSel(0);
	pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO2);
	pComboBox->SetCurSel(0);
	pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO3);
	pComboBox->SetCurSel(0);

	ShowData();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CEmployeeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CEmployeeDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CEmployeeDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


///////////////////////////////////////////////////////////
//  以下为按钮事件。
///////////////////////////////////////////////////////////

void CEmployeeDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
}

void CEmployeeDlg::OnButtonOpen() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(TRUE);
	dlg.m_ofn.lpstrTitle = "徐钢主编";
	dlg.m_ofn.lpstrFilter = "Dat Files (*.dat)\0*.dat\0\0";
	dlg.m_ofn.lpstrInitialDir = ".\\";
	dlg.m_ofn.lpstrDefExt = "dat";
	if(dlg.DoModal()==IDOK)
	{
		m_manager.OpenFile(dlg.GetFileName());
		ShowData();
	}
}
// 辅助函数
void CEmployeeDlg::ShowData()
{
	m_list.DeleteAllItems();
	//int pos=m_manager.myList.GetHeadPosition();
	POSITION pos=m_manager.myList.GetHeadPosition();
	AEmployee *employee;
	int i=0;
	CString s;
	//while(pos<m_manager.myList.GetCount())
	while(pos)
	{
		employee=(AEmployee*)m_manager.myList.GetNext(pos);
		// 传送数据到"网格控件"中
		s=employee->name;
		m_list.InsertItem(i,s,0);
		s=employee->dep;
		m_list.SetItemText(i,1,s);
		s=employee->stime;
		m_list.SetItemText(i,2,s);
		s=employee->work;
		m_list.SetItemText(i,3,s);
		s=employee->age;
		m_list.SetItemText(i,4,s);
		s=employee->sex;
		m_list.SetItemText(i,5,s);
		s=employee->birth;
		m_list.SetItemText(i,6,s);
		s=employee->graduate;
		m_list.SetItemText(i,7,s);
		s=employee->addr;
		m_list.SetItemText(i,8,s);
		s=employee->tel;
		m_list.SetItemText(i,9,s);
		s=employee->money;
		m_list.SetItemText(i,10,s);

		m_list.SetItemData(i,i);
		i++;
	}
}
// "保存" 按钮 
void CEmployeeDlg::OnButtonSave() 
{
	// TODO: Add your control notification handler code here
	if(!m_manager.Save())
	{
		AfxMessageBox("保存失败");
		return;
	}
	AfxMessageBox("保存完成");	
}
// "另存为" 按钮
void CEmployeeDlg::OnButtonSaveAs() 
{
	// TODO: Add your control notification handler code here
	CFileDialog dlg(FALSE);
	dlg.m_ofn.lpstrTitle = "徐钢主编";
	dlg.m_ofn.lpstrFilter = "Dat Files (*.dat)\0*.dat\0\0";
	dlg.m_ofn.lpstrDefExt = "dat";
	if(dlg.DoModal()==IDOK)
	{
		m_manager.SaveToFile(dlg.GetFileName());
	}
}
void CEmployeeDlg::OnButtonSort() 
{
	// TODO: Add your control notification handler code here
	CComboBox* pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO2);
	CString s;
	pComboBox->GetLBText(pComboBox->GetCurSel(),s); 
	pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO3);
	if(!m_list.GetItemCount())  
	{
		return;
	}
	if(!m_manager.Sort(s,pComboBox->GetCurSel()))  // 排序处理
	{
		AfxMessageBox("排序失败");
		return;
	}
	ShowData();	
}
void CEmployeeDlg::OnButtonSearch() 
{
	// TODO: Add your control notification handler code here
	CComboBox* pComboBox=(CComboBox*)GetDlgItem(IDC_COMBO1); 
	CString s,s1;
	pComboBox->GetLBText(pComboBox->GetCurSel(),s); 
	CEdit* pEdit=(CEdit*)GetDlgItem(IDC_EDIT1);
	pEdit->GetWindowText(s1);  
	if(!m_manager.Search(s,s1))
	{
		AfxMessageBox("查询失败");
		return;
	}
	ShowData();
}
void CEmployeeDlg::OnButtonAdd() 
{
	// TODO: Add your control notification handler code here
	AEmployee employee;
	CString s;
	// 从文本框中提取数据
	CEdit* pEdit=(CEdit*)GetDlgItem(IDC_EDIT_NAME);
	pEdit->GetWindowText(s);
	// 对姓名的长度进行判断
	if(s.GetLength()>sizeof(employee.name))
	{
		AfxMessageBox("姓名最多不超过20个字符!");
		return;
	}
	if(s.GetLength()<2)
	{
		AfxMessageBox("姓名最小不小于2个字符!");
		return;
	}
	memcpy(employee.name,s,s.GetLength());  // 将数据保存在相应的字段
	// 从文本框中提取数据
	pEdit=(CEdit*)GetDlgItem(IDC_EDIT_DEP);
	pEdit->GetWindowText(s);
	// 对部门的长度进行判断
	if(s.GetLength()>sizeof(employee.dep))
	{
		AfxMessageBox("部门最多不超过20个字符!");
		return;
	}
	if(s.GetLength()<2)
	{
		AfxMessageBox("部门最小不小于2个字符!");
		return;
	}
	memcpy(employee.dep,s,s.GetLength());
	// 从文本框中提取数据
	pEdit=(CEdit*)GetDlgItem(IDC_EDIT_STIME);
	pEdit->GetWindowText(s);
	// 对开始工作时间的长度进行判断
	if(s.GetLength()>sizeof(employee.stime))
	{
		AfxMessageBox("开始工作时间最多不超过12个字符!");
		return;
	}
	if(s.GetLength()<2)
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -