www.pudn.com > 个人考勤软件开发实例配套代码.zip > attendanceDlg.cpp


// attendanceDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "attendance.h" 
#include "attendanceDlg.h" 
#include "DlgProxy.h" 
#include "DualListDialog.h" 
#include "PageSetup.h" 
#include "PrintSelect.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
/* 
#define ID_FILE_OPEN	WM_USER + 100  
#define ID_FILE_SAVEAS	WM_USER + 101  
#define ID_PRINT		WM_USER + 102  
#define ID_PRINT_PREVIEW	WM_USER + 103 
*/ 
// CAboutDlg dialog used for App About 
 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	CButton	m_ctrlMore; 
	CString	m_sEmail; 
	CString	m_sWWW; 
	CString	m_sExplain; 
	//}}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) 
	virtual BOOL OnInitDialog(); 
	afx_msg void OnBtnMore(); 
	//}}AFX_MSG 
	DECLARE_MESSAGE_MAP() 
private: 
	BOOL	m_bToggleSize; 
	CRect	m_rectFull; 
	CRect	m_rectHalf; 
	void ToggleSize() ; 
}; 
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CAboutDlg) 
	m_sEmail = _T("Email:   ylguang@21cn.com"); 
	m_sWWW = _T("http://www.vckbase.com/code/viewcode.asp?id=1471\nhttp://www.vchelp.net/vchelp/view_article.asp?ft=2&article_id=128"); 
	m_sExplain = _T(""); 
	//}}AFX_DATA_INIT 
	m_sExplain.LoadString(IDS_EXPLAIN);//华文隶书 
	m_bToggleSize=FALSE; 
} 
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAboutDlg) 
	DDX_Control(pDX, IDC_BTN_MORE, m_ctrlMore); 
	DDX_Text(pDX, IDC_EDT_EMAIL, m_sEmail); 
	DDX_Text(pDX, IDC_EDT_WWW, m_sWWW); 
	DDX_Text(pDX, IDC_STATIC_EXPLAIN, m_sExplain); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
	ON_BN_CLICKED(IDC_BTN_MORE, OnBtnMore) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
BOOL CAboutDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	// save our full size 
	GetWindowRect(&m_rectFull); 
	m_rectHalf=m_rectFull; 
 
	// calculate our half size based on bottom of "More" button 
	CRect rect; 
	m_ctrlMore.GetWindowRect(&rect); 
	m_rectHalf.bottom=rect.bottom+10; // + 10 for cosmetics 
 
	// toggle window size 
	ToggleSize(); 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CAboutDlg::OnBtnMore()  
{ 
	// TODO: Add your control notification handler code here 
	ToggleSize();	 
	 
} 
 
void CAboutDlg::ToggleSize()  
{ 
	CRect rect; 
	CString str; 
	if (m_bToggleSize) 
	{ 
		str="<< 收拢吧"; 
		rect=m_rectFull; 
	} 
	else 
	{ 
		str="算法说明>>"; 
		rect=m_rectHalf; 
	} 
	SetWindowPos(NULL,0,0,rect.Width(),rect.Height(),SWP_NOZORDER|SWP_NOMOVE); 
	m_ctrlMore.SetWindowText(str); 
	m_bToggleSize=!m_bToggleSize; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAttendanceDlg dialog 
 
IMPLEMENT_DYNAMIC(CAttendanceDlg, CDialog); 
 
CAttendanceDlg::CAttendanceDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CAttendanceDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CAttendanceDlg) 
	m_sYearMonth = _T(""); 
	m_dDayPay = 0.0; 
	m_iObtain = 0; 
	m_iPay = 2000; 
	m_iWorkDays = 0; 
	m_dFactWorks = 0.0; 
	m_iFactPay = 0; 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
	m_pAutoProxy = NULL; 
	m_toolbarCtrl = NULL ; 
 
	m_iBottom = 0; 
	m_iLeft = 0; 
	m_iRight = 0; 
	m_iTop = 0; 
	m_iPrtSel = 0; 
 
	m_iCurItem = 0; 
	for(int i=0;i<=31;i++) 
	{ 
		//sAttend[i].iDate=0; 
		//sAttend[i].iWeek=0; 
		sAttend[i].tAmOnDuty=0; 
		sAttend[i].tAmOffDuty=0; 
		sAttend[i].tPmOnDuty=0; 
		sAttend[i].tPmOffDuty=0; 
		sAttend[i].tWork=0; 
	} 
	sDuty.tAmOnDuty=0; 
	sDuty.tAmOffDuty=0; 
	sDuty.tPmOnDuty=0; 
	sDuty.tPmOffDuty=0; 
	sDuty.tWork=0; 
	m_iHoliday=-1; 
	m_iMonths=-1; 
	m_bFirst=true; 
	m_iTotalSel=0; 
 
} 
 
CAttendanceDlg::~CAttendanceDlg() 
{ 
	// If there is an automation proxy for this dialog, set 
	//  its back pointer to this dialog to NULL, so it knows 
	//  the dialog has been deleted. 
	if (m_pAutoProxy != NULL) 
		m_pAutoProxy->m_pDialog = NULL; 
 
} 
 
void CAttendanceDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAttendanceDlg) 
	DDX_Control(pDX, IDOK, m_BtnOk); 
	DDX_Control(pDX, IDC_FACTPAY, m_EdtFactPay); 
	DDX_Control(pDX, IDC_STATIC_YEAR, m_cYear); 
	DDX_Control(pDX, IDC_STATIC_MONTH, m_cMonth); 
	DDX_Control(pDX, IDC_WORKDAYS, m_EdtWorkDays); 
	DDX_Control(pDX, IDC_PAY, m_EdtPay); 
	DDX_Control(pDX, IDC_OBTAIN, m_EdtObtain); 
	DDX_Control(pDX, IDC_FACTWORKS, m_EDtFactWorks); 
	DDX_Control(pDX, IDC_DAYPAY, m_EdtDayPay); 
	DDX_Control(pDX, IDC_DUTY, m_ListDuty); 
	DDX_Control(pDX, IDC_TOTAL, m_ListTotal); 
	DDX_Control(pDX, IDC_ATTENDANCE, m_ListAttend); 
	DDX_Text(pDX, IDC_YEAR_MONTH, m_sYearMonth); 
	DDX_Text(pDX, IDC_DAYPAY, m_dDayPay); 
	DDV_MinMaxDouble(pDX, m_dDayPay, 0., 2000.); 
	DDX_Text(pDX, IDC_OBTAIN, m_iObtain); 
	DDV_MinMaxInt(pDX, m_iObtain, 0, 62000); 
	DDX_Text(pDX, IDC_PAY, m_iPay); 
	DDV_MinMaxInt(pDX, m_iPay, 0, 62000); 
	DDX_Text(pDX, IDC_WORKDAYS, m_iWorkDays); 
	DDV_MinMaxInt(pDX, m_iWorkDays, 0, 31); 
	DDX_Text(pDX, IDC_FACTWORKS, m_dFactWorks); 
	DDV_MinMaxDouble(pDX, m_dFactWorks, 0., 31.); 
	DDX_Text(pDX, IDC_FACTPAY, m_iFactPay); 
	DDV_MinMaxInt(pDX, m_iFactPay, 0, 62000); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAttendanceDlg, CDialog) 
	//{{AFX_MSG_MAP(CAttendanceDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_CLOSE() 
	ON_NOTIFY(LVN_COLUMNCLICK, IDC_DUTY, OnColumnclickDuty) 
	ON_BN_CLICKED(IDC_HOLIDAY, OnHoliday) 
	ON_EN_UPDATE(IDC_PAY, OnUpdatePay) 
	ON_BN_CLICKED(IDC_DELETE, OnDelete) 
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_TOTAL, OnItemchangedTotal) 
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen) 
	ON_COMMAND(ID_FILE_SAVEAS, OnFileSaveas) 
	ON_COMMAND(ID_PRINT_PREVIEW, OnPrintPreview) 
	ON_WM_CREATE() 
	ON_COMMAND(ID_PRINT, OnPrint) 
	ON_COMMAND(ID_PGSETUP, OnPgsetup) 
	ON_EN_UPDATE(IDC_FACTPAY, OnUpdateFactpay) 
	ON_COMMAND(ID_ABOUT, OnAbout) 
	//}}AFX_MSG_MAP 
	ON_NOTIFY_EX( TTN_NEEDTEXT, 0, NotifyFunction ) 
	//ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) 
	//ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CAttendanceDlg message handlers 
 
BOOL CAttendanceDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
//	app->pDeskTop=GetDesktopWindow(); 
 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
 
	btn[0].iBitmap = 0 ; 
	btn[0].idCommand = ID_FILE_OPEN ; 
	btn[0].fsState = TBSTATE_ENABLED  ; 
	btn[0].fsStyle = TBSTYLE_BUTTON  ; 
	btn[0].dwData = 0 ; 
	btn[0].iString = 0; 
 
	btn[1].iBitmap = 1 ; 
	btn[1].idCommand = ID_FILE_SAVEAS ; 
	btn[1].fsState = TBSTATE_ENABLED  ; 
	btn[1].fsStyle = TBSTYLE_BUTTON ; 
	btn[1].dwData = 0 ; 
	btn[1].iString = 1; 
 
	btn[2].iBitmap = 2 ; 
	btn[2].idCommand = ID_PGSETUP ; 
	btn[2].fsState = TBSTATE_ENABLED  ; 
	btn[2].fsStyle = TBSTYLE_BUTTON ; 
	btn[2].dwData = 0 ; 
	btn[2].iString = 2; 
 
	btn[3].iBitmap = 3 ; 
	btn[3].idCommand = ID_PRINT ; 
	btn[3].fsState = TBSTATE_ENABLED  ; 
	btn[3].fsStyle = TBSTYLE_BUTTON ; 
	btn[3].dwData = 0 ; 
	btn[3].iString = 3; 
 
	btn[4].iBitmap = 4 ; 
	btn[4].idCommand = ID_PRINT_PREVIEW ; 
	btn[4].fsState = TBSTATE_ENABLED  ; 
	btn[4].fsStyle = TBSTYLE_BUTTON ; 
	btn[4].dwData = 0 ; 
	btn[4].iString = 4; 
 
	btn[5].iBitmap = 5 ; 
	btn[5].idCommand = ID_ABOUT ; 
	btn[5].fsState = TBSTATE_ENABLED  ; 
	btn[5].fsStyle = TBSTYLE_BUTTON ; 
	btn[5].dwData = 0 ; 
	btn[5].iString = 5; 
 
	//Enable the Tool Tips with the following line 
	EnableToolTips(TRUE); 
 
	SetToolBarPosition(0); 
 
/*	CString s; 
	s.Format("%d年%2d月份月报 ", m_Time.GetYear(),m_Time.GetMonth()); 
	char* ch = s.GetBuffer(s.GetLength()); 
	m_cMonth.SetWindowText(ch); 
	s.Format("%d年度 年报 ", m_Time.GetYear()); 
	ch = s.GetBuffer(s.GetLength()); 
	m_cYear.SetWindowText(ch); 
*/ 
	// 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 
	//DWORD dwStyle = m_ListAttend.GetStyle();LVS_EX_FULLROWSELECT| 
	DWORD dwStyle = m_ListDuty.GetStyle(); 
	dwStyle |= LVS_EX_GRIDLINES | LVS_SHOWSELALWAYS; 
	dwStyle &= !LVS_EX_TRACKSELECT; 
	m_ListDuty.SetExtendedStyle(dwStyle); 
	m_ListDuty.SetBkColor(RGB(240,247,233)); 
	m_ListDuty.SetTextBkColor(RGB(240,247,233)); 
 
	RECT rect; 
	m_ListDuty.GetClientRect(&rect); 
 
	LV_COLUMN lvc; 
	lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT; 
	lvc.fmt=LVCFMT_CENTER; 
	lvc.iSubItem = 0; 
	lvc.pszText = _T("Am 点到"); 
	lvc.cx = 60; 
	m_ListDuty.InsertColumn(1,&lvc); 
	lvc.iSubItem = 1; 
	lvc.pszText = _T("午饭"); 
	lvc.cx = 60; 
	m_ListDuty.InsertColumn(2,&lvc); 
	lvc.iSubItem = 2; 
	lvc.pszText = _T("Pm 点到"); 
	lvc.cx = 60; 
	m_ListDuty.InsertColumn(3,&lvc); 
	lvc.iSubItem = 3; 
	lvc.pszText = _T("下班"); 
	lvc.cx = 60; 
	m_ListDuty.InsertColumn(4,&lvc); 
	lvc.iSubItem = 4; 
	lvc.pszText = _T("晚间工作"); 
	lvc.cx = 70; 
	m_ListDuty.InsertColumn(5,&lvc); 
	lvc.iSubItem = 5; 
	lvc.pszText = _T("结束"); 
	lvc.cx = 70; 
	m_ListDuty.InsertColumn(6,&lvc); 
	lvc.iSubItem = 6; 
	lvc.pszText = _T("日工时"); 
	lvc.cx = rect.right-6*60-20; 
	m_ListDuty.InsertColumn(7,&lvc); 
 
	dwStyle = m_ListAttend.GetStyle(); 
	dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ; 
	m_ListAttend.SetExtendedStyle(dwStyle); 
	m_ListAttend.SetBkColor(RGB(240,247,233)); 
	m_ListAttend.SetTextBkColor(RGB(240,247,233)); 
 
	m_ListAttend.GetClientRect(&rect); 
//	LV_COLUMN lvc; 
	lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT; 
	lvc.fmt=LVCFMT_CENTER; 
	lvc.iSubItem = 0; 
	lvc.pszText = _T("日期");//NO. 
	lvc.cx = 40; 
	m_ListAttend.InsertColumn(1,&lvc); 
	lvc.iSubItem = 1; 
	lvc.pszText = _T("星期");//NO. 
	lvc.cx = 60; 
	m_ListAttend.InsertColumn(2,&lvc); 
	lvc.iSubItem = 2; 
	lvc.pszText = _T("Am 点到"); 
	lvc.cx = 60; 
	m_ListAttend.InsertColumn(3,&lvc); 
	lvc.iSubItem = 3; 
	lvc.pszText = _T("午饭"); 
	lvc.cx = 55; 
	m_ListAttend.InsertColumn(4,&lvc); 
	lvc.iSubItem = 4; 
	lvc.pszText = _T("Pm 点到"); 
	lvc.cx = 60; 
	m_ListAttend.InsertColumn(5,&lvc); 
	lvc.iSubItem = 5; 
	lvc.pszText = _T("下班"); 
	lvc.cx = 55; 
	m_ListAttend.InsertColumn(6,&lvc); 
	lvc.iSubItem = 6; 
	lvc.pszText = _T("晚间工作"); 
	lvc.cx = 70; 
	m_ListAttend.InsertColumn(7,&lvc); 
	lvc.iSubItem = 7; 
	lvc.pszText = _T("结束"); 
	lvc.cx = 60; 
	m_ListAttend.InsertColumn(8,&lvc); 
	lvc.iSubItem = 8; 
	lvc.pszText = _T("日工时"); 
	lvc.cx = rect.right-40-7*60; 
	m_ListAttend.InsertColumn(9,&lvc); 
// 
	dwStyle = m_ListTotal.GetStyle(); 
	dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ; 
	m_ListTotal.SetExtendedStyle(dwStyle); 
	m_ListTotal.SetBkColor(RGB(240,247,233)); 
	m_ListTotal.SetTextBkColor(RGB(240,247,233)); 
 
	m_ListTotal.GetClientRect(&rect); 
//	LV_COLUMN lvc; 
	lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT; 
	lvc.fmt=LVCFMT_CENTER; 
	lvc.iSubItem = 0; 
	lvc.pszText = _T("月份");//NO. 
	lvc.cx = 40; 
	m_ListTotal.InsertColumn(1,&lvc); 
	lvc.iSubItem = 1; 
	lvc.pszText = _T("法定工作日");//NO. 
	lvc.cx = 80; 
	m_ListTotal.InsertColumn(2,&lvc); 
	lvc.iSubItem = 2; 
	lvc.pszText = _T("全勤工资"); 
	lvc.cx = 75; 
	m_ListTotal.InsertColumn(3,&lvc); 
	lvc.iSubItem = 3; 
	lvc.pszText = _T("日均工资额"); 
	lvc.cx = 85; 
	m_ListTotal.InsertColumn(4,&lvc); 
	lvc.iSubItem = 4; 
	lvc.pszText = _T("实出勤日"); 
	lvc.cx = 75; 
	m_ListTotal.InsertColumn(5,&lvc); 
	lvc.iSubItem = 5; 
	lvc.pszText = _T("出勤工资"); 
	lvc.cx = 75; 
	m_ListTotal.InsertColumn(6,&lvc); 
	lvc.iSubItem = 6; 
	lvc.pszText = _T("实发工资"); 
	lvc.cx = rect.right-430; 
	m_ListTotal.InsertColumn(6,&lvc); 
 
	lvitem.pszText=""; 
	lvitem.mask=LVIF_TEXT; 
    lvitem.iSubItem=0; 
 
//	CTime time=CTime::GetCurrentTime(); 
//	CTimeSpan tm=time-m_Time; 
 
	m_iCurDate=m_Time.GetDay(); 
	m_iMaxDate=m_iCurDate; 
 
//	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
	m_sOpenPath = app->m_pszHelpFilePath; 
	int index = m_sOpenPath.ReverseFind('\\');			 
	m_sOpenPath = m_sOpenPath.Left(index); 
 
	m_sSavePath=m_sOpenPath; 
	m_sAttendFile="考勤"+m_Time.Format("%Y年"); 
	m_sAttendFile+=".atd"; 
	CString filename=m_sOpenPath+"\\"+m_sAttendFile; 
	m_sFileExt="atd"; 
	CFile file; 
	if(file.Open(filename,CFile::modeRead)!=0) 
	{ 
		CArchive ar(&file,CArchive::load); 
 
		CWaitCursor wait; 
		Serialize(ar);     // save mem_sCfgFile 
		ar.Close(); 
		file.Close(); 
		m_sOpenPath=m_sSavePath; 
	}else 
	{ 
		CString s = m_Time.Format("%Y"); 
		char* ch = s.GetBuffer(s.GetLength()); 
		int	i = atoi(ch); 
		i--; 
		itoa(i,ch,10); 
		s = "考勤"+s; 
		s += "年"; 
		s += ".atd"; 
		filename=m_sOpenPath+"\\"+s; 
		if(file.Open(filename,CFile::modeRead)!=0) 
		{ 
			CArchive ar(&file,CArchive::load); 
 
			CWaitCursor wait; 
			Serialize(ar);     // save mem_sCfgFile 
			ar.Close(); 
			file.Close(); 
//			m_sOpenPath=m_sSavePath; 
			m_iPay = sYearTotal[m_iMonths-1].iPay; 
			m_iMonths = -1; 
		} 
	} 
 
	if(m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m%d")==m_Time.Format("%Y%m%d")) 
	{ 
/*		m_iPay = sYearTotal[m_iMonths].iPay; 
		m_iHoliday = sYearTotal[m_iMonths].iHoliday; 
		m_ArrayHoliday.SetSize(m_iHoliday); 
        for(int iIndex = 0; iIndex < m_iHoliday; ++iIndex) 
			m_ArrayHoliday[iIndex] = sYearTotal[m_iMonths].ArrayHoliday[iIndex]; 
 
		for(int i=0;i<=m_iCurItem;i++) 
			sAttend[i] = sYearTotal[m_iMonths].sAttend[i]; 
*/		m_iCurItem = sYearTotal[m_iMonths].iDayItems; 
		sDuty.tAmOnDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOnDuty; 
		sDuty.tAmOffDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOffDuty; 
		sDuty.tPmOnDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOnDuty; 
		sDuty.tPmOffDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOffDuty; 
		sDuty.tNinOnDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tNinOnDuty; 
		sDuty.tNinOffDuty=sYearTotal[m_iMonths].sAttend[m_iCurItem].tNinOffDuty; 
		sDuty.tWork=(sDuty.tAmOffDuty-sDuty.tAmOnDuty)+(sDuty.tPmOffDuty-sDuty.tPmOnDuty)+(sDuty.tNinOffDuty-sDuty.tNinOnDuty); 
	} 
 
	if(m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m")==m_Time.Format("%Y%m") 
		&& sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetDay()!=m_Time.GetDay()) 
	{ 
		sYearTotal[m_iMonths].iDayItems++; 
		m_iCurItem = sYearTotal[m_iMonths].iDayItems; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOnDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOffDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOnDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOffDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tNinOnDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tNinOffDuty=m_Time; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tWork=m_Time-m_Time; 
		sDuty.tAmOnDuty=m_Time; 
		sDuty.tAmOffDuty=m_Time; 
		sDuty.tPmOnDuty=m_Time; 
		sDuty.tPmOffDuty=m_Time; 
		sDuty.tNinOnDuty=m_Time; 
		sDuty.tNinOffDuty=m_Time; 
		sDuty.tWork=m_Time-m_Time; 
	} 
 
	if(m_iMonths==-1 || (m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m")!=m_Time.Format("%Y%m"))) 
	{ 
		m_iMonths++; 
		sYearTotal[m_iMonths].iPay = m_iMonths-1==-1 ? m_iPay : sYearTotal[m_iMonths-1].iPay; 
		if(m_iMonths==0) 
		{ 
			 
			CString s; 
			s.Format("%d元",sYearTotal[m_iMonths].iPay); 
			s =	"祝贺您! 新的工作或新一年的工作又开始了!\n\n默认的或从上一年继承下来的月工资是:"+s; 
			s += "\n\n有没有变化? 如果有变化,请别忘记在\"月全勤工资\"一栏中改正过来!"; 
			char* ch = s.GetBuffer(s.GetLength()); 
			::MessageBox(NULL,ch,"提醒",MB_OK|MB_ICONQUESTION); 
		} 
		sYearTotal[m_iMonths].iFactPay =0; 
		sYearTotal[m_iMonths].iDayItems = 0; 
/*		m_ArrayHoliday.SetSize(m_iHoliday); 
        for(int iIndex = 0; iIndex < m_iHoliday; ++iIndex) 
			m_ArrayHoliday[iIndex] = sYearTotal[m_iMonths].ArrayHoliday[iIndex]; 
*/		sYearTotal[m_iMonths].sAttend[0].tAmOnDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tAmOffDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tPmOnDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tPmOffDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tNinOnDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tNinOffDuty = m_Time; 
		sYearTotal[m_iMonths].sAttend[0].tWork=m_Time-m_Time; 
		sDuty.tAmOnDuty=m_Time; 
		sDuty.tAmOffDuty=m_Time; 
		sDuty.tPmOnDuty=m_Time; 
		sDuty.tPmOffDuty=m_Time; 
		sDuty.tNinOnDuty=m_Time; 
		sDuty.tNinOffDuty=m_Time; 
		sDuty.tWork=m_Time-m_Time; 
		m_iHoliday=0; 
	int year = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetYear(); 
	int mth = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetMonth(); 
	int monthday=MonthDay[mth-1]; 
	if(mth==2 && fmod(year,4)==0) 
		monthday++; 
		int day = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDay(); 
		int wk = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDayOfWeek();//1..7 
		int	wks = day/7; 
		int surplus = fmod(day-1,7);//0..6 
 
		int wk1 = surplus>=wk ? wk+7-surplus : wk-surplus; 
		 
		for(int i=0;i7) wk-=7; 
			 
			if(wk==1 || wk==7) 
			{ 
				//m_ArrayHoliday.Add(i+1); 
				sYearTotal[m_iMonths].ArrayHoliday[m_iHoliday] = i+1;//m_ArrayHoliday[m_iHoliday]; 
				m_iHoliday++; 
			} 
		} 
		//m_iWorkDays=monthday-m_iHoliday; 
		sYearTotal[m_iMonths].iHoliday = m_iHoliday; 
	} 
 
	GetDutyData(); 
 
	GetYearData(); 
	m_bFirst=false; 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CAttendanceDlg::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 CAttendanceDlg::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 CAttendanceDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
// Automation servers should not exit when a user closes the UI 
//  if a controller still holds on to one of its objects.  These 
//  message handlers make sure that if the proxy is still in use, 
//  then the UI is hidden but the dialog remains around if it 
//  is dismissed. 
 
void CAttendanceDlg::OnClose()  
{ 
	if (CanExit()) 
		CDialog::OnClose(); 
} 
 
void CAttendanceDlg::OnOK()  
{ 
 
	if (CanExit()) 
	{ 
		if(sYearTotal[0].sAttend[0].tAmOnDuty.GetYear()==m_Time.GetYear()) 
			m_sAttendFile="考勤"+m_Time.Format("%Y年"); 
		else 
			m_sAttendFile="考勤"+sYearTotal[0].sAttend[0].tAmOnDuty.Format("%Y年"); 
		m_sAttendFile+=".atd"; 
		CString filename=m_sSavePath+"\\"+m_sAttendFile; 
		m_sFileExt="atd"; 
		CFile file; 
		if(file.Open(filename,CFile::modeWrite|CFile::modeCreate)!=0) 
		{ 
			CArchive ar(&file,CArchive::store); 
 
			CWaitCursor wait; 
			Serialize(ar);     // save mem_sCfgFile 
			ar.Close(); 
			file.Close(); 
		} 
		CDialog::OnOK(); 
	} 
} 
 
void CAttendanceDlg::OnCancel()  
{ 
	if (CanExit()) 
		CDialog::OnCancel(); 
} 
 
BOOL CAttendanceDlg::CanExit() 
{ 
	// If the proxy object is still around, then the automation 
	//  controller is still holding on to this application.  Leave 
	//  the dialog around, but hide its UI. 
	if (m_pAutoProxy != NULL) 
	{ 
		ShowWindow(SW_HIDE); 
		return FALSE; 
	} 
	m_pChildFrame->ShowWindow(SW_SHOW);     // destroy preview view 
 
	return TRUE; 
} 
 
void CAttendanceDlg::GetTableData() 
{ 
	m_ListAttend.DeleteAllItems(); 
	CString str; 
	for(int j=0;j<=m_iCurItem;j++) 
	{ 
		sAttend[j].tWork = sAttend[j].tAmOffDuty-sAttend[j].tAmOnDuty; 
		sAttend[j].tWork += sAttend[j].tPmOffDuty-sAttend[j].tPmOnDuty; 
		sAttend[j].tWork += sAttend[j].tNinOffDuty-sAttend[j].tNinOnDuty; 
		 
		lvitem.iItem=j; 
		m_ListAttend.InsertItem(&lvitem); 
		str.Format("%d",sAttend[j].tAmOnDuty.GetDay());//j+1 
		m_ListAttend.SetItemText(j,0,str); 
 
		if(sAttend[j].tAmOnDuty!=0) 
		{ 
			int n=sAttend[j].tAmOnDuty.GetDayOfWeek(); 
			str=WeekTable[n-1]; 
			m_ListAttend.SetItemText(j,1,str); 
 
			if(sAttend[j].tAmOnDuty==sAttend[j].tAmOffDuty) 
			{ 
				str=_T(" "); 
				m_ListAttend.SetItemText(j,2,str); 
				m_ListAttend.SetItemText(j,3,str); 
			} 
			else 
			{ 
				str=sAttend[j].tAmOnDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,2,str); 
 
				str=sAttend[j].tAmOffDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,3,str); 
			} 
 
			if(sAttend[j].tPmOnDuty==sAttend[j].tPmOffDuty) 
			{ 
				str=_T(" "); 
				m_ListAttend.SetItemText(j,4,str); 
				m_ListAttend.SetItemText(j,5,str); 
			} 
			else 
			{ 
				str=sAttend[j].tPmOnDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,4,str); 
 
				str=sAttend[j].tPmOffDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,5,str); 
			} 
 
			if(sAttend[j].tNinOnDuty==sAttend[j].tNinOffDuty) 
			{ 
				str=_T(" "); 
				m_ListAttend.SetItemText(j,6,str); 
				m_ListAttend.SetItemText(j,7,str); 
			} 
			else 
			{ 
				str=sAttend[j].tNinOnDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,6,str); 
 
				str=sAttend[j].tNinOffDuty.Format("%H:%M"); 
				m_ListAttend.SetItemText(j,7,str); 
			} 
 
			str=sAttend[j].tWork.Format("%H:%M"); 
			m_ListAttend.SetItemText(j,8,str); 
		} 
	} 
} 
 
void CAttendanceDlg::Serialize(CArchive &ar) 
{ 
	if (ar.IsStoring() && m_sFileExt=="atd") 
	{ 
		ar<>m_iTop; 
		ar>>m_iBottom; 
		ar>>m_iLeft; 
		ar>>m_iRight; 
		ar>>m_iMonths; 
		for(int i=0;i<=m_iMonths;i++) 
		{ 
			ar>>sYearTotal[i].iPay; 
			ar>>sYearTotal[i].iFactPay; 
			ar>>sYearTotal[i].iHoliday; 
			for(int iIndex = 0; iIndex < sYearTotal[i].iHoliday; ++iIndex) 
				ar>>sYearTotal[i].ArrayHoliday[iIndex]; 
			ar>>sYearTotal[i].iDayItems; 
			for(int j=0;j<=sYearTotal[i].iDayItems;j++) 
			{ 
				ar>>sYearTotal[i].sAttend[j].tAmOnDuty; 
				ar>>sYearTotal[i].sAttend[j].tAmOffDuty; 
				ar>>sYearTotal[i].sAttend[j].tPmOnDuty; 
				ar>>sYearTotal[i].sAttend[j].tPmOffDuty; 
				ar>>sYearTotal[i].sAttend[j].tNinOnDuty;//=sYearTotal[i].sAttend[j].tPmOffDuty; 
				ar>>sYearTotal[i].sAttend[j].tNinOffDuty;//=sYearTotal[i].sAttend[j].tPmOffDuty; 
			} 
		} 
	} 
 
} 
 
void CAttendanceDlg::OnColumnclickDuty(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here 
	if(sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetYear()!=m_Time.GetYear()) 
	{ 
		*pResult = 0; 
		return; 
	} 
	int iSubItem=pNMListView->iSubItem; 
 
 	UINT ui=pNMHDR->code; 
 
	bool b=sYearTotal[0].sAttend[0].tAmOnDuty.GetYear()==m_Time.GetYear(); 
 
	switch(iSubItem) 
	{ 
	case 0: 
		sDuty.tAmOnDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty=sDuty.tAmOnDuty; 
	case 1: 
		sDuty.tAmOffDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOffDuty=sDuty.tAmOffDuty; 
	case 2: 
		sDuty.tPmOnDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tPmOnDuty=sDuty.tPmOnDuty; 
	case 3: 
		sDuty.tPmOffDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tPmOffDuty=sDuty.tPmOffDuty; 
	case 4: 
		sDuty.tNinOnDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tNinOnDuty=sDuty.tNinOnDuty; 
	case 5: 
		sDuty.tNinOffDuty=CTime::GetCurrentTime(); 
		if(b) sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tNinOffDuty=sDuty.tNinOffDuty; 
 
		GetDutyData(); 
 
/*		if(sAttend[m_iCurItem].tAmOnDuty.GetMonth()==m_Time.GetMonth()) 
		{ 
			sAttend[m_iCurItem]=sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems]; 
			m_ListAttend.DeleteItem(m_iCurItem); 
			lvitem.iItem=m_iCurItem; 
			m_ListAttend.InsertItem(&lvitem); 
 
			str.Format("%d",sAttend[m_iCurItem].tAmOnDuty.GetDay());//j+1 
			m_ListAttend.SetItemText(m_iCurItem,0,str); 
 
			sAttend[m_iCurItem].tWork = sAttend[m_iCurItem].tAmOffDuty-sAttend[m_iCurItem].tAmOnDuty; 
			sAttend[m_iCurItem].tWork += sAttend[m_iCurItem].tPmOffDuty-sAttend[m_iCurItem].tPmOnDuty; 
 
			n=sAttend[m_iCurItem].tAmOnDuty.GetDayOfWeek(); 
			str=WeekTable[n-1]; 
			m_ListAttend.SetItemText(m_iCurItem,1,str); 
 
			str=sAttend[m_iCurItem].tAmOnDuty.Format("%H:%M"); 
			m_ListAttend.SetItemText(m_iCurItem,2,str); 
 
			str=sAttend[m_iCurItem].tAmOffDuty.Format("%H:%M"); 
			m_ListAttend.SetItemText(m_iCurItem,3,str); 
 
			str=sAttend[m_iCurItem].tPmOnDuty.Format("%H:%M"); 
			m_ListAttend.SetItemText(m_iCurItem,4,str); 
 
			str=sAttend[m_iCurItem].tPmOffDuty.Format("%H:%M"); 
			m_ListAttend.SetItemText(m_iCurItem,5,str); 
 
			str=sAttend[m_iCurItem].tWork.Format("%H:%M"); 
			m_ListAttend.SetItemText(m_iCurItem,6,str); 
		} 
*/		if(b) GetYearData(); 
	default: 
		break; 
	} 
	 
	*pResult = 0; 
} 
 
void CAttendanceDlg::GetDutyData() 
{ 
	m_ListDuty.DeleteAllItems(); 
	CString str; 
 
	lvitem.iItem=0; 
	m_ListDuty.InsertItem(&lvitem); 
 
	sDuty.tWork = sDuty.tAmOffDuty-sDuty.tAmOnDuty; 
	sDuty.tWork += sDuty.tPmOffDuty-sDuty.tPmOnDuty; 
	sDuty.tWork += sDuty.tNinOffDuty-sDuty.tNinOnDuty; 
 
	str=sDuty.tAmOnDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,0,str); 
 
	str=sDuty.tAmOffDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,1,str); 
 
	str=sDuty.tPmOnDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,2,str); 
 
	str=sDuty.tPmOffDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,3,str); 
 
	str=sDuty.tNinOnDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,4,str); 
 
	str=sDuty.tNinOffDuty.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,5,str); 
 
	str=sDuty.tWork.Format("%H:%M"); 
	m_ListDuty.SetItemText(0,6,str); 
} 
 
void CAttendanceDlg::OnHoliday()  
{ 
	// TODO: Add your control notification handler code here 
	CDualListDialog dlg; 
	dlg.m_pParentDlg=this; 
	if(dlg.DoModal()==IDOK) 
	{ 
	m_dDayPay = (double)m_iPay/(double)m_iWorkDays; 
	m_iObtain=m_dFactWorks*m_dDayPay; 
	sYearTotal[m_iMonths].iHoliday = m_iHoliday; 
	for(int i=0;i62000) 
		return; 
	m_iPay = i; 
	m_dDayPay = (double)m_iPay/(double)m_iWorkDays; 
	m_iObtain=m_dFactWorks*m_dDayPay; 
	sYearTotal[m_iMonths].iPay = m_iPay; 
	GetYearData(); 
//	UpdateData(false); 
	 
} 
 
void CAttendanceDlg::OnDelete()  
{ 
	// TODO: Add your control notification handler code here 
	int iState;	 
	int nItemSelected=m_ListAttend.GetSelectedCount();//所选表项数	 
	int nItemCount=m_ListAttend.GetItemCount();//表项总数	 
	if(nItemSelected<1) 
		return; 
	int	n=0; 
	for(int i=0;i=0;i--) 
	{		 
		iState=m_ListAttend.GetItemState(i,LVIS_SELECTED); 
		if(iState!=0) 
		{ 
		//	m_cList.DeleteItem(i); 
			for(int j=i-n;j=0 && (sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetYear()==m_Time.GetYear()  
											&& sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetMonth()!=m_Time.GetMonth())) 
	{ 
		m_iMonths++; 
		sYearTotal[m_iMonths].iPay = m_iPay; 
		sYearTotal[m_iMonths].iDayItems = 0; 
		sYearTotal[m_iMonths].sAttend[0] = sDuty; 
 
		m_iHoliday=0; 
	int year = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetYear(); 
	int mth = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetMonth(); 
	int monthday=MonthDay[mth-1]; 
	if(mth==2 && fmod(year,4)==0) 
		monthday++; 
		int day = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDay(); 
		int wk = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDayOfWeek();//1..7 
		int	wks = day/7; 
		int surplus = fmod(day-1,7);//0..6 
 
		int wk1 = surplus>=wk ? wk+7-surplus : wk-surplus; 
		 
		for(int i=0;i7) wk-=7; 
			 
			if(wk==1 || wk==7) 
			{ 
				//m_ArrayHoliday.Add(i+1); 
				sYearTotal[m_iMonths].ArrayHoliday[m_iHoliday] = i+1;//m_ArrayHoliday[m_iHoliday]; 
				m_iHoliday++; 
			} 
		} 
		//m_iWorkDays=monthday-m_iHoliday; 
		sYearTotal[m_iMonths].iHoliday = m_iHoliday; 
	} 
 
	if(m_iMonths>=0 && (sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m")==m_Time.Format("%Y%m")  
											&& sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetDay()!=m_Time.GetDay())) 
	{ 
		sYearTotal[m_iMonths].iDayItems++; 
		sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems] = sDuty; 
	} 
	GetYearData(); 
} 
 
void CAttendanceDlg::GetYearData() 
{ 
	m_ListTotal.DeleteAllItems(); 
	CString str; 
	for(int i=0;i<=m_iMonths;i++) 
	{ 
	double fctwks = 0; 
	for(int j=0;j<=sYearTotal[i].iDayItems;j++) 
	{ 
		sYearTotal[i].sAttend[j].tWork = sYearTotal[i].sAttend[j].tAmOffDuty-sYearTotal[i].sAttend[j].tAmOnDuty; 
		sYearTotal[i].sAttend[j].tWork += sYearTotal[i].sAttend[j].tPmOffDuty-sYearTotal[i].sAttend[j].tPmOnDuty; 
		sYearTotal[i].sAttend[j].tWork += sYearTotal[i].sAttend[j].tNinOffDuty-sYearTotal[i].sAttend[j].tNinOnDuty; 
		fctwks += (double)sYearTotal[i].sAttend[j].tWork.GetHours()+(double)sYearTotal[i].sAttend[j].tWork.GetMinutes()/60.0; 
	} 
	int year = sYearTotal[i].sAttend[0].tAmOnDuty.GetYear(); 
	int mth = sYearTotal[i].sAttend[0].tAmOnDuty.GetMonth(); 
	int monthday=MonthDay[mth-1]; 
	if(mth==2 && fmod(year,4)==0) 
		monthday++; 
	int wkd = monthday-sYearTotal[i].iHoliday; 
	lvitem.iItem=i; 
	m_ListTotal.InsertItem(&lvitem); 
	str.Format("%d",mth); 
	m_ListTotal.SetItemText(i,0,str); 
 
	str.Format("%d",wkd); 
	m_ListTotal.SetItemText(i,1,str); 
 
	str.Format("%d",sYearTotal[i].iPay); 
	m_ListTotal.SetItemText(i,2,str); 
 
	double DayPay = (double)sYearTotal[i].iPay/(double)wkd; 
	DayPay = int(DayPay*100.0+0.5)/100.0; 
	str.Format("%6.2f",DayPay); 
	m_ListTotal.SetItemText(i,3,str); 
 
//	double fctwks = 0; 
//	for(int j=0;j<=sYearTotal[i].iDayItems;j++) 
//	{ 
//		sYearTotal[i].sAttend[j].tWork = sYearTotal[i].sAttend[j].tAmOffDuty-sYearTotal[i].sAttend[j].tAmOnDuty; 
//		sYearTotal[i].sAttend[j].tWork += sYearTotal[i].sAttend[j].tPmOffDuty-sYearTotal[i].sAttend[j].tPmOnDuty; 
//		fctwks += (double)sYearTotal[i].sAttend[j].tWork.GetHours()+(double)sYearTotal[i].sAttend[j].tWork.GetMinutes()/60.0; 
//	} 
	fctwks /=8.0; 
	fctwks = floor(fctwks*10.0)/10.0; 
	str.Format("%.1f",fctwks); 
	m_ListTotal.SetItemText(i,4,str); 
	int iObtain=(double)sYearTotal[i].iPay*fctwks/(double)wkd; 
	str.Format("%d",iObtain); 
	m_ListTotal.SetItemText(i,5,str); 
 
	str.Format("%d",sYearTotal[i].iFactPay); 
	m_ListTotal.SetItemText(i,6,str); 
 
	} 
 
} 
 
void CAttendanceDlg::OnItemchangedTotal(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here 
	int iItem=pNMListView->iItem;//! 
	int n; 
	 
	if(m_bFirst==true && iItem!=m_iMonths) 
	{ 
		*pResult = 0; 
		return; 
	} 
	m_iTotalSel = iItem; 
	CString s; 
	s.Format("%d年%2d月份月报 ", sYearTotal[iItem].sAttend[0].tAmOnDuty.GetYear(),sYearTotal[iItem].sAttend[0].tAmOnDuty.GetMonth(),sYearTotal[iItem].sAttend[0].tAmOnDuty.GetDay()); 
	char* ch = s.GetBuffer(s.GetLength()); 
	m_cMonth.SetWindowText(ch); 
	s.Format("%d年度 年报 ", sYearTotal[iItem].sAttend[0].tAmOnDuty.GetYear()); 
	ch = s.GetBuffer(s.GetLength()); 
	m_cYear.SetWindowText(ch); 
 
 		m_iPay = sYearTotal[iItem].iPay; 
 		m_iFactPay = sYearTotal[iItem].iFactPay; 
		m_iHoliday = sYearTotal[iItem].iHoliday; 
		m_ArrayHoliday.SetSize(m_iHoliday); 
        for(int iIndex = 0; iIndex < m_iHoliday; ++iIndex) 
			m_ArrayHoliday[iIndex] = sYearTotal[iItem].ArrayHoliday[iIndex]; 
		m_iCurItem = sYearTotal[iItem].iDayItems; 
		for(int i=0;i<=m_iCurItem;i++) 
			sAttend[i] = sYearTotal[iItem].sAttend[i]; 
	int year = sAttend[0].tAmOnDuty.GetYear(); 
	int mth = sAttend[0].tAmOnDuty.GetMonth(); 
	int monthday=MonthDay[mth-1]; 
	if(mth==2 && fmod(year,4)==0) 
		monthday++; 
	m_iWorkDays = monthday-m_iHoliday; 
	m_dDayPay = int(((double)m_iPay/(double)m_iWorkDays)*100.0+0.5)/100.0; 
	m_dFactWorks = 0; 
	for(i=0;i<=m_iCurItem;i++) 
		m_dFactWorks += (double)sAttend[i].tWork.GetHours()+(double)sAttend[i].tWork.GetMinutes()/60.0; 
	m_dFactWorks /= 8.0; 
	m_dFactWorks = floor(m_dFactWorks*100.0)/100.0; 
	m_iObtain=(double)m_iPay*double(floor(m_dFactWorks*10.0)/10.0)/(double)m_iWorkDays; 
	GetTableData(); 
	UpdateData(false); 
 
	if(sYearTotal[iItem].sAttend[0].tAmOnDuty.Format("%Y%m")!=m_Time.Format("%Y%m")) 
	{ 
		m_EdtPay.SetReadOnly(true); 
		m_EdtFactPay.SetReadOnly(true); 
	} 
	else 
	{ 
		m_EdtPay.SetReadOnly(false); 
		m_EdtFactPay.SetReadOnly(false); 
	} 
 
/*	lvitem.iItem=iItem; 
	lvitem.stateMask |= LVIS_SELECTED; 
	for(i=0;i<=m_iMonths;i++) 
	{ 
		int iState; 
		if(iItem==i) 
	iState=m_ListTotal.SetItemState(i,2,LVIS_SELECTED);//&lvitem 
		else 
	iState=m_ListTotal.SetItemState(i,0,LVIS_SELECTED);//&lvitem 
	} 
*/	*pResult = 0; 
} 
 
BOOL CAttendanceDlg::NotifyFunction( UINT id, NMHDR * pTTTStruct, LRESULT * pResult ) 
{ 
	pResult = NULL ;	// Not Used  
	id = 0 ;	// Not used  
 
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;     
	UINT nID = pTTTStruct->idFrom; 
	switch ( nID) 
	{ 
		case ID_FILE_OPEN: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_FILE_OPEN)); 
			break ; 
		case ID_FILE_SAVEAS: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_FILE_SAVEAS)); 
			break ; 
		case ID_PGSETUP: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_PGSETUP)); 
			break ; 
		case ID_PRINT: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_PRINT)); 
			break ; 
		case ID_PRINT_PREVIEW: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_PRINT_PREVIEW)); 
			break ; 
		case ID_ABOUT: 
			pTTT->lpszText = MAKEINTRESOURCE((LPCSTR)(IDS_ABOUT)); 
			break ; 
	} 
	return(TRUE); 
} 
 
void CAttendanceDlg::SetToolBarPosition(int pos) 
{ 
	m_toolbarCtrl = NULL ; 
	VERIFY(m_toolbarCtrl == NULL ); 
	m_toolbarCtrl = new CToolBarCtrl() ; 
 
	CRect wndRect ; 
	GetWindowRect(&wndRect);//wndRect.right-100 
	CRect rc(0,0,18*9 , 18);//50 
//	if ( pos == 0 )//WS_DLGFRAME | CBRS_GRIPPER | 
		m_toolbarCtrl->Create(TBSTYLE_TOOLTIPS | TBSTYLE_DROPDOWN |WS_CHILD | WS_VISIBLE | CBRS_GRIPPER | CBRS_FLYBY | CCS_TOP | CCS_NODIVIDER, rc ,this , 0 ); 
//	else 
//		m_toolbarCtrl->Create(TBSTYLE_TOOLTIPS |WS_CHILD | WS_VISIBLE | CBRS_GRIPPER | CCS_BOTTOM  | CCS_NODIVIDER , rc ,this , 0 ); 
 
	m_toolbarCtrl->AddButtons(6, btn); 
	m_toolbarCtrl->AddBitmap(1, IDR_TOOLBAR);//IDR_MAINFRAME 
 
	CSize sz_btn(18,17); 
	m_toolbarCtrl->SetButtonSize(sz_btn); 
	 
	CSize sz_img(19,18); 
	m_toolbarCtrl->SetBitmapSize(sz_img); 
 
	m_toolbarCtrl->AutoSize(); 
} 
 
void CAttendanceDlg::OnFileOpen()  
{ 
	// TODO: Add your command handler code here 
 
	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
    //CMainFrame* pMFrame=(CMainFrame*)AfxGetMainWnd(); 
	CFileDialog dlg(true,"atd",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"考勤数据文件(*.atd)|*.atd|所有文件(*.*)|*.*||",NULL);//pMFrame 
	 
	CString s=m_sOpenPath; 
	dlg.m_ofn.lpstrInitialDir=s.GetBuffer(512); 
	CString t=m_sAttendFile; 
//	CString t="Choose Dir.bmp"; 
	dlg.m_ofn.lpstrFile=t.GetBuffer(512);//lpstrFile; 
	if(dlg.DoModal()==IDCANCEL) 
		return; 
	m_sFileExt=dlg.GetFileExt(); 
	char* h=m_sFileExt.GetBuffer(m_sFileExt.GetLength()); 
	strlwr(h); 
	if(strcmp(h,"atd")!=0 ) 
		return; 
	m_sFileExt=dlg.GetFileExt(); 
	m_sAttendFile=dlg.GetFileName(); 
	m_sOpenPath=dlg.GetPathName(); 
	CString str; 
	CFile file;//FileNamem_sFileName 
	if(file.Open(m_sOpenPath,CFile::modeRead)==0) 
	{ 
		str="打开数据文件:\n"+m_sOpenPath+"\n失败!"; 
		AfxMessageBox(str); 
		return; 
	} 
	m_sFileExt=dlg.GetFileExt(); 
	//char* h=m_sFileExt.GetBuffer(m_sFileExt.GetLength()); 
	//strlwr(h); 
	CArchive ar(&file,CArchive::load); 
 
	CWaitCursor wait; 
	Serialize(ar);     // save me 
	ar.Close(); 
	file.Close(); 
	//SetModifiedFlag(FALSE);     // back to unmodified 
	 
	if(m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m%d")==m_Time.Format("%Y%m%d")) 
	{ 
		m_iCurItem = sYearTotal[m_iMonths].iDayItems; 
/*		sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOnDuty = sDuty.tAmOnDuty; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tAmOffDuty = sDuty.tAmOffDuty; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOnDuty = sDuty.tPmOnDuty; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem].tPmOffDuty = sDuty.tPmOffDuty; 
		sDuty.tWork=(sDuty.tAmOffDuty-sDuty.tAmOnDuty)+(sDuty.tPmOffDuty-sDuty.tPmOnDuty); 
*/ 
		sYearTotal[m_iMonths].sAttend[m_iCurItem] = sDuty; 
 
	} 
 
	if(m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.Format("%Y%m")==m_Time.Format("%Y%m") 
		&& sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetDay()!=m_Time.GetDay()) 
	{ 
		sYearTotal[m_iMonths].iDayItems++; 
		m_iCurItem = sYearTotal[m_iMonths].iDayItems; 
		sYearTotal[m_iMonths].sAttend[m_iCurItem]=sDuty; 
 
	} 
 
	if(m_iMonths>=0 && sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetYear()==m_Time.GetYear() 
		&& sYearTotal[m_iMonths].sAttend[sYearTotal[m_iMonths].iDayItems].tAmOnDuty.GetMonth()!=m_Time.GetMonth()) 
	{ 
		m_iMonths++; 
		sYearTotal[m_iMonths].iPay = m_iMonths-1==-1 ? m_iPay : sYearTotal[m_iMonths-1].iPay; 
		sYearTotal[m_iMonths].iDayItems = 0; 
		sYearTotal[m_iMonths].sAttend[0] = sDuty; 
		m_iHoliday=0; 
		int year = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetYear(); 
		int mth = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetMonth(); 
		int monthday=MonthDay[mth-1]; 
		if(mth==2 && fmod(year,4)==0) 
			monthday++; 
		int day = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDay(); 
		int wk = sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.GetDayOfWeek();//1..7 
		int	wks = day/7; 
		int surplus = fmod(day-1,7);//0..6 
 
		int wk1 = surplus>=wk ? wk+7-surplus : wk-surplus; 
		 
		for(int i=0;i7) wk-=7; 
			 
			if(wk==1 || wk==7) 
			{ 
				//m_ArrayHoliday.Add(i+1); 
				sYearTotal[m_iMonths].ArrayHoliday[m_iHoliday] = i+1;//m_ArrayHoliday[m_iHoliday]; 
				m_iHoliday++; 
			} 
		} 
		//m_iWorkDays=monthday-m_iHoliday; 
		sYearTotal[m_iMonths].iHoliday = m_iHoliday; 
	} 
 
	GetDutyData(); 
 
	m_bFirst=true; 
	GetYearData(); 
	m_bFirst=false; 
 
} 
 
void CAttendanceDlg::OnFileSaveas()  
{ 
	// TODO: Add your command handler code here 
	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
    //CMainFrame* pMFrame=(CMainFrame*)AfxGetMainWnd(); 
	CFileDialog dlg(false,"atd",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"考勤数据文件(*.atd)|*.atd|所有文件(*.*)|*.*||",NULL);//pMFrame 
	CString s=m_sSavePath; 
	dlg.m_ofn.lpstrInitialDir=s.GetBuffer(512); 
	CString t=m_sAttendFile; 
	dlg.m_ofn.lpstrFile=t.GetBuffer(512);//lpstrFile; 
	if(dlg.DoModal()==IDCANCEL) 
		return; 
	CString filename=dlg.GetFileName(); 
	s=dlg.GetPathName(); 
	int index = s.ReverseFind('\\');			 
	 //返回索引值左边的所有字符 
	m_sSavePath = s.Left(index); 
	CString str; 
	CFile file; 
	if(file.Open(filename,CFile::modeWrite|CFile::modeCreate)==0) 
	{ 
		str="保存数据文件"+filename+"失败\n请改变保存目录后再试试"; 
		AfxMessageBox(str); 
		return; 
	} 
	m_sFileExt=dlg.GetFileExt(); 
	char* h=m_sFileExt.GetBuffer(m_sFileExt.GetLength()); 
	strlwr(h); 
	CArchive ar(&file,CArchive::store); 
 
				CWaitCursor wait; 
				Serialize(ar);     // save me 
				ar.Close(); 
				file.Close(); 
			//SetModifiedFlag(false);     // back to unmodified 
	 
} 
 
void CAttendanceDlg::OnPrint()  
{ 
	// TODO: Add your command handler code here 
	CPrintSelect dlg; 
	dlg.m_iPrtSel = m_iPrtSel; 
	if(dlg.DoModal() != IDOK) 
		return; 
	m_iPrtSel = dlg.m_iPrtSel; 
 
	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
	app->SetPrntOrientation(); 
	m_pChildFrame->SendMessage(WM_COMMAND, ID_FILE_PRINT); 
	 
} 
 
void CAttendanceDlg::OnPrintPreview()  
{ 
	// TODO: Add your command handler code here 
	CPrintSelect dlg; 
	dlg.m_iPrtSel = m_iPrtSel; 
	if(dlg.DoModal() != IDOK) 
		return; 
	m_iPrtSel = dlg.m_iPrtSel; 
 
	CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); 
	app->SetPrntOrientation(); 
	m_pChildFrame->ShowWindow(SW_SHOW);//HIDE 
	m_pChildFrame->UpdateWindow(); 
	m_pChildFrame->SendMessage(WM_COMMAND, ID_FILE_PRINT_PREVIEW); 
	 
} 
 
 
int CAttendanceDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CDialog::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	// TODO: Add your specialized creation code here 
	CChildFrame* pFrame = new CChildFrame; 
	m_pChildFrame = pFrame; 
 
	// create and load the frame with its resources 
 
	pFrame->LoadFrame(IDR_MAINFRAME, 
		WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,//,m_pMainWnd 
		NULL); 
 
	m_pChildFrame->SetWindowText("打印考勤资料"); 
	m_pChildFrame->SetIcon(m_hIcon, FALSE);		// Set small icon 
	m_pChildFrame->ShowWindow(SW_HIDE);//SHOW 
	m_pChildFrame->UpdateWindow(); 
 
	 
	return 0; 
} 
 
void CAttendanceDlg::OnPgsetup()  
{ 
	// TODO: Add your command handler code here 
	CPageSetup dlg; 
	dlg.m_iTop = m_iTop; 
	dlg.m_iBottom = m_iBottom; 
	dlg.m_iLeft = m_iLeft; 
	dlg.m_iRight = m_iRight; 
//	dlg.m_bChkYear = m_bChkYear; 
	if(dlg.DoModal() != IDOK) 
		return; 
	m_iTop = dlg.m_iTop; 
	m_iBottom = dlg.m_iBottom; 
	m_iLeft = dlg.m_iLeft; 
	m_iRight = dlg.m_iRight; 
//	m_bChkYear = dlg.m_bChkYear; 
 
	 
} 
 
void CAttendanceDlg::OnUpdateFactpay()  
{ 
	// TODO: If this is a RICHEDIT control, the control will not 
	// send this notification unless you override the CDialog::OnInitDialog() 
	// function to send the EM_SETEVENTMASK message to the control 
	// with the ENM_UPDATE flag ORed into the lParam mask. 
	 
	// TODO: Add your control notification handler code here 
	if(sYearTotal[m_iMonths].sAttend[0].tAmOnDuty.Format("%Y%m")!=m_Time.Format("%Y%m")) 
		return; 
	char buf[10]; 
	int x=m_EdtFactPay.GetLine(0,buf,10); 
	buf[x]=0; 
	int i=atoi(buf); 
	if(i<0 || i>62000) 
		return; 
	m_iFactPay = i; 
	sYearTotal[m_iMonths].iFactPay = m_iFactPay; 
	GetYearData(); 
	 
} 
 
void CAttendanceDlg::OnAbout()  
{ 
	// TODO: Add your command handler code here 
	CAboutDlg dlg; 
	dlg.DoModal(); 
 
}