📄 filerecord.cpp
字号:
// FileRecord.cpp : implementation file
//
#include "stdafx.h"
#include "HRMS.h"
#include "FileRecord.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFileRecord dialog
CFileRecord::CFileRecord(CWnd* pParent /*=NULL*/)
: CDialog(CFileRecord::IDD, pParent)
{
//{{AFX_DATA_INIT(CFileRecord)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_IsModifyDlg = FALSE;
m_Index = -1;
m_CurSel = -1;
}
void CFileRecord::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileRecord)
DDX_Control(pDX, IDC_COMBO3, m_Duty);
DDX_Control(pDX, IDC_COMBO4, m_Dept);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileRecord, CDialog)
//{{AFX_MSG_MAP(CFileRecord)
ON_BN_CLICKED(IDC_LOADPICTURE, OnLoadPicture)
ON_BN_CLICKED(IDB_FILE_RECORD_SAVE, OnFileRecordSave)
ON_BN_CLICKED(IDB_FILE_RECORD_RESET, OnFileRecordReset)
ON_WM_PAINT()
ON_WM_CANCELMODE()
ON_BN_CLICKED(IDC_COMPACT_EDIT, OnCompactEdit)
ON_CBN_SELCHANGE(IDC_COMBO4, OnSelchangeCombo4)
ON_BN_CLICKED(IDC_SEELIST, OnSeelist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileRecord message handlers
BOOL CFileRecord::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//部门组合框初始化
InitDeptComboBox(&m_Dept);
SendMessage(WM_COMMAND, MAKEWPARAM(IDC_COMBO4, CBN_SELCHANGE), (LPARAM)m_Dept.m_hWnd);
//显示修改员工信息视图
if(m_IsModifyDlg)
{
InitModiView();
return TRUE;
}
//从应聘者中增加新员工
if(m_IsAppler && !m_ApplerId.IsEmpty())
{
SetApplerInfo(m_ApplerId);
return TRUE;
}
((CComboBox* )GetDlgItem(IDC_COMBO1))->SetCurSel(0);
((CComboBox* )GetDlgItem(IDC_COMBO2))->SetCurSel(0);
SetDlgItemInt(IDC_EDIT5, 0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFileRecord::OnLoadPicture()
{
// TODO: Add your control notification handler code here
CFileDialog fileDlg(TRUE, "bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "位图文件(*.bmp)|*.bmp||", this);
if(IDOK != fileDlg.DoModal())
return ;
m_PhotoFileName = fileDlg.GetFileName();
m_Photo = (HBITMAP)::LoadImage(::AfxGetInstanceHandle(), m_PhotoFileName, IMAGE_BITMAP, 128, 128,
LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
//((CStatic*)GetDlgItem(IDC_PHOTO))->SetBitmap(m_Photo);
this->Invalidate();
}
void CFileRecord::OnFileRecordSave()
{
// TODO: Add your control notification handler code here
if(m_IsModifyDlg && m_Index > -1)
{
if(!ModifyRecord(m_Index))
MessageBox("保存出现错误!", "注意", MB_OK | MB_ICONHAND);
else
{
MessageBox("保存成功!", "提示", MB_OK | MB_ICONHAND);
EndDialog(0);
}
return ;
}
if(!SaveFile())
MessageBox("保存出现错误请注意序号的唯一性!", "注意", MB_OK | MB_ICONHAND);
else
{
int ret;
ret = MessageBox("保存成功!\n是否继续录入?", "提示", MB_YESNO | MB_ICONWARNING);
if(ret == IDYES)
OnFileRecordReset();
else if(ret = IDNO)
EndDialog(0);
}
}
void CFileRecord::OnFileRecordReset()
{
// TODO: Add your control notification handler code here
CTime tm;
tm.GetLocalTm(NULL);
SetDlgItemText(IDC_EDIT1, "");
SetDlgItemText(IDC_EDIT2, "");
SetDlgItemInt(IDC_EDIT5, 0);
SetDlgItemText(IDC_EDIT6, "");
SetDlgItemText(IDC_EDIT3, "");
((CDateTimeCtrl *)GetDlgItem(IDC_DATETIMEPICKER2))->SetTime(&tm);
((CDateTimeCtrl *)GetDlgItem(IDC_DATETIMEPICKER1))->SetTime(&tm);
m_Dept.SetCurSel(0);
m_Duty.SetCurSel(0);
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
((CComboBox*)GetDlgItem(IDC_COMBO2))->SetCurSel(0);
::DeleteObject(m_Photo);
m_Photo = NULL;
UpdateData();
Invalidate();
}
BOOL CFileRecord::SaveFile()
{
CString str;
SYSTEMTIME sysTime = {0};
int integer = 0;
BOOL ret;
CADOOperation dbo;
dbo.OpenTable("tb_employee");
dbo.AddNew();
GetDlgItemText(IDC_EDIT1, str); //保存员工ID
ret = dbo.SetItemContent("employee_id",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_EDIT2, str); //保存员工名字
ret = dbo.SetItemContent("employee_name",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_COMBO1, str); //保存员工性别
ret = dbo.SetItemContent("employee_sex",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
((CDateTimeCtrl*)GetDlgItem( //保存员工生日
IDC_DATETIMEPICKER1))->GetTime(&sysTime);
ret = dbo.SetItemContent("employee_birthday",
CADOOperation::ADO_TYPE_DATE, &sysTime);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
integer = GetDlgItemInt(IDC_EDIT5); //保存员工工龄
ret = dbo.SetItemContent("employee_lenofser",
CADOOperation::ADO_TYPE_INT, &integer);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
if(!m_PhotoFileName.IsEmpty()) //保存员工相片
ret = dbo.SetItemContent("employee_photo",
CADOOperation::ADO_TYPE_BITMAP_FIEL, &m_PhotoFileName);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_COMBO2, str); //保存员工学历
ret = dbo.SetItemContent("employee_edulev",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_EDIT3, str); //保存员工家庭住址
ret = dbo.SetItemContent("employee_dwel",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_EDIT3, str); //保存员工家庭住址
ret = dbo.SetItemContent("employee_dwel",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
GetDlgItemText(IDC_EDIT6, str); //保存员工电话
ret = dbo.SetItemContent("employee_phone",
CADOOperation::ADO_TYPE_STRING, &str);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
((CDateTimeCtrl*)GetDlgItem( //保存员工入职时间
IDC_DATETIMEPICKER2))->GetTime(&sysTime);
ret = dbo.SetItemContent("employee_timeofser",
CADOOperation::ADO_TYPE_DATE, &sysTime);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
DWORD numDept = 0; //保存员工所在部门
m_Dept.GetWindowText(str);
numDept = GetDeptNumber(str);
ret = dbo.SetItemContent("employee_dept", CADOOperation::ADO_TYPE_INT, &numDept);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
DWORD numDuty = 0; //保存员工所在职位
m_Duty.GetWindowText(str);
numDuty = GetDutyNumber(str);
ret = dbo.SetItemContent("employee_duty", CADOOperation::ADO_TYPE_INT, &numDuty);
if(!ret)
{
dbo.CloseTable();
return FALSE;
}
dbo.UpdateData();
dbo.CloseTable();
return TRUE;
}
BOOL CFileRecord::ShowRecord(int index)
{
CADOOperation dbo;
CString str;
SYSTEMTIME sysTime = {0};
HBITMAP hBitmap = NULL;
int integer = 0;
CClientDC dc(this);
dbo.SetClientDC(dc.m_hDC);
dbo.OpenTable("tb_employee");
dbo.MoveTo(index);
dbo.GetItemContent("employee_id", //读取员工ID
CADOOperation::ADO_TYPE_STRING, &str);
SetDlgItemText(IDC_EDIT1, str);
dbo.GetItemContent("employee_name", //读取员工姓名
CADOOperation::ADO_TYPE_STRING, &str);
SetDlgItemText(IDC_EDIT2, str);
((CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER1))->SetTime(&sysTime);
dbo.GetItemContent("employee_photo", //读取员工相片
CADOOperation::ADO_TYPE_BITMAP_HANDLE, &m_Photo);
dbo.GetItemContent("employee_lenofser", //读取员工工龄
CADOOperation::ADO_TYPE_INT, &integer);
SetDlgItemInt(IDC_EDIT5, integer);
dbo.GetItemContent("employee_birthday", //读取员工生日
CADOOperation::ADO_TYPE_DATE, &sysTime);
((CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER1))->SetTime(&sysTime);
dbo.GetItemContent("employee_timeofser", //读取员工入职时间
CADOOperation::ADO_TYPE_DATE, &sysTime);
((CDateTimeCtrl*)GetDlgItem(IDC_DATETIMEPICKER2))->SetTime(&sysTime);
dbo.GetItemContent("employee_sex", //读取员工性别
CADOOperation::ADO_TYPE_STRING, &str);
str.Replace(" ", "");
if(str.Compare("男") == 0)
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
else
((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(1);
dbo.GetItemContent("employee_edulev", //读取员工学历
CADOOperation::ADO_TYPE_STRING, &str);
SetDlgItemText(IDC_COMBO2, str);
dbo.GetItemContent("employee_dwel", //读取员工家庭住址
CADOOperation::ADO_TYPE_STRING, &str);
SetDlgItemText(IDC_EDIT3, str);
dbo.GetItemContent("employee_phone", //读取员工电话
CADOOperation::ADO_TYPE_STRING, &str);
SetDlgItemText(IDC_EDIT6, str);
dbo.GetItemContent("employee_dept", //读取员工所在部门
CADOOperation::ADO_TYPE_INT, &integer);
str = GetDeptName(integer);
m_Dept.SetCurSel(m_Dept.FindString(0, str.GetBuffer(0)));
OnSelchangeCombo4();
dbo.GetItemContent("employee_duty", //读取员工职务
CADOOperation::ADO_TYPE_INT, &integer);
str = GetDutyName(integer);
m_Duty.SetCurSel(m_Duty.FindString(0, str.GetBuffer(0)));
dbo.CloseTable();
return TRUE;
}
void CFileRecord::SetShowItem(int index)
{
m_Index = index;
}
void CFileRecord::SetModifyDlg(BOOL is)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -