EmailInfo.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // EmailInfo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "StoneU_HC_OCX.h"
  5. #include "EmailInfo.h"
  6. #include ".\emailinfo.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEmailInfo dialog
  14. BOOL EmailCh_is_Legal(BOOL front,TCHAR ch)
  15. {
  16. if(ch<='z'&&ch>='a' || ch<='Z'&&ch>='A' || ch<='9'&&ch>='0')
  17. return TRUE;
  18. if(front && (ch == '-' || ch =='_'))
  19. return TRUE;
  20. if(!front && ch =='.')
  21. return TRUE;
  22. return FALSE;
  23. }
  24. BOOL CheckEmailAddress(CString email)
  25. {
  26. int pos = email.Find('@');
  27. if(pos == -1 || pos == 0 || pos == (email.GetLength()-1))
  28. return FALSE;
  29. CString tmp = email.Left(pos);
  30. int i;
  31. for(i=0;i<pos;i++)
  32. if(!EmailCh_is_Legal(TRUE,tmp.GetAt(i)))
  33. return FALSE;
  34. tmp.Empty();
  35. tmp = email.Right(email.GetLength()-1-pos);
  36. pos = tmp.Find('.');
  37. if(pos == -1 || pos == 0 || pos == (tmp.GetLength()-1))
  38. return FALSE;
  39. for(i=0;i<tmp.GetLength();i++)
  40. if(!EmailCh_is_Legal(FALSE,tmp.GetAt(i)))
  41. return FALSE;
  42. return TRUE;
  43. }
  44. CEmailInfo::CEmailInfo(CWnd* pParent /*=NULL*/)
  45. : CDialog(CEmailInfo::IDD, pParent)
  46. {
  47. //{{AFX_DATA_INIT(CEmailInfo)
  48. m_EmailName = _T("");
  49. m_EmailAddress = _T("");
  50. //}}AFX_DATA_INIT
  51. }
  52. void CEmailInfo::DoDataExchange(CDataExchange* pDX)
  53. {
  54. CDialog::DoDataExchange(pDX);
  55. //{{AFX_DATA_MAP(CEmailInfo)
  56. DDX_Text(pDX, IDC_EMAILNAME, m_EmailName);
  57. DDX_Text(pDX, IDC_EMAILADDRESS, m_EmailAddress);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CEmailInfo, CDialog)
  61. //{{AFX_MSG_MAP(CEmailInfo)
  62. //}}AFX_MSG_MAP
  63. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CEmailInfo message handlers
  67. void CEmailInfo::OnOK()
  68. {
  69. // TODO: Add extra validation here
  70. UpdateData(TRUE);
  71. if(m_EmailName.IsEmpty())
  72. {
  73. MessageBox("姓名不能为空!", "温馨提示", MB_ICONINFORMATION);
  74. return;
  75. }
  76. if(!CheckEmailAddress(m_EmailAddress))
  77. {
  78. MessageBox("Email地址非法!请确认后重输...!", "温馨提示", MB_ICONINFORMATION);
  79. return;
  80. }
  81. CDialog::OnOK();
  82. }
  83. void CEmailInfo::OnCancel()
  84. {
  85. // TODO: Add extra cleanup here
  86. CDialog::OnCancel();
  87. }
  88. void CEmailInfo::OnBnClickedOk()
  89. {
  90. // TODO: 在此添加控件通知处理程序代码
  91. OnOK();
  92. }