/** * @file XTPGridDataManager.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPGRIDDATAMANAGER_H__) # define __XTPGRIDDATAMANAGER_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPGridRecord; class CXTPGridRecords; class CXTPGridRecordItemVariant; class CXTPGridDataManager; class CXTPGridControl; class CXTPGridRecordItem; # define XTP_GRIDDATAMANAGER_MAX_LAST_COM_ERRORS 3 /** * @brief * Basic set of parameters transferred to item handlers. This structure * groups together essential parameters used in item processing * activities. It is the parent for all other structures: * XTP_GRIDRECORDITEM_DRAWARGS, XTP_GRIDRECORDITEM_CLICKARGS, etc. * * Example: *
 * XTP_GRIDRECORDITEM_ARGS itemArgs(pControl, pRow, pColumn);
 * pItem->OnBeginEdit(&itemArgs);
 * 
* @see * CXTPGridRecordItem::OnBeginEdit */ struct XTP_GRIDDATAMANAGER_COM_ERROR { HRESULT hResult; /**< The HRESULT error value. */ CString strMessage; /**< The error message. */ CString strSource; /**< The error source. */ /** * @brief * Performs default error object construction. */ XTP_GRIDDATAMANAGER_COM_ERROR() { hResult = S_OK; strMessage.Empty(); strSource.Empty(); } /** * @brief * Overloaded assignment operator. * Copies data values from a source error object. * @param errorSrc A source error object. * @return Self reference. */ const XTP_GRIDDATAMANAGER_COM_ERROR& operator=(const XTP_GRIDDATAMANAGER_COM_ERROR& errorSrc) { this->hResult = errorSrc.hResult; this->strMessage = errorSrc.strMessage; this->strSource = errorSrc.strSource; return *this; } }; class _XTP_EXT_CLASS CRstEvent : public XTPGRIDADODB::RecordsetEventsVt { private: ULONG m_cRef; CXTPGridDataManager* m_pDataManager; public: CRstEvent(CXTPGridDataManager* pDataManager); virtual ~CRstEvent(); STDMETHODIMP QueryInterface(REFIID riid, void** ppv); STDMETHODIMP_(ULONG) AddRef(void); STDMETHODIMP_(ULONG) Release(void); virtual HRESULT __stdcall raw_WillChangeField(long cFields, VARIANT Fields, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_FieldChangeComplete(long cFields, VARIANT Fields, struct XTPGRIDADODB::Error* pError, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_WillChangeRecord(enum XTPGRIDADODB::EventReasonEnum adReason, long cRecords, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_RecordChangeComplete(enum XTPGRIDADODB::EventReasonEnum adReason, long cRecords, struct XTPGRIDADODB::Error* pError, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_WillChangeRecordset(enum XTPGRIDADODB::EventReasonEnum adReason, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_RecordsetChangeComplete( enum XTPGRIDADODB::EventReasonEnum adReason, struct XTPGRIDADODB::Error* pError, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_WillMove(enum XTPGRIDADODB::EventReasonEnum adReason, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_MoveComplete(enum XTPGRIDADODB::EventReasonEnum adReason, struct XTPGRIDADODB::Error* pError, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_EndOfRecordset(VARIANT_BOOL* fMoreData, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_FetchProgress(long Progress, long MaxProgress, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); virtual HRESULT __stdcall raw_FetchComplete(struct XTPGRIDADODB::Error* pError, enum XTPGRIDADODB::EventStatusEnum* adStatus, struct XTPGRIDADODB::_Recordset* pRecordset); protected: CArray m_adReasonStack; }; /** * @brief * Represents a grid data manager. */ class _XTP_EXT_CLASS CXTPGridDataManager : public CXTPCmdTarget { DECLARE_DYNAMIC(CXTPGridDataManager); /** @cond */ friend class CXTPGridControl; friend class CRstEvent; void AFX_CDECL TRACE_ComError(_com_error& e); void AFX_CDECL TRACE_ProviderError(XTPGRIDADODB::_Connection* pConnDB); /** @endcond */ public: /** * @brief * Constructs a CXTPGridDataManager object. * @param pGridControl Pointer to a CXTPGridControl object. */ CXTPGridDataManager(CXTPGridControl* pGridControl); /** * @brief * Destroys a CXTPGridDataManager object, handles cleanup and deallocation. */ virtual ~CXTPGridDataManager(); /** * @brief * Sets the data source. * * @param pDataSource Pointer to a custom ADODB object. */ virtual void SetDataSource(XTPGRIDADODB::_RecordsetPtr pDataSource); /** * @brief * Gets the data source. * @return * A pointer to a custom ADODB object. */ virtual XTPGRIDADODB::_RecordsetPtr GetDataSource() const; /** * @brief * Binds the data (i.e. brings the data to the control). * @return * TRUE if the operation was successful, otherwise FALSE. */ virtual BOOL DataBind(); /** * @brief * Creates the columns based on the fields. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT CreateColumns(); /** * @brief * Updates the grid records. * * @param pRecordset Pointer to a custom ADODB record set. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT UpdateGridRecords(XTPGRIDADODB::_RecordsetPtr pRecordset); /** * @brief * Adds a record to the Grid control. * * @param pRecordset Pointer to a custom ADODB record set * @param bAddNow Add now. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT AddGridRecords(XTPGRIDADODB::_RecordsetPtr pRecordset, BOOL bAddNow); /** * @brief * Performs preperation for the deletion of grid records. * * @param pRecordset Pointer to a custom ADODB record set * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT PrepareDeleteGridRecords(XTPGRIDADODB::_RecordsetPtr pRecordset); /** * @brief * Clears deleted records. */ virtual void ClearDeleteGridRecords(); /** * @brief * Deletes the grid records. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT DeleteGridRecords(); /** * @brief * Deletes the grid records. * * @param pRecordset - Pointer to a custom ADODB record set. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT DeleteGridRecords(XTPGRIDADODB::_RecordsetPtr pRecordset); /** * @brief * Updates a field. * * @param pItem Pointer to a grid record item variant. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT UpdateField(CXTPGridRecordItemVariant* pItem); /** * @brief * Updates a grid record. * * @param pRecord Pointer to a grid record object. * @param pItemChanged Specifies an optional changed item pointer. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT UpdateRecord(CXTPGridRecord* pRecord, CXTPGridRecordItem* pItemChanged = NULL); /** * @brief * Adds a record. * * @param pRecord Pointer to a grid record object. * @param bAddToGrid TRUE if the record should also be added to * the Grid control, FALSE otherwise. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT AddRecord(CXTPGridRecord* pRecord, BOOL bAddToGrid); /** * @brief * Creates an empty record. * * @param ppRecord Pointer to a grid record pointer. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT CreateEmptyRecord(CXTPGridRecord** ppRecord); /** * @brief * Deletes a record. * * @param pRecord Pointer to a grid record object. * @return * S_OK if the operation was successful, otherwise E_FAIL. */ virtual HRESULT DeleteRecord(CXTPGridRecord* pRecord); /** * @brief * Gets the last COM error. * @return * An XTP_GRIDDATAMANAGER_COM_ERROR value specifying the COM error. */ virtual XTP_GRIDDATAMANAGER_COM_ERROR GetLastComError(); protected: /** * @brief * Removes the data source. */ void RemoveDataSource(); /** * @brief * Clears the Grid control. */ void ClearGridControl(); protected: CXTPGridControl* m_pGridControl; /**< Pointer to the Grid control. */ XTPGRIDADODB::_ConnectionPtr m_pConnection; /**< The custom ADODB connection point. */ XTPGRIDADODB::_RecordsetPtr m_pDataSource; /**< The data source. */ CRstEvent* m_pRstEvent; /**< Pointer to the record set event object. */ DWORD m_dwRstEvent; /**< The record set event. */ CXTPGridRecords* m_pDeleteRecords; /**< The delete records. */ BOOL m_bLocalUpdate; /**< Tells whether the update is local only. */ CArray m_LastComError; public: # ifdef _XTP_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPGridDataManager); public: static CXTPGridDataManager* AFX_CDECL FromDispatch(LPDISPATCH pDisp); LPDISPATCH OleGetDataSource(); void OleSetDataSource(LPDISPATCH lpDispatch); BOOL OleUpdateField(LPDISPATCH lpDispatch); BOOL OleUpdateRecord(LPDISPATCH lpDispatch); BOOL OleUpdateRecordItem(LPDISPATCH lpDispatch); BOOL OleAddRecord(LPDISPATCH lpDispatch, BOOL bAddToGrid); BOOL OleDeleteRecord(LPDISPATCH lpDispatch); LPDISPATCH OleCreateEmptyRecord(); /** @endcond */ # endif /*_XTP_ACTIVEX*/ // CXTPGridDataManager diagnostics # ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; friend _XTP_EXT_CLASS CDumpContext& AFXAPI operator<<(CDumpContext& dc, const CXTPGridDataManager& obj); # endif }; // class _XTP_EXT_CLASS CXTPGridDataManager AFX_INLINE XTPGRIDADODB::_RecordsetPtr CXTPGridDataManager::GetDataSource() const { return m_pDataSource; } # ifdef _DEBUG _XTP_EXT_CLASS CDumpContext& AFXAPI operator<<(CDumpContext& dc, const CXTPGridDataManager& obj); # endif /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPGRIDDATAMANAGER_H__) /** @endcond */