?? textdlg.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)
m_Sqlsentence = _T("");
m_frist = true;
m_edit_values = _T("");
//}}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_DATETIMEPICKER_end, m_date_end);
DDX_Control(pDX, IDC_DATETIMEPICKER_begin, m_deta_begin);
DDX_Control(pDX, IDC_STATIC_end, m_static_end);
DDX_Control(pDX, IDC_STATIC_begin, m_static_begin);
DDX_Control(pDX, IDC_RADIO_all, m_radioall);
DDX_Control(pDX, IDC_LIST2, m_datalist);
DDX_Text(pDX, IDC_EDIT_sqlsentence, m_Sqlsentence);
DDX_Control(pDX, IDC_RADIO_tablename, m_radio_tablename);
DDX_Text(pDX, IDC_EDIT_values, m_edit_values);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTextDlg, CDialog)
//{{AFX_MSG_MAP(CTextDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_execute1, OnBUTTONexecute1)
ON_EN_UPDATE(IDC_EDIT_sqlsentence, OnUpdateEDITsqlsentence)
ON_BN_CLICKED(IDC_RADIO_all, OnRADIOall)
ON_BN_CLICKED(IDC_RADIO_date, OnRADIOdate)
ON_BN_CLICKED(IDC_BUTTON_ok, OnBUTTONok)
//}}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
//---------------------------------------------------------------------------------
m_radioall.SetCheck(1);
m_radio_tablename.SetCheck(1);
m_static_begin.ShowWindow(SW_HIDE);
m_static_end.ShowWindow(SW_HIDE);
m_deta_begin.ShowWindow(SW_HIDE);
m_date_end.ShowWindow(SW_HIDE);
//---------------------------------------------------------------------------------
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CTextDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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::OnRADIOall()
{
// TODO: Add your control notification handler code here
m_static_begin.ShowWindow(SW_HIDE);
m_static_end.ShowWindow(SW_HIDE);
m_deta_begin.ShowWindow(SW_HIDE);
m_date_end.ShowWindow(SW_HIDE);
}
void CTextDlg::OnRADIOdate()
{
// TODO: Add your control notification handler code here
m_static_begin.ShowWindow(1);
m_static_end.ShowWindow(1);
m_deta_begin.ShowWindow(1);
m_date_end.ShowWindow(1);
}
void CTextDlg::OnBUTTONok()
{
_RecordsetPtr ptrTable;
_RecordsetPtr ptrTableInfo;
_variant_t var;
UpdateData(TRUE);
OpenSqlite();
//判斷用戶選中的是按表名同步還是按照用戶的sql語句同步----------------------------------
if(m_radio_tablename.GetCheck())
{
char **tableResult;
char **fieldResult;
int nRow, nColumn;
int TempRow,TempColumn;
char **errmsg = NULL;
bool tableexist = false;
CString tempName;
//取得sqlite里所有表---------------------------------------------------------------
CString sql = "SELECT name FROM sqlite_master";
if(SQLITE_OK != sqlite3_get_table( db, sql, &tableResult, &nRow, &nColumn, errmsg))
{
::MessageBox(NULL,sqlite3_errmsg(db),NULL,MB_OK | MB_ICONERROR);
sqlite3_close(db);
sqlite3_free_table( tableResult );
return;
}
sql = "";
//循環于sqlite取得的每一個表名-----------------------------------------------------------
for(int i = 0; i < nRow; i++)
{
tempName = tableResult[i+1];
if(m_edit_values == tempName)
{
xunhuan:
tableexist = true;
CString fieldname = "";
int iCount = 0;
//獲取sqlite當前表各個字段名-----------------------------------------------------
sql = "SELECT * FROM "+ tempName;
if(SQLITE_OK != sqlite3_get_table( db, sql, &fieldResult, &TempRow, &TempColumn, errmsg))
{
::MessageBox(NULL,sqlite3_errmsg(db),NULL,MB_OK | MB_ICONERROR);
sqlite3_close(db);
sqlite3_free_table( fieldResult );
return;
}
CString strMiddleName;
for(int j = 0; j < TempColumn; j++)
{
strMiddleName += fieldResult[j];
strMiddleName += " ";
}
//獲取sql server記錄集信息-----------------------------------------------------------
ptrTable = ado.ExecuteSQLSentence("SELECT * FROM SysColumns WHERE id = Object_Id('"+ m_edit_values +"')");
if(!ptrTable->BOF)
ptrTable->MoveFirst();
while(!ptrTable->adoEOF)
{
var = ptrTable->GetCollect("name");
if(var.vt!=VT_NULL)
{
fieldname += (LPCSTR)_bstr_t(var);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -