Attendance.cpp
Upload User: bjvcxy
Upload Date: 2021-05-06
Package Size: 2054k
Code Size: 3k
Development Platform:

Visual C++

  1. // Attendance.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "Attendance.h"
  5. #include "AttendanceDlg.h"
  6. #include "LoginDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAttendanceApp
  14. BEGIN_MESSAGE_MAP(CAttendanceApp, CWinApp)
  15. //{{AFX_MSG_MAP(CAttendanceApp)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. //    DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG
  19. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CAttendanceApp construction
  23. CAttendanceApp::CAttendanceApp()
  24. {
  25. // TODO: add construction code here,
  26. // Place all significant initialization in InitInstance
  27. }
  28. /////////////////////////////////////////////////////////////////////////////
  29. // The one and only CAttendanceApp object
  30. CAttendanceApp theApp;
  31. CDatabase db;
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CAttendanceApp initialization
  34. BOOL CAttendanceApp::InitInstance()
  35. {
  36. AfxEnableControlContainer();
  37. // Standard initialization
  38. // If you are not using these features and wish to reduce the size
  39. //  of your final executable, you should remove from the following
  40. //  the specific initialization routines you do not need.
  41. #ifdef _AFXDLL
  42. Enable3dControls(); // Call this when using MFC in a shared DLL
  43. #else
  44. Enable3dControlsStatic(); // Call this when linking to MFC statically
  45. #endif
  46. // 显示登录对话框
  47. CLoginDlg LoginDlg;
  48. if(LoginDlg.DoModal()!=IDOK) return FALSE;
  49. // 显示主对话框
  50. CAttendanceDlg dlg;
  51. m_pMainWnd = &dlg;
  52. int nResponse = dlg.DoModal();
  53. if (nResponse == IDOK)
  54. {
  55. // TODO: Place code here to handle when the dialog is
  56. //  dismissed with OK
  57. }
  58. else if (nResponse == IDCANCEL)
  59. {
  60. // TODO: Place code here to handle when the dialog is
  61. //  dismissed with Cancel
  62. }
  63. // Since the dialog has been closed, return FALSE so that we exit the
  64. //  application, rather than start the application's message pump.
  65. return FALSE;
  66. }
  67. int CAttendanceApp::ExitInstance() 
  68. {
  69. if(db.IsOpen()) db.Close();// 关闭数据库
  70. return CWinApp::ExitInstance();
  71. }
  72. // 全局函数,将时间串转换为CTime型变量
  73. CTime StrToTime(CString str)
  74. {// 时间串格式 "%Y-%m-%d %H:%M:%S",如"1999-01-01 11:11:11"
  75. int nYear,nMonth,nDay,nHour,nMinute,nSecond;
  76. sscanf(str.Left(4), "%d", &nYear); // 得到年
  77. sscanf(str.Mid(5,2), "%d", &nMonth); // 得到月
  78. sscanf(str.Mid(8,2), "%d", &nDay); // 得到日
  79. sscanf(str.Mid(11,2), "%d", &nHour); // 得到时
  80. sscanf(str.Mid(14,2), "%d", &nMinute); // 得到分
  81. sscanf(str.Mid(17,2), "%d", &nSecond); // 得到分
  82. // 构造CTime变量
  83. CTime result(nYear,nMonth,nDay,nHour,nMinute,nSecond);
  84. return result;
  85. }