📄 seworkdlg.cpp
字号:
// SEWORKDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SEWORK.h"
#include "SEWORKDlg.h"
#include "MoniDuKaQi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include"DengLu.h"
#define TIMER 12345
#include"Staff.h"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CSEWORKDlg dialog
CSEWORKDlg::CSEWORKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSEWORKDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSEWORKDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_zhuangtai=true;
}
void CSEWORKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSEWORKDlg)
DDX_Control(pDX, IDC_LIST_YIDAO, m_yidao);
DDX_Control(pDX, IDC_LIST_WEIDAO, m_weidao);
DDX_Control(pDX, IDC_STATIC_CAOZUOZHE, m_caozuozhe);
DDX_Control(pDX, IDC_STATIC_TIME, m_time);
DDX_Control(pDX, IDC_STATIC_TIME1, m_time1);
DDX_Control(pDX, IDC_STATIC_ZHUANGTAI, m_static_zhuangtai);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSEWORKDlg, CDialog)
//{{AFX_MSG_MAP(CSEWORKDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_QIDONGDUKAQI, OnButtonQidongdukaqi)
ON_BN_CLICKED(IDC_BUTTON_SHANCHU, OnButtonShanchu)
ON_BN_CLICKED(IDC_BUTTON_TIANJIA, OnButtonTianjia)
ON_BN_CLICKED(IDC_BUTTON_ZHUANGTAI, OnButtonZhuangtai)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSEWORKDlg message handlers
BOOL CSEWORKDlg::OnInitDialog()//初始化对话框
{
CDialog::OnInitDialog();
//启动登录画面
CDengLu denglu;
if(denglu.DoModal()==1)//启动登录对话框
{
m_caozuozhe.SetWindowText(denglu.m_dengluyuan);
}
else//单击【取消】退出登录
{
exit(1);
}
//读取数据文件
TRY
{
readfile.Open("staff.dll",CFile::modeReadWrite);//打开员工信息数据文件
}
CATCH( CFileException, e )
{
AfxMessageBox("员工信息文件打开失败!");
}
END_CATCH
CString temp;
CStaff *tempstaff=NULL;
while(readfile.GetPosition()<readfile.GetLength())//将读取的数据初始化为单个的CStaff对象添加到保存数据的变量中
{
readfile.ReadString(temp);
tempstaff=new CStaff(temp);
m_all_staff.Add(*tempstaff);
}
//员工添加完毕
//初始化未到员工列表
for(int i=0;i<m_all_staff.GetSize();i++)
{
m_weidao.AddString(m_all_staff[i].m_staff_name+" "+m_all_staff[i].m_staff_num);
}
// 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_zhuangtai=true;
m_static_zhuangtai.SetWindowText("上班考勤状态");
//启动计时器
SetTimer(TIMER,200,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSEWORKDlg::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 CSEWORKDlg::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 CSEWORKDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSEWORKDlg::OnButtonQidongdukaqi() //启动模拟读卡器来得到员工编号
{
// TODO: Add your control notification handler code here
CMoniDuKaQi dlg;
if(dlg.DoModal()==1)
{
m_bianhao=dlg.m_shurubianhao;
}
else
{
return;
}
for(int i=0;i<m_all_staff.GetSize();i++)
{
if(m_all_staff[i].m_staff_num==m_bianhao)
{
if(m_zhuangtai)//上班状态
{
m_all_staff[i].m_working=true;
int dd=m_weidao.FindString(-1,m_all_staff[i].m_staff_name);
CString str;
m_weidao.GetText(dd,str);
m_yidao.AddString(str);
m_weidao.DeleteString(dd);
return ;
}
else//下班状态
{
m_all_staff[i].m_working=false;
int dd=m_yidao.FindString(-1,m_all_staff[i].m_staff_name);
CString str;
m_yidao.GetText(dd,str);
m_weidao.AddString(str);
m_yidao.DeleteString(dd);
return ;
}
}
}
AfxMessageBox("您输入的员工编号有误!");
}
void CSEWORKDlg::OnButtonShanchu() //将员工从已到列表中删除到未到员工列表中
{
// TODO: Add your control notification handler code here
int i=m_yidao.GetCurSel();
if(i==LB_ERR)
{
MessageBox("请选择考勤员工");
}
else
{
//界面操作
CString str;
m_yidao.GetText(i,str);
m_weidao.AddString(str);
m_yidao.DeleteString(i);
//数据操作
for(int j=0;j<m_all_staff.GetSize();j++)
{
if(m_all_staff[j].m_staff_name==str)
{
m_all_staff[j].m_working=false;
}
else
{
continue;
}
}
}
}
void CSEWORKDlg::OnButtonTianjia() //将员工从未到员工中添加到已到列表
{
// TODO: Add your control notification handler code here
int i=m_weidao.GetCurSel();
if(i==LB_ERR)
{
MessageBox("请选择考勤员工!");
}
else
{
//界面操作
CString str;
m_weidao.GetText(i,str);
m_yidao.AddString(str);
m_weidao.DeleteString(i);
//数据操作
for(int j=0;j<m_all_staff.GetSize();j++)
{
if(str==m_all_staff[j].m_staff_name)
{
m_all_staff[j].m_working=true;
return ;
}
else
{
continue;
}
}
}
}
void CSEWORKDlg::OnButtonZhuangtai() //单击修改状态按钮的响应
{
// TODO: Add your control notification handler code here
if(m_zhuangtai)
{
m_zhuangtai=false;
m_static_zhuangtai.SetWindowText("下班考勤状态");
}
else
{
m_zhuangtai=true;
m_static_zhuangtai.SetWindowText("上班考勤状态");
}
}
void CSEWORKDlg::OnTimer(UINT nIDEvent) //更新时间,修改界面时间
{
// TODO: Add your message handler code here and/or call default
CTime current_time=CTime::GetCurrentTime();
m_time.SetWindowText(current_time.Format("%Y年%m月%d日%H时%M分%S秒"));
m_time1.SetWindowText(current_time.Format("%Y年%m月%d日%H时%M分%S秒"));
CDialog::OnTimer(nIDEvent);
}
void CSEWORKDlg::OnCancel()
{
// TODO: Add extra cleanup here
//关闭计时器
KillTimer(TIMER);
//关闭文件
readfile.Close();
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -