📄 changeusrinfo.cpp
字号:
// ChangeUsrInfo.cpp : implementation file
//
#include "stdafx.h"
#include "SoftDocSystem.h"
#include "ChangeUsrInfo.h"
#include "Rrypt.h"
#include "LogMngr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChangeUsrInfo dialog
CChangeUsrInfo::CChangeUsrInfo(CWnd* pParent /*=NULL*/)
: CDialog(CChangeUsrInfo::IDD, pParent)
{
//{{AFX_DATA_INIT(CChangeUsrInfo)
m_UserName = _T("");
m_PassWord = _T("");
m_RealName = _T("");
m_Department = _T("");
m_Tel = _T("");
m_Context = _T("");
//}}AFX_DATA_INIT
}
void CChangeUsrInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChangeUsrInfo)
DDX_Text(pDX, IDC_EDIT1, m_UserName);
DDX_Text(pDX, IDC_EDIT2, m_PassWord);
DDX_Text(pDX, IDC_EDIT4, m_RealName);
DDX_Text(pDX, IDC_EDIT5, m_Department);
DDX_Text(pDX, IDC_EDIT6, m_Tel);
DDX_Text(pDX, IDC_EDIT7, m_Context);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChangeUsrInfo, CDialog)
//{{AFX_MSG_MAP(CChangeUsrInfo)
ON_BN_CLICKED(IDC_BUTTON1, OnSummit)
ON_BN_CLICKED(IDC_BUTTON2, OnReset)
ON_BN_CLICKED(IDOK2, OnChange)
ON_BN_CLICKED(IDCANCEL2, OnCancel)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChangeUsrInfo message handlers
void CChangeUsrInfo::OnSummit()
{
// TODO: Add your control notification handler code here
UpdateData();
CString sql_,PasswordChar,str1,pASS;
CString strName,strDepartment,strTel,strContext;
if(m_UserName.IsEmpty ()){AfxMessageBox("请输入用户名!");return;}
if(m_PassWord.IsEmpty())
PasswordChar=_T("RX67YM3482C");//对空密码进行处理
else
PasswordChar=CCrypt::Encrypt (m_PassWord,376);
sql_.Format ("SELECT * FROM UserInfo WHERE 用户名 = '%s'",m_UserName);
_bstr_t sql=sql_;
_bstr_t source=m_strSource;
_RecordsetPtr Myset;
Myset.CreateInstance (__uuidof(Recordset));
try{
Myset->Open (sql,source,adOpenDynamic,adLockOptimistic,adCmdText);}
catch(_com_error& e){
AfxMessageBox(e.ErrorMessage());}
int Count=0;
while(!Myset->adoEOF)
{Count+=1;Myset->MoveNext();};
if(Count==0){AfxMessageBox("你输入的用户名不存在");return;}
_variant_t Holder;
Myset->MoveFirst();
Holder=Myset->GetCollect ("密码");
//派出两种部窜在的情况
if(Holder.vt==VT_NULL)
{AfxMessageBox("这个密码已被破坏,下次请不要字使用这个用户名!");
return;}
else{
pASS=(char*)(_bstr_t)Holder;
pASS.TrimLeft (" ");
pASS.TrimRight (" ");
if(PasswordChar!=pASS)
{AfxMessageBox("密码不正确");return;}
//输入该用户的信息
Holder=Myset->GetCollect ("姓名");//
if(Holder.vt!=VT_NULL){
strName=(char*)(_bstr_t)Holder;
strName.TrimRight(" ");}
else
strName="不明姓名";
Holder=Myset->GetCollect ("部门");//
if(Holder.vt!=VT_NULL){
strDepartment=(char*)(_bstr_t)Holder;
strDepartment.TrimRight(" ");}
else
strDepartment="不明部门";
Holder=Myset->GetCollect ("联系电话");//
if(Holder.vt!=VT_NULL){
strTel=(char*)(_bstr_t)Holder;
strTel.TrimRight(" ");}
else
strTel="不明电话";
Holder=Myset->GetCollect ("详细信息");//
if(Holder.vt!=VT_NULL){
strContext=(char*)(_bstr_t)Holder;
strContext.TrimRight(" ");}
else
strContext="不明信息";
GetDlgItem(IDC_EDIT4)->SetWindowText(strName);
GetDlgItem(IDC_EDIT5)->SetWindowText(strDepartment);
GetDlgItem(IDC_EDIT6)->SetWindowText(strTel);
GetDlgItem(IDC_EDIT7)->SetWindowText(strContext);
GetDlgItem(IDOK2)->EnableWindow(true); //将数据匡是能
GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
}
UpdateData(true);
}
void CChangeUsrInfo::OnReset()
{
// TODO: Add your control notification handler code here
GetDlgItem(IDC_EDIT1)->SetWindowText("");
GetDlgItem(IDC_EDIT2)->SetWindowText("");
UpdateData();
}
void CChangeUsrInfo::OnChange()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_RealName.IsEmpty ()){AfxMessageBox("你没有输入姓名,请重新输入!");return;}
if(m_Department.IsEmpty ()){AfxMessageBox("你没有输入部门的名称!");return;}
if(m_Tel.IsEmpty ()){AfxMessageBox("你没有输入联系电话,请重新输入!");return;}
CString strContext,sql_;
if(m_Context.IsEmpty ())strContext=m_Context;
else
strContext="无信息";
try{m_DBCnt->BeginTrans ();//开始事务
sql_.Format ("UPDATE UserInfo SET 姓名='%s',部门='%s',联系电话='%s',详细信息='%s' WHERE 用户名 = '%s'",m_RealName,m_Department,m_Tel,m_Context,m_UserName);
_bstr_t sql=sql_;
_bstr_t source=m_strSource;
_RecordsetPtr Myset;
Myset.CreateInstance (__uuidof(Recordset));
try{
m_DBCnt->Execute (sql,NULL,adCmdText);}
catch(_com_error& e){
AfxMessageBox(e.ErrorMessage());return;}
m_DBCnt->CommitTrans();
}
catch(_com_error& e){
m_DBCnt->RollbackTrans();return;}//出错则回滚
if(m_Log.Setup (m_DBCnt))
m_Log.Addlog (m_UserName,"更改用户资料",m_RealName);//操作日志
Init();
AfxMessageBox("你的用户信息已成功修改!",MB_ICONINFORMATION);
}
BOOL CChangeUsrInfo::OnInitDialog()
{
CDialog::OnInitDialog();
// 字体
LOGFONT LogFont;
int height;
(CFont*)CWnd::GetFont()->GetLogFont(&LogFont);
LogFont.lfItalic=true;
strcpy(LogFont.lfFaceName,"楷体_GB2312");
height=LogFont.lfHeight*2.5;
LogFont.lfHeight=height;
int width=LogFont.lfWidth*2;
LogFont.lfWidth=width;
m_font.CreateFontIndirect(&LogFont);
GetDlgItem(IDC_SHENSTATIC)->SetFont(&m_font,true);
//Databaxe Initialled
CSoftDocSystemApp* myApp=(CSoftDocSystemApp*)AfxGetApp();
CString source_;
source_.Format ("driver={SQL Server};server=%s;database=SoftDocument",myApp->ConnectServer);
_bstr_t source=source_;
_bstr_t pwd=myApp->ConnectPwd;
_bstr_t user=myApp->ConnectUser;
HRESULT hr;
try{
hr = m_DBCnt.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
hr = m_DBCnt->Open(source, user, pwd, 16);
if(SUCCEEDED(hr))
{m_fConnected = TRUE;
}
else
m_fConnected = FALSE;
}
catch (_com_error &e){
MessageBox(e.ErrorMessage());
m_fConnected = FALSE;
}
if(!m_fConnected)
//if(m_DBCnt->GetState()!=adStateOpen)
{MessageBox("ADO数据源初始化失败!");
return false;}
else m_strSource = (char * )source;
Init();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChangeUsrInfo::Init()
{
GetDlgItem(IDOK2)->EnableWindow(false);
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
GetDlgItem(IDC_EDIT5)->SetWindowText("");
GetDlgItem(IDC_EDIT6)->SetWindowText("");
GetDlgItem(IDC_EDIT7)->SetWindowText("");
GetDlgItem(IDC_EDIT4)->SetWindowText("");
UpdateData();
}
void CChangeUsrInfo::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel ();
}
void CChangeUsrInfo::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(m_DBCnt->GetState()==adStateOpen)
m_DBCnt->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -