📄 etldemodlg.cpp
字号:
// ETLdemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ETLdemo.h"
#include "ETLdemoDlg.h"
#include "DemoCopyHelper.h"
#include "DlgCopyDesign.h"
#include "DataSourceLocator.h"
#include <sstream>
#include "radix40.h"
#include ".\etldemodlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
enum { MODE_CUSTOMERS_ALL, MODE_CUSTOMERS_SELECT, MODE_CUSTOMERS_QUERY };
enum { MODE_EMPLOYEES_ALL, MODE_EMPLOYEES_SELECT, MODE_EMPLOYEES_QUERY };
bool GetConnectString(CString& strConnectString, CWnd* pParent)
{
CDataSourceLocator dlg;
if(dlg.CreateDispatch(_T("Datalinks")))
{
dlg.SetHWnd((long) pParent->GetSafeHwnd());
LPDISPATCH lpDispatch = dlg.PromptNew();
if(lpDispatch != NULL)
{
_ConnectionPtr ptrConnection = lpDispatch;
BSTR bstrConnectString = ptrConnection->ConnectionString;
USES_CONVERSION;
strConnectString = W2CT(bstrConnectString);
TRACE("Connect String: %s\n", strConnectString);
return true;
}
}
return false;
}
const TCHAR g_szConnectStrings[] = _T("Connnect Strings");
const TCHAR g_szSource[] = _T("Source");
const TCHAR g_szDestination[] = _T("Destination");
const TCHAR g_szQueries[] = _T("Queries");
const TCHAR g_szCustomers[] = _T("Customers");
const TCHAR g_szEmployees[] = _T("Employees");
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CETLdemoDlg dialog
CETLdemoDlg::CETLdemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CETLdemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CETLdemoDlg)
m_connectStringFrom = _T("");
m_connectStringTo = _T("");
m_bCustomersOrEmployeesOrders = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_nCustomersMode = 0;
m_nEmployeesMode = 0;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CETLdemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CETLdemoDlg)
DDX_Text(pDX, IDC_CONNECT_STRING_FROM, m_connectStringFrom);
DDX_Text(pDX, IDC_CONNECT_STRING_TO, m_connectStringTo);
DDX_Radio(pDX, IDC_ALL_CUSTOMERS, m_nCustomersMode);
DDX_Radio(pDX, IDC_ALL_EMPLOYEES, m_nEmployeesMode);
DDX_Check(pDX, IDC_CUSTOMERS_OR_EMPLOYEES_ORDERS, m_bCustomersOrEmployeesOrders);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_LIST_CUSTOMERS, m_listCustomers);
DDX_Control(pDX, IDC_LIST_EMPLOYEES, m_listEmployees);
}
BEGIN_MESSAGE_MAP(CETLdemoDlg, CDialog)
//{{AFX_MSG_MAP(CETLdemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TRANSFORM, OnTransform)
ON_BN_CLICKED(IDC_BTN_SELECT_CONNECT_STRING_FROM, OnSelectConnectStringFrom)
ON_BN_CLICKED(IDC_BTN_SELECT_CONNECT_STRING_TO, OnSelectConnectStringTo)
ON_BN_CLICKED(IDC_SELECT_CUSTOMERS, OnSelectCustomers)
ON_BN_CLICKED(IDC_CLEAR_TARGET, OnClearTarget)
ON_BN_CLICKED(IDC_QUERY_CUSTOMERS, OnQueryCustomers)
ON_BN_CLICKED(IDC_ALL_CUSTOMERS, OnAllCustomers)
ON_BN_CLICKED(IDC_ALL_EMPLOYEES, OnAllEmployees)
ON_BN_CLICKED(IDC_SELECT_EMPLOYEES, OnSelectEmployees)
ON_BN_CLICKED(IDC_QUERY_EMPLOYEES, OnQueryEmployees)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_TEST, OnBnClickedTest)
END_MESSAGE_MAP()
inline LPCTSTR Null2None(LPCTSTR psz)
{
return psz? psz : _T("<none>");
}
void CETLdemoDlg::ReportComError(_com_error& e)
{
std::basic_ostringstream<TCHAR> s;
s //<< _T("Code meaning = ") << e.ErrorMessage()
<< _T("Source = ") << Null2None(e.Source())
<< _T("\nDescription = ") << Null2None(e.Description());
MessageBox(s.str().c_str(), e.ErrorMessage(), MB_OK | MB_ICONEXCLAMATION);
}
/////////////////////////////////////////////////////////////////////////////
// CETLdemoDlg message handlers
BOOL CETLdemoDlg::OnInitDialog()
{
m_connectStringFrom = AfxGetApp()->GetProfileString(g_szConnectStrings, g_szSource);
m_connectStringTo = AfxGetApp()->GetProfileString(g_szConnectStrings, g_szDestination);
CDialog::OnInitDialog();
SetDlgItemText(IDC_EDIT_CUSTOMERS, AfxGetApp()->GetProfileString(g_szQueries, g_szCustomers));
SetDlgItemText(IDC_EDIT_EMPLOYEES, AfxGetApp()->GetProfileString(g_szQueries, g_szEmployees));
// 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
}
void CETLdemoDlg::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 CETLdemoDlg::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 CETLdemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CETLdemoDlg::OnTransform()
{
clock_t start = clock();
if (DoTransform())
{
CString strBuf;
strBuf.Format("Stuff was copied successfully in %g seconds."
, (double)(clock() - start) / CLOCKS_PER_SEC);
MessageBox(strBuf);
}
}
void CETLdemoDlg::OnSelectConnectStringFrom()
{
CString connectStringFrom = m_connectStringFrom;
if (GetConnectString(m_connectStringFrom, this)
&& connectStringFrom != m_connectStringFrom)
{
m_nCustomersMode = 0;
m_listCustomers.ResetContent();
m_nEmployeesMode = 0;
m_listEmployees.ResetContent();
UpdateData(false);
UpdateCustomersView();
UpdateEmployeesView();
}
}
void CETLdemoDlg::OnSelectConnectStringTo()
{
if (GetConnectString(m_connectStringTo, this))
UpdateData(false);
}
void CETLdemoDlg::OnSelectCustomers()
{
UpdateCustomersView();
if (m_listCustomers.GetCount() == 0)
{
CWaitCursor waitCursor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -