📄 login.cpp
字号:
// Login.cpp : 实现文件
//
#include "stdafx.h"
#include "电信收费系统.h"
#include "Login.h"
// Login 对话框
IMPLEMENT_DYNAMIC(Login, CDialog)
Login::Login(CWnd* pParent /*=NULL*/)
: CDialog(Login::IDD, pParent)
, L_User(_T(""))
, L_Password(_T(""))
, newUser(_T(""))
, newPassword(_T(""))
{
}
Login::~Login()
{
}
BOOL Login::OnInitDialog()
{
CDialog::OnInitDialog();
if(bLink)
{
m_pCon.CreateInstance("ADODB.Connection");
_bstr_t strConnect= "Provider=SQLOLEDB;Server=(local);Database=Charge; uid=sa; pwd=;";//123456";
m_pCon->Open(strConnect,"","",adModeUnknown);
}
bUserlink = false;
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void Login::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_User, L_User);
DDX_Text(pDX, IDC_EDIT_Password, L_Password);
DDX_Text(pDX, IDC_EDIT_newUser, newUser);
DDV_MaxChars(pDX, newUser, 12);
DDX_Text(pDX, IDC_EDIT_newPassword, newPassword);
DDV_MaxChars(pDX, newPassword, 12);
}
BEGIN_MESSAGE_MAP(Login, CDialog)
ON_BN_CLICKED(IDOK1, &Login::OnBnClickedOk1)
ON_BN_CLICKED(ID_Register, &Login::OnBnClickedRegister)
END_MESSAGE_MAP()
// Login 消息处理程序
void Login::OnBnClickedOk1()
{
if(bLink && UpdateData())
{
if(L_User.GetLength()> 0 && L_Password.GetLength() >= 0) {
try{
_RecordsetPtr Rec("ADODB.Recordset");
Rec.CreateInstance(__uuidof(Recordset));
CString Cmd ="select * from User_info where UserName ='"+L_User+"' and Passwordx ='"+L_Password+"'";
_bstr_t bstrCmd = Cmd.AllocSysString();
Rec->Open(bstrCmd,m_pCon.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
Rec->MoveLast();
bUserlink =true;
AfxMessageBox("登入成功");
Rec->Close();
}
catch(_com_error e)
{
bUserlink =false;
AfxMessageBox("没有此用户或者密码错误");
}
}
}
if(bUserlink) {
OnOK();
}
}
void Login::OnBnClickedRegister()
{
if(bLink && UpdateData())
{
CString Cmd1 = "insert into User_info values ('"+newUser+"','"+newPassword+"')";
_bstr_t strCmd1 = Cmd1.AllocSysString();
bool exist = false;
if(newUser.GetLength()> 0 && newPassword.GetLength() >= 0)
{
CString Cmd = "Select * from User_info where UserName ='"+newUser+"'";
_bstr_t bstrCmd = Cmd.AllocSysString();
try{
_RecordsetPtr Rec("ADODB.Recordset");
Rec.CreateInstance(__uuidof(Recordset));
Rec->Open(bstrCmd,m_pCon.GetInterfacePtr(),adOpenStatic,adLockOptimistic,adCmdText);
Rec->MoveLast();
if( Rec->GetRecordCount() == 1)
{
AfxMessageBox("存在的用户");
exist = true;
}
Rec->Close();
}
catch(_com_error e)
{
exist= false;
}
if(!exist)
{
try{
m_pCon->Execute(strCmd1,NULL,0);
AfxMessageBox("注册成功,请在上方登入");
}
catch(_com_error e)
{
AfxMessageBox("注册失败,请重启系统");
exist= true;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -