📄 user.cpp
字号:
// User.cpp : implementation file
//
#include "stdafx.h"
#include "Toolmangne.h"
#include "User.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUser dialog
extern CString UserId;
extern CToolmangneApp theApp;
CUser::CUser(CWnd* pParent /*=NULL*/)
: CDialog(CUser::IDD, pParent)
{
//{{AFX_DATA_INIT(CUser)
m_pass = _T("");
m_addr = _T("");
m_tell = _T("");
m_info = _T("");
m_name = _T("");
//init();
//}}AFX_DATA_INIT
}
void CUser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUser)
DDX_Text(pDX, IDC_EDIT1, m_pass);
DDX_Text(pDX, IDC_EDIT2, m_addr);
DDX_Text(pDX, IDC_EDIT3, m_tell);
DDX_Text(pDX, IDC_EDIT4, m_info);
DDX_Text(pDX, IDC_EDIT5, m_name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUser, CDialog)
//{{AFX_MSG_MAP(CUser)
//}}AFX_MSG_MAP
//moeity
ON_BN_CLICKED(IDC_BUTTON1, moeity)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUser message handlers
void CUser::OnOK()
{
//CDialog::OnOK();
UpdateData();
/*CString sql = "delete from Provider where ID = " +m_reasch;
// TODO: Add extra validation here
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open(_variant_t(sql), // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
} */
//m_pRecordset->Close();
//m_pRecordset = NULL;
//sql = "insert into Provider values("+UserId+",'"+m_name+"','"+m_pass+"','"+m_addr+"','"+m_tell+"','"+m_info+"')";
CString sql = "select * from Provider where ID ="+UserId;
// TODO: Add extra validation here
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open(_variant_t(sql), // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
_variant_t var;
if(!m_pRecordset->BOF)
m_pRecordset->MoveFirst();
else
{
//AfxMessageBox("没有你查找的数据");
return ;
}
// 读入库中各字段并加入列表框中
while(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("Name");
if(var.vt != VT_NULL)
m_name = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("PassWord");
if(var.vt != VT_NULL)
m_pass = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("Address");
if(var.vt != VT_NULL)
m_addr = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("Tel");
if(var.vt != VT_NULL)
m_tell = (LPCSTR)_bstr_t(var);
var = m_pRecordset->GetCollect("Intro");
if(var.vt != VT_NULL)
m_info = (LPCSTR)_bstr_t(var);
m_pRecordset->MoveNext();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
UpdateData(false);
}
//m_pRecordset->Close();
//m_pRecordset = NULL;
//DEL void CUser::init()
//DEL {
//DEL
//DEL }
void CUser::moeity()
{
CString sql = "delete from Provider where ID = " +UserId;
// TODO: Add extra validation here
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open(_variant_t(sql), // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
insert();
/*
UpdateData();
//CString sql = "insert into Provider values("+UserId+",'"+m_name+"','"+m_pass+"','"+m_addr+"','"+m_tell+"','"+m_info+"')";
CString sql = "UPDATE Provider Set Name ='"+m_name+"',PassWord ='"+m_pass+"',Address='"+m_addr+"',Tel='"+m_tell+"',Intro='"+m_info+"' WHERE ID="+UserId;
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
_variant_t RecordsAffected;
try
{
m_pRecordset->Open(_variant_t(sql), // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(...)
{
AfxMessageBox("修改数据失败");
return ;
}
//m_pRecordset->Close();
//m_pRecordset = NULL;
//sql = "insert into Provider values ("+"+)";
*/
//AfxMessageBox("修改数据成功");
}
void CUser::insert()
{
UpdateData();
CString sql = "insert into Provider values("+UserId+",'"+m_name+"','"+m_pass+"','"+m_addr+"','"+m_tell+"','"+m_info+"')";
//CString sql = "UPDATE Provider Set PassWord ='"+m_pass+"',Address='"+m_addr+"',Tel='"+m_tell+"',Intro='"+m_info+"' WHERE ID="+UserId;
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
_variant_t RecordsAffected;
try
{
m_pRecordset->Open(_variant_t(sql), // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(...)
{
AfxMessageBox("修改数据失败");
return ;
}
//m_pRecordset->Close();
//m_pRecordset = NULL;
//sql = "insert into Provider values ("+"+)";
AfxMessageBox("修改数据成功");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -