259 lines
6.0 KiB
C++
259 lines
6.0 KiB
C++
#include "stdafx.h"
|
|
#include "SJQYDlg.h"
|
|
#include "CoreTools.h"
|
|
#include "LJCSDlg.h"
|
|
#include "Base64.h"
|
|
#include "comutil.h"
|
|
#include "uiiado.h"
|
|
|
|
IMPLEMENT_DYNAMIC(CSJQYDlg, CDialog)
|
|
|
|
CSJQYDlg::CSJQYDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CSJQYDlg::IDD, pParent)
|
|
{
|
|
m_sPassword2 = _T("");
|
|
}
|
|
|
|
CSJQYDlg::~CSJQYDlg(void)
|
|
{
|
|
}
|
|
|
|
void CSJQYDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LIST1, m_wndDBList);
|
|
DDX_Control(pDX, IDC_PROGRESS1, m_wndProgressCtrl);
|
|
DDX_Text(pDX, IDC_EDIT1,m_sPassword2);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CSJQYDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CSJQYDlg::OnBnClickedOk)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CSJQYDlg::OnBnClickedButton1)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CSJQYDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CBitmap bmp;
|
|
if (!bmp.LoadBitmap (IDB_BITMAPPRIV))
|
|
{
|
|
AfxMessageBox(_T("Can't load bitmap: %x\n"), IDB_BITMAPPRIV);
|
|
ASSERT (FALSE);
|
|
return FALSE;
|
|
}
|
|
|
|
BITMAP bmpObj;
|
|
bmp.GetBitmap (&bmpObj);
|
|
|
|
UINT nFlags = ILC_COLOR24 | ILC_MASK;
|
|
|
|
m_imageList.Create (16, bmpObj.bmHeight, nFlags, 0, 0);
|
|
m_imageList.Add (&bmp, RGB (255, 0, 0));
|
|
|
|
m_wndDBList.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_SINGLEROW | LVS_EX_CHECKBOXES);
|
|
m_wndDBList.InsertColumn(0,_T("本地数据库"),LVCFMT_LEFT,700);
|
|
m_wndDBList.InsertColumn(1,_T("迁移状态"),LVCFMT_LEFT,100);
|
|
m_wndDBList.SetImageList(&m_imageList,LVSIL_SMALL);
|
|
|
|
m_wndProgressCtrl.ShowWindow(SW_HIDE);
|
|
|
|
FindLocalDbFiles();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CSJQYDlg::FindLocalDbFiles()
|
|
{
|
|
std::vector<CString> arDbFiles;
|
|
bool bOnlyName = false;
|
|
bool bRecursive = false;
|
|
|
|
CoreTools::getFilesInFolder(FilePath::GetSysDir(),_T("*.db"),arDbFiles,false,false);
|
|
int nItem = 0;
|
|
for (int i = 0;i < arDbFiles.size();i++)
|
|
{
|
|
CString& sDbFile = arDbFiles.at(i);
|
|
sDbFile.MakeLower();
|
|
|
|
if (sDbFile.Find(_T("ktparampart.db")) != -1)
|
|
continue;
|
|
|
|
if (sDbFile.Find(_T("sh_export.db")) != -1)
|
|
continue;
|
|
|
|
nItem = m_wndDBList.GetItemCount();
|
|
m_wndDBList.InsertItem(nItem,sDbFile,11);
|
|
m_wndDBList.SetItemText(nItem,1,_T(""));
|
|
|
|
m_wndDBList.SetCheck(i,FALSE);
|
|
|
|
if (sDbFile.Find(_T("aec3dmep.db")) != -1)
|
|
m_wndDBList.SetCheck(nItem,TRUE);
|
|
|
|
if (sDbFile.Find(_T("plumbing.db")) != -1)
|
|
m_wndDBList.SetCheck(nItem,TRUE);
|
|
}
|
|
}
|
|
|
|
BOOL CSJQYDlg::GetProductIni(CString& _sSQLSrvName,CString& _sUser,CString& _sPWD)
|
|
{
|
|
CString sProductIni;
|
|
sProductIni.Format(_T("%s\\product.ini"),FilePath::GetSysDir());
|
|
|
|
CString sVal;
|
|
TCHAR szVal[MAX_PATH];
|
|
if ( ::GetPrivateProfileString(_T("Product"), _T("SQLServer"), _T(""), szVal, MAX_PATH, sProductIni) > 0)
|
|
{
|
|
_sSQLSrvName = szVal;
|
|
|
|
//userid
|
|
if ( ::GetPrivateProfileString(_T("Product"), _T("UserID"), _T(""), szVal, MAX_PATH, sProductIni) > 0 )
|
|
{
|
|
//去除干扰
|
|
CString sVal = szVal;
|
|
sVal.TrimRight(_T("sh"));
|
|
_tcscpy(szVal,sVal);
|
|
std::string suser = (LPCSTR)_bstr_t((LPCTSTR)szVal);
|
|
|
|
//解密
|
|
std::string suserM = Base64::Decode(suser);
|
|
std::wstring swuserM = Base64::ansii2Unicode(suserM.c_str(),CP_UTF8);
|
|
_sUser = swuserM.c_str();
|
|
}
|
|
|
|
//password
|
|
if (::GetPrivateProfileString(_T("Product"), _T("Password"), _T(""), szVal, MAX_PATH, sProductIni) > 0)
|
|
{
|
|
//去除干扰
|
|
sVal = szVal;
|
|
sVal.TrimRight(_T("rm"));
|
|
_tcscpy(szVal,sVal);
|
|
|
|
std::string spwd = (LPCSTR)_bstr_t((LPCTSTR)szVal);
|
|
//解密
|
|
std::string spwdM = Base64::Decode(spwd);
|
|
std::wstring swpwdM = Base64::ansii2Unicode(spwdM.c_str(),CP_UTF8);
|
|
_sPWD = swpwdM.c_str();
|
|
|
|
return TRUE;
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void CSJQYDlg::CreateDatabase(CString& _sSQLSrvName,CString& _sUser,CString& _sPWD)
|
|
{
|
|
::CoInitialize(NULL);
|
|
|
|
TCHAR sDrive[MAX_PATH],sDir[MAX_PATH],sFileName[MAX_PATH],sExt[MAX_PATH];
|
|
|
|
//连接后执行sql 脚本
|
|
CString sSQL,sDbFile;
|
|
sSQL.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;"),
|
|
_sSQLSrvName,_T("master"),_sUser,_sPWD);
|
|
|
|
CUIISQLiteServer dbSQRemo;
|
|
if (dbSQRemo.InitSQLServer(sSQL))
|
|
{
|
|
for(int i = 0;i < m_wndDBList.GetItemCount();i++)
|
|
{
|
|
if (!m_wndDBList.GetCheck(i))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
sDbFile = m_wndDBList.GetItemText(i,0);
|
|
|
|
#ifdef _UNICODE
|
|
_wsplitpath(sDbFile, sDrive, sDir, sFileName, sExt);
|
|
#else
|
|
_splitpath(sDbFile, sDrive, sDir, sFileName, sExt);
|
|
#endif
|
|
|
|
sSQL.Format(_T("select count(*) From master.dbo.sysdatabases where name='%s'"),sFileName);
|
|
if ( !dbSQRemo.IsSelEmpty(sSQL) )
|
|
{
|
|
sSQL.Format(_T("Create database %s"),sFileName);
|
|
if ( dbSQRemo.ExecuteSQL(sSQL) )
|
|
{
|
|
//...
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CSJQYDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
if (m_sPassword2.CompareNoCase(_T("ShanghuaSoft")) != 0)
|
|
{
|
|
AfxMessageBox(_T("建数据库许可密码不正确"));
|
|
return;
|
|
}
|
|
|
|
CString _sSQLSrvName,_sUser,_sPWD;
|
|
if (!GetProductIni(_sSQLSrvName,_sUser,_sPWD) )
|
|
{
|
|
AfxMessageBox(_T("协同数据库没有连接配置!"));
|
|
OnBnClickedButton1();
|
|
return;
|
|
}
|
|
|
|
if (m_wndDBList.GetItemCount() == 0)
|
|
return;
|
|
|
|
CWaitCursor wait;
|
|
TCHAR sDrive[MAX_PATH],sDir[MAX_PATH],sFileName[MAX_PATH],sExt[MAX_PATH];
|
|
|
|
m_wndProgressCtrl.ShowWindow(SW_SHOW);
|
|
m_wndProgressCtrl.SetRange32(0,m_wndDBList.GetItemCount());
|
|
m_wndProgressCtrl.SetStep(1);
|
|
|
|
CreateDatabase(_sSQLSrvName,_sUser,_sPWD);
|
|
|
|
//然后数据迁移
|
|
BOOL bFinished = FALSE;
|
|
CString sDbFile,sConnect;
|
|
for(int i = 0;i < m_wndDBList.GetItemCount();i++)
|
|
{
|
|
if (!m_wndDBList.GetCheck(i))
|
|
{
|
|
m_wndProgressCtrl.StepIt();
|
|
continue;
|
|
}
|
|
|
|
sDbFile = m_wndDBList.GetItemText(i,0);
|
|
|
|
#ifdef _UNICODE
|
|
_wsplitpath(sDbFile, sDrive, sDir, sFileName, sExt);
|
|
#else
|
|
_splitpath(sDbFile, sDrive, sDir, sFileName, sExt);
|
|
#endif
|
|
sConnect.Format(_T("Driver=SQL Server;Server=%s;Database=%s;User Id=%s;Password=%s;"),
|
|
_sSQLSrvName, sFileName, _sUser, _sPWD);
|
|
|
|
if ( CUIISQLiteServer::SQLite3Data2SQLServer(sDbFile,sFileName,sConnect) )
|
|
{
|
|
m_wndDBList.SetItemText(i,1,_T("√"));
|
|
bFinished = TRUE;
|
|
}
|
|
m_wndProgressCtrl.StepIt();
|
|
}
|
|
|
|
m_wndProgressCtrl.ShowWindow(SW_HIDE);
|
|
|
|
if (bFinished)
|
|
AfxMessageBox(_T("数据库迁移完毕,不需要再次迁移!!!"));
|
|
|
|
OnOK();
|
|
}
|
|
|
|
void CSJQYDlg::OnBnClickedButton1()
|
|
{
|
|
CLJCSDlg dlg;
|
|
dlg.DoModal();
|
|
}
|