📄 replication.cpp
字号:
// Replication.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "Replication.h"
#include "SQLCEDemo.h"
#include "CESync.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReplication
IMPLEMENT_DYNCREATE(CReplication, CFormView)
CReplication::CReplication()
: CFormView(CReplication::IDD)
{
//{{AFX_DATA_INIT(CReplication)
m_strDBLoginID = _T("sa"); //登录名
m_strDBPassword = _T(""); //密码
m_strPublication =L"cnemb"; //发布数据库组名称
m_strPublishDB = _T("cnemb"); //发布数据库名称
m_strPublisher = _T("taling"); //发布数据库名称
m_strSubscriber = _T("44"); //
m_strInternetURL = _T("http://192.168.10.100/sqlce/sscesa20.dll"); //REPLICATION的INTERNET属性
//}}AFX_DATA_INIT
}
CReplication::~CReplication()
{
}
void CReplication::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReplication)
DDX_Text(pDX, IDC_EDIT_DBLOGIN, m_strDBLoginID);
DDX_Text(pDX, IDC_EDIT_DBPASSWORD, m_strDBPassword);
DDX_Text(pDX, IDC_EDIT_PUBLICATION, m_strPublication);
DDX_Text(pDX, IDC_EDIT_PUBLISHDB, m_strPublishDB);
DDX_Text(pDX, IDC_EDIT_PUBLISHER, m_strPublisher);
DDX_Text(pDX, IDC_EDIT_SUBSCRIBER, m_strSubscriber);
DDX_Text(pDX, IDC_EDIT_URL, m_strInternetURL);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReplication, CFormView)
//{{AFX_MSG_MAP(CReplication)
ON_BN_CLICKED(IDC_BUTTON_REPLICATE, OnButtonReplicate)
ON_BN_CLICKED(IDC_BUTTON_RETURN, OnButtonReturn)
ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReplication diagnostics
#ifdef _DEBUG
void CReplication::AssertValid() const
{
CFormView::AssertValid();
}
void CReplication::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CReplication message handlers
void CReplication::OnButtonReplicate()
{
// TODO: Add your control notification handler code here
WIN32_FIND_DATA fd;
HANDLE hFind;
CFile nFile;
CWaitCursor waitcursor;
CSQLCEDemoApp *pTheApp = (CSQLCEDemoApp*)AfxGetApp();
if (pTheApp->m_pADORs->IsOpened())
pTheApp->m_pADORs->Close();
if (pTheApp->m_pADOConn->IsConnected())
pTheApp->m_pADOConn->Close();
CCESync* pCEsync=new CCESync();
UpdateData(TRUE);
pCEsync->setInternetURL(m_strInternetURL.GetBuffer(m_strInternetURL.GetLength()));
pCEsync->setPublisher(m_strPublisher.GetBuffer(m_strPublisher.GetLength()));
pCEsync->setPublisherDatabase(m_strPublishDB.GetBuffer(m_strPublishDB.GetLength()));
pCEsync->setPublication(m_strPublication.GetBuffer(m_strPublication.GetLength()));
pCEsync->setPublisherLogin(m_strDBLoginID.GetBuffer(m_strDBLoginID.GetLength()));
pCEsync->setPublisherPassword(m_strDBPassword.GetBuffer(m_strDBPassword.GetLength()));
pCEsync->setSubscriber(m_strSubscriber.GetBuffer(m_strSubscriber.GetLength()));
pCEsync->setDistributor(m_strPublisher.GetBuffer(m_strPublisher.GetLength()));
pCEsync->setDistributorLogin(m_strDBLoginID.GetBuffer(m_strDBLoginID.GetLength()));
pCEsync->setDistributorPassword(m_strDBPassword.GetBuffer(m_strDBPassword.GetLength()));
hFind=::FindFirstFile(_T("\\palmheart.sdf"), &fd);
if (hFind !=INVALID_HANDLE_VALUE) {
//using a existed one
if ((pCEsync->AddSubscription(EXISTING_DATABASE))) { //means this db has been set for subscription
if (pCEsync->Synchronization())
AfxMessageBox(_T("successful."));
else
AfxMessageBox(_T("1,Failed."));
} else {
if (pCEsync->Synchronization())
AfxMessageBox(_T("successful."));
else
AfxMessageBox(_T("2,Failed."));
}
} else {
//not existed, create a new one
if ((pCEsync->AddSubscription()) && (pCEsync->Synchronization()))
AfxMessageBox(_T("successful."));
else
AfxMessageBox(_T("3,failed."));
}
::FindClose(hFind);
delete pCEsync;
if ((pTheApp->m_pADOConn != NULL) && (pTheApp->m_pADORs != NULL)) {
AdoNS::_ConnectionPtr pConnection = pTheApp->m_pADOConn->OpenDB(_T("\\palmheart.sdf"));
if ((pConnection != NULL) &&
(pTheApp->m_pADORs->PutConnection(pConnection))) {
::PostMessage(AfxGetMainWnd()->m_hWnd,WM_USER_COMMAND, CMainFrame.LoginForm, 0);
return;
}
}
waitcursor.Restore();
}
void CReplication::OnButtonReturn()
{
// TODO: Add your control notification handler code here
::PostMessage(AfxGetMainWnd()->m_hWnd,WM_USER_COMMAND, CMainFrame.MainForm, 0);
}
void CReplication::OnButtonSave()
{
// TODO: Add your control notification handler code here
}
void CReplication::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
// TODO: Add your specialized code here and/or call the base class
CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
void CReplication::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -