496 lines
11 KiB
C++
496 lines
11 KiB
C++
// GridSheetDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "GridSheetDlg.h"
|
|
#include "chardlg.h"//add by whl
|
|
#include "TgAs.h"
|
|
#include "Project.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
TARCH_IMPEXP bool FindRT_MANIFEST();
|
|
#define MM2PIXEL 3.0
|
|
|
|
bool TSheetGrid::OnBeforeInsertCol(long i,WDGridCol*&pNewCol)
|
|
{
|
|
if(m_bNew)
|
|
return false;
|
|
m_pSheet->AddColumnAt(i);
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforeDeleteCol()
|
|
{
|
|
if(m_bNew)
|
|
return false;
|
|
|
|
for(long i=GetColSelNum()-1;i>=0;i--)
|
|
{
|
|
long index=GetSelCol(i).GetIndex();
|
|
if(index<m_pSheet->GetColumnNum())
|
|
m_pSheet->RemoveColumn(index);
|
|
}
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforeInsertRow(long i,WDGridRow*&pNewRow)
|
|
{
|
|
if(m_bNew)
|
|
{
|
|
if(i>=m_nRowNum)
|
|
m_pSheet->AddRowAt(i);
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
m_pSheet->AddRowAt(i);
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforePaste(long i)
|
|
{
|
|
if(m_bNew)
|
|
return false;
|
|
|
|
for(long j=0;j<pasteList.GetLength();j++)
|
|
m_pSheet->AddRowAt(i);
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforeClip()
|
|
{
|
|
if(m_bNew)
|
|
return false;
|
|
|
|
for(long i=GetRowSelNum()-1;i>=0;i--)
|
|
{
|
|
long index=GetSelRow(i).GetIndex();
|
|
if(index<m_pSheet->GetRowNum())
|
|
m_pSheet->RemoveRow(index);
|
|
}
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforeDeleteRow()
|
|
{
|
|
for(long i=GetRowSelNum()-1;i>=0;i--)
|
|
{
|
|
long index=GetSelRow(i).GetIndex();
|
|
if(m_bNew)
|
|
{
|
|
if(index<m_pSheet->GetRowNum()&&index>m_nRowNum)
|
|
m_pSheet->RemoveRow(index);
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if(index<m_pSheet->GetRowNum())
|
|
m_pSheet->RemoveRow(index);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TSheetGrid::Read(TDbSheet*pSheet)
|
|
{
|
|
m_pSheet=pSheet;
|
|
|
|
Clear();
|
|
while(GetColNum()>0)
|
|
DelCol(0);
|
|
|
|
int nColumn=m_pSheet->GetColumnNum();
|
|
for(int i=0; i<nColumn; i++)
|
|
AppendCol(_T(""),AS_INT(m_pSheet->GetColumn(i)->GetWidth()*MM2PIXEL));
|
|
|
|
SetRowNum(m_pSheet->GetRowNum());
|
|
|
|
for(i=0;i<m_pSheet->GetRowNum();i++)
|
|
for(int j=0;j<m_pSheet->GetColumnNum();j++)
|
|
GetCell(i,j).SetText((*m_pSheet)(i,j)->GetText());
|
|
}
|
|
void TSheetGrid::Save()
|
|
{
|
|
m_pSheet->assertWriteEnabled();
|
|
if(m_pSheet->GetRowNum()<GetRowNum())
|
|
{
|
|
while(m_pSheet->GetRowNum()<GetRowNum())
|
|
m_pSheet->AddRowAt(m_pSheet->GetRowNum());
|
|
|
|
}
|
|
else
|
|
{
|
|
while(m_pSheet->GetRowNum()>GetRowNum())
|
|
m_pSheet->RemoveRow(m_pSheet->GetRowNum()-1);
|
|
}
|
|
|
|
if(m_pSheet->GetColumnNum()<GetColNum())
|
|
{
|
|
while(m_pSheet->GetColumnNum()<GetColNum())
|
|
m_pSheet->AddColumnAt(m_pSheet->GetColumnNum());
|
|
|
|
}
|
|
else
|
|
{
|
|
while(m_pSheet->GetColumnNum()>GetColNum())
|
|
m_pSheet->RemoveColumn(m_pSheet->GetColumnNum()-1);
|
|
}
|
|
|
|
for(long i=0;i<GetRowNum();i++)
|
|
for(long j=0;j<GetColNum();j++)
|
|
{
|
|
TGridCell*pCell=(*m_pSheet)(i,j);
|
|
pCell->SetText(GetCell(i,j).GetText());
|
|
}
|
|
}
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridSheetDlg dialog
|
|
IMPLEMENT_DYNAMIC(CGridSheetDlg, CAcUiDialog)
|
|
|
|
CGridSheetDlg::CGridSheetDlg(TDbSheet *pSheet, CWnd* pParent /*=NULL*/)
|
|
: CAcUiDialog(CGridSheetDlg::IDD, pParent)
|
|
{
|
|
m_pSheet=pSheet;
|
|
m_bInit=FALSE;
|
|
m_nOldSizeX=520;
|
|
m_nOldSizeY=380;
|
|
|
|
m_bNew=FALSE;
|
|
m_nRowNum=0;
|
|
}
|
|
|
|
void CGridSheetDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CGridSheetDlg)
|
|
DDX_Control(pDX, IDC_GRID, m_grid);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CGridSheetDlg, CAcUiDialog)
|
|
//{{AFX_MSG_MAP(CGridSheetDlg)
|
|
ON_WM_SIZE()
|
|
ON_WM_CREATE()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridSheetDlg message handlers
|
|
|
|
|
|
|
|
|
|
//布置Grid的界面
|
|
void CGridSheetDlg::ConfigGrid()
|
|
{
|
|
if(!m_pSheet) return;
|
|
|
|
//modify by xlc on 090618 解决表格全屏编辑无法删除列的问题
|
|
m_grid.m_bNew=m_bNew;
|
|
|
|
if(m_bNew)
|
|
{
|
|
m_grid.m_nRowNum=m_nRowNum;
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetRowPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.SetNoPaste();
|
|
}
|
|
m_grid.Read(m_pSheet);
|
|
m_grid.SetModify(false);
|
|
}
|
|
|
|
BOOL CGridSheetDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
|
|
{
|
|
OnOK();
|
|
return TRUE;
|
|
}
|
|
return CAcUiDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
int intcmp(const int *i, const int *j)
|
|
{
|
|
if(*i < *j)
|
|
return -1;
|
|
else if(*i > *j)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
void CGridSheetDlg::ResetSize()
|
|
{
|
|
CRect rectGrid, rectCancel, rectOk,rectNewStyle,rectOldStyle;
|
|
m_grid.GetWindowRect(rectGrid);
|
|
ScreenToClient(rectGrid);
|
|
CWnd *pCancel = GetDlgItem(IDCANCEL);
|
|
CWnd *pOk = GetDlgItem(IDOK);
|
|
CWnd *pNewStyle=GetDlgItem(IDC_NEW_STYLE);
|
|
CWnd *pOldStyle=GetDlgItem(IDC_OLD_STYLE);
|
|
pCancel->GetWindowRect(rectCancel);
|
|
ScreenToClient(rectCancel);
|
|
pOk->GetWindowRect(rectOk);
|
|
ScreenToClient(rectOk);
|
|
pNewStyle->GetWindowRect(rectNewStyle);
|
|
ScreenToClient(rectNewStyle);
|
|
pOldStyle->GetWindowRect(rectOldStyle);
|
|
ScreenToClient(rectOldStyle);
|
|
|
|
long nIncY = sizeDlg.cy - m_nOldSizeY; //380; // 对话框绝对尺寸
|
|
long nIncX = sizeDlg.cx - m_nOldSizeX; //520;
|
|
|
|
m_grid.MoveWindow(rectGrid.left, rectGrid.top,
|
|
rectGrid.Width() + nIncX, rectGrid.Height() + nIncY);
|
|
|
|
pCancel->MoveWindow(rectCancel.left, rectCancel.top + nIncY,
|
|
rectCancel.Width(), rectCancel.Height());
|
|
pOk->MoveWindow(rectOk.left, rectOk.top + nIncY,
|
|
rectOk.Width(), rectOk.Height());
|
|
pNewStyle->MoveWindow(rectNewStyle.left,rectNewStyle.top+nIncY,
|
|
rectNewStyle.Width(),rectNewStyle.Height());
|
|
pOldStyle->MoveWindow(rectOldStyle.left,rectOldStyle.top+nIncY,
|
|
rectOldStyle.Width(),rectOldStyle.Height());
|
|
}
|
|
|
|
void CGridSheetDlg::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
|
|
//CAcUiDialog::OnSize(nType, cx, cy);
|
|
if(m_bInit && (!nType || nType==SIZE_MAXIMIZED)) {
|
|
CRect rectGrid;
|
|
m_grid.GetWindowRect(rectGrid);
|
|
ScreenToClient(rectGrid);
|
|
CSize sizeOld = sizeDlg;
|
|
sizeDlg.cx = cx;
|
|
sizeDlg.cy = cy;
|
|
|
|
CRect rectCancel, rectOk,rectNewStyle,rectOldStyle;
|
|
CWnd *pCancel = GetDlgItem(IDCANCEL);
|
|
CWnd *pOk = GetDlgItem(IDOK);
|
|
CWnd *pNewStyle=GetDlgItem(IDC_NEW_STYLE);
|
|
CWnd *pOldStyle=GetDlgItem(IDC_OLD_STYLE);
|
|
pCancel->GetWindowRect(rectCancel);
|
|
ScreenToClient(rectCancel);
|
|
pOk->GetWindowRect(rectOk);
|
|
ScreenToClient(rectOk);
|
|
pNewStyle->GetWindowRect(rectNewStyle);
|
|
ScreenToClient(rectNewStyle);
|
|
pOldStyle->GetWindowRect(rectOldStyle);
|
|
ScreenToClient(rectOldStyle);
|
|
|
|
long nIncY = sizeDlg.cy-sizeOld.cy;
|
|
long nIncX = sizeDlg.cx-sizeOld.cx;
|
|
m_grid.MoveWindow(rectGrid.left, rectGrid.top,
|
|
rectGrid.Width()+nIncX, rectGrid.Height()+nIncY);
|
|
|
|
pCancel->MoveWindow(rectCancel.left, rectCancel.top + nIncY,
|
|
rectCancel.Width(), rectCancel.Height());
|
|
pOk->MoveWindow(rectOk.left, rectOk.top + nIncY,
|
|
rectOk.Width(), rectOk.Height());
|
|
pNewStyle->MoveWindow(rectNewStyle.left,rectNewStyle.top+nIncY,
|
|
rectNewStyle.Width(),rectNewStyle.Height());
|
|
pOldStyle->MoveWindow(rectOldStyle.left,rectOldStyle.top+nIncY,
|
|
rectOldStyle.Width(),rectOldStyle.Height());
|
|
}
|
|
|
|
}
|
|
|
|
void CGridSheetDlg::OnOK()
|
|
{
|
|
if(m_grid.IsModified())
|
|
m_grid.Save();
|
|
|
|
CAcUiDialog::OnOK();
|
|
}
|
|
|
|
|
|
|
|
extern BOOL StringAnalysis(const TCHAR *src, XString &sPrefix, int *num, int *numWidth);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int CGridSheetDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CAcUiDialog::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
m_nOldSizeX=rect.Width();
|
|
m_nOldSizeY=rect.Height();
|
|
return 0;
|
|
}
|
|
|
|
BOOL CGridSheetDlg::OnInitDialog() //modified by whl
|
|
{
|
|
CAcUiDialog::OnInitDialog();
|
|
|
|
m_grid.Create(this,IDC_GRID);
|
|
|
|
m_bInit=TRUE;
|
|
CRect rectDlg;
|
|
GetClientRect(rectDlg);
|
|
sizeDlg.cx = rectDlg.Width();
|
|
sizeDlg.cy = rectDlg.Height();
|
|
ResetSize();
|
|
if(m_pSheet)
|
|
ConfigGrid();
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////
|
|
int COpGridSheetDlg::s_bNewSheet=0;
|
|
COpGridSheetDlg::COpGridSheetDlg(TDbSheet*pOldSheet,TDbSheet*pNewSheet,CWnd*pParent)
|
|
:CGridSheetDlg(NULL,pParent),m_pOldSheet(pOldSheet),m_pNewSheet(pNewSheet)
|
|
{
|
|
}
|
|
void COpGridSheetDlg::DoDataExchange(CDataExchange*pDX)
|
|
{
|
|
CGridSheetDlg::DoDataExchange(pDX);
|
|
DDX_Radio(pDX,IDC_OLD_STYLE,s_bNewSheet);
|
|
m_pSheet=s_bNewSheet?m_pNewSheet:m_pOldSheet;
|
|
if(!pDX->m_bSaveAndValidate)
|
|
ConfigGrid();
|
|
}
|
|
BOOL COpGridSheetDlg::OnInitDialog()
|
|
{
|
|
if(!CGridSheetDlg::OnInitDialog())
|
|
return FALSE;
|
|
//GetDlgItem(ID_RETURN)->ShowWindow(SW_SHOW);
|
|
GetDlgItem(IDC_NEW_STYLE)->ShowWindow(SW_SHOW);
|
|
GetDlgItem(IDC_OLD_STYLE)->ShowWindow(SW_SHOW);
|
|
return TRUE;
|
|
}
|
|
BEGIN_MESSAGE_MAP(COpGridSheetDlg,CGridSheetDlg)
|
|
ON_BN_CLICKED(IDC_NEW_STYLE,OnChangeStyle)
|
|
ON_BN_CLICKED(IDC_OLD_STYLE,OnChangeStyle)
|
|
END_MESSAGE_MAP()
|
|
|
|
void COpGridSheetDlg::OnChangeStyle()
|
|
{
|
|
UpdateData();
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
int COpFloorDlg::s_bWinFirst=0;//门排前
|
|
COpFloorDlg::COpFloorDlg(CWnd*pParent):CAcUiDialog(IDD_OP_FLOOR,pParent),grid(false,50)
|
|
{
|
|
grid.SetColNum(2);
|
|
grid.GetCol(0).SetName(_T("层号"));
|
|
WDGridCol&col1=grid.GetCol(1);
|
|
col1.SetName(_T("层门窗选择"));
|
|
col1.SetTextColor(RGB(0,80,150));
|
|
col1.SetReadOnly();
|
|
grid.SetColPosFix();
|
|
grid.SetColFixLength();
|
|
grid.SetRowPosFix();
|
|
grid.SetNoPaste();//禁上粘贴
|
|
|
|
//默认为楼层表
|
|
XString sProjectDbf;
|
|
if(::GetProjectDbf(sProjectDbf)!=RTNORM)
|
|
return;
|
|
CodeBase db;
|
|
XDbfTable *pData=db.Open(sProjectDbf);
|
|
if(pData==NULL)
|
|
return;
|
|
grid.SetRowNum(pData->GetRecordCount(1));
|
|
long i=0;
|
|
for(pData->MoveFirst();!pData->IsEOF();pData->MoveNext(),i++)
|
|
{
|
|
// sg modify 100825,解决64位移植后的BUG,强制转换后,数据为空
|
|
// XString sDwgFile,sFloor;
|
|
CString sDwgFile,sFloor;
|
|
GET_FIELD(pData, _T("dwgfile"), sDwgFile);
|
|
GET_FIELD(pData, _T("floor"), sFloor);
|
|
|
|
grid.GetCell(i,0).SetText(sFloor);
|
|
grid.GetCell(i,1).SetText(sDwgFile);
|
|
}
|
|
}
|
|
void COpFloorDlg::DoDataExchange(CDataExchange*pDX)
|
|
{
|
|
CAcUiDialog::DoDataExchange(pDX);
|
|
DDX_Radio(pDX,IDC_DOOR_FIRST,s_bWinFirst);
|
|
}
|
|
BOOL COpFloorDlg::OnInitDialog()
|
|
{
|
|
if(!CAcUiDialog::OnInitDialog())
|
|
return FALSE;
|
|
grid.Create(this,IDC_GRID);
|
|
grid.FitLastCol();
|
|
return TRUE;
|
|
}
|
|
BEGIN_MESSAGE_MAP(COpFloorDlg,CAcUiDialog)
|
|
ON_BN_CLICKED(ID_FILE,OnFile)
|
|
ON_BN_CLICKED(ID_PICK,OnPick)
|
|
ON_BN_CLICKED(ID_NEW,OnNew)
|
|
ON_BN_CLICKED(ID_DEL,OnDel)
|
|
END_MESSAGE_MAP()
|
|
void COpFloorDlg::OnPick()
|
|
{
|
|
int iRow=grid.GetCurRowIndex();
|
|
if(iRow==NOT_FOUND)
|
|
{
|
|
AfxMessageBox(_T("请先选定一行"));
|
|
return;
|
|
}
|
|
TPickSetData *pSet=new TPickSetData;
|
|
BeginEditorCommand();
|
|
RBList mask(RTDXF0, _T("ATS_OPENING,ATS_CORNER_WINDOW,ATS_DORMER"), NULL);
|
|
g_ssPickFirst.Free();
|
|
int nRet=SelectEntities(_T("\n请选择当前层门窗:"), pSet->set, mask);
|
|
CompleteEditorCommand();
|
|
|
|
if(nRet!=RTNORM||pSet->set.Length()<1)
|
|
delete pSet;
|
|
else
|
|
{
|
|
WDGridRow &row=grid.GetRow(iRow);
|
|
CString temp;
|
|
temp.Format(_T("<从本图选,门窗数量%d>"),pSet->set.Length());
|
|
row[1].SetText(temp);
|
|
row.SetExtendData(pSet);
|
|
grid.Refresh();
|
|
}
|
|
}
|
|
void COpFloorDlg::OnFile()
|
|
{
|
|
int iRow=grid.GetCurRowIndex();
|
|
if(iRow==NOT_FOUND)
|
|
{
|
|
AfxMessageBox(_T("请先选定一行"));
|
|
return;
|
|
}
|
|
XString sFile,sTitle(256);
|
|
xg_getvar(_T("DWGPREFIX"), sFile);
|
|
if(GetFileDia(sFile, 0, _T("dwg"), _T("选择标准层图形文件"))==RTNORM)
|
|
{
|
|
XPathParser parser(sFile);
|
|
WDGridRow&row=grid.GetRow(iRow);
|
|
row[1].SetText(parser.m_sFileName);
|
|
row.SetExtendData(NULL);
|
|
grid.Refresh();
|
|
}
|
|
}
|
|
void COpFloorDlg::OnNew()
|
|
{
|
|
if(grid.IsRowSelected())
|
|
grid.DoInsertRowAfter();
|
|
else
|
|
grid.DoAppendRow();
|
|
}
|
|
void COpFloorDlg::OnDel()
|
|
{
|
|
grid.DoDelete();
|
|
} |