123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- // 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;
- }
- }
|