⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlglogin.cpp

📁 visual C++ mysql Connect Source
💻 CPP
字号:
// DlgLogin.cpp : implementation file
//

#include "stdafx.h"
#include "Sample.h"
#include "DlgLogin.h"

#include "DlgJoin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgLogin dialog


CDlgLogin::CDlgLogin(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgLogin::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLogin)
	m_strID = _T("");
	m_strPW = _T("");
	//}}AFX_DATA_INIT
}


void CDlgLogin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLogin)
	DDX_Control(pDX, IDC_PW, m_PW);
	DDX_Control(pDX, IDC_ID, m_ID);
	DDX_Text(pDX, IDC_ID, m_strID);
	DDV_MaxChars(pDX, m_strID, 8);
	DDX_Text(pDX, IDC_PW, m_strPW);
	DDV_MaxChars(pDX, m_strPW, 15);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgLogin, CDialog)
	//{{AFX_MSG_MAP(CDlgLogin)
	ON_BN_CLICKED(IDC_JOIN, OnJoin)
	ON_BN_CLICKED(IDC_RESET, OnReset)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgLogin message handlers

BOOL CDlgLogin::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgLogin::OnJoin() 
{
	// 雀盔啊涝阑 喘范阑锭
	CDlgJoin dlg;
	dlg.DoModal();
}

void CDlgLogin::OnOK() 
{
	UpdateData();

	if(m_strID.GetLength() <= 0)
	{
		MessageBox("ID甫 涝仿窍绞矫坷", "Error", MB_OK|MB_ICONERROR);
		m_ID.SetFocus();
		return;
	}

	if(m_strPW.GetLength() <= 0)
	{
		MessageBox("Password甫 涝仿窍绞矫坷", "Error", MB_OK|MB_ICONERROR);
		m_PW.SetFocus();
		return;
	}

	if(m_strID.GetLength() > 8)
	{
		MessageBox("ID啊 8磊 捞惑涝聪促", "Error", MB_OK|MB_ICONERROR);
		m_ID.SetFocus();
		return;
	}

	if(m_strPW.GetLength() > 15)
	{	
		MessageBox("Password啊 15磊 捞惑涝聪促", "Error", MB_OK|MB_ICONERROR);
		m_PW.SetFocus();
		return;
	}

	// id, pw 八荤 何盒
	char Query[128];
	ZeroMemory(&Query[0], sizeof(Query));
	long i=0;

	// 孽府焊郴扁
	sprintf(Query, "SELECT * FROM %s WHERE %s LIKE '%s'", TABLE, ID, m_strID.GetBuffer(0));
	if(mysql_query(&g_MySQL, Query))
	{
		MessageBox("Query 傈价 角菩", "Error", MB_OK|MB_ICONERROR);
		return;
	}
	else
	{
		// 孽府 己傍
		MYSQL_RES *result = mysql_store_result(&g_MySQL);

        if(result)
        {
			MYSQL_ROW row;
			if(result->row_count)
			{
				row = mysql_fetch_row(result);
				
				// 菩胶况靛啊 老摹窍看绰啊
				if(strcmp(m_strPW.GetBuffer(0), row[1]) == 0)
				{
					// id, pw 老摹
					// MyInfo 皋葛府 历厘
					ZeroMemory(&g_MyInfo, sizeof(g_MyInfo));
					memcpy(g_MyInfo.id, row[0], sizeof(g_MyInfo.id));
					memcpy(g_MyInfo.pw, row[1], sizeof(g_MyInfo.pw));
					// 眠玫牢 何盒 NULL 蜡公 贸府
					if(row[2]!=NULL)
					{	memcpy(g_MyInfo.re, row[2], sizeof(g_MyInfo.re)); }
					else
					{	ZeroMemory(g_MyInfo.re, sizeof(g_MyInfo.re)); }
					g_MyInfo.lv = atoi(row[3]);
					g_MyInfo.pn = atoi(row[4]);

					CDialog::OnOK();
				}
				else
				{
					MessageBox("Password啊 撇赋聪促", "Error", MB_OK|MB_ICONERROR);
					return;
				}
			}
			else
			{
				MessageBox("拌沥捞 粮犁窍瘤 臼嚼聪促", "Error", MB_OK|MB_ICONERROR);
				return;
			}
		}
	}
	
	CDialog::OnOK();
}

void CDlgLogin::OnReset() 
{
	char Query[128];
	ZeroMemory(&Query[0], sizeof(Query));

	sprintf(Query, "DELETE FROM %s WHERE %s<5", TABLE, LEVEL);
	if(mysql_query(&g_MySQL, Query))
	{
		MessageBox("Query 傈价 角菩", "Error", MB_OK|MB_ICONERROR);
		return;
}
	else
	{
		// 眠啊
		ZeroMemory(&Query[0], sizeof(Query));
		sprintf(Query, "INSERT INTO %s VALUES('%s','%s',NULL,%d,%d)", 
			TABLE, ADMINISTRATOR_ID, ADMINISTRATOR_PW, 0, 0);
		if(mysql_query(&g_MySQL, Query))
		{
			MessageBox("Query 傈价 角菩", "Error", MB_OK|MB_ICONERROR);
			return;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -