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

📄 textdlg.cpp

📁 本源码中应用了sqlite的读写操作 要记着在解压本程序之后不能放在有中文的目录地下 要不然会报错 本程序支持sqlite的插入查询删除等功能 可输入select * from tbArodrome
💻 CPP
字号:
// textDlg.cpp : implementation file
//

#include "stdafx.h"
#include "text.h"
#include "textDlg.h"
#include "sqlite3.h"
#include "String.h"

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

//---------------------------------------------------------
extern CDatabaseAccess ado;
extern _RecordsetPtr ptr;
//---------------------------------------------------------

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA
	
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL
	
	// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTextDlg dialog

CTextDlg::CTextDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTextDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTextDlg)

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	//-----------------------------------------------------------
	
	//-----------------------------------------------------------
	
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CTextDlg::~CTextDlg()
{
	
}
void CTextDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTextDlg)

	DDX_Control(pDX, IDC_LIST2, m_datalist);
	DDX_Text(pDX, IDC_EDIT_sqlsentence, m_Sqlsentence);

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTextDlg, CDialog)
//{{AFX_MSG_MAP(CTextDlg)

ON_BN_CLICKED(IDC_BUTTON_execute1, OnBUTTONexecute1)
ON_EN_UPDATE(IDC_EDIT_sqlsentence, OnUpdateEDITsqlsentence)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTextDlg message handlers

BOOL CTextDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
	
	// 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
	
	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 CTextDlg::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();
	}
}

HCURSOR CTextDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//执行插入和删除语句调用本函数
void CTextDlg::OnBUTTONexecute1() 
{
	UpdateData(true);
	OpenSqlite();
	
	m_Sqlsentence = _T(m_Sqlsentence);
	if(m_Sqlsentence.Left(6) == _T("select") || m_Sqlsentence.Left(6) == _T("Select") ||
		m_Sqlsentence.Left(6) == _T("SELECT"))
	{
		char **errmsg = NULL;
		char **dbResult;
		int nRow, nColumn;
		CString temp = m_Sqlsentence;
		char* sql = temp.GetBuffer(0);
		temp.ReleaseBuffer();
		
		//取得sqlite里所有表
		if(SQLITE_OK != sqlite3_get_table( db, sql, &dbResult, &nRow, &nColumn, errmsg))
		{
			::MessageBox(NULL,sqlite3_errmsg(db),NULL,MB_OK | MB_ICONERROR);
			sqlite3_close(db);
			sqlite3_free_table( dbResult ); 
			return;
		}
		
		m_inumber = nColumn;
		m_datalist.ModifyStyle(0L,LVS_REPORT);
		m_datalist.ModifyStyle(0L,LVS_SINGLESEL);
		m_datalist.ModifyStyle(0L,LVS_SHOWSELALWAYS);
		m_datalist.ModifyStyle(0L,LVS_NOSORTHEADER);
		m_datalist.SetExtendedStyle(LVS_EX_GRIDLINES);
		
		if (m_frist)
		{
			for (int i = 0; i <nColumn; i++)
			{
				m_datalist.InsertColumn(i,dbResult[i]);
				m_datalist.SetColumnWidth(i,strlen(dbResult[i])+100);
			}
			
			int number = nColumn;
			for (int k = 0; k < nRow; k++)
			{
				m_datalist.InsertItem(k,"");
				for(int j = 0; j < nColumn; j++)
				{
					m_datalist.SetItemText(k, j, dbResult[number]);
					number++;
				}
			}
			m_frist = false;
		}
		sqlite3_free_table( dbResult ); 
	}
	
	else
	{
		//执行除查询以外的sql语句
		char* zErrMsg = 0;
		CString temp = m_Sqlsentence;
		char* sql = temp.GetBuffer(0);
		temp.ReleaseBuffer();
		
		if(SQLITE_OK!=sqlite3_exec(db,sql,0,0,&zErrMsg))
		{
			::MessageBox(NULL,sqlite3_errmsg(db),NULL,MB_OK | MB_ICONERROR);
			sqlite3_close(db);
			return;
		}
	}
	sqlite3_close(db);
}

void CTextDlg::OnUpdateEDITsqlsentence() 
{
	m_frist = true;
	m_datalist.DeleteAllItems();
	for (int i = 0; i < m_inumber; i++)
	{
		m_datalist.DeleteColumn(i);
	}
}


void CTextDlg::OpenSqlite()
{
	//创建打开sqlite数据库
	sqlite3 *sdb;
	char buffer[MAX_PATH];
	::GetCurrentDirectory(MAX_PATH,buffer);
	strcat(buffer,"\\sqlite.db"); //创建名字为sqlite的数据库于工程目录下
	
	if(SQLITE_OK!=sqlite3_open(buffer,&sdb))
	{
		::MessageBox(NULL,sqlite3_errmsg(sdb),NULL,MB_OK | MB_ICONERROR);
		sqlite3_close(sdb);
		exit(1);
		return;
	}
	db=sdb;
	
}




⌨️ 快捷键说明

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