801 lines
20 KiB
C++
801 lines
20 KiB
C++
#include "stdafx.h"
|
|
#include "JDRKDlg.h"
|
|
#include "UITools.h"
|
|
#include <set>
|
|
#include "coreTools.h"
|
|
|
|
#define STANDARD_DB _T("\\cityStandard.db")
|
|
#define STANDARD_TABLE _T("standard")
|
|
|
|
namespace
|
|
{
|
|
int generateID(const CStringArray &arr)
|
|
{
|
|
std::set<int> ss;
|
|
int v(0), result(0);
|
|
for (int i = 0; i < arr.GetCount(); ++i)
|
|
{
|
|
const CString &str(arr[i]);
|
|
if (!CoreTools::isDigitString<double>(str)) continue;
|
|
v = TypeConvert::convert<int, std::wstring>((LPCTSTR)str);
|
|
ss.insert(v);
|
|
}
|
|
if (!ss.empty())
|
|
result = *ss.rbegin() + 1;
|
|
return result;
|
|
}
|
|
|
|
void getFeatureList(CStringArray &arNodeSpecNames)
|
|
{
|
|
CString sPath = FilePath::getProgramDataFolder() + _T("\\feature.ini");
|
|
if (_taccess(sPath, 0x0) != 0x0) return;
|
|
|
|
std::map<CString, CString> content;
|
|
std::vector<CString> sections(0);
|
|
INITools::getSections(sPath, sections);
|
|
for (size_t i = 0; i < sections.size(); ++i)
|
|
{
|
|
INITools::getSectionContent(sPath, sections[i], content);
|
|
std::map<CString, CString>::iterator it = content.begin();
|
|
for (; it != content.end(); ++it)
|
|
arNodeSpecNames.Add(it->second);
|
|
}
|
|
}
|
|
|
|
void setFeatureList(int idx, LPCTSTR psz)
|
|
{
|
|
if (!psz) return;
|
|
CString sPath = FilePath::getProgramDataFolder() + _T("\\feature.ini");
|
|
if (_taccess(sPath, 0x0) != 0x0) return;
|
|
::WritePrivateProfileString(_T("feature"), TypeConvert::i2s(idx), psz, sPath);
|
|
}
|
|
|
|
void refreshFeatureList(CHeaderCtrl *pHead)
|
|
{
|
|
if (!pHead) return;
|
|
CString sPath = FilePath::getProgramDataFolder() + _T("\\feature.ini");
|
|
|
|
HDITEM hdi;
|
|
TCHAR lpBuffer[256] = {0, };
|
|
|
|
hdi.mask = HDI_TEXT;
|
|
hdi.pszText = lpBuffer;
|
|
hdi.cchTextMax = 256;
|
|
|
|
std::map<CString, CString> mapv;
|
|
for (int i = 1; i < pHead->GetItemCount(); ++i) // i + 1 的原因是跳过第一列舱室名称
|
|
{
|
|
pHead->GetItem(i, &hdi);
|
|
mapv.insert(std::make_pair(TypeConvert::i2s(i - 1), hdi.pszText));
|
|
}
|
|
|
|
INITools::setSectionContent(sPath, _T("feature"), mapv);
|
|
}
|
|
}
|
|
|
|
extern void SplitStrintToArray(LPCTSTR pszDescr,CStringArray& arInfo,TCHAR tcSpace);
|
|
|
|
IMPLEMENT_DYNAMIC(CJDRKDlg, CDialog)
|
|
|
|
CJDRKDlg::CJDRKDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CJDRKDlg::IDD, pParent)
|
|
, m_sFolderName(_T(""))
|
|
, m_sClassName(_T(""))
|
|
, m_sNodeName(_T(""))
|
|
, m_sRem(_T(""))
|
|
, m_sUser(_T(""))
|
|
, m_sPassword(_T(""))
|
|
, m_bUploadToSQLServer(FALSE)
|
|
, m_sNodeSpecName(_T(""))
|
|
{
|
|
m_nField0 = 0;
|
|
m_nField1 = 0;
|
|
m_nField2 = 0;
|
|
m_nField3 = 0;
|
|
}
|
|
|
|
CJDRKDlg::~CJDRKDlg()
|
|
{
|
|
}
|
|
|
|
void CJDRKDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_CBString(pDX, IDC_COMBO1, m_sFolderName);
|
|
DDX_CBString(pDX, IDC_COMBO2, m_sClassName);
|
|
DDX_Text(pDX, IDC_EDIT2, m_sNodeName);
|
|
DDX_Text(pDX, IDC_EDIT3, m_sRem);
|
|
DDX_Control(pDX, IDC_COMBO1, m_wndFolderCombo);
|
|
DDX_Control(pDX, IDC_COMBO2, m_wndClassCombo);
|
|
DDX_Text(pDX, IDC_EDITSA, m_sUser);
|
|
DDX_Text(pDX, IDC_EDITPASSWORD, m_sPassword);
|
|
DDX_Control(pDX, IDC_BTCONNECTTEST, m_wndBT);
|
|
DDX_Check(pDX, IDC_CHECK1, m_bUploadToSQLServer);
|
|
DDX_CBString(pDX, IDC_COMBO3, m_sNodeSpecName);
|
|
DDX_Control(pDX, IDC_LIST1, m_wndListFuncSet);
|
|
DDX_Control(pDX, IDC_COMBO3, m_wndComboNode);
|
|
DDX_Text(pDX, IDC_EDIT1, m_sSQLSrv);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CJDRKDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CJDRKDlg::OnBnClickedOk)
|
|
ON_CBN_SELCHANGE(IDC_COMBO1, &CJDRKDlg::OnCbnSelchangeCombo1)
|
|
ON_BN_CLICKED(IDC_BTCONNECTTEST, &CJDRKDlg::OnBnClickedBtconnecttest)
|
|
ON_BN_CLICKED(IDC_BTINSDB, &CJDRKDlg::OnBnClickedBtinsdb)
|
|
ON_NOTIFY(HDN_ITEMCLICK, 0, &CJDRKDlg::OnLstCtrlHeadClick)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CJDRKDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CString sProductIni = FilePath::GetSysDir() + _T("\\product.ini");
|
|
|
|
TCHAR szVal[MAX_PATH];
|
|
::GetPrivateProfileString(_T("Product"), _T("SQLServer"), _T(""), szVal, MAX_PATH, sProductIni);
|
|
m_sSQLSrv = szVal;
|
|
::GetPrivateProfileString(_T("Product"), _T("UserID"), _T(""), szVal, MAX_PATH, sProductIni);
|
|
m_sUser = szVal;
|
|
::GetPrivateProfileString(_T("Product"), _T("Password"), _T(""), szVal, MAX_PATH, sProductIni);
|
|
m_sPassword = szVal;
|
|
|
|
ReadDbFolderAndClass();
|
|
|
|
//_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
|
|
//"Initial Catalog=pubs;User Id=sa;Password=;");
|
|
/*
|
|
CString sConnect;
|
|
sConnect.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;"),
|
|
m_sSQLSrv,_T("SH-EarthWorm"),m_sUser,m_sPassword);
|
|
|
|
if (m_dbSQRemo.InitSQLServer(sConnect))
|
|
{
|
|
CString sText;
|
|
m_wndBT.GetWindowText(sText);
|
|
sText += _T("√");
|
|
m_wndBT.SetWindowText(sText);
|
|
ReadFromSQLFolderAndClass(&dbSrv);
|
|
}*/
|
|
|
|
m_ImageList.Create(IDB_BITMAP4,16,1,RGB(0, 255, 255));
|
|
m_wndListFuncSet.SetImageList(&m_ImageList,LVSIL_SMALL);
|
|
m_wndListFuncSet.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
|
|
|
m_wndListFuncSet.InsertColumn(0,_T("舱室"),LVCFMT_LEFT,100,100);
|
|
|
|
//CString sNodeSpecNames;
|
|
//sNodeSpecNames.LoadString(IDS_NODESPECNAME);
|
|
|
|
CStringArray arNodeSpecNames;
|
|
//SplitStrintToArray(sNodeSpecNames,arNodeSpecNames,_T(';'));
|
|
getFeatureList(arNodeSpecNames);
|
|
|
|
|
|
CString sRoomName;
|
|
for (int i = 0;i < arNodeSpecNames.GetSize();i++)
|
|
{
|
|
sRoomName = arNodeSpecNames.GetAt(i);
|
|
m_wndListFuncSet.SetColumnItemData(i+1,NULL,ET_Check);
|
|
m_wndListFuncSet.InsertColumn(i+1,sRoomName,LVCFMT_LEFT,80,80);
|
|
}
|
|
|
|
for (int j = 0;j < m_arRoomNames.GetCount();j++)
|
|
{
|
|
sRoomName = m_arRoomNames.GetAt(j);
|
|
|
|
int nItem = m_wndListFuncSet.InsertItem(j,sRoomName,0);
|
|
for (int n = 1;n < m_wndListFuncSet.GetHeaderCtrl()->GetItemCount();n++)
|
|
{
|
|
m_wndListFuncSet.SetItemText(nItem,n,_T("X"),FALSE);
|
|
}
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CJDRKDlg::GetRoomFunSet(CMapStringToString& mapRoomSet)
|
|
{
|
|
CString sRoomName,sSet;
|
|
BOOL bCheck = FALSE;
|
|
CHeaderCtrl* pHeadCtrl = m_wndListFuncSet.GetHeaderCtrl();
|
|
|
|
TCHAR szBuffer[MAX_PATH];
|
|
for (int i = 0;i < m_wndListFuncSet.GetItemCount();i++)
|
|
{
|
|
sRoomName = m_wndListFuncSet.GetItemText(i,0);
|
|
|
|
sSet = _T("");
|
|
for (int j = 1;j < pHeadCtrl->GetItemCount();j++)
|
|
{
|
|
bCheck = m_wndListFuncSet.GetCheck(i,j);
|
|
if (bCheck)
|
|
{
|
|
HDITEM hItem;
|
|
hItem.mask = HDI_TEXT;
|
|
hItem.pszText = szBuffer;
|
|
hItem.cchTextMax = MAX_PATH;
|
|
pHeadCtrl->GetItem(j,&hItem);
|
|
|
|
sSet += hItem.pszText;
|
|
sSet += _T(";");
|
|
}
|
|
}
|
|
sSet.TrimRight(_T(";"));
|
|
|
|
if (sSet.IsEmpty())
|
|
sSet = _T(" ");
|
|
mapRoomSet.SetAt(sRoomName,sSet);
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::SetRoomNames(CStringArray& arRoomNames)
|
|
{
|
|
if (arRoomNames.GetSize() > 0)
|
|
m_arRoomNames.Append(arRoomNames);
|
|
}
|
|
|
|
void CJDRKDlg::ReadDbFolderAndClass()
|
|
{
|
|
// 数据库
|
|
CString path = FilePath::GetSysDir() + STANDARD_DB;
|
|
if (!m_dbSQLite.InitADOServer(path))
|
|
{
|
|
AfxMessageBox(CString(_T("数据库初始化失败,请检查 sys")) + STANDARD_DB + _T("文件是否存在."));
|
|
return;
|
|
}
|
|
|
|
CString sSQL;
|
|
sSQL = _T("select ID,Folder from Aec_Folder order by ID");
|
|
|
|
CUIIValueTable table;
|
|
m_dbSQLite.GetSelData(sSQL,table);
|
|
|
|
int nIndex = 0;
|
|
CStringArray arVals;
|
|
for (int i = 0;i < table.GetTableLogicSize();i++)
|
|
{
|
|
arVals.RemoveAll();
|
|
table.GetValueRecord(i,arVals);
|
|
|
|
nIndex = m_wndFolderCombo.AddString(arVals.GetAt(1));
|
|
m_wndFolderCombo.SetItemData(nIndex,_ttof(arVals.GetAt(0)));
|
|
}
|
|
|
|
if (m_wndFolderCombo.GetCount() > 0)
|
|
{
|
|
m_wndFolderCombo.SetCurSel(0);
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::ReadFromSQLFolderAndClass(CUIISQLiteServer* pDbSrv)
|
|
{
|
|
if (pDbSrv == NULL)
|
|
return;
|
|
|
|
CString sSQL;
|
|
sSQL.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;"),m_sSQLSrv,_T("SH-EarthWorm"),m_sUser,m_sPassword);
|
|
if (!pDbSrv->InitSQLServer(sSQL))
|
|
{
|
|
AfxMessageBox(_T("连接数据失败!请确认服务端数据库安装"));
|
|
return;
|
|
}
|
|
|
|
// 数据库
|
|
sSQL = _T("select ID,Folder from Aec_Folder order by ID");
|
|
|
|
CUIIValueTable table;
|
|
pDbSrv->GetSelData(sSQL,table);
|
|
|
|
int nIndex = 0;
|
|
CStringArray arVals;
|
|
for (int i = 0;i < table.GetTableLogicSize();i++)
|
|
{
|
|
arVals.RemoveAll();
|
|
table.GetValueRecord(i,arVals);
|
|
|
|
nIndex = m_wndFolderCombo.AddString(arVals.GetAt(1));
|
|
m_wndFolderCombo.SetItemData(nIndex,_ttof(arVals.GetAt(0)));
|
|
}
|
|
|
|
if (m_wndFolderCombo.GetCount() > 0)
|
|
{
|
|
m_wndFolderCombo.SetCurSel(0);
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
if (m_sFolderName.IsEmpty() || m_sClassName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("请选择或输入目录名或分类名!"));
|
|
return;
|
|
}
|
|
|
|
if (m_sNodeName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("节点标识不能为空,请输入节点标识!"));
|
|
return;
|
|
}
|
|
|
|
if (m_sNodeSpecName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("节点名称不能为空,请输入节点名称!"));
|
|
return;
|
|
}
|
|
|
|
m_mapRoomSet.RemoveAll();
|
|
GetRoomFunSet(m_mapRoomSet);
|
|
|
|
OnOK();
|
|
}
|
|
|
|
void CJDRKDlg::UpdateToLocalOrSQLDb()
|
|
{
|
|
//电力舱 ---
|
|
if (m_sFolderName.IsEmpty() || m_sClassName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("请选择或输入目录名或分类名!"));
|
|
return;
|
|
}
|
|
|
|
if (m_sNodeName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("节点标识不能为空,请输入节点标识!"));
|
|
return;
|
|
}
|
|
|
|
if (m_sNodeSpecName.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("节点名称不能为空,请输入节点名称!"));
|
|
return;
|
|
}
|
|
|
|
//创建可能的Folder
|
|
int nFolderID = 0,nClassID = 0,nMaxID = 0;
|
|
int nCurSel = m_wndFolderCombo.GetCurSel();
|
|
if (nCurSel != -1)
|
|
{
|
|
nFolderID = (int)m_wndFolderCombo.GetItemData(nCurSel);
|
|
}
|
|
|
|
try
|
|
{
|
|
CStringArray arVals;
|
|
CString sSQL;
|
|
CString sID,sTip;
|
|
|
|
sSQL.Format(_T("select name from Aec_Package where name='%s' and IDClass='%s'"),m_sNodeName, m_sClassName);
|
|
if (!m_dbSQLite.IsSelEmpty(sSQL))
|
|
{
|
|
sTip.Format(_T("节点标识[ %s ]已经存在,请输入其它标识!"),m_sNodeName);
|
|
AfxMessageBox(sTip);
|
|
return;
|
|
}
|
|
|
|
sSQL.Format(_T("select ID from Aec_Folder where Folder='%s'"),m_sFolderName);
|
|
if ( m_dbSQLite.IsSelEmpty(sSQL) )
|
|
{
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Folder order by ID DESC");
|
|
m_dbSQLite.GetSelData(sSQL,arVals);
|
|
|
|
// if (arVals.GetSize() > 0)
|
|
// {
|
|
// nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
// }
|
|
nMaxID = generateID(arVals);
|
|
|
|
sSQL.Format(_T("insert into Aec_Folder (ID,Folder) values (%d,'%s')"),nMaxID,m_sFolderName);
|
|
m_dbSQLite.ExecuteSQL(sSQL);
|
|
|
|
nFolderID = nMaxID;
|
|
}
|
|
else//有
|
|
{
|
|
m_dbSQLite.GetSelData(sSQL,sID);
|
|
nFolderID = _ttoi(sID);
|
|
}
|
|
|
|
//创建可能的Class
|
|
sSQL.Format(_T("select ID from Aec_Class where Class='%s' and IDFolder=%d"),m_sClassName,nFolderID);
|
|
if ( m_dbSQLite.IsSelEmpty(sSQL) )
|
|
{
|
|
CStringArray arVals;
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Class order by ID DESC");
|
|
m_dbSQLite.GetSelData(sSQL,arVals);
|
|
|
|
// if (arVals.GetSize() > 0)
|
|
// {
|
|
// nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
// }
|
|
nMaxID = generateID(arVals);
|
|
|
|
sSQL.Format(_T("insert into Aec_Class (ID,Class,IDFolder) values (%d,'%s',%d)"),nMaxID,m_sClassName,nFolderID);
|
|
m_dbSQLite.ExecuteSQL(sSQL);
|
|
|
|
nClassID = nMaxID;
|
|
}
|
|
else
|
|
{
|
|
m_dbSQLite.GetSelData(sSQL,sID);
|
|
nClassID = _ttoi(sID);
|
|
}
|
|
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Package order by ID DESC");
|
|
m_dbSQLite.GetSelData(sSQL,arVals);
|
|
// if (arVals.GetSize() > 0)
|
|
// {
|
|
// nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
// }
|
|
nMaxID = generateID(arVals);
|
|
|
|
m_sRem += _T("|");
|
|
m_sRem += m_sNodeSpecName;
|
|
|
|
//insert into table (id,name,picture) values (0,'namestr',?)
|
|
sSQL.Format(_T("insert into Aec_Package (id,Name,IDClass,Rem,PackageEW) values (%d,'%s',%d,'%s',?)"),nMaxID,m_sNodeName,nClassID,m_sRem);
|
|
m_dbSQLite.InsertBlob(sSQL,m_sEWMFile);
|
|
|
|
////update table set id=,name='namestr',picture=? where ...
|
|
sSQL.Format(_T("update Aec_Package set PackageHS=? where id=%d"),nMaxID);
|
|
m_dbSQLite.UpdateBlob(sSQL,m_sXDHFile);
|
|
|
|
AfxMessageBox(_T("入库成功完毕!请启动节点管理命令查看入库模型!"));
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
|
|
|
|
CUIISQLiteServer dbSrv;
|
|
//CString sConnect;
|
|
//sConnect.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;"),
|
|
// m_sSQLSrv,_T("SH-EarthWorm"),m_sUser,m_sPassword);
|
|
|
|
CString sConnect;
|
|
sConnect.Format(_T("Driver=SQL Server;Server=%s;Database=%s;User Id=%s;Password=%s;"),
|
|
m_sSQLSrv,_T("SH-EarthWorm"),m_sUser,m_sPassword);
|
|
|
|
BOOL bSuccessSQLSrv = FALSE;
|
|
if (m_bUploadToSQLServer)
|
|
{
|
|
bSuccessSQLSrv = m_dbSQRemo.IsDatabaseOpen();
|
|
if (bSuccessSQLSrv)
|
|
{
|
|
UploadToSQLServer(&m_dbSQRemo);
|
|
}
|
|
else
|
|
{
|
|
bSuccessSQLSrv = m_dbSQRemo.InitADOServer(sConnect);
|
|
if (bSuccessSQLSrv)
|
|
{
|
|
UploadToSQLServer(&m_dbSQRemo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::UploadToSQLServer(CUIISQLiteServer* pSQLSrv)
|
|
{
|
|
if (pSQLSrv == NULL) return;
|
|
|
|
//创建可能的Folder
|
|
int nFolderID = 0,nClassID = 0,nMaxID = 0;
|
|
int nCurSel = m_wndFolderCombo.GetCurSel();
|
|
if (nCurSel != -1)
|
|
{
|
|
nFolderID = (int)m_wndFolderCombo.GetItemData(nCurSel);
|
|
}
|
|
|
|
try
|
|
{
|
|
CStringArray arVals;
|
|
CString sSQL;
|
|
|
|
CString sID,sTip;
|
|
|
|
sSQL.Format(_T("select name from Aec_Package where name='%s'"),m_sNodeName);
|
|
if (!pSQLSrv->IsSelEmpty(sSQL))
|
|
{
|
|
sTip.Format(_T("节点名称[ %s ]已经存在,请输入其它名称!"),m_sNodeName);
|
|
AfxMessageBox(sTip);
|
|
return;
|
|
}
|
|
|
|
sSQL.Format(_T("select ID from Aec_Folder where Folder='%s'"),m_sFolderName);
|
|
if ( pSQLSrv->IsSelEmpty(sSQL) )
|
|
{
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Folder order by ID DESC");
|
|
pSQLSrv->GetSelData(sSQL,arVals);
|
|
|
|
if (arVals.GetSize() > 0)
|
|
{
|
|
nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
}
|
|
|
|
sSQL.Format(_T("insert into Aec_Folder (ID,Folder) values (%d,'%s')"),nMaxID,m_sFolderName);
|
|
pSQLSrv->ExecuteSQL(sSQL);
|
|
|
|
nFolderID = nMaxID;
|
|
}
|
|
else//有
|
|
{
|
|
pSQLSrv->GetSelData(sSQL,sID);
|
|
nFolderID = _ttoi(sID);
|
|
}
|
|
|
|
//创建可能的Class
|
|
sSQL.Format(_T("select ID from Aec_Class where Class='%s' and IDFolder=%d"),m_sClassName,nFolderID);
|
|
if ( pSQLSrv->IsSelEmpty(sSQL) )
|
|
{
|
|
CStringArray arVals;
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Class order by ID DESC");
|
|
pSQLSrv->GetSelData(sSQL,arVals);
|
|
|
|
if (arVals.GetSize() > 0)
|
|
{
|
|
nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
}
|
|
|
|
sSQL.Format(_T("insert into Aec_Class (ID,Class,IDFolder) values (%d,'%s',%d)"),nMaxID,m_sClassName,nFolderID);
|
|
pSQLSrv->ExecuteSQL(sSQL);
|
|
|
|
nClassID = nMaxID;
|
|
}
|
|
else
|
|
{
|
|
pSQLSrv->GetSelData(sSQL,sID);
|
|
nClassID = _ttoi(sID);
|
|
}
|
|
|
|
nMaxID = 0;
|
|
sSQL = _T("select ID from Aec_Package order by ID DESC");
|
|
pSQLSrv->GetSelData(sSQL,arVals);
|
|
if (arVals.GetSize() > 0)
|
|
{
|
|
nMaxID = _ttoi(arVals.GetAt(0)) + 1;
|
|
}
|
|
|
|
m_sRem += _T("|");
|
|
m_sRem += m_sNodeSpecName;
|
|
|
|
//insert into table (id,name,picture) values (0,'namestr',?)
|
|
sSQL.Format(_T("insert into Aec_Package (id,Name,IDClass,Rem,PackageEW) values (%d,'%s',%d,'%s',?)"),nMaxID,m_sNodeName,nClassID,m_sRem);
|
|
pSQLSrv->InsertBlob(sSQL,m_sEWMFile);
|
|
|
|
////update table set id=,name='namestr',picture=? where ...
|
|
sSQL.Format(_T("update Aec_Package set PackageHS=? where id=%d"),nMaxID);
|
|
pSQLSrv->UpdateBlob(sSQL,m_sXDHFile);
|
|
|
|
AfxMessageBox(_T("入库成功完毕!请启动节点管理命令查看入库模型!"));
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::OnCbnSelchangeCombo1()
|
|
{
|
|
int nCurSel = m_wndFolderCombo.GetCurSel();
|
|
if (nCurSel > -1)
|
|
{
|
|
m_wndClassCombo.ResetContent();
|
|
|
|
int nID = (int)m_wndFolderCombo.GetItemData(nCurSel);
|
|
|
|
CString sSQL;
|
|
sSQL.Format(_T("select ID,Class from Aec_Class where IDFolder=%d order by ID"),nID);
|
|
|
|
CUIIValueTable table;
|
|
m_dbSQLite.GetSelData(sSQL,table);
|
|
|
|
int nIndex = 0;
|
|
CStringArray arVals;
|
|
for (int i = 0;i < table.GetTableLogicSize();i++)
|
|
{
|
|
arVals.RemoveAll();
|
|
table.GetValueRecord(i,arVals);
|
|
|
|
nIndex = m_wndClassCombo.AddString(arVals.GetAt(1));
|
|
m_wndClassCombo.SetItemData(nIndex,_ttof(arVals.GetAt(0)));
|
|
}
|
|
|
|
if (m_wndClassCombo.GetCount() > 0)
|
|
{
|
|
m_wndClassCombo.SetCurSel(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::OnBnClickedBtconnecttest()
|
|
{
|
|
UpdateData();
|
|
|
|
CString sVal;
|
|
if (m_sSQLSrv.IsEmpty() || m_sUser.IsEmpty() || m_sPassword.IsEmpty())
|
|
{
|
|
AfxMessageBox(_T("请输入完整的服务器名称、账号、密码!"));
|
|
return;
|
|
}
|
|
|
|
//_bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
|
|
//"Initial Catalog=pubs;User Id=sa;Password=;");
|
|
CString sConnect;
|
|
sConnect.Format(_T("Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s;"),
|
|
m_sSQLSrv,_T("master"),m_sUser,m_sPassword);
|
|
|
|
if (m_dbSQRemo.InitSQLServer(sConnect))
|
|
{
|
|
CString sText;
|
|
m_wndBT.GetWindowText(sText);
|
|
sText += _T("√");
|
|
m_wndBT.SetWindowText(sText);
|
|
AfxMessageBox(_T("数据库连接测试通过!"));
|
|
|
|
CString sFullPath = FilePath::GetSysDir() + _T("\\product.ini");
|
|
|
|
//sqlserver
|
|
::WritePrivateProfileString(_T("Product"), _T("SQLServer"),m_sSQLSrv, sFullPath);
|
|
::WritePrivateProfileString(_T("Product"), _T("Database"), _T("SH_EarthWorm"), sFullPath);
|
|
::WritePrivateProfileString(_T("Product"), _T("UserID"), m_sUser, sFullPath);
|
|
::WritePrivateProfileString(_T("Product"), _T("Password"), m_sPassword, sFullPath);
|
|
|
|
ReadFromSQLFolderAndClass(&m_dbSQRemo);
|
|
}
|
|
else
|
|
{
|
|
int nRes = AfxMessageBox(_T("数据库连接测试没有通过!请重新配置!或64位系统没有安装64位ADO驱动!\n是否需要安装64位ADO驱动?"),MB_YESNO);
|
|
if (nRes == IDYES)
|
|
{
|
|
CString sFullPath = FilePath::GetSysDir() + _T("\\AccessDatabaseEngine_X64\\");
|
|
|
|
//sFullPath += _T("AceRedist.msi");
|
|
ShellExecute(NULL, _T("open"), _T("AceRedist.msi"), NULL, sFullPath, SW_SHOWNORMAL);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::OnBnClickedBtinsdb()
|
|
{
|
|
CString sFullPath = FilePath::GetSysDir() + _T("\\EarthWorm.sql");
|
|
|
|
//连接后执行sql 脚本
|
|
CString sSQL;
|
|
sSQL.Format(_T("Provider=sqloledb;Integrated Security=SSPI;Persist Security Info=False;User ID=%s;Initial Catalog= SH_EarthWorm;Data Source='%s'"),m_sUser,m_sSQLSrv);
|
|
if (!m_dbSQRemo.InitSQLServer(sSQL))
|
|
{
|
|
sSQL.Format(_T("Provider=sqloledb;Integrated Security=SSPI;Persist Security Info=False;User ID=%s;Initial Catalog= master;Data Source='%s'"),m_sUser,m_sSQLSrv);
|
|
if (m_dbSQRemo.InitSQLServer(sSQL))
|
|
{
|
|
//判断数据库是否存在
|
|
sSQL = _T("Create database SH_EarthWorm");
|
|
if ( m_dbSQRemo.ExecuteSQL(sSQL) )
|
|
{
|
|
//创建表
|
|
|
|
CStdioFile file;
|
|
if(!file.Open(sFullPath,CFile::modeRead | CFile::typeText))
|
|
{
|
|
AfxMessageBox(_T("读取管廊数据库安装文件失败!"));
|
|
return;
|
|
}
|
|
|
|
CString strSql,strRead;
|
|
strSql.Empty();
|
|
|
|
while(file.ReadString(strRead))
|
|
{
|
|
if(strRead.Trim().CompareNoCase(_T("GO"))==0)
|
|
{
|
|
if(!strSql.IsEmpty())
|
|
{
|
|
if(! m_dbSQRemo.ExecuteSQL(strSql) )
|
|
{
|
|
return;
|
|
}
|
|
strSql.Empty();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strSql+=_T(" ")+strRead;
|
|
}
|
|
}
|
|
file.Close();
|
|
AfxMessageBox(_T("创建管廊数据库成功!"));
|
|
|
|
//读取web服务器设置
|
|
sFullPath = FilePath::GetSysDir() + _T("\\product.ini");
|
|
|
|
//sqlserver
|
|
::WritePrivateProfileString(_T("Product"), _T("SQLServer"),m_sSQLSrv, sFullPath);
|
|
::WritePrivateProfileString(_T("Product"), _T("UserID"), m_sUser, sFullPath);
|
|
::WritePrivateProfileString(_T("Product"), _T("Password"), m_sPassword, sFullPath);
|
|
|
|
}
|
|
else//创建失败
|
|
{
|
|
AfxMessageBox(_T("创建管廊数据库失败!或连接数据库服务器失败!"));
|
|
}
|
|
}
|
|
}
|
|
else //数据库已经存在
|
|
{
|
|
AfxMessageBox(_T("管廊数据库已经存在!不需要创建!"));
|
|
}
|
|
}
|
|
|
|
void CJDRKDlg::OnLstCtrlHeadClick(NMHDR * pNMHDR, LRESULT * pResult)
|
|
{
|
|
NMHEADER *pHdr = (NMHEADER*)pNMHDR;
|
|
if (!pHdr) return;
|
|
|
|
if (!pHdr->iItem) return;
|
|
|
|
CHeaderCtrl *pHeader = m_wndListFuncSet.GetHeaderCtrl();
|
|
|
|
HDITEM hdi;
|
|
TCHAR lpBuffer[256];
|
|
|
|
hdi.mask = HDI_TEXT;
|
|
hdi.pszText = lpBuffer;
|
|
hdi.cchTextMax = 256;
|
|
|
|
pHeader->GetItem(pHdr->iItem, &hdi);
|
|
|
|
CPoint pt;
|
|
GetCursorPos(&pt);
|
|
|
|
CMenu menu;
|
|
menu.CreatePopupMenu();
|
|
|
|
menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, IDM_JDHEAD_MOD, _T("修改(&M)"));
|
|
menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, IDM_JDHEAD_ADD, _T("添加(&A)"));
|
|
menu.AppendMenu(MF_BYCOMMAND | MF_STRING | MF_ENABLED, IDM_JDHEAD_DEL, _T("删除(&D)"));
|
|
|
|
int nID = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, pHeader);
|
|
switch (nID)
|
|
{
|
|
case IDM_JDHEAD_MOD:
|
|
{
|
|
CString sName(lpBuffer);
|
|
if (!CoreTools::getNameByDialog(_T("修改功能名称"), _T("功能:"), sName)) return;
|
|
if (sName.GetLength() >= 256)
|
|
{
|
|
AfxMessageBox(_T("功能名称过长,请小于256个字符。"));
|
|
return;
|
|
}
|
|
::memset(hdi.pszText, 0, sizeof(TCHAR) * hdi.cchTextMax);
|
|
_tcscpy(hdi.pszText, sName);
|
|
pHeader->SetItem(pHdr->iItem, &hdi);
|
|
break;
|
|
}
|
|
case IDM_JDHEAD_ADD:
|
|
{
|
|
CString sName(_T("新功能"));
|
|
if (!CoreTools::getNameByDialog(_T("添加功能名称"), _T("功能:"), sName)) return;
|
|
m_wndListFuncSet.InsertColumn(pHdr->iItem + 1, sName, LVCFMT_LEFT, 80, 80);
|
|
int nItem(0);
|
|
for (int i = 0; i < m_arRoomNames.GetCount(); ++i)
|
|
m_wndListFuncSet.SetItemText(i, pHdr->iItem + 1, _T("X"), FALSE);
|
|
|
|
break;
|
|
}
|
|
case IDM_JDHEAD_DEL:
|
|
{
|
|
m_wndListFuncSet.DeleteColumn(pHdr->iItem);
|
|
break;
|
|
}
|
|
default: return;
|
|
}
|
|
refreshFeatureList(pHeader);
|
|
}
|