2026-10-04 00:04:20 +08:00
|
|
|
#include "StdAfx.h"
|
2026-09-28 15:28:50 +08:00
|
|
|
#include "Resource.h"
|
|
|
|
|
#include "DlgParamImport.h"
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
#undef THIS_FILE
|
|
|
|
|
static char THIS_FILE[] = __FILE__;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
KTImportService::KTImportService()
|
|
|
|
|
: KTParamService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KTImportService::~KTImportService()
|
|
|
|
|
{
|
|
|
|
|
ReleaseService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL KTImportService::InitService(LPCTSTR pszDatabase)
|
|
|
|
|
{
|
2026-10-04 00:04:20 +08:00
|
|
|
// 检查数据库已经初始化(已经连接到数据库)
|
2026-09-28 15:28:50 +08:00
|
|
|
|
|
|
|
|
KTParamService::InitService();
|
|
|
|
|
|
|
|
|
|
if (!m_pParamDatabase) return FALSE;
|
|
|
|
|
|
|
|
|
|
int iFlag = 0;
|
|
|
|
|
CStringArray arsTables;
|
|
|
|
|
m_pParamDatabase->GetDbTableNameArray(arsTables);
|
|
|
|
|
int iPos = arsTables.GetSize();
|
|
|
|
|
while ((--iPos) >= 0)
|
|
|
|
|
{
|
|
|
|
|
if (arsTables[iPos].CompareNoCase(_T("Class")) == 0)
|
|
|
|
|
iFlag |= 0x1;
|
|
|
|
|
else if (arsTables[iPos].CompareNoCase(_T("Attribute")) == 0)
|
|
|
|
|
iFlag |= 0x2;
|
|
|
|
|
else if (arsTables[iPos].CompareNoCase(_T("Rules")) == 0)
|
|
|
|
|
iFlag |= 0x4;
|
|
|
|
|
else if (arsTables[iPos].CompareNoCase(_T("Expression")) == 0)
|
|
|
|
|
iFlag |= 0x8;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-04 00:04:20 +08:00
|
|
|
// 返回成功状态
|
2026-09-28 15:28:50 +08:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL KTImportService::IsDatabaseOpen()
|
|
|
|
|
{
|
|
|
|
|
return (NULL != m_pParamDatabase);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CDlgParamImport::CDlgParamImport(CTreeCtrl* pTree, CWnd* pParent)
|
|
|
|
|
: CDialog(CDlgParamImport::IDD, pParent), m_pTree(pTree)
|
|
|
|
|
{
|
|
|
|
|
//{{AFX_DATA_INIT(CDlgParamImport)
|
|
|
|
|
//}}AFX_DATA_INIT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDlgParamImport::DoDataExchange(CDataExchange* pDX)
|
|
|
|
|
{
|
|
|
|
|
CDialog::DoDataExchange(pDX);
|
|
|
|
|
//{{AFX_DATA_MAP(CDlgParamImport)
|
|
|
|
|
DDX_Control(pDX, IDC_EDT_CODE, m_wndEdtCode);
|
|
|
|
|
DDX_Control(pDX, IDC_EDT_NAME, m_wndEdtName);
|
|
|
|
|
DDX_Control(pDX, IDOK, m_wndBtnImport);
|
|
|
|
|
DDX_Control(pDX, IDC_EDT_FILE, m_wndEdtFile);
|
|
|
|
|
DDX_Control(pDX, IDC_CMB_CLASS, m_wndCmbClass);
|
|
|
|
|
//}}AFX_DATA_MAP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDlgParamImport, CDialog)
|
|
|
|
|
//{{AFX_MSG_MAP(CDlgParamImport)
|
|
|
|
|
ON_BN_CLICKED(IDC_BTN_BROWSE, OnBtnBrowse)
|
|
|
|
|
ON_CBN_SELENDOK(IDC_CMB_CLASS, OnSelendokCmbClass)
|
|
|
|
|
//}}AFX_MSG_MAP
|
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
|
|
BOOL CDlgParamImport::OnInitDialog()
|
|
|
|
|
{
|
|
|
|
|
CDialog::OnInitDialog();
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDlgParamImport::OnBtnBrowse()
|
|
|
|
|
{
|
|
|
|
|
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST,
|
|
|
|
|
_T("Access Database file(*.mdb)|*.mdb||"));
|
|
|
|
|
if (IDOK == dlg.DoModal())
|
|
|
|
|
{
|
|
|
|
|
m_wndCmbClass.ResetContent();
|
|
|
|
|
m_wndEdtFile.SetWindowText(_T(""));
|
|
|
|
|
|
|
|
|
|
if (m_cParamService.InitService(dlg.GetPathName()))
|
|
|
|
|
{
|
|
|
|
|
CString sRoot;
|
|
|
|
|
sRoot.LoadString(IDS_CLASSROOTNAME);
|
|
|
|
|
m_wndCmbClass.AddString(sRoot);
|
|
|
|
|
|
|
|
|
|
CWaitCursor waiter;
|
|
|
|
|
|
|
|
|
|
OnInitClassList(0, NULL);
|
|
|
|
|
|
|
|
|
|
m_wndEdtFile.SetWindowText(dlg.GetPathName());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CString sTitle, sMsg;
|
|
|
|
|
GetWindowText(sTitle);
|
|
|
|
|
sMsg.LoadString(IDS_INVALIDDATABASE);
|
|
|
|
|
MessageBox(sMsg, sTitle, MB_ICONINFORMATION);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDlgParamImport::OnInitClassList(ULONG lUpId, LPCTSTR pszPrefix)
|
|
|
|
|
{
|
|
|
|
|
if (!m_cParamService.IsDatabaseOpen())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
KTParamClassArray arItems;
|
|
|
|
|
m_cParamService.GetSubClassItems(lUpId, arItems);
|
|
|
|
|
int iSize = arItems.GetSize() - 1;
|
|
|
|
|
if (iSize < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CString sPrefix1(pszPrefix), sPrefix2(pszPrefix);
|
2026-10-04 00:04:20 +08:00
|
|
|
sPrefix1 += _T("├"); sPrefix2 += _T("│");
|
2026-09-28 15:28:50 +08:00
|
|
|
|
|
|
|
|
int iIndex;
|
|
|
|
|
for (int i = 0; i < iSize; i++)
|
|
|
|
|
{
|
|
|
|
|
iIndex = m_wndCmbClass.AddString(sPrefix1 + arItems[i].GetName());
|
|
|
|
|
ASSERT(iIndex >= 0);
|
|
|
|
|
|
|
|
|
|
lUpId = arItems[i].GetId();
|
|
|
|
|
m_wndCmbClass.SetItemData(iIndex, lUpId);
|
|
|
|
|
|
|
|
|
|
OnInitClassList(lUpId, sPrefix2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sPrefix1 = pszPrefix; sPrefix2 = pszPrefix;
|
2026-10-04 00:04:20 +08:00
|
|
|
sPrefix1 += _T("└"); sPrefix2 += _T(" ");
|
2026-09-28 15:28:50 +08:00
|
|
|
|
|
|
|
|
iIndex = m_wndCmbClass.AddString(sPrefix1 + arItems[i].GetName());
|
|
|
|
|
ASSERT(iIndex >= 0);
|
|
|
|
|
|
|
|
|
|
lUpId = arItems[i].GetId();
|
|
|
|
|
m_wndCmbClass.SetItemData(iIndex, lUpId);
|
|
|
|
|
|
|
|
|
|
OnInitClassList(lUpId, sPrefix2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDlgParamImport::OnSelendokCmbClass()
|
|
|
|
|
{
|
|
|
|
|
int iSel = m_wndCmbClass.GetCurSel();
|
|
|
|
|
ULONG lId = (iSel < 0 ? 0 : m_wndCmbClass.GetItemData(iSel));
|
|
|
|
|
m_wndBtnImport.EnableWindow(0 != lId);
|
|
|
|
|
m_wndEdtName.EnableWindow(0 != lId);
|
|
|
|
|
m_wndEdtCode.EnableWindow(0 != lId);
|
|
|
|
|
if (0 == lId)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
KTParamClass data;
|
|
|
|
|
m_cParamService.GetClassItemById(lId, data);
|
|
|
|
|
|
|
|
|
|
m_wndEdtName.SetWindowText(data.GetName());
|
|
|
|
|
m_wndEdtCode.SetWindowText(data.GetCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HTREEITEM CDlgParamImport::OnImportClass(ULONG& lId)
|
|
|
|
|
{
|
|
|
|
|
KTParamClass cClassData;
|
|
|
|
|
m_cParamService.GetClassItemById(lId, cClassData);
|
|
|
|
|
|
|
|
|
|
HTREEITEM hItem = m_pTree->GetChildItem(TVI_ROOT);
|
|
|
|
|
ULONG lUpId = cClassData.GetUpId();
|
|
|
|
|
if (0 != lUpId)
|
|
|
|
|
{
|
|
|
|
|
hItem = OnImportClass(lUpId);
|
|
|
|
|
if (NULL == hItem || 0 == lUpId)
|
|
|
|
|
return NULL;
|
|
|
|
|
cClassData.SetUpId(lUpId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lId = cClassData.GetId();
|
|
|
|
|
KTParamAttributePtrArray arpAttrData;
|
|
|
|
|
m_cParamService.GetAttributeItems(lId, arpAttrData);
|
|
|
|
|
KTParamRulePtrArray arpRuleData;
|
|
|
|
|
m_cParamService.GetRuleItems(lId, arpRuleData);
|
|
|
|
|
|
|
|
|
|
KTParamService* pService = GetKTParamService();
|
|
|
|
|
ASSERT(NULL != pService);
|
|
|
|
|
|
|
|
|
|
KTParamClass cCurClass;
|
|
|
|
|
if (pService->GetClassItemByCode(cClassData.GetCode(), cCurClass))
|
|
|
|
|
cClassData.SetId(cCurClass.GetId());
|
|
|
|
|
else
|
|
|
|
|
cClassData.SetId(NULL);
|
|
|
|
|
|
|
|
|
|
KTParamRule* pRule;
|
|
|
|
|
int iPos = arpRuleData.GetSize();
|
|
|
|
|
while ((--iPos) >= 0)
|
|
|
|
|
{
|
|
|
|
|
pRule = arpRuleData[iPos];
|
|
|
|
|
m_cParamService.GetExpressionItems(pRule->GetId(), pRule->m_arExpression);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-04 00:04:20 +08:00
|
|
|
// 更新类型数据
|
2026-09-28 15:28:50 +08:00
|
|
|
BOOL bSuccess = pService->UpdateClassData(&cClassData);
|
|
|
|
|
if (bSuccess && 0 != (lId = cClassData.GetId()))
|
|
|
|
|
{
|
2026-10-04 00:04:20 +08:00
|
|
|
// 更新属性数据
|
2026-09-28 15:28:50 +08:00
|
|
|
bSuccess &= pService->UpdateAttributeData(lId, arpAttrData);
|
2026-10-04 00:04:20 +08:00
|
|
|
// 更新约束数据
|
2026-09-28 15:28:50 +08:00
|
|
|
bSuccess &= pService->UpdateRuleData(lId, arpRuleData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bSuccess)
|
|
|
|
|
{
|
|
|
|
|
HTREEITEM hSub = m_pTree->GetChildItem(hItem);
|
|
|
|
|
while (NULL != hSub)
|
|
|
|
|
{
|
|
|
|
|
if (lId == m_pTree->GetItemData(hSub))
|
|
|
|
|
break;
|
|
|
|
|
hSub = m_pTree->GetNextSiblingItem(hSub);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NULL == hSub)
|
|
|
|
|
{
|
|
|
|
|
hItem = m_pTree->InsertItem(cClassData.GetName(), hItem);
|
|
|
|
|
m_pTree->SetItemData(hItem, lId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hItem = hSub;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KTParamAttribute* pAttr;
|
|
|
|
|
iPos = arpAttrData.GetSize();
|
|
|
|
|
while ((--iPos) >= 0)
|
|
|
|
|
{
|
|
|
|
|
pAttr = arpAttrData[iPos];
|
|
|
|
|
delete pAttr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iPos = arpRuleData.GetSize();
|
|
|
|
|
while ((--iPos) >= 0)
|
|
|
|
|
{
|
|
|
|
|
pRule = arpRuleData[iPos];
|
|
|
|
|
delete pRule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (bSuccess ? hItem : NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CDlgParamImport::OnOK()
|
|
|
|
|
{
|
|
|
|
|
int iSel = m_wndCmbClass.GetCurSel();
|
|
|
|
|
ULONG lId = (iSel < 0 ? 0 : m_wndCmbClass.GetItemData(iSel));
|
|
|
|
|
if (0 == lId)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CWaitCursor waiter;
|
|
|
|
|
|
|
|
|
|
OnImportClass(lId);
|
|
|
|
|
|
|
|
|
|
m_wndBtnImport.EnableWindow(FALSE);
|
|
|
|
|
}
|