///////////////////////////////////////////////////////////
// Author:			Stefan Liersch
// Contact:			stefan.liersch@googlemail.com,
//					stefan.liersch@ufz.de
//
// Date:			2007-07-17
// last modified:	2007-07-18
//
//---------------------------------------------------------
// DESCRIPTION
//---------------------------------------------------------
//	This dialog gets the necessary information to export
//	a SAGA table to a PostgreSQL table.
//---------------------------------------------------------
// ToDo
//---------------------------------------------------------
//
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#ifndef __pg_dlg_sqtable2pgsql_H
#define __pg_dlg_sqtable2pgsql_H

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma interface "pg_dlg_sgtable2pgsql"
#endif

// Include wxWidgets' headers
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include <wx/grid.h>
#include <wx/arrstr.h>

#include "saga_api/table.h"
#include "saga_gui/wksp_data_manager.h" // adding items to SAGA Workspace *g_pData
#include "saga_gui/wksp_table_manager.h"
#include "wksp_table.h"
//---------------------------------------------------------
enum {
	ID_TEXT1 = 10050,
	ID_CHOICE_TABLE,
	ID_TxtCtrl_ExportName,
	ID_GRID1,
	ID_BUTTON_Load_Settings,
	ID_BUTTON_Save_Settings
};
//---------------------------------------------------------
// Some SQL Field types corresponding to SAGA Field Types
const wxString m_SQL_FTypes[] =
{
	_T(""),
	//_T("ABSTIME"),
	_T("BOOL"),
	_T("CSTRING"),
	_T("DATE"),
	_T("INT4"),
	_T("INT8"),
	_T("FLOAT4"),
	_T("FLOAT8"),
	//_T("RELTIME"),
	_T("TEXT"),
	_T("TIME"),
	_T("TINTERVAL"),
	_T("UNKNOWN"),
	_T("VARCHAR"),
	_T("CHAR"),
};
//---------------------------------------------------------
const wxString m_Constraints[] =
{
	_T(""),
	_T("NOT NULL"),
	_T("PRIMARY KEY"),
};
//---------------------------------------------------------

class Cdlg_table2pg : public wxDialog
{
public:
	Cdlg_table2pg(wxWindow *parent, wxWindowID id, const wxString &title);
	~Cdlg_table2pg();

	CSG_Table*				Get_ExportTable() { return(m_pExportTable); };
	const char*				Get_ExportTableName();
	wxString				Get_ExportTableName_wxString();
	const char*				Get_FieldName(int i);
	wxString				Get_FieldName_wxString(int i);
	const char*				Get_FieldType(int i);
	const char*				Get_Constraint(int i);
	bool					IsNumeric(int i);
	bool					IsNumeric_sql(int col);

private:
	bool					*m_pIsNumeric;

	void					_CreateDlg();
	wxArrayString			_GetTableNames();
	bool					_SetTableManager(); // assign m_pTableManager

	void					_On_ChoiceTableChanged(wxCommandEvent& event);
	
	void					_On_Button_Load_Settings(wxCommandEvent& event);
	void					_On_Button_Save_Settings(wxCommandEvent& event);

	bool					_SetExportName();
	CSG_Table*				_GetExportTable();
	void					_Set_GRID_FieldNames();
	void					_Set_GRID_FieldTypes();
	void					_Set_GRID_FieldType(int row);
	void					_Set_GRID_Constraints();

	wxChoice				*m_pChoice_Table;
	wxTextCtrl				*m_pTxtCtrl_ExportName;
	wxGrid					*m_pGrid;
	wxButton				*m_pButExport;
	wxButton				*m_pButLoad;
	wxButton				*m_pButSave;

	CWKSP_Table_Manager		*m_pTableManager;
	CSG_Table				*m_pExportTable;

	DECLARE_EVENT_TABLE()
};


//---------------------------------------------------------

#endif /* __pg_dlg_sqtable2pgsql_H */


