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

📄 mysqldlg.cpp

📁 次,根据硬件序列号生成注册号,生成的注册码可以按字母颠倒、按顺序互换、数字交换、序列号分离和变形,最终形成正式的注册码,这样尽量保证了注册好的唯一,没有重复,并且有安全,可以放心使用. 9. List
💻 CPP
字号:
// MySQLDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MySQL.h"
#include "MySQLDlg.h"

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

#include "AboutDlg.h"
/////////////////////////////////////////////////////////////////////////////
// CMySQLDlg dialog

CMySQLDlg::CMySQLDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMySQLDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMySQLDlg)
	m_sSQL = _T("select * from user");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	ColNum=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMySQLDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMySQLDlg)
	DDX_Control(pDX, IDC_DBNAME, m_cDbName);
	DDX_Control(pDX, IDC_LIST, m_cList);
	DDX_Text(pDX, IDC_SQL, m_sSQL);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMySQLDlg, CDialog)
	//{{AFX_MSG_MAP(CMySQLDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SELECT, OnSelect)
	ON_CBN_SELCHANGE(IDC_DBNAME, OnSelchangeDbname)
	ON_BN_CLICKED(IDC_ABOUT, OnAbout)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMySQLDlg message handlers

BOOL CMySQLDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_cList.SetBkColor(RGB(180,200,220));
	m_cList.SetTextBkColor(RGB(180,200,220));
	m_cList.SetExtendedStyle(LVS_EX_INFOTIP|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	InitDatabase();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMySQLDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMySQLDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

LRESULT CMySQLDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	switch(message)
	{
	case WM_SEL_CH:
		m_cDbName.GetWindowText(SelDbName);
		mysql_select_db(MyData,SelDbName);
		break;
	default:
		break;
	}
	return CDialog::WindowProc(message, wParam, lParam);
}

void CMySQLDlg::InitDatabase()
{
	MyData=mysql_init((MYSQL*)0);
	mysql_real_connect(MyData,NULL,NULL,NULL,NULL,MYSQL_PORT,NULL,0);
	
	My_Res=mysql_list_dbs(MyData,NULL);
	if(!mysql_num_rows(My_Res))
		return;
	int i,
		j;
	CString DbName;
	i=0;
	DbName.Empty();
	while(My_Row=mysql_fetch_row(My_Res))
	{
		i=mysql_num_fields(My_Res);
		for(j=0;j<i;j++)
		{
			if(DbName.IsEmpty())
				DbName=My_Row[j];
			m_cDbName.AddString(My_Row[j]);
		}
	}
	mysql_free_result(My_Res);
	m_cDbName.SetCurSel(0);
	
	mysql_select_db(MyData,DbName);
	return;
}

void CMySQLDlg::OnSelect() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if(ColNum)
	{
		for(int i=0;i<ColNum;i++)
		m_cList.DeleteColumn(0);
	}
	m_cList.DeleteAllItems();
	if(m_sSQL.IsEmpty())
	{
		MessageBox("请输入SQL语句 ...",
					"MySQL",MB_OK | MB_ICONINFORMATION);
		return;
	}
	mysql_query(MyData,m_sSQL);
	My_Res=mysql_store_result(MyData);
	if(!My_Res)
	{
		MessageBox("mysql_store_result(...) 函数出错!",
						"MySQL",MB_OK | MB_ICONERROR);
		return;
	}
	for(ColNum=0;My_Field=mysql_fetch_field(My_Res);ColNum++)
		m_cList.InsertColumn(ColNum,My_Field->name,LVCFMT_CENTER,80,30);
	if(!mysql_num_rows(My_Res))
	{
		MessageBox("程序在数据库中未检测到任何数据 ...",
					"MySQL",MB_OK | MB_ICONINFORMATION);
		return;
	}
	int i,j,k;
	i=0;
	while(My_Row=mysql_fetch_row(My_Res))
	{
		j=mysql_num_fields(My_Res);
		for(k=0;k<j;k++)
			if(k==0)
				m_cList.InsertItem(i,My_Row[k]);
			else
				m_cList.SetItemText(i,k,My_Row[k]);
		++i;
	}
	mysql_free_result(My_Res);
	GetDlgItem(IDC_SQL)->SetFocus();
	return;
}

void CMySQLDlg::OnSelchangeDbname() 
{
	// TODO: Add your control notification handler code here
	PostMessage(WM_SEL_CH);
}

void CMySQLDlg::OnAbout() 
{
	// TODO: Add your control notification handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}

⌨️ 快捷键说明

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