// AnalogPropertyDlg1.cpp : implementation file // #include "stdafx.h" #include "IDE.h" #include "DlgUser.h" #include "StringOperation.h" #include "UserDBProcess.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDlgUser dialog CDlgUser::CDlgUser(CWnd* pParent /*=NULL*/) : CDialog(CDlgUser::IDD, pParent) { //{{AFX_DATA_INIT(CDlgUser) //}}AFX_DATA_INIT m_operation=EDIT; m_DDXFields.SetSize(9); } void CDlgUser::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgUser) //}}AFX_DATA_MAP m_DDXFields.DDX(pDX); } BEGIN_MESSAGE_MAP(CDlgUser, CDialog) //{{AFX_MSG_MAP(CDlgUser) //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BTN_CANCEL, OnBnClickedBtnCancel) ON_BN_CLICKED(IDC_BTN_SAVE, OnBnClickedBtnSave) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDlgUser message handlers BOOL CDlgUser::OnInitDialog() { CDialog::OnInitDialog(); int i; m_DDXFields.m_pWnd=this; m_DDXFields.SetDBType( g_strDBType ); i=0; m_DDXFields.ElementAt(i).Set(_T("id"), IDC_EDT_ID); m_DDXFields.ElementAt(i).m_description=_T("ID"); m_DDXFields.ElementAt(i).m_nDataType = DATA_NUM; i=1; m_DDXFields.ElementAt(i).Set(_T( "uid" ),IDC_EDT_USER_ID) ; m_DDXFields.ElementAt(i).m_description=g_strUserID; m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=2; m_DDXFields.ElementAt(i).Set(_T( "username" ),IDC_EDT_USER_NAME); m_DDXFields.ElementAt(i).m_description=g_strUserName; m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=3; m_DDXFields.ElementAt(i).Set(_T( "tel" ),IDC_EDT_TEL); m_DDXFields.ElementAt(i).m_description=g_strTel; m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=4; m_DDXFields.ElementAt(i).Set(_T( "mobiletel" ),IDC_EDT_MOBIL) ; m_DDXFields.ElementAt(i).m_description=g_strMobile; m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=5; m_DDXFields.ElementAt(i).Set(_T( "fax" ),IDC_EDT_FAX); m_DDXFields.ElementAt(i).m_description=g_strFax; m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=6; m_DDXFields.ElementAt(i).Set(_T( "email" ),IDC_EDT_EMAIL); m_DDXFields.ElementAt(i).m_description=_T("Email"); m_DDXFields.ElementAt(i).m_nDataType = DATA_STR; i=7; m_DDXFields.ElementAt(i).Set(_T( "status" ),IDC_EDT_USER_STATUS); m_DDXFields.ElementAt(i).m_description=g_strStatus; m_DDXFields.ElementAt(i).m_nDataType = DATA_BOOL; i=8; m_DDXFields.ElementAt(i).Set(_T( "pwd" ),IDC_EDT_USER_PWD); m_DDXFields.ElementAt(i).m_description=g_strPassword; m_DDXFields.ElementAt(i).m_nDataType = DATA_MD5; UpdateData(TRUE); switch (m_operation) { case NEW: break; default: m_DDXFields.ReadData(m_pSet); break; } UpdateData(FALSE); CString str; str.Format("%d", m_nID); GetDlgItem(IDC_EDT_ID)->SetWindowText(str); if( m_operation == EDIT ) { GetDlgItem(IDC_EDT_USER_PWD)->EnableWindow(FALSE); GetDlgItem(IDC_EDT_USER_PWD_CONFIRM)->EnableWindow(FALSE); //CString str; //GetDlgItem(IDC_EDT_USER_PWD)->GetWindowText( str ); //GetDlgItem(IDC_EDT_USER_PWD_CONFIRM)->SetWindowText( str ); } GetDlgItem(IDC_EDT_USER_STATUS)->GetWindowText(str); ((CButton *)GetDlgItem(IDC_CHK_USER_STATUS))->SetCheck(!str.Compare("TRUE") || !str.Compare("1") ? TRUE : FALSE ); m_btnSave.SubclassDlgItem(IDC_BTN_SAVE, this); m_btnSave.SetBitmaps(IDB_SAVE, RGB(255, 0, 255)); m_btnSave.SetFlat(FALSE); m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ); m_btnCancel.SubclassDlgItem(IDC_BTN_CANCEL, this); m_btnCancel.SetBitmaps(IDB_DEL, RGB(255, 0, 255)); m_btnCancel.SetFlat(FALSE); m_btnCancel.SetAlign(CButtonST::ST_ALIGN_HORIZ); UpdateData( false ); GetDlgItem(IDC_EDT_USER_ID)->GetWindowText( m_sUserID_Old ); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CDlgUser::OnBnClickedBtnCancel() { // TODO: 在此添加控件通知处理程序代码 OnCancel(); } int CDlgUser::CheckDataValid() { CString strID, strUserID, strUserName, strPwd, strConfirmPwd; CString strTel, strMobileTel, strEmail, strFax; strID = m_DDXFields.ElementAt(0).m_value; strUserID = m_DDXFields.ElementAt(1).m_value; strPwd = m_DDXFields.ElementAt(8).m_value; GetDlgItem(IDC_EDT_USER_PWD_CONFIRM)->GetWindowText(strConfirmPwd); m_sUserID = strUserID; if( strUserID.IsEmpty() ) { MessageBox(g_strUserNameCannotEmpty, g_strTip, MB_ICONINFORMATION); GetDlgItem(IDC_EDT_USER_ID)->SetFocus(); return 1; } else if(strPwd.Compare(strConfirmPwd)) { if( m_operation == NEW || m_operation == COPY ) { MessageBox(g_strPasswordNotMatch2, g_strTip, MB_ICONINFORMATION); GetDlgItem(IDC_EDT_USER_PWD)->SetFocus(); return 1; } else if( m_operation==EDIT ) ; return 2; } CHAR szID[MAX_ID] = {0}; if( m_operation == NEW || m_operation == COPY ) { int nRet = CDBInterface::GetInstancePtr()->GetUserID( szID, (char *)(LPCTSTR)strUserID ); if( nRet > 0 ) { MessageBox(g_strUserNameExit, g_strTip, MB_ICONINFORMATION); return 1; } } return 0; } void CDlgUser::OnBnClickedBtnSave() { // TODO: 在此添加控件通知处理程序代码 // 存盘操作 CExString strField; CHAR szMaxID[MAX_ID + 1] = {0}; CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0}; if( ((CButton *)GetDlgItem(IDC_CHK_USER_STATUS))->GetCheck() ) { GetDlgItem(IDC_EDT_USER_STATUS)->SetWindowText("1"); } else { GetDlgItem(IDC_EDT_USER_STATUS)->SetWindowText("0"); } CDBInterface::GetInstancePtr()->GetMaxID("t_user_info", "id", szMaxID); int nID; CString strID; try { switch (m_operation) { case EDIT: //nID = atoi(szMaxID); break; default: if( atoi(szMaxID) > 0 ) { nID = atoi(szMaxID) + 1; } else if( atoi(szMaxID) == 0 ) { nID = 1; } strID.Format("%d", nID); GetDlgItem(IDC_EDT_ID)->SetWindowText(strID); //m_pSet->AddNew(); break; } UpdateData(TRUE); try { // 校验数据的正确性 int nRet = CheckDataValid(); if( nRet == 1 ) { return; //CDialog::OnOK(); } //else if( nRet == 0 ) { sprintf(strSQLText, "insert into t_user_info(id, uid, username, tel, mobiletel, fax, email, status, pwd) values("); if( m_DDXFields.WriteData("t_user_info", strSQLText, m_operation) == -1 ) return; } } catch(...) { ; } UpdateData(FALSE); CDialog::OnOK(); }//try catch( _com_error &e ) { CString mes1,mes2,mes3,mes4; mes1.Format(_T("Error:%08lx.\n"), e.Error()); mes2.Format(_T("ErrorMessage:%s.\n"), e.ErrorMessage()); mes3.Format(_T("Source:%s.\n"), (LPCTSTR) _bstr_t(e.Source())); mes4.Format(_T("Description:%s.\n"), (LPCTSTR) _bstr_t(e.Description())); MessageBox(mes1+mes2+mes3+mes4,_T("Invalid field "),MB_ICONERROR); return; } catch(...) { MessageBox(_T("Unhandled Exception"),_T("Invalid field ")+strField,MB_ICONERROR); return; } }