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

📄 attendmisdlg.cpp

📁 一个员工考勤管理的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// AttendMISDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AttendMIS.h"
#include "AttendMISDlg.h"
#include "DBConfigDlg.h"
#include "ScheduleSetDlg.h"
#include "DlgStat.h"
#include "PersonDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CAttendMISDlg dialog

CAttendMISDlg::CAttendMISDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAttendMISDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAttendMISDlg)
	m_bInChecked = FALSE;
	m_strPerIDAtt = _T("");
	m_strPerIDErrand = _T("");
	m_strPerIDLeave = _T("");
	m_strPerIDOT = _T("");
	m_strPerNameAtt = _T("");
	m_strPerNameErrand = _T("");
	m_strPerNameLeave = _T("");
	m_strPerNameOT = _T("");
	m_dtErEndDate = COleDateTime::GetCurrentTime();
	m_dtErEndTime = COleDateTime::GetCurrentTime();
	m_dtErStartDate = COleDateTime::GetCurrentTime();
	m_dtErStartTime = COleDateTime::GetCurrentTime();
	m_dtIODate = COleDateTime::GetCurrentTime();
	m_dtIOTime = COleDateTime::GetCurrentTime();
	m_dtLeEndDate = COleDateTime::GetCurrentTime();
	m_dtLeEndTime = COleDateTime::GetCurrentTime();
	m_dtLeStartDate = COleDateTime::GetCurrentTime();
	m_dtLeStartTime = COleDateTime::GetCurrentTime();
	m_dtOTDate = COleDateTime::GetCurrentTime();
	m_fOTHour = 0.0f;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CAttendMISDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAttendMISDlg)
	DDX_Control(pDX, IDC_LIST_OVERTIME, m_listOT);
	DDX_Control(pDX, IDC_LIST_LEAVE, m_listLeave);
	DDX_Control(pDX, IDC_LIST_ERRAND, m_listErrand);
	DDX_Control(pDX, IDC_LIST_ATT, m_listAtt);
	DDX_Check(pDX, IDC_CHECK1, m_bInChecked);
	DDX_Text(pDX, IDC_EDIT_PERID_ATT, m_strPerIDAtt);
	DDX_Text(pDX, IDC_EDIT_PERID_ERRAND, m_strPerIDErrand);
	DDX_Text(pDX, IDC_EDIT_PERID_LEAVE, m_strPerIDLeave);
	DDX_Text(pDX, IDC_EDIT_PERID_OVERTIME, m_strPerIDOT);
	DDX_Text(pDX, IDC_EDIT_PERNAME_ATT, m_strPerNameAtt);
	DDX_Text(pDX, IDC_EDIT_PERNAME_ERRAND, m_strPerNameErrand);
	DDX_Text(pDX, IDC_EDIT_PERNAME_LEAVE, m_strPerNameLeave);
	DDX_Text(pDX, IDC_EDIT_PERNAME_OVERTIME, m_strPerNameOT);
	DDX_DateTimeCtrl(pDX, IDC_ERRAND_END_DATE, m_dtErEndDate);
	DDX_DateTimeCtrl(pDX, IDC_ERRAND_END_TIME, m_dtErEndTime);
	DDX_DateTimeCtrl(pDX, IDC_ERRAND_START_DATE, m_dtErStartDate);
	DDX_DateTimeCtrl(pDX, IDC_ERRAND_START_TIME, m_dtErStartTime);
	DDX_DateTimeCtrl(pDX, IDC_IO_DATE, m_dtIODate);
	DDX_DateTimeCtrl(pDX, IDC_IO_TIME, m_dtIOTime);
	DDX_DateTimeCtrl(pDX, IDC_LEAVE_END_DATE, m_dtLeEndDate);
	DDX_DateTimeCtrl(pDX, IDC_LEAVE_END_TIME, m_dtLeEndTime);
	DDX_DateTimeCtrl(pDX, IDC_LEAVE_START_DATE, m_dtLeStartDate);
	DDX_DateTimeCtrl(pDX, IDC_LEAVE_START_TIME, m_dtLeStartTime);
	DDX_DateTimeCtrl(pDX, IDC_OVERTIME_DATE, m_dtOTDate);
	DDX_Text(pDX, IDC_OVERTIME_HOUR, m_fOTHour);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAttendMISDlg, CDialog)
	//{{AFX_MSG_MAP(CAttendMISDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_DBCON, OnBtnDbcon)
	ON_BN_CLICKED(IDC_BTN_TIMESET, OnBtnTimeset)
	ON_EN_CHANGE(IDC_EDIT_PERID_ATT, OnChangeEditPeridAtt)
	ON_EN_CHANGE(IDC_EDIT_PERID_ERRAND, OnChangeEditPeridErrand)
	ON_EN_CHANGE(IDC_EDIT_PERID_LEAVE, OnChangeEditPeridLeave)
	ON_EN_CHANGE(IDC_EDIT_PERID_OVERTIME, OnChangeEditPeridOvertime)
	ON_BN_CLICKED(IDC_BTN_ATT_ADD, OnBtnAttAdd)
	ON_BN_CLICKED(IDC_BTN_ATT_DEL, OnBtnAttDel)
	ON_BN_CLICKED(IDC_BTN_ATT_QUERY, OnBtnAttQuery)
	ON_BN_CLICKED(IDC_BTN_ATT_STAT, OnBtnAttStat)
	ON_BN_CLICKED(IDC_BTN_OT_ADD, OnBtnOtAdd)
	ON_BN_CLICKED(IDC_BTN_OT_DEL, OnBtnOtDel)
	ON_BN_CLICKED(IDC_BTN_OT_QUERY, OnBtnOtQuery)
	ON_BN_CLICKED(IDC_BTN_LEAVE_ADD, OnBtnLeaveAdd)
	ON_BN_CLICKED(IDC_BTN_LEAVE_DEL, OnBtnLeaveDel)
	ON_BN_CLICKED(IDC_BTN_LEAVE_QUERY, OnBtnLeaveQuery)
	ON_BN_CLICKED(IDC_BTN_ERRAND_ADD, OnBtnErrandAdd)
	ON_BN_CLICKED(IDC_BTN_ERRAND_DEL, OnBtnErrandDel)
	ON_BN_CLICKED(IDC_BTN_ERRAND_QUERY, OnBtnErrandQuery)
	ON_BN_CLICKED(IDC_BTN_PERSON_ADD, OnBtnPersonAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAttendMISDlg message handlers

BOOL CAttendMISDlg::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
	
	//连接数据库
	ConnectDB();
	//初始化列表框控件和数据
	InitControl();
	InitCtrlData();

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

void CAttendMISDlg::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 CAttendMISDlg::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 CAttendMISDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAttendMISDlg::ConnectDB()
{
	char szPath[255];
	//获取应用程序完全路径
	::GetModuleFileName(NULL,szPath,255);
	CString strFileName = szPath;
	//获取所在的目录名称
	strFileName.Delete(strFileName.ReverseFind('\\')+1,strFileName.GetLength ()-strFileName.ReverseFind('\\')-1);
    //构造配置文件的完全路径
	strFileName += "AttendMIS.ini";
	TCHAR sz[101];
	memset(sz,0,sizeof(TCHAR)*101);
	//获取配置文件中数据库数据源的值,如果没有,缺省值为AttDB
	GetPrivateProfileString(_T("General"),_T("ODBC数据源名称"),_T("misdb"),sz,100,strFileName);
	CString strSource(sz);
	GetPrivateProfileString(_T("General"),_T("数据库用户"),_T("dbattend"),sz,100,strFileName);
	CString strUser(sz);
	GetPrivateProfileString(_T("General"),_T("数据库密码"),_T("dbattend"),sz,100,strFileName);
	CString strPwd(sz);	
	//获取上下班工作时间
	GetPrivateProfileString(_T("General"),_T("上午上班时间"),_T("08:30:00"),sz,100,strFileName);
	CString strAMStart(sz);
	m_dtAMStart = CTime(2004,12,15,atoi(strAMStart.Left(2)),atoi(strAMStart.Mid(3,2)),atoi(strAMStart.Right(2)));
	int nhour = m_dtAMStart.GetHour();
	GetPrivateProfileString(_T("General"),_T("上午下班时间"),_T("12:00:00"),sz,100,strFileName);
	CString strAMEnd(sz);
	m_dtAMEnd = CTime(2004,12,15,atoi(strAMEnd.Left(2)),atoi(strAMEnd.Mid(3,2)),atoi(strAMEnd.Right(2)));
	GetPrivateProfileString(_T("General"),_T("下午上班时间"),_T("13:00:00"),sz,100,strFileName);
	CString strPMStart(sz);
	m_dtPMStart= CTime(2004,12,15,atoi(strPMStart.Left(2)),atoi(strPMStart.Mid(3,2)),atoi(strPMStart.Right(2)));
	GetPrivateProfileString(_T("General"),_T("下午下班时间"),_T("17:30:00"),sz,100,strFileName);
	CString strPMEnd(sz);
	m_dtPMEnd = CTime(2004,12,15,atoi(strPMEnd.Left(2)),atoi(strPMEnd.Mid(3,2)),atoi(strPMEnd.Right(2)));
	//
	m_strDBSource = strSource;
	m_strDBUser = strUser;
	m_strDBPassword = strPwd;
	//打开数据库的连接
	g_odbcDB.Connect(m_strDBSource,m_strDBUser,m_strDBPassword);
}


void CAttendMISDlg::OnBtnDbcon() 
{
	// TODO: Add your control notification handler code here
	CDBConfigDlg dlg;
	//给对话框赋初始值
	dlg.m_strDBSource = m_strDBSource;
	dlg.m_strDBUser = m_strDBUser;
	dlg.m_strDBPassword = m_strDBPassword;
	//打开数据库对话框
	if(dlg.DoModal() == IDOK){
		m_strDBSource = dlg.m_strDBSource;
		m_strDBUser = dlg.m_strDBUser;
		m_strDBPassword = dlg.m_strDBPassword;
		char szPath[255];
		//获取应用程序完全路径
		::GetModuleFileName(NULL,szPath,255);
		CString strFileName = szPath;
		//获取所在的目录名称
		strFileName.Delete(strFileName.ReverseFind('\\')+1,strFileName.GetLength ()-strFileName.ReverseFind('\\')-1);
		//构造配置文件的完全路径
		strFileName += "AttendMIS.ini";
		//保存数据库配置信息到配置文件中
		WritePrivateProfileString(_T("General"),_T("ODBC数据源名称"),m_strDBSource,strFileName);
		WritePrivateProfileString(_T("General"),_T("数据库用户"),m_strDBUser,strFileName);
		WritePrivateProfileString(_T("General"),_T("数据库密码"),m_strDBPassword,strFileName);
		//创建连接字符串.
		CString strConnect;
		strConnect.Format("DSN=%s;UID=%s;PWD=%s",m_strDBSource,m_strDBUser,m_strDBPassword);
		//检查数据库是否已经连接,如果已连接,则关闭已经打开的数据库.
		if(g_odbcDB.IsOpen())
			g_odbcDB.DisConnect();
		//打开数据库的连接
		g_odbcDB.Connect(m_strDBSource,m_strDBUser,m_strDBPassword);
		InitCtrlData();
	}	
}

void CAttendMISDlg::OnBtnTimeset() 
{
	// TODO: Add your control notification handler code here
	CScheduleSetDlg dlg;
	//给对话框赋初始值	
	dlg.m_dtAMStart = m_dtAMStart;
	dlg.m_dtAMEnd = m_dtAMEnd;
	dlg.m_dtPMStart = m_dtPMStart;
	dlg.m_dtPMEnd = m_dtPMEnd;
	//打开数据库对话框
	if(dlg.DoModal() == IDOK){	
		m_dtAMStart = dlg.m_dtAMStart;
		m_dtAMEnd = dlg.m_dtAMEnd;
		m_dtPMStart = dlg.m_dtPMStart;
		m_dtPMEnd = dlg.m_dtPMEnd;
		//保存参数到配置文件中		
		char szPath[255];
		//获取应用程序完全路径
		::GetModuleFileName(NULL,szPath,255);
		CString strFileName = szPath;
		//获取所在的目录名称
		strFileName.Delete(strFileName.ReverseFind('\\')+1,strFileName.GetLength ()-strFileName.ReverseFind('\\')-1);
		//构造配置文件的完全路径
		strFileName += "AttendMIS.ini";
		//保存数据库配置信息到配置文件中
		WritePrivateProfileString(_T("General"),_T("上午上班时间"),m_dtAMStart.Format("%H:%M:%S"),strFileName);
		WritePrivateProfileString(_T("General"),_T("上午下班时间"),m_dtAMEnd.Format("%H:%M:%S"),strFileName);
		WritePrivateProfileString(_T("General"),_T("下午上班时间"),m_dtPMStart.Format("%H:%M:%S"),strFileName);
		WritePrivateProfileString(_T("General"),_T("下午下班时间"),m_dtPMEnd.Format("%H:%M:%S"),strFileName);
	}	
}

void CAttendMISDlg::InitControl()
{
	//设置列表框控件扩展风格
	DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
		LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
	m_listAtt.SetExtendedStyle(dwExStyle);
	m_listOT.SetExtendedStyle(dwExStyle);	
	m_listLeave.SetExtendedStyle(dwExStyle);
	m_listErrand.SetExtendedStyle(dwExStyle);	

	//初始化上下班出勤信息列表框控件
	m_listAtt.InsertColumn(0,"ID",LVCFMT_CENTER,40);
	m_listAtt.InsertColumn(1,"员工ID",LVCFMT_CENTER,60);
	m_listAtt.InsertColumn(2,"员工姓名",LVCFMT_CENTER,60);
	m_listAtt.InsertColumn(3,"上下班",LVCFMT_CENTER,60);
	m_listAtt.InsertColumn(4,"下班上班时间",LVCFMT_CENTER,140);
	//初始化加班信息列表框控件
	m_listOT.InsertColumn(0,"ID",LVCFMT_CENTER,40);
	m_listOT.InsertColumn(1,"员工ID",LVCFMT_CENTER,60);
	m_listOT.InsertColumn(2,"员工姓名",LVCFMT_CENTER,60);
	m_listOT.InsertColumn(3,"加班时间",LVCFMT_CENTER,60);
	m_listOT.InsertColumn(4,"加班日期",LVCFMT_CENTER,140);
	//初始化请假信息列表框控件
	m_listLeave.InsertColumn(0,"ID",LVCFMT_CENTER,40);
	m_listLeave.InsertColumn(1,"员工ID",LVCFMT_CENTER,60);
	m_listLeave.InsertColumn(2,"员工姓名",LVCFMT_CENTER,60);
	m_listLeave.InsertColumn(3,"开始时间",LVCFMT_CENTER,140);
	m_listLeave.InsertColumn(4,"结束时间",LVCFMT_CENTER,140);
	//初始化出差信息列表框控件
	m_listErrand.InsertColumn(0,"ID",LVCFMT_CENTER,40);
	m_listErrand.InsertColumn(1,"员工ID",LVCFMT_CENTER,60);
	m_listErrand.InsertColumn(2,"员工姓名",LVCFMT_CENTER,60);
	m_listErrand.InsertColumn(3,"开始时间",LVCFMT_CENTER,140);
	m_listErrand.InsertColumn(4,"结束时间",LVCFMT_CENTER,140);
}

void CAttendMISDlg::InitCtrlData()
{
	m_listAtt.DeleteAllItems();
	CDStrs attFields;
	//获取上下班出勤数据
	g_odbcDB.ExecuteQuery("select a.id,a.personid,b.name,in_out,io_time "
		"from attend_info_tab a, person_info_tab b where a.personid=b.personid order by a.id",attFields);
	for(int i = 0 ; i < attFields.size() ; i++)
	{
		CStrs strs = attFields[i];
		InsertDataToList(m_listAtt,strs[0],strs[1],strs[2],
			atoi(strs[3])==1?"上班":"下班",strs[4]);	
	}
	m_listOT.DeleteAllItems();
	CDStrs otFields;
	//获取加班数据
	g_odbcDB.ExecuteQuery( "select a.id,a.personid,b.name,ot_hours,ot_date "
		"from overtime_info_tab a, person_info_tab b where a.personid=b.personid order by a.id",otFields);
	for(i = 0 ; i < otFields.size() ; i++)
	{
		CStrs strs = otFields[i];
		InsertDataToList(m_listOT,strs[0],strs[1],strs[2],
			strs[3],strs[4].Left(10));			
	}

⌨️ 快捷键说明

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