Files
l7/LResultSet.h

278 lines
6.6 KiB
C
Raw Normal View History

2018-04-25 20:43:41 +02:00
/*
* File: LResultSet.h
2022-11-19 16:05:44 +01:00
* Author: Saleem Edah-Tally - nmset@yandex.com
2018-04-25 20:43:41 +02:00
* License : LGPL version 2.1
2022-11-19 16:05:44 +01:00
* Copyright Saleem Edah-Tally, M. D. - © 2014
2018-04-25 20:43:41 +02:00
*
* Created on 28 mai 2014, 21:11
*/
#ifndef LRESULTSET_H
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
#define LRESULTSET_H
2018-04-25 20:43:41 +02:00
#include "LInformation.h"
#include "LBoundControl.h"
#include "LLightResultSet.h"
class LBoundControl;
class LResultSetEvent;
/**
* An abstract class that allows data modification using GUI elements.
*
* Don't use aliases for table names.
*
* A column alias must still be a real column name of the table specified in SetTableName.
*
* Ex : SELECT tbl1.pk1, tbl1.text1, list2.text2 AS num1 FROM tbl1 LEFT JOIN list2 ON tbl1.num1 = list2.pk2
*
*/
class LResultSet : public LLightResultSet
{
public:
LResultSet();
LResultSet(LConnection * newConnection);
/**
* All controls are unregistered in the destructor.
*/
virtual ~LResultSet();
/**
*
* @param newTableName : the database table to update.
*/
void SetTableName(const wxString& newTableName)
{
m_tblName = newTableName;
}
const wxString& GetTableName() const
{
return m_tblName;
}
/**
* May not necessarily be the real primary key of the table.
*
* @param newPKColumnName : an auto-increment column.
*/
void SetPKColumnName(const wxString& newPKColumnName)
{
m_pkColName = newPKColumnName;
}
const wxString& GetPKColumnName() const
{
return m_pkColName;
}
void RegisterControl(LBoundControl * comp);
/**
* Unregisters a control and set its internal resultset member to NULL.
* @param comp
*/
void UnRegisterControl(LBoundControl * comp);
virtual void UnRegisterAllControls();
const wxArrayPtrVoid GetRegisteredControls() const
{
return m_BoundControls;
}
bool IsControlRegistered(LBoundControl * comp) const
{
return (m_BoundControls.Index(comp) != wxNOT_FOUND);
}
virtual void Display() = 0;
/**
*
* @return true if any registered control is dirty, false otherwise.
*/
bool IsDirty() const;
virtual bool Save() = 0;
bool Refresh();
bool Cancel();
bool AddNew();
bool Delete();
LBoundControl* GetControl(const wxString& colName) const;
void SetCanSave(bool newCanSave)
{
m_canSave = newCanSave;
}
bool GetCanSave() const
{
return m_canSave;
}
void SetCanInsert(bool newCanInsert)
{
m_canInsert = newCanInsert;
}
bool GetCanInsert() const
{
return m_canInsert;
}
void SetCanUpdate(bool newCanUpdate)
{
m_canUpdate = newCanUpdate;
}
bool GetCanUpdate() const
{
return m_canUpdate;
}
void SetCanDelete(bool newCanDelete)
{
m_canDelete = newCanDelete;
}
bool GetCanDelete() const
{
return m_canDelete;
}
void SetReadOnly(bool newReadOnly)
{
m_readOnly = newReadOnly;
}
bool IsReadOnly() const
{
return m_readOnly;
}
void SetCanMove(bool newCanMove)
{
m_canMove = newCanMove;
}
bool GetCanMove() const
{
return m_canMove;
}
bool IsInserting() const
{
return m_inserting;
}
void SetMasterResultSet(LResultSet * newResultSet)
{
m_masterResultSet = newResultSet;
}
const LResultSet* GetMasterResultSet() const
{
return m_masterResultSet;
}
void SetMasterColumnNames(const wxString& newColumnNames)
{
m_masterColumnNames = newColumnNames;
}
const wxString& GetMasterColumnNames() const
{
return m_masterColumnNames;
}
void SetChildColumnNames(const wxString& newColumnNames)
{
m_childColumnNames = newColumnNames;
}
const wxString& GetChildColumnNames() const
{
return m_childColumnNames;
}
virtual void InformInserting() const = 0;
virtual void InformDirty() const = 0;
void RegisterEventHandler(LResultSetEvent * evh);
void UnRegisterEventHandler(LResultSetEvent * evh);
wxArrayPtrVoid& GetEventHandlers()
{
return m_evtHandlers;
}
protected:
wxString m_tblName;
wxString m_pkColName;
wxArrayPtrVoid m_BoundControls;
virtual const wxString MakeUpdateSQL() const = 0;
virtual const wxString MakeDeleteSQL() const = 0;
virtual const int GetRowByPKValue(const wxAny& pkValue) const = 0;
bool m_inserting;
bool m_canSave;
bool m_canInsert;
bool m_canUpdate;
bool m_canDelete;
bool m_readOnly;
bool m_canMove;
wxArrayPtrVoid m_evtHandlers;
void InformInitialised();
void InformDataChanged();
2018-04-25 20:43:41 +02:00
void InformBeforeSave();
void InformBeforeInsert();
void InformBeforeUpdate();
void InformBeforeDelete();
void InformBeforeChangeRow();
void InformAfterSave();
void InformAfterChangeRow();
void InformAfterAction(const int action);
void InformAfterInsert(const wxAny& newPK, const wxString& sql);
void InformAfterUpdate(const wxAny& curPK, const wxString& sql);
void InformAfterDelete(const wxAny& oldPK, const wxString& sql);
void InformLibMessage(const LInformation& msg) const;
wxWeakRef<LResultSet> m_masterResultSet;
wxString m_masterColumnNames;
wxString m_childColumnNames;
bool IsChild() const;
wxString MakeChildInsertColList() const;
wxString MakeMasterValueList() const;
private:
};
////////////////////////////////////////////////////////////////////////
class LResultSetEvent
{
public:
LResultSetEvent();
virtual ~LResultSetEvent();
enum ACTIONS
{
ACTION_ADDNEW = 0, ACTION_SAVE, ACTION_CANCEL, ACTION_REFRESH, ACTION_DELETE
};
virtual void Initialised(LResultSet * caller);
virtual void DataChanged(LResultSet * caller);
2018-04-25 20:43:41 +02:00
virtual void BeforeSave(LResultSet * caller);
virtual void BeforeInsert(LResultSet * caller);
virtual void BeforeUpdate(LResultSet * caller);
virtual void BeforeDelete(LResultSet * caller);
virtual void BeforeChangeRow(LResultSet * caller);
virtual void AfterSave(LResultSet * caller);
virtual void AfterInsert(LResultSet * caller, const wxAny& newPK, const wxString& sql);
virtual void AfterUpdate(LResultSet * caller, const wxAny& curPK, const wxString& sql);
virtual void AfterDelete(LResultSet * caller, const wxAny& oldPK, const wxString& sql);
virtual void AfterChangeRow(LResultSet * caller);
virtual void AfterAction(LResultSet * caller, ACTIONS action);
virtual void Inform(const LResultSet * caller, const LInformation& msg) const;
private:
};
Added classes to manage simple tabular data of known structure using a popup containing a wxGrid object. BasePicker : Abstract class adding a popup to wxPickerBase styled with a wxTextCtrl. BaseGridPicker : Abstract class adding a wxGrid in the popup. JsonGridPickerCtrl : UI control storing the tabular data in a JSON array. LBoundJsonGridPicker : connect JsonGridPicker to database. LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects. LGridJsonCellRenderer : render cell JSON data. XmlGridPickerCtrl : UI control storing the tabular data in as XML document. LBoundXmlGridPicker : connect XmlGridPicker to database. LGridXmlCellEditor : grid editor for LBoundXmlGridPicker. LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker. JsonHelper and XmlHelper : for applications to quickly get intent value from database data.. The structure of managed tabular data : Column 1 : Intent - this is what we want to store/edit. This can be telephone numbers, email addresses, instant messaging addresses... any single line piece of information that can exist many times for one entity (person, company...). Column 2 : Type - A short description of the intent : 'Home, Work, Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox. Column 3 : Preferred - One line of data can be selected as the preferred one. It is not mandatory, but it must be a single choice. Column 4 : Notes - single line notes. Adjust sql scripts and L7.dox. Applied ANSI formatting style to all files. Other changes : Work around a nasty misbehavior. Grid columns edited by a translated combobox expect full string data as cell values. LResultSet::BEData() will report these mapped strings, instead of database real data. LBoundComboBox::IsDirty() will always be true even if the editor is unchanged once created. Simplest workaround : disconnect m_BoundComboBox if unchanged. LGridTextEditor::ProvideFormEditor() : set the form editor's value explicitely.; wxTextCtrl does not interpret data it receives LBoundControl::SetNull must be void. LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind:: LConnection::GetReturnedKeys should return NULL. LConnection::SetData should return void. Notes : wxJSON must be configured with the same prefix as wxWidgets, here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
#endif /* LRESULTSET_H */
2018-04-25 20:43:41 +02:00