DlgLogin.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // DlgLogin.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "OGCAssistTool.h"
  5. #include "DlgLogin.h"
  6. #include "MD5.h"
  7. // CDlgLogin 对话框
  8. IMPLEMENT_DYNAMIC(CDlgLogin, CDialogEx)
  9. CDlgLogin::CDlgLogin(CWnd* pParent /*=NULL*/)
  10. : CDialogEx(CDlgLogin::IDD, pParent)
  11. {
  12. }
  13. CDlgLogin::~CDlgLogin()
  14. {
  15. }
  16. void CDlgLogin::DoDataExchange(CDataExchange* pDX)
  17. {
  18. CDialogEx::DoDataExchange(pDX);
  19. }
  20. BEGIN_MESSAGE_MAP(CDlgLogin, CDialogEx)
  21. ON_WM_CTLCOLOR()
  22. ON_BN_CLICKED(IDOK, &CDlgLogin::OnBnClickedOk)
  23. ON_BN_CLICKED(IDCANCEL, &CDlgLogin::OnBnClickedCancel)
  24. END_MESSAGE_MAP()
  25. // CDlgLogin 消息处理程序
  26. BOOL CDlgLogin::OnInitDialog()
  27. {
  28. CDialogEx::OnInitDialog();
  29. // TODO: 在此添加额外的初始化
  30. CFont font;
  31. VERIFY(font.CreateFont(
  32. 19, // nHeight
  33. 0, // nWidth
  34. 0, // nEscapement
  35. 0, // nOrientation
  36. FW_NORMAL, // nWeight
  37. FALSE, // bItalic
  38. FALSE, // bUnderline
  39. 0, // cStrikeOut
  40. ANSI_CHARSET, // nCharSet
  41. OUT_DEFAULT_PRECIS, // nOutPrecision
  42. CLIP_DEFAULT_PRECIS, // nClipPrecision
  43. DEFAULT_QUALITY, // nQuality
  44. DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
  45. _T("Arial")));
  46. SetFont(&font);
  47. //SetBackgroundColor(RGB(125,0,25));
  48. SetBackgroundImage(IDB_LOGO);
  49. if ( _tcslen(GLOBAL::g_config.szLine) )
  50. SetDlgItemText(EDIT_LINE, GLOBAL::g_config.szLine);
  51. if ( _tcslen(GLOBAL::g_config.szAccount) )
  52. SetDlgItemText(EDIT_ACCOUNT, GLOBAL::g_config.szAccount);
  53. return TRUE; // return TRUE unless you set the focus to a control
  54. // 异常: OCX 属性页应返回 FALSE
  55. }
  56. HBRUSH CDlgLogin::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  57. {
  58. HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
  59. // TODO: 在此更改 DC 的任何属性
  60. switch ( pWnd->GetDlgCtrlID() )
  61. {
  62. case CHECK_OFFLINE:
  63. {
  64. #if 1 // 透明控件处理;
  65. pDC->SetBkMode(TRANSPARENT);
  66. CRect rc;
  67. pWnd->GetWindowRect(&rc);
  68. ScreenToClient(&rc);
  69. CDC* dc = GetDC();
  70. pDC->BitBlt(0,0,rc.Width(),rc.Height(),dc,rc.left,rc.top,SRCCOPY); //把父窗口背景图片先画到按钮上
  71. ReleaseDC(dc);
  72. hbr = (HBRUSH) ::GetStockObject(NULL_BRUSH);
  73. #endif
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  80. return hbr;
  81. }
  82. void CDlgLogin::OnBnClickedOk()
  83. {
  84. // TODO: 在此添加控件通知处理程序代码
  85. CString strAccount, strPassword, strLine;
  86. GetDlgItemText(EDIT_LINE, strLine);
  87. GetDlgItemText(EDIT_ACCOUNT, strAccount);
  88. GetDlgItemText(EDIT_PASSWORD, strPassword);
  89. #ifdef _DEBUG
  90. GLOBAL::g_config.nOffline = ((CButton*)GetDlgItem(CHECK_OFFLINE))->GetCheck();
  91. _stprintf_s(GLOBAL::g_config.szLine, _T("%s"), strLine.GetString());
  92. return CDialogEx::OnOK();
  93. #endif
  94. if ( strAccount.IsEmpty() )
  95. {
  96. MessageBox(_T("请输入账号"), _T("提示"), MB_OK);
  97. return;
  98. }
  99. if ( strPassword.IsEmpty() )
  100. {
  101. MessageBox(_T("请输入密码"), _T("提示"), MB_OK);
  102. return;
  103. }
  104. if ( strLine.IsEmpty() )
  105. {
  106. MessageBox(_T("请输入线体"), _T("提示"), MB_OK);
  107. return;
  108. }
  109. GLOBAL::g_config.nOffline = ((CButton*)GetDlgItem(CHECK_OFFLINE))->GetCheck();
  110. _stprintf_s(GLOBAL::g_config.szLine, _T("%s"), strLine.GetString());
  111. #pragma region 账号密码验证
  112. // 获取账号密码;
  113. // 默认账号密码:OGCAssist、OGC+当前PC日期年月日;
  114. if ( _tcslen(GLOBAL::g_config.szAccount) == 0 )
  115. {
  116. if ( strAccount != _T("Assist") )
  117. {
  118. MessageBox(_T("账号错误"), _T("提示"), MB_OK);
  119. return;
  120. }
  121. CString strDynamicPassword;
  122. strDynamicPassword.Format(_T("OGC%s"), CTime::GetCurrentTime().Format(_T("%y%m%d")));
  123. if ( strPassword != strDynamicPassword )
  124. {
  125. MessageBox(_T("密码错误"), _T("提示"), MB_OK);
  126. return;
  127. }
  128. }
  129. else
  130. {
  131. CMD5 md5((BYTE*)strPassword.GetString(), strPassword.GetLength()*sizeof(TCHAR));
  132. if ( _tcscmp(GLOBAL::g_config.szAccount, strAccount.GetString()) != 0 )
  133. {
  134. MessageBox(_T("账号错误"), _T("提示"), MB_OK);
  135. return;
  136. }
  137. if ( _tcscmp(GLOBAL::g_config.szPassword, md5.GetMD5Digest()) != 0 )
  138. {
  139. MessageBox(_T("账号错误"), _T("提示"), MB_OK);
  140. return;
  141. }
  142. }
  143. #pragma endregion
  144. CDialogEx::OnOK();
  145. }
  146. void CDlgLogin::OnBnClickedCancel()
  147. {
  148. // TODO: 在此添加控件通知处理程序代码
  149. CDialogEx::OnCancel();
  150. }