// DLG_User_Modify2.cpp : implementation file // #include "stdafx.h" #include "corpsms.h" #include "DLG_User_Modify2.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // DLG_User_Modify2 dialog #include "MainFrm.h" #include "FGAddress.h" DLG_User_Modify2::DLG_User_Modify2(CWnd* pParent /*=NULL*/) : CDialog(DLG_User_Modify2::IDD, pParent) { //{{AFX_DATA_INIT(DLG_User_Modify2) m_tBirthday = COleDateTime::GetCurrentTime(); m_strBZ = _T(""); m_strEmail = _T(""); m_strFax = _T(""); m_strJob = _T(""); m_strLocal = _T(""); m_strMobile = _T(""); m_strName = _T(""); m_strNickName = _T(""); m_strQQ = _T(""); m_lSex = -1; m_strTel = _T(""); //}}AFX_DATA_INIT m_pFGAddress = (CFGAddress *)pParent; m_AdoRS.SetAdoConnection( &m_pFGAddress->m_pMainFrame->m_adoConnection ); memset( &m_Address , 0 , sizeof(m_Address)); m_bAdd = false; m_bModify = false; memset( m_szLocal,0, sizeof(m_szLocal)); } void DLG_User_Modify2::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(DLG_User_Modify2) DDX_DateTimeCtrl(pDX, IDC_USERMODIFY2_BIRTHDAY, m_tBirthday); DDX_Text(pDX, IDC_USERMODIFY2_BZ, m_strBZ); DDV_MaxChars(pDX, m_strBZ, 49); DDX_Text(pDX, IDC_USERMODIFY2_EMAIL, m_strEmail); DDV_MaxChars(pDX, m_strEmail, 29); DDX_Text(pDX, IDC_USERMODIFY2_FAX, m_strFax); DDV_MaxChars(pDX, m_strFax, 15); DDX_Text(pDX, IDC_USERMODIFY2_JOB, m_strJob); DDV_MaxChars(pDX, m_strJob, 15); DDX_Text(pDX, IDC_USERMODIFY2_LOCAL, m_strLocal); DDX_Text(pDX, IDC_USERMODIFY2_MOBILE, m_strMobile); DDV_MaxChars(pDX, m_strMobile, 15); DDX_Text(pDX, IDC_USERMODIFY2_NAME, m_strName); DDV_MaxChars(pDX, m_strName, 15); DDX_Text(pDX, IDC_USERMODIFY2_NICKNAME, m_strNickName); DDV_MaxChars(pDX, m_strNickName, 15); DDX_Text(pDX, IDC_USERMODIFY2_QQ, m_strQQ); DDV_MaxChars(pDX, m_strQQ, 15); DDX_CBIndex(pDX, IDC_USERMODIFY2_SEX, m_lSex); DDX_Text(pDX, IDC_USERMODIFY2_TEL, m_strTel); DDV_MaxChars(pDX, m_strTel, 15); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(DLG_User_Modify2, CDialog) //{{AFX_MSG_MAP(DLG_User_Modify2) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // DLG_User_Modify2 message handlers BOOL DLG_User_Modify2::OnInitDialog() { CDialog::OnInitDialog(); m_strName = m_Address.szName; m_strNickName = m_Address.szNickName; long lSex = 0; if ( CString(m_Address.szSex)==_T("男") ) lSex = 1; if ( CString(m_Address.szSex)==_T("女") ) lSex = 2; m_lSex = lSex; COleDateTime tTemp(m_Address.tBirthday); if ( tTemp.GetStatus() != COleDateTime::valid ) //无效时间 { m_tBirthday.SetStatus( COleDateTime::null ); } else { m_tBirthday = tTemp; } m_strJob = m_Address.szJob; m_strTel = m_Address.szTel; m_strFax = m_Address.szFax; m_strMobile = m_Address.szMobile; m_strEmail = m_Address.szEmail; m_strQQ = m_Address.szQQ; m_strBZ = m_Address.szBZ; m_strLocal = m_szLocal; UpdateData(false); if ( m_bAdd ) { GetDlgItem( IDOK )->SetWindowText( _T("添 加") ); } if ( !m_bModify ) //没有修改权限 { GetDlgItem(IDOK)->EnableWindow(false); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void DLG_User_Modify2::SetParam(ANS_GAddress_SeeData data, ULONG ulPurview , TCHAR *pLocal, BOOL bAdd) { m_Address = data; m_bModify = ulPurview&PURVIEW_GADDRESS_MODIFY; m_bAdd = bAdd; _tcscpy( m_szLocal , pLocal ); } ANS_GAddress_SeeData DLG_User_Modify2::GetParam() { return m_Address; } void DLG_User_Modify2::OnOK() { UpdateData(true); if (m_strName.GetLength() <= 0 ) { GetDlgItem(IDC_USERMODIFY2_NAME)->SetFocus(); MessageBox( _T("用户姓名不能为空,请重新输入!") , _T("错误") , MB_ICONWARNING ); return ; } //查重,姓名不能重复 if ( CString(m_Address.szName) != m_strName) { TCHAR szSelect[128]={0}; _stprintf( szSelect , _T("select * from users where Name='%s' and UserType='1' ") , m_strName); BOOL b = m_AdoRS.Open( szSelect ); if ( b && m_AdoRS.GetRecordCount() ) { GetDlgItem(IDC_USERMODIFY2_NAME)->SetFocus(); MessageBox( _T("此姓名已使用,请重新输入!") , _T("错误") , MB_ICONWARNING ); return ; } } _tcscpy( m_Address.szName , m_strName ); _tcscpy( m_Address.szNickName , m_strNickName ); if ( m_lSex == 0 ) _tcscpy( m_Address.szSex , _T("") ); else if ( m_lSex == 1 ) _tcscpy( m_Address.szSex , _T("男") ); else _tcscpy( m_Address.szSex , _T("女") ); _tcscpy( m_Address.szJob , m_strJob ); _tcscpy( m_Address.szTel , m_strTel ); _tcscpy( m_Address.szFax , m_strFax ); _tcscpy( m_Address.szMobile , m_strMobile ); _tcscpy( m_Address.szEmail , m_strEmail ); _tcscpy( m_Address.szQQ , m_strQQ ); _tcscpy( m_Address.szBZ , m_strBZ ); if ( m_tBirthday.GetStatus() == COleDateTime::valid ) m_tBirthday.GetAsSystemTime( m_Address.tBirthday ); else memset(&m_Address.tBirthday,0,sizeof(m_Address.tBirthday)); if ( m_bAdd ) //添加 { m_pFGAddress->AddUser( m_Address ); m_strName = _T(""); m_strNickName = _T(""); m_tBirthday.SetStatus( COleDateTime::null ); m_strMobile = _T(""); m_strEmail = _T(""); m_strQQ = _T(""); UpdateData(false); GetDlgItem(IDC_USERMODIFY2_NAME)->SetFocus(); return ; } CDialog::OnOK(); }