DlgUser.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // AnalogPropertyDlg1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "DlgUser.h"
  6. #include "StringOperation.h"
  7. #include "UserDBProcess.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDlgUser dialog
  15. CDlgUser::CDlgUser(CWnd* pParent /*=NULL*/)
  16. : CDialog(CDlgUser::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CDlgUser)
  19. //}}AFX_DATA_INIT
  20. m_operation=EDIT;
  21. m_DDXFields.SetSize(9);
  22. }
  23. void CDlgUser::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CDlgUser)
  27. //}}AFX_DATA_MAP
  28. m_DDXFields.DDX(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CDlgUser, CDialog)
  31. //{{AFX_MSG_MAP(CDlgUser)
  32. //}}AFX_MSG_MAP
  33. ON_BN_CLICKED(IDC_BTN_CANCEL, OnBnClickedBtnCancel)
  34. ON_BN_CLICKED(IDC_BTN_SAVE, OnBnClickedBtnSave)
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CDlgUser message handlers
  38. BOOL CDlgUser::OnInitDialog()
  39. {
  40. CDialog::OnInitDialog();
  41. int i;
  42. m_DDXFields.m_pWnd=this;
  43. m_DDXFields.SetDBType( g_strDBType );
  44. i=0;
  45. m_DDXFields.ElementAt(i).Set(_T("id"), IDC_EDT_ID);
  46. m_DDXFields.ElementAt(i).m_description=_T("ID");
  47. m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM;
  48. i=1;
  49. m_DDXFields.ElementAt(i).Set(_T( "uid" ),IDC_EDT_USER_ID) ;
  50. m_DDXFields.ElementAt(i).m_description=g_strUserID;
  51. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  52. i=2;
  53. m_DDXFields.ElementAt(i).Set(_T( "username" ),IDC_EDT_USER_NAME);
  54. m_DDXFields.ElementAt(i).m_description=g_strUserName;
  55. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  56. i=3;
  57. m_DDXFields.ElementAt(i).Set(_T( "tel" ),IDC_EDT_TEL);
  58. m_DDXFields.ElementAt(i).m_description=g_strTel;
  59. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  60. i=4;
  61. m_DDXFields.ElementAt(i).Set(_T( "mobiletel" ),IDC_EDT_MOBIL) ;
  62. m_DDXFields.ElementAt(i).m_description=g_strMobile;
  63. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  64. i=5;
  65. m_DDXFields.ElementAt(i).Set(_T( "fax" ),IDC_EDT_FAX);
  66. m_DDXFields.ElementAt(i).m_description=g_strFax;
  67. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  68. i=6;
  69. m_DDXFields.ElementAt(i).Set(_T( "email" ),IDC_EDT_EMAIL);
  70. m_DDXFields.ElementAt(i).m_description=_T("Email");
  71. m_DDXFields.ElementAt(i).m_nDataType = DATA_STR;
  72. i=7;
  73. m_DDXFields.ElementAt(i).Set(_T( "status" ),IDC_EDT_USER_STATUS);
  74. m_DDXFields.ElementAt(i).m_description=g_strStatus;
  75. m_DDXFields.ElementAt(i).m_nDataType = DATA_BOOL;
  76. i=8;
  77. m_DDXFields.ElementAt(i).Set(_T( "pwd" ),IDC_EDT_USER_PWD);
  78. m_DDXFields.ElementAt(i).m_description=g_strPassword;
  79. m_DDXFields.ElementAt(i).m_nDataType = DATA_MD5;
  80. UpdateData(TRUE);
  81. switch (m_operation)
  82. {
  83. case NEW:
  84. break;
  85. default:
  86. m_DDXFields.ReadData(m_pSet);
  87. break;
  88. }
  89. UpdateData(FALSE);
  90. CString str;
  91. str.Format("%d", m_nID);
  92. GetDlgItem(IDC_EDT_ID)->SetWindowText(str);
  93. if( m_operation == EDIT )
  94. {
  95. GetDlgItem(IDC_EDT_USER_PWD)->EnableWindow(FALSE);
  96. GetDlgItem(IDC_EDT_USER_PWD_CONFIRM)->EnableWindow(FALSE);
  97. }
  98. GetDlgItem(IDC_EDT_USER_STATUS)->GetWindowText(str);
  99. ((CButton *)GetDlgItem(IDC_CHK_USER_STATUS))->SetCheck(!str.Compare("TRUE") || !str.Compare("1") ? TRUE : FALSE );
  100. m_btnSave.SubclassDlgItem(IDC_BTN_SAVE, this);
  101. m_btnSave.SetBitmaps(IDB_SAVE, RGB(255, 0, 255));
  102. m_btnSave.SetFlat(FALSE);
  103. m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  104. m_btnCancel.SubclassDlgItem(IDC_BTN_CANCEL, this);
  105. m_btnCancel.SetBitmaps(IDB_DEL, RGB(255, 0, 255));
  106. m_btnCancel.SetFlat(FALSE);
  107. m_btnCancel.SetAlign(CButtonST::ST_ALIGN_HORIZ);
  108. return TRUE; // return TRUE unless you set the focus to a control
  109. // EXCEPTION: OCX Property Pages should return FALSE
  110. }
  111. void CDlgUser::OnBnClickedBtnCancel()
  112. {
  113. // TODO: 在此添加控件通知处理程序代码
  114. OnCancel();
  115. }
  116. int CDlgUser::CheckDataValid()
  117. {
  118. CString strID, strUserID, strUserName, strPwd, strConfirmPwd;
  119. CString strTel, strMobileTel, strEmail, strFax;
  120. strID = m_DDXFields.ElementAt(0).m_value;
  121. strUserID = m_DDXFields.ElementAt(1).m_value;
  122. strPwd = m_DDXFields.ElementAt(8).m_value;
  123. GetDlgItem(IDC_EDT_USER_PWD_CONFIRM)->GetWindowText(strConfirmPwd);
  124. m_sUserID = strUserID;
  125. if( strUserID.IsEmpty() )
  126. {
  127. MessageBox(g_strUserNameCannotEmpty, g_strTip, MB_ICONINFORMATION);
  128. GetDlgItem(IDC_EDT_USER_ID)->SetFocus();
  129. return 1;
  130. }
  131. else if(strPwd.Compare(strConfirmPwd))
  132. {
  133. if( m_operation == NEW || m_operation == COPY )
  134. {
  135. MessageBox(g_strPasswordNotMatch2, g_strTip, MB_ICONINFORMATION);
  136. GetDlgItem(IDC_EDT_USER_PWD)->SetFocus();
  137. return 1;
  138. }
  139. else if( m_operation==EDIT )
  140. return 2;
  141. }
  142. CHAR szID[MAX_ID] = {0};
  143. if( m_operation == NEW || m_operation == COPY )
  144. {
  145. int nRet = CDBInterface::GetInstancePtr()->GetUserID( szID, (char *)(LPCTSTR)strUserID );
  146. if( nRet > 0 )
  147. {
  148. MessageBox(g_strUserNameExit, g_strTip, MB_ICONINFORMATION);
  149. return 1;
  150. }
  151. }
  152. return 0;
  153. }
  154. void CDlgUser::OnBnClickedBtnSave()
  155. {
  156. // TODO: 在此添加控件通知处理程序代码
  157. // 存盘操作
  158. CExString strField;
  159. CHAR szMaxID[MAX_ID + 1] = {0};
  160. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  161. if( ((CButton *)GetDlgItem(IDC_CHK_USER_STATUS))->GetCheck() )
  162. {
  163. GetDlgItem(IDC_EDT_USER_STATUS)->SetWindowText("1");
  164. }
  165. else
  166. {
  167. GetDlgItem(IDC_EDT_USER_STATUS)->SetWindowText("0");
  168. }
  169. CDBInterface::GetInstancePtr()->GetMaxID("t_user_info", "id", szMaxID);
  170. int nID;
  171. CString strID;
  172. try
  173. {
  174. switch (m_operation)
  175. {
  176. case EDIT:
  177. //nID = atoi(szMaxID);
  178. break;
  179. default:
  180. if( atoi(szMaxID) > 0 )
  181. {
  182. nID = atoi(szMaxID) + 1;
  183. }
  184. else if( atoi(szMaxID) == 0 )
  185. {
  186. nID = 1;
  187. }
  188. strID.Format("%d", nID);
  189. GetDlgItem(IDC_EDT_ID)->SetWindowText(strID);
  190. //m_pSet->AddNew();
  191. break;
  192. }
  193. UpdateData(TRUE);
  194. try
  195. {
  196. // 校验数据的正确性
  197. int nRet = CheckDataValid();
  198. if( nRet == 1 )
  199. {
  200. return;
  201. //CDialog::OnOK();
  202. }
  203. //else if( nRet == 0 )
  204. {
  205. sprintf(strSQLText, "insert into t_user_info(id, uid, username, tel, mobiletel, fax, email, status, pwd) values(");
  206. if( m_DDXFields.WriteData("t_user_info", strSQLText, m_operation) == -1 ) return;
  207. }
  208. }
  209. catch(...)
  210. {
  211. ;
  212. }
  213. UpdateData(FALSE);
  214. CDialog::OnOK();
  215. }//try
  216. catch( _com_error &e )
  217. {
  218. CString mes1,mes2,mes3,mes4;
  219. mes1.Format(_T("Error:%08lx.\n"), e.Error());
  220. mes2.Format(_T("ErrorMessage:%s.\n"), e.ErrorMessage());
  221. mes3.Format(_T("Source:%s.\n"), (LPCTSTR) _bstr_t(e.Source()));
  222. mes4.Format(_T("Description:%s.\n"), (LPCTSTR) _bstr_t(e.Description()));
  223. MessageBox(mes1+mes2+mes3+mes4,_T("Invalid field "),MB_ICONERROR);
  224. return;
  225. }
  226. catch(...)
  227. {
  228. MessageBox(_T("Unhandled Exception"),_T("Invalid field ")+strField,MB_ICONERROR);
  229. return;
  230. }
  231. }