319 lines
7.7 KiB
C++
319 lines
7.7 KiB
C++
// LayerDefineDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
//#include "arxtools.h"
|
|
|
|
#include "LayerDefineDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLayerDefineDlg dialog
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// 定义图层
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
extern TARCH_IMPEXP int g_nProductId;
|
|
|
|
void DefineLayer()
|
|
{
|
|
CAcModuleResourceOverride exm;
|
|
CLayerDefineDlg dlg;
|
|
if(dlg.DoModal() != IDOK)
|
|
return;
|
|
|
|
}
|
|
|
|
CLayerDefineDlg::CLayerDefineDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CLayerDefineDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CLayerDefineDlg)
|
|
m_csTch = _T("");
|
|
m_csTwt = _T("");
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void CLayerDefineDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CLayerDefineDlg)
|
|
DDX_Control(pDX, IDC_TWT_LAYER, m_listTwt);
|
|
DDX_Control(pDX, IDC_TCH_LAYER, m_listTch);
|
|
DDX_Text(pDX, IDC_EDIT_NEW1, m_csTch);
|
|
DDX_Text(pDX, IDC_EDIT_NEW2, m_csTwt);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CLayerDefineDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CLayerDefineDlg)
|
|
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
|
|
ON_BN_CLICKED(IDC_BUTTON_ADD2, OnButtonAdd2)
|
|
ON_BN_CLICKED(IDC_BUTTON_DEL2, OnButtonDel2)
|
|
ON_BN_CLICKED(IDC_BUTTON_PICK1, OnButtonPick1)
|
|
ON_BN_CLICKED(IDC_BUTTON_PICK2, OnButtonPick2)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CLayerDefineDlg message handlers
|
|
|
|
BOOL CLayerDefineDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_listTch.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
|
m_listTch.InsertColumn ( 0, _T("图层"), LVCFMT_LEFT, 150 );
|
|
|
|
m_listTwt.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
|
m_listTwt.InsertColumn ( 0, _T("图层"), LVCFMT_LEFT, 150 );
|
|
|
|
ReadDbf();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
void CLayerDefineDlg::ReadDbf()
|
|
{
|
|
XString xsDbfFile;
|
|
if(!FindFile(_T("userlayer.dbf"), xsDbfFile)) {
|
|
MessageBox(_T("对不起,没有发现userlayer.dbf文件!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(xsDbfFile);
|
|
if(!pTable) {
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
|
AfxMessageBox(csTmp);
|
|
|
|
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
|
return;
|
|
}
|
|
|
|
m_listTch.DeleteAllItems();
|
|
m_listTwt.DeleteAllItems();
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
int id(0);
|
|
CString sName, sComment;
|
|
GET_FIELD(pTable, _T("product"), id);
|
|
GET_FIELD(pTable, _T("name"), sName);
|
|
GET_FIELD(pTable, _T("des"), sComment);
|
|
|
|
if(id == 1){
|
|
int len = m_listTch.GetItemCount();
|
|
m_listTch.InsertItem ( len, sName, 0 );
|
|
}
|
|
else if(id == g_nProductId){
|
|
int len = m_listTwt.GetItemCount();
|
|
m_listTwt.InsertItem ( len, sName, 0 );
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonDel()
|
|
{
|
|
UpdateData(TRUE);
|
|
int nSel = m_listTch.GetSelectionMark();
|
|
if(nSel < 0)
|
|
return;
|
|
CString csName = m_listTch.GetItemText(nSel, 0);
|
|
m_listTch.DeleteItem(nSel);
|
|
|
|
XString xsDbfFile;
|
|
if(!FindFile(_T("userlayer.dbf"), xsDbfFile)) {
|
|
MessageBox(_T("对不起,没有发现userlayer.dbf文件!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(xsDbfFile);
|
|
if(!pTable) {
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
|
AfxMessageBox(csTmp);
|
|
|
|
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
|
return;
|
|
}
|
|
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
int id(0);
|
|
CString sName, sComment;
|
|
GET_FIELD(pTable, _T("product"), id);
|
|
GET_FIELD(pTable, _T("name"), sName);
|
|
if(_tcsicmp(sName, csName) == 0 && id == 1){
|
|
pTable->Delete();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonAdd()
|
|
{
|
|
UpdateData(TRUE);
|
|
if(m_csTch == "")
|
|
return;
|
|
int len = m_listTch.GetItemCount();
|
|
for(int i=0;i<len;i++){
|
|
CString csTmp = m_listTch.GetItemText(i, 0);
|
|
if(csTmp == m_csTch){
|
|
return;
|
|
}
|
|
}
|
|
m_listTch.InsertItem ( len, m_csTch, 0 );
|
|
|
|
XString xsDbfFile;
|
|
if(!FindFile(_T("userlayer.dbf"), xsDbfFile)) {
|
|
MessageBox(_T("对不起,没有发现userlayer.dbf文件!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(xsDbfFile);
|
|
if(!pTable) {
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
|
AfxMessageBox(csTmp);
|
|
|
|
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
|
return;
|
|
}
|
|
pTable->AppendBegin();
|
|
SET_FIELD(pTable, _T("product"), 1);
|
|
SET_FIELD(pTable, _T("name"), (const TCHAR*)m_csTch);
|
|
pTable->AppendEnd();
|
|
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonAdd2()
|
|
{
|
|
UpdateData(TRUE);
|
|
if(m_csTwt == "")
|
|
return;
|
|
int len = m_listTwt.GetItemCount();
|
|
for(int i=0;i<len;i++){
|
|
CString csTmp = m_listTwt.GetItemText(i, 0);
|
|
if(csTmp == m_csTwt){
|
|
return;
|
|
}
|
|
}
|
|
m_listTwt.InsertItem ( len, m_csTwt, 0 );
|
|
|
|
XString xsDbfFile;
|
|
if(!FindFile(_T("userlayer.dbf"), xsDbfFile)) {
|
|
MessageBox(_T("对不起,没有发现userlayer.dbf文件!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(xsDbfFile);
|
|
if(!pTable) {
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
|
AfxMessageBox(csTmp);
|
|
|
|
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
|
return;
|
|
}
|
|
pTable->AppendBegin();
|
|
SET_FIELD(pTable, _T("product"), g_nProductId);
|
|
SET_FIELD(pTable, _T("name"), (const TCHAR*)m_csTwt);
|
|
pTable->AppendEnd();
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonDel2()
|
|
{
|
|
UpdateData(TRUE);
|
|
int nSel = m_listTwt.GetSelectionMark();
|
|
if(nSel < 0)
|
|
return;
|
|
CString csName = m_listTwt.GetItemText(nSel, 0);
|
|
m_listTwt.DeleteItem(nSel);
|
|
|
|
XString xsDbfFile;
|
|
if(!FindFile(_T("userlayer.dbf"), xsDbfFile)) {
|
|
MessageBox(_T("对不起,没有发现userlayer.dbf文件!"));
|
|
return;
|
|
}
|
|
CodeBase db;
|
|
XDbfTable *pTable = db.Open(xsDbfFile);
|
|
if(!pTable) {
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
|
AfxMessageBox(csTmp);
|
|
|
|
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
|
return;
|
|
}
|
|
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
int id(0);
|
|
CString sName, sComment;
|
|
GET_FIELD(pTable, _T("product"), id);
|
|
GET_FIELD(pTable, _T("name"), sName);
|
|
if(_tcsicmp(sName, csName) == 0 && id == g_nProductId){
|
|
pTable->Delete();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CLayerDefineDlg::HideDialog(BOOL Flag)
|
|
{
|
|
if (Flag) {
|
|
GetParent()->EnableWindow(TRUE);
|
|
GetParent()->SetFocus();
|
|
GetParent()->SetActiveWindow();
|
|
ShowWindow(SW_HIDE);
|
|
}
|
|
else {
|
|
GetParent()->EnableWindow(FALSE);
|
|
EnableWindow(TRUE);
|
|
SetActiveWindow();
|
|
ShowWindow(SW_SHOW);
|
|
}
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonPick1()
|
|
{
|
|
HideDialog(TRUE);
|
|
Entity entSel;
|
|
|
|
if(SelectEntity(_T("\n请选择指定图层的图元:<退出>"), entSel, RBList()) == RTNORM){
|
|
TCHAR szLay[256];
|
|
entSel.GetData(8, szLay);
|
|
m_csTch = szLay;
|
|
HideDialog(FALSE);
|
|
UpdateData(FALSE);
|
|
return;
|
|
}
|
|
HideDialog(FALSE);
|
|
|
|
}
|
|
|
|
void CLayerDefineDlg::OnButtonPick2()
|
|
{
|
|
HideDialog(TRUE);
|
|
Entity entSel;
|
|
|
|
if(SelectEntity(_T("\n请选择指定图层的图元:<退出>"), entSel, RBList()) == RTNORM){
|
|
TCHAR szLay[256];
|
|
entSel.GetData(8, szLay);
|
|
m_csTwt = szLay;
|
|
HideDialog(FALSE);
|
|
UpdateData(FALSE);
|
|
return;
|
|
}
|
|
HideDialog(FALSE);
|
|
|
|
}
|