// 按钮的提示信息
CToolTipCtrl m_toolTip;
// 各个按钮关联变量
CXTPButton m_btnAddProject;
m_toolTip.Create(this);
m_toolTip.AddTool(&m_btnAddProject, _T("添加方案"));
m_toolTip.AddTool(&m_btnDelProject, _T("删除当前方案"));
头文件.h
#pragma once
class CReportToolBar : public CToolBar
{
public:
CReportToolBar();
BOOL CreateEx(CWnd* pParentWnd, DWORD dwCtrlStyle = TBSTYLE_FLAT,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP,
CRect rcBorders = CRect(0, 0, 0, 0),
UINT nID = AFX_IDW_TOOLBAR);
BOOL SetEnableButton(int nID, BOOL bEnable);
protected:
DECLARE_MESSAGE_MAP()
afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
private:
CImageList m_lstImage, m_lstImageDisable;
};
/*
class CXTPCustomDrawReportPaintManager : public CXTPReportPaintManager
{
public:
virtual void DrawItemCaption(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pMetrics);
BOOL DrawItem(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* = pMetrics);
virtual int GetRowHeight(CDC* pDC, CXTPReportRow* pRow);
};
*/
class CReportTableControl : public CXTPReportControl
{
public:
CReportTableControl();
virtual ~CReportTableControl();
void UpdateUpDownButtonState() const;
const XTP_NM_REPORTTOOLTIPINFO& OnGetToolTipInfo( CXTPReportRow* pRow, CXTPReportRecordItem* pItem, CString& rstrToolTipText )
{
rstrToolTipText = pItem->GetCaption(0);
return CXTPReportControl::OnGetToolTipInfo(pRow, pItem, rstrToolTipText);
}
void SelectRecord(const CXTPReportRecord* pRecord);
void SetToolbar(CReportToolBar* toolBar);
void MoveUpward();
void MoveDownward();
void Delete();
void DeleteRows();
void Add(CXTPReportRecord* pRecord);
void EnableWindow(BOOL bEnable);
protected:
virtual void OnSelectionChanged();
private:
CReportToolBar* m_toolbar;
};
class CDoubleItem : public CXTPReportRecordItem
{
public:
CDoubleItem(IN double dDef)
{
m_bAllowNeg = false;
m_strDef.Format(_T("%f"), dDef);
m_strDef = MathUtils::TrimZero(m_strDef);
SetCaption(m_strDef);
}
public:
virtual void OnEditChanged(XTP_REPORTRECORDITEM_ARGS* pItemArgs, LPCTSTR szText)
{
CString strText(szText);
strText.TrimLeft();
strText.TrimRight();
if (strText.IsEmpty())
{
strText = m_strDef;
}
if (!StringUtils::IsNumeric(strText))
{
strText = m_strDef;
}
else
{
if (!m_bAllowNeg && _tstof(strText) < 0.0)
{
strText = m_strDef;
}
}
strText = MathUtils::TrimZero(strText);
SetCaption(strText);
}
void SetAllowNeg(bool bAllow = false)
{
m_bAllowNeg = bAllow;
}
void SetValue(IN double dValue)
{
m_strDef.Format(_T("%f"), dValue);
m_strDef = MathUtils::TrimZero(m_strDef);
SetCaption(m_strDef);
}
BOOL SetEditable(BOOL bEditable)
{
SetTextColor(bEditable ? RGB(0,0,0) : RGB(167,166,170));
return CXTPReportRecordItem::SetEditable(bEditable);
}
double GetValue()
{
return _tstof(GetCaption(NULL));
}
private:
CString m_strDef;
bool m_bAllowNeg;
};
class CRecordItemCheck : public CXTPReportRecordItem
{
public:
CRecordItemCheck(BOOL bCheck = FALSE)
{
HasCheckbox(TRUE);
SetChecked(bCheck);
}
virtual int Compare(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
{
return int(IsChecked()) - int(pItem->IsChecked());
}
virtual void OnClick(XTP_REPORTRECORDITEM_CLICKARGS* pClickArgs)
{
CXTPReportRecordItem::OnClick(pClickArgs);
if (m_bChecked == IsChecked())
{
return;
}
BOOL bChecked = IsChecked();
SetChecked(bChecked);
}
void SetChecked(BOOL bChecked)
{
CXTPReportRecordItem::SetChecked(bChecked);
COLORREF clrNew = m_bChecked ? RGB(0,0,0) : RGB(167,166,170);
for (int i = 0; i < m_intArray.GetSize(); i++)
{
CXTPReportRecordItem* pItem = GetRecord()->GetItem(m_intArray[i]);
if (NULL == pItem)
continue;
pItem->SetEditable(m_bChecked);
pItem->SetTextColor(clrNew);
if (pItem->GetHasCheckbox())
{
pItem->SetChecked(m_bChecked);
}
}
}
void SetSubControl(int nIndex, ...)
{
va_list args;
va_start(args, nIndex);
for (int nColIndex = nIndex; nColIndex != -1; nColIndex = va_arg(args, int))
{
HyTrace(_T("DYQ:: nCol=%d"), nColIndex);
//if (m_pControl->GetColumns()->GetAt(nColIndex) != NULL)
{
m_intArray.Add(nColIndex);
}
}
va_end(args);
}
private:
CUIntArray m_intArray;
};
class CComboList : public CXTPReportRecordItem
{
public:
CComboList()
{
GetEditOptions(NULL)->AddComboButton(FALSE);
GetEditOptions(NULL)->m_bAllowEdit = FALSE;
}
CComboList(const CString& strCaption)
{
GetEditOptions(NULL)->AddComboButton(FALSE);
GetEditOptions(NULL)->m_bAllowEdit = FALSE;
SetCaption(strCaption);
}
CComboList(const CStringArray& aryStr)
{
GetEditOptions(NULL)->AddComboButton(TRUE);
GetEditOptions(NULL)->m_bAllowEdit = FALSE;
SetConstraints(aryStr);
}
CString SetConstraints(const CStringArray& aryStr)
{
CString strCaption = GetCaption(NULL);
GetEditOptions(NULL)->m_pConstraints->RemoveAll();
if (aryStr.IsEmpty())
{
return _T("");
}
bool bInArray = false;
for (int i = 0; i < aryStr.GetCount(); i++)
{
GetEditOptions(NULL)->AddConstraint(aryStr.GetAt(i));
if (!strCaption.IsEmpty() && strCaption.CompareNoCase(aryStr.GetAt(i)) == 0)
{
bInArray = true;
}
}
if (!bInArray)
{
strCaption = aryStr.GetAt(0);
}
SetCaption(strCaption);
return strCaption;
}
void OnConstraintChanged(XTP_REPORTRECORDITEM_ARGS* pItemArgs, CXTPReportRecordItemConstraint* pConstraint)
{
CString strValue = pConstraint->m_strConstraint;
SetCaption(strValue);
}
virtual BOOL SetEditable(BOOL bEditable = TRUE)
{
BOOL bRet = CXTPReportRecordItem::SetEditable(bEditable);
if (!bEditable)
{
SetCaption(NULL);
}
else
{
CXTPReportRecordItemConstraints* pConstraints = GetEditOptions(NULL)->m_pConstraints;
if (pConstraints->GetCount() > 0)
{
SetCaption(pConstraints->GetAt(0)->m_strConstraint);
}
}
return bRet;
}
void SetItemIndex(const int& index)
{
if (index < 0)
{
return;
}
CXTPReportRecordItemConstraints* pConstraints = GetEditOptions(NULL)->m_pConstraints;
if (index < pConstraints->GetCount())
{
SetCaption(pConstraints->GetAt(index)->m_strConstraint);
}
}
int GetItemIndex()
{
CString strText = GetCaption(NULL);
CXTPReportRecordItemConstraints* pConstraints = GetEditOptions(NULL)->m_pConstraints;
if (pConstraints->GetCount() > 0)
{
for (int i = 0; i < pConstraints->GetCount(); i++)
{
if (pConstraints->GetAt(i)->m_strConstraint.CompareNoCase(strText) == 0)
{
return i;
}
}
}
return -1;
}
};
class CDoubleList: public CXTPReportRecordItem
{
public:
CDoubleList(double dValue)
{
SetValue(dValue);
GetEditOptions(NULL)->AddComboButton(TRUE);
GetEditOptions(NULL)->m_bAllowEdit = FALSE;
}
CDoubleList( const CArray<double,double>& arySlope )
{
CXTPReportRecordItemEditOptions* pList = GetEditOptions(NULL);
pList->AddComboButton(TRUE);
pList->m_bAllowEdit = FALSE;
for (int i = 0; i < arySlope.GetCount(); i++)
{
CString strSlope;
strSlope.Format(_T("%.4f"), arySlope.GetAt(i));
strSlope = MathUtils::TrimZero(strSlope);
if (i == 0)
{
SetCaption(strSlope);
}
pList->AddConstraint(strSlope);
}
}
void SetConstraints( const CArray<double,double>& arySlope )
{
GetEditOptions(NULL)->m_pConstraints->RemoveAll();
for (int i = 0; i < arySlope.GetCount(); i++)
{
CString strSlope;
strSlope.Format(_T("%.4f"), arySlope.GetAt(i));
strSlope = MathUtils::TrimZero(strSlope);
if (i == 0)
{
SetCaption(strSlope);
}
GetEditOptions(NULL)->AddConstraint(strSlope);
}
}
void OnConstraintChanged(XTP_REPORTRECORDITEM_ARGS* pItemArgs, CXTPReportRecordItemConstraint* pConstraint)
{
CString strValue = pConstraint->m_strConstraint;
SetCaption(strValue);
}
void OnEditChanged(XTP_REPORTRECORDITEM_ARGS* pItemArgs, LPCTSTR szText)
{
if (!GetEditOptions(NULL)->m_bAllowEdit)
{
return;
}
if(!StringUtils::IsNumeric(szText))
{
return;
}
if (!m_bAllowZero || _tstof(szText) < 0.0)
{
return;
}
SetCaption(szText);
}
void AllowZero(bool bAllow)
{
m_bAllowZero = bAllow;
}
void SetValue(double dValue)
{
CString str;
str.Format(_T("%f"), dValue);
MathUtils::TrimZero(str);
SetCaption(str);
}
double GetValue()
{
return _tstof(GetCaption(NULL));
}
private:
bool m_bAllowZero;
};
class CRecordItemCheckGroup : public CXTPReportRecordItem
{
public:
// Default constructor.
CRecordItemCheckGroup()
{
m_aryCaptions.RemoveAll();
m_ulValue = 0;
}
// Constructs record item with the initial value.
CRecordItemCheckGroup(const CStringArray& aryCaptions, ULONG ulValue = 0)
{
m_aryCaptions.RemoveAll();
m_aryCaptions.Append(aryCaptions);
m_ulValue = ulValue;
}
int Compare(CXTPReportColumn* pColumn, CXTPReportRecordItem* pItem)
{
return int(m_ulValue) - int(((CRecordItemCheckGroup*)pItem)->m_ulValue);
}
// Gets radio buttons number.
unsigned int GetControlsNumber()
{
return (unsigned int)m_aryCaptions.GetCount();
}
CString GetControlsCaption(int nIndex)
{
return m_aryCaptions.GetAt(nIndex);
}
// Sets new radio buttons number.
void SetControlCaptions(const CStringArray& aryCaptions)
{
m_aryCaptions.RemoveAll();
m_aryCaptions.Append(aryCaptions);
}
// Gets item value.
ULONG GetValue()
{
return m_ulValue;
}
// Sets new item value.
void SetValue(ULONG ulValue)
{
m_ulValue = ulValue;
}
// Sets a bit by the specified bit number.
void SetBit(unsigned int unBitNumber)
{
m_ulValue |= (1 << unBitNumber);
}
// Clears a bit by the specified bit number.
void ClearBit(unsigned int unBitNumber)
{
m_ulValue &= ~(1 << unBitNumber);
}
// Toggles a bit by the specified bit number.
void ToggleBit(unsigned int unBitNumber)
{
if(m_ulValue & (1 << unBitNumber))
m_ulValue &= ~(1 << unBitNumber);
else
m_ulValue |= (1 << unBitNumber);
}
virtual int Draw(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs)
{
CXTPReportRecordItem::Draw(pDrawArgs);
CRect rc = pDrawArgs->pRow->GetItemRect(pDrawArgs->pItem);
rc.left += 5;
rc.right = rc.left + 14;
rc.bottom = rc.top + 14;
for(unsigned int i = 0; i < m_aryCaptions.GetCount(); i++)
{
UINT unFlags;
UINT unIconId;
CString strText = m_aryCaptions.GetAt(i);
unFlags = DFCS_BUTTONCHECK;
if(GetValue() & (1 << i))
{
unFlags |= DFCS_CHECKED;
unIconId = 1;
}
else
{
unFlags &= ~DFCS_CHECKED;
unIconId = 0;
}
::DrawFrameControl(pDrawArgs->pDC->GetSafeHdc(), rc, DFC_BUTTON, unFlags);
TextOut(pDrawArgs->pDC->GetSafeHdc(), rc.left + 20, rc.top, strText, strText.GetLength());
rc.top += 15;
rc.bottom += 15;
}
return 0;
}
virtual void OnClick(XTP_REPORTRECORDITEM_CLICKARGS* pClickArgs)
{
CPoint pt = pClickArgs->ptClient;
unsigned int unControls = GetControlsNumber();
if(unControls == 0)
return;
CRect rc = pClickArgs->pRow->GetItemRect(pClickArgs->pItem);
rc.right = rc.left + 14 + 25;
rc.bottom = rc.top + 14;
for(unsigned int i = 0; i < unControls; i++)
{
if(rc.PtInRect(pt))
{
ToggleBit(i);
}
rc.OffsetRect(0, 15);
}
//return CXTPReportRecordItem::OnClick(pClickArgs);
}
//virtual void DoPropExchange(CXTPPropExchange* pPX);
protected:
CStringArray m_aryCaptions;
ULONG m_ulValue; // checkboxes value
};
源文件.cpp
#include "StdAfx.h"
#include "resource.h"
#include "XTPReportControlSection.h"
BEGIN_MESSAGE_MAP(CReportToolBar, CToolBar)
ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)
END_MESSAGE_MAP()
CReportToolBar::CReportToolBar()
{
m_lstImage.Create(16, 16, ILC_COLOR32 | ILC_MASK, 4, 1);
HICON hIcon1 = AfxGetApp()->LoadIcon(IDI_NEW);
HICON hIcon2 = AfxGetApp()->LoadIcon(IDI_DELETE);
HICON hIcon3 = AfxGetApp()->LoadIcon(IDI_UP);
HICON hIcon4 = AfxGetApp()->LoadIcon(IDI_DOWN);
m_lstImage.Add(hIcon1);
m_lstImage.Add(hIcon2);
m_lstImage.Add(hIcon3);
m_lstImage.Add(hIcon4);
m_lstImageDisable.Create(16, 16, ILC_COLOR32 | ILC_MASK, 4, 1);
HICON hIcon1D = AfxGetApp()->LoadIcon(IDI_NEW_D);
HICON hIcon2D = AfxGetApp()->LoadIcon(IDI_DELETE_D);
HICON hIcon3D = AfxGetApp()->LoadIcon(IDI_UP_D);
HICON hIcon4D = AfxGetApp()->LoadIcon(IDI_DOWN_D);
m_lstImageDisable.Add(hIcon1D);
m_lstImageDisable.Add(hIcon2D);
m_lstImageDisable.Add(hIcon3D);
m_lstImageDisable.Add(hIcon4D);
}
BOOL CReportToolBar::CreateEx( CWnd* pParentWnd, DWORD dwCtrlStyle /*= TBSTYLE_FLAT*/, DWORD dwStyle /*= WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP*/, CRect rcBorders /*= CRect(0, 0, 0, 0)*/, UINT nID /*= AFX_IDW_TOOLBAR*/ )
{
CToolBar::CreateEx(pParentWnd, dwCtrlStyle, dwStyle, rcBorders, nID);
if(!LoadToolBar(IDR_TOOLBAR) )
{
return FALSE;
}
SetSizes(CSize(22, 22), CSize(16, 16));
GetToolBarCtrl().SetImageList(&m_lstImage);
GetToolBarCtrl().SetDisabledImageList(&m_lstImageDisable);
GetToolBarCtrl().EnableButton(ID_BUTTON_NEW, TRUE);
GetToolBarCtrl().EnableButton(ID_BUTTON_DELETE, TRUE);
GetToolBarCtrl().EnableButton(ID_BUTTON_UP, TRUE);
GetToolBarCtrl().EnableButton(ID_BUTTON_DOWN, TRUE);
return TRUE;
}
BOOL CReportToolBar::SetEnableButton(int nID, BOOL bEnable)
{
return GetToolBarCtrl().EnableButton(nID, bEnable);
}
BOOL CReportToolBar::OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
// UNICODE消息
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CString strTipText;
UINT nID = (UINT)pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom为工具条的HWND
nID = ::GetDlgCtrlID((HWND)nID);
}
if (nID>=ID_BUTTON_NEW && nID<=ID_BUTTON_DOWN) //不为分隔符
{
strTipText.LoadString(nID);
strTipText = strTipText.Mid(strTipText.Find(_T("\n"),0)+1);
#ifndef _UNICODE
if (pNMHDR->code == TTN_NEEDTEXTA)
{
lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
}
else
{
_mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
}
#else
if (pNMHDR->code == TTN_NEEDTEXTA)
{
_wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
}
else
{
lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
}
#endif
*pResult = 0;
// 使工具条提示窗口在最上面
// ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|
// SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
return TRUE;
}
return TRUE;
}
/*
void CXTPCustomDrawReportPaintManager::DrawItemCaption(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pMetrics)
{
if(DrawItem(pDrawArgs, pMetrics))
return;
CXTPReportPaintManager::DrawItemCaption(pDrawArgs, pMetrics);
}
int CXTPCustomDrawReportPaintManager::GetRowHeight(CDC* , CXTPReportRow* pRow)
{
unsigned int unControls = 0;
CXTPReportRecordItem* pItem = pRow->GetRecord()->GetItem(COLUMN_TOMAIN);
if(pItem)
unControls = max(unControls, ((CRecordItemCheckGroup*)pItem)->GetControlsNumber());
if (!pRow->IsGroupRow())
{
return unControls * 15 + (IsGridVisible(FALSE) ? 1 : 0);
}
if (m_bShadeGroupHeadings)
return unControls * 15 + 6;
return unControls * 15 + 16;
}
BOOL CXTPCustomDrawReportPaintManager::DrawItem(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS*)
{
if(pDrawArgs->pColumn->GetIndex() != COLUMN_TOMAIN)
return FALSE;
CRect rc = pDrawArgs->pRow->GetItemRect(pDrawArgs->pItem);
rc.left += 5;
rc.right = rc.left + 14;
rc.bottom = rc.top + 14;
int nControlsNumber = ((CRecordItemCheckGroup*)pDrawArgs->pItem)->GetControlsNumber();
for(unsigned int i = 0; i < nControlsNumber; i++)
{
UINT unFlags;
UINT unIconId;
unFlags = DFCS_BUTTONCHECK;
CRecordItemCheckGroup* pRecord = (CRecordItemCheckGroup*)pDrawArgs->pItem;
CString strText = pRecord->GetControlsCaption(i);
if(pRecord->GetValue() & (1 << i))
{
unFlags |= DFCS_CHECKED;
unIconId = 1;
}
else
{
unFlags &= ~DFCS_CHECKED;
unIconId = 0;
}
::DrawFrameControl(pDrawArgs->pDC->GetSafeHdc(), rc, DFC_BUTTON, unFlags);
TextOut(pDrawArgs->pDC->GetSafeHdc(), rc.left + 20, rc.top, strText, strText.GetLength());
rc.top += 15;
rc.bottom += 15;
}
return TRUE;
}
*/
CReportTableControl::CReportTableControl(): CXTPReportControl()
{
SetGridStyle(TRUE, xtpReportGridSolid);
AllowEdit(TRUE);
ModifyStyle(0, WS_CHILD | WS_TABSTOP | WS_HSCROLL | WS_VSCROLL);
GetReportHeader()->AllowColumnRemove(FALSE);
GetReportHeader()->AllowColumnSort(FALSE);
GetReportHeader()->AllowColumnResize(TRUE);
GetReportHeader()->AllowColumnReorder(FALSE);
GetReportHeader()->SetAutoColumnSizing(TRUE);
SetMultipleSelection(FALSE);
}
CReportTableControl::~CReportTableControl()
{
}
void CReportTableControl::UpdateUpDownButtonState() const
{
if (m_toolbar == NULL)
{
return;
}
m_toolbar->SetEnableButton(ID_BUTTON_DELETE, GetRecords()->GetCount() > 0);
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
if (NULL != pSelectedRows && 0 != pSelectedRows->GetCount())
{
CXTPReportRow *pRow = pSelectedRows->GetAt(pSelectedRows->GetCount() - 1);
if (NULL != pRow)
{
m_toolbar->SetEnableButton(ID_BUTTON_UP, pRow->GetIndex() == 0 ? FALSE : TRUE);
m_toolbar->SetEnableButton(ID_BUTTON_DOWN, pRow->GetIndex() == GetRows()->GetCount() - 1 ? FALSE : TRUE);
return;
}
}
m_toolbar->SetEnableButton(ID_BUTTON_UP, FALSE);
m_toolbar->SetEnableButton(ID_BUTTON_DOWN, FALSE);
}
void CReportTableControl::OnSelectionChanged()
{
CXTPReportControl::OnSelectionChanged();
UpdateUpDownButtonState();
}
void CReportTableControl::SelectRecord(const CXTPReportRecord* pRecord)
{
if (NULL == pRecord)
return;
CXTPReportRow* pFocusRow = NULL;
for (int j = 0; j < GetRows()->GetCount(); ++j)
{
pFocusRow = GetRows()->GetAt(j);
if (pFocusRow->GetRecord() == pRecord)
break;
pFocusRow = NULL;
}
GetSelectedRows()->Clear();
if (NULL != pFocusRow)
{
GetSelectedRows()->Select(pFocusRow);
EnsureVisible(pFocusRow);
}
}
void CReportTableControl::SetToolbar( CReportToolBar* toolBar )
{
m_toolbar = toolBar;
}
void CReportTableControl::MoveUpward()
{
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
if (0 == pSelectedRows->GetCount())
{
AfxMessageBox(_T("请选择要移动的行!"), MB_OK | MB_ICONINFORMATION);
return;
}
CXTPReportRow *pRow = pSelectedRows->GetAt(0);
//当前行是首行
if (pRow->GetIndex() == 0)
return;
CXTPReportRecord *pCurRecord = pRow->GetRecord();
int nIndex = GetRows()->GetAt(pRow->GetIndex() - 1)->GetRecord()->GetIndex();
GetRecords()->MoveRecord(nIndex, pCurRecord, TRUE);
SelectRecord(pCurRecord);
Populate();
}
void CReportTableControl::MoveDownward()
{
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
if (0 == pSelectedRows->GetCount())
{
AfxMessageBox(_T("请选择要移动的行!"), MB_OK | MB_ICONINFORMATION);
return;
}
CXTPReportRow *pRow = pSelectedRows->GetAt(pSelectedRows->GetCount() - 1);
if (pRow->IsGroupRow() || pRow->GetIndex() == GetRows()->GetCount() - 1) // 当前行是末行
return;
CXTPReportRecord *pCurRecord = pRow->GetRecord();
int nIndex = GetRows()->GetAt(pRow->GetIndex() + 1)->GetRecord()->GetIndex();
GetRecords()->MoveRecord(nIndex + 1, pCurRecord, TRUE);
SelectRecord(pCurRecord);
Populate();
}
void CReportTableControl::Delete()
{
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
if (0 == pSelectedRows->GetCount())
{
AfxMessageBox(_T("请选择要删除的行!"), MB_OK | MB_ICONINFORMATION);
return;
}
CXTPReportRow *pRow = pSelectedRows->GetAt(0);
pRow->GetRecord()->GetRecords()->RemoveAt(pRow->GetRecord()->GetIndex());
int nDel = GetRows()->RemoveRow(pRow);
SetFocusedRow(GetRows()->GetAt(nDel - 1),TRUE,TRUE);
UpdateUpDownButtonState();
Populate();
}
// 使用前需要在CReportTableControl初始化函数中更改其选定方式为多行选中(TRUE)
void CReportTableControl::DeleteRows()
{
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
int nIndex = 0;
if (0 == pSelectedRows->GetCount())
{
AfxMessageBox(_T("请选择要删除的行!"), MB_OK | MB_ICONINFORMATION);
return;
}
for (int i = 0; i < pSelectedRows->GetCount(); i++)
{
CXTPReportRow *pRow = pSelectedRows->GetAt(i);
nIndex = pRow->GetRecord()->GetIndex();
pRow->GetRecord()->GetRecords()->RemoveRecord(pRow->GetRecord());
}
if (nIndex <= 1)
{
nIndex = 1;
}
Populate();
SetFocusedRow(GetRows()->GetAt(nIndex - 1), FALSE, FALSE);
}
void CReportTableControl::Add( CXTPReportRecord* pRecord )
{
if (NULL == pRecord)
return;
CXTPReportSelectedRows* pSelectedRows = GetSelectedRows();
AddRecordEx(pRecord);
if (pSelectedRows->GetCount() > 0)
{
CXTPReportRow *pRow = pSelectedRows->GetAt(pSelectedRows->GetCount() - 1);
CXTPReportRow *pDataRow = pRow;
int nIndex = pRow->GetRecord()->GetIndex() + 1;
AddRecordEx(pRecord);
GetRecords()->MoveRecord(nIndex, pRecord, TRUE);
}
SelectRecord(pRecord);
UpdateUpDownButtonState();
Populate();
}
void CReportTableControl::EnableWindow(BOOL bEnable)
{
CXTPReportControl::EnableWindow(bEnable);
if (m_toolbar != NULL)
{
m_toolbar->EnableWindow(bEnable);
}
}