📄 logdialog.cpp
字号:
// LogDialog.cpp : implementation file
//
#include "stdafx.h"
#include "chat_Ado.h"
#include "LogDialog.h"
#include "_recordset1.h"
#include "fields1.h"
#include "field1.h"
#include "COMUTIL.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLogDialog dialog
CLogDialog::CLogDialog(CWnd* pParent /*=NULL*/)
: CDialog(CLogDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CLogDialog)
m_sServerName = _T("");
m_sUserName = _T("");
//}}AFX_DATA_INIT
}
void CLogDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLogDialog)
DDX_Text(pDX, IDC_EDIT_SERVER, m_sServerName);
DDX_Text(pDX, IDC_EDIT_USERNAME, m_sUserName);
DDX_Control(pDX, IDC_ADODC, m_ADOCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLogDialog, CDialog)
//{{AFX_MSG_MAP(CLogDialog)
ON_BN_CLICKED(IDC_BUTTON_SELETE_DB, OnButtonSeleteDb)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLogDialog message handlers
void CLogDialog::OnButtonSeleteDb()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE,NULL,NULL,NULL,"数据库|*.mdb");
if(dlg.DoModal()==IDOK)
{
CString FileName=dlg.GetPathName();
CString FileExt=dlg.GetFileExt();
if(FileExt!="mdb")
{
MessageBox("无效的扩展名!!!");
return;
}
/*生成连接字符串*/
CString strConnect;
strConnect.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False",FileName);
/*设置连接字符串*/
m_ADOCtrl.SetConnectionString(strConnect);
m_strConnection=strConnect;
CString strSource;
strSource.Format("select * from user_online");
/*设置数据源*/
m_ADOCtrl.SetRecordSource(strSource);
/*必要的刷新*/
m_ADOCtrl.Refresh();
m_sServerName=FileName;
}
UpdateData(FALSE);
}
void CLogDialog::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
if(m_sServerName.IsEmpty()) {MessageBox("无效的服务器名");return;}
/*判断用户是否已经存在*/
CString strSource;
strSource.Format("select * from user_online where name= '%s'",m_sUserName);
m_ADOCtrl.SetRecordSource(strSource);
m_ADOCtrl.Refresh();
C_Recordset1 &rst=m_ADOCtrl.GetRecordset();
int count =rst.GetRecordCount();
if(count==1) {MessageBox("用户名已经存在,请使用别的名字!!");return;}
/*不存在,则将用户加入online表里*/
try{
variant_t var1;
var1=long(0);
rst.AddNew(variant_t(long(0)),variant_t(m_sUserName));
rst.Update(variant_t(long(0)),variant_t(m_sUserName));
rst.Close();
}
catch(_com_error * e)
{
MessageBox("ERROE!!");
return;
}
CDialog::OnOK() ;
}
BOOL CLogDialog::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DestroyWindow();
}
void CLogDialog::OnClose()
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -