I am having a problem to make my program work correctly.
I need to create a grid with the following columns:
Name Score1 Score2 Score3 Score4 Score5 Score6
And each of the lines is an alumn, and his/her scores.
Those scores need to be stored inside a SQLite database, to be compared and filtered later.
The real problem is: I can't understand how to input data on wxGrid, and store each data on wxSQLite3 database. I'm trying to do that
for a MONTH now, but I can't do it right. The sample program doesn't help much, because it's a command line program. I tryed to read
the code from some programs that use wxSQLite3, such as CodeLite, wxquickrun and wxSQLitePlus, but they are much more complex than my
program. They have things that I don't need, such as encryption or memory buffer.
I know Ulrich Telle and the other guys don't have much time available, but I would be very thankful if you check the code attached to this post.
Code: Select all
#ifndef TESTSCORESAPP_H
#define TESTSCORESAPP_H
#include <wx/app.h>
class TestScoresApp : public wxApp
{
public:
virtual bool OnInit();
};
#endif // TESTSCORESAPP_H
Code: Select all
#include "TestScoresApp.h"
//(*AppHeaders
#include "TestScoresMain.h"
#include <wx/image.h>
//*)
IMPLEMENT_APP(TestScoresApp);
bool TestScoresApp::OnInit()
{
//(*AppInitialize
bool wxsOK = true;
wxInitAllImageHandlers();
if ( wxsOK )
{
TestScoresFrame* Frame = new TestScoresFrame(0);
Frame->Show();
SetTopWindow(Frame);
}
//*)
return wxsOK;
}
Code: Select all
#ifndef TESTSCORESMAIN_H
#define TESTSCORESMAIN_H
//(*Headers(TestScoresFrame)
#include <wx/grid.h>
#include <wx/toolbar.h>
#include <wx/frame.h>
//*)
class TestScoresFrame: public wxFrame
{
public:
TestScoresFrame(wxWindow* parent,wxWindowID id = -1);
virtual ~TestScoresFrame();
private:
//(*Handlers(TestScoresFrame)
void OnToolBarItemAddClicked(wxCommandEvent& WXUNUSED(ev));
void OnToolBarItemCloseClicked(wxCommandEvent& event);
//*)
//(*Identifiers(TestScoresFrame)
static const long ID_GRIDSCORES;
static const long ID_TOOLADD;
static const long ID_TOOLCLOSE;
static const long ID_TOOLBARMAIN;
//*)
//(*Declarations(TestScoresFrame)
wxToolBarToolBase* ToolBarItemAdd;
wxToolBar* ToolBarMain;
wxToolBarToolBase* ToolBarItemClose;
wxGrid* GridScores;
//*)
DECLARE_EVENT_TABLE()
};
#endif // TESTSCORESMAIN_H
Code: Select all
#include "TestScoresMain.h"
#include <wx/msgdlg.h>
//(*InternalHeaders(TestScoresFrame)
#include <wx/string.h>
#include <wx/intl.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/artprov.h>
//*)
#include <wx/wxsqlite3.h>
//(*IdInit(TestScoresFrame)
const long TestScoresFrame::ID_GRIDSCORES = wxNewId();
const long TestScoresFrame::ID_TOOLADD = wxNewId();
const long TestScoresFrame::ID_TOOLCLOSE = wxNewId();
const long TestScoresFrame::ID_TOOLBARMAIN = wxNewId();
//*)
BEGIN_EVENT_TABLE(TestScoresFrame,wxFrame)
//(*EventTable(TestScoresFrame)
//*)
END_EVENT_TABLE()
TestScoresFrame::TestScoresFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(TestScoresFrame)
Create(parent, id, _("Test Scores"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
GridScores = new wxGrid(this, ID_GRIDSCORES, wxPoint(128,184), wxDefaultSize, 0, _T("ID_GRIDSCORES"));
GridScores->CreateGrid(10,7);
GridScores->EnableEditing(true);
GridScores->EnableGridLines(true);
GridScores->SetColLabelValue(0, _("Name"));
GridScores->SetColLabelValue(1, _("Score 1"));
GridScores->SetColLabelValue(2, _("Score 2"));
GridScores->SetColLabelValue(3, _("Score 3"));
GridScores->SetColLabelValue(4, _("Score 4"));
GridScores->SetColLabelValue(5, _("Score 5"));
GridScores->SetColLabelValue(6, _("Score 6"));
GridScores->SetDefaultCellFont( GridScores->GetFont() );
GridScores->SetDefaultCellTextColour( GridScores->GetForegroundColour() );
ToolBarMain = new wxToolBar(this, ID_TOOLBARMAIN, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxTB_LEFT|wxNO_BORDER, _T("ID_TOOLBARMAIN"));
ToolBarItemAdd = ToolBarMain->AddTool(ID_TOOLADD, _("Add Line"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_ADD_BOOKMARK")),wxART_TOOLBAR), wxNullBitmap, wxITEM_NORMAL, _("Add Line"), wxEmptyString);
ToolBarItemClose = ToolBarMain->AddTool(ID_TOOLCLOSE, _("Close"), wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(_T("wxART_QUIT")),wxART_TOOLBAR), wxNullBitmap, wxITEM_NORMAL, _("Close"), wxEmptyString);
ToolBarMain->Realize();
SetToolBar(ToolBarMain);
Connect(ID_TOOLADD,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&TestScoresFrame::OnToolBarItemAddClicked);
Connect(ID_TOOLCLOSE,wxEVT_COMMAND_TOOL_CLICKED,(wxObjectEventFunction)&TestScoresFrame::OnToolBarItemCloseClicked);
//*)
}
TestScoresFrame::~TestScoresFrame()
{
//(*Destroy(TestScoresFrame)
//*)
}
void TestScoresFrame::OnToolBarItemAddClicked(wxCommandEvent& WXUNUSED(ev))
{
int totalLines = GridScores->GetNumberRows();
GridScores->InsertRows(totalLines +1);
}
void TestScoresFrame::OnToolBarItemCloseClicked(wxCommandEvent& event)
{
Close();
}
Code: Select all
#ifndef DBSCORES_H
#define DBSCORES_H
#include "wx/wxsqlite3.h"
class dbScores : public wxSQLite3Database
{
wxSQLite3Database * ScoresDatabase;
public:
dbScores();
virtual ~dbScores();
protected:
private:
};
#endif // DBSCORES_H
Code: Select all
#include "dbScores.h"
#include "TestScoresMain.h"
dbScores::dbScores()
{
//ctor
ScoresDatabase = new wxSQLite3Database();
}
dbScores::~dbScores()
{
//dtor
if (ScoresDatabase)
{
ScoresDatabase->Close;
delete ScoresDatabase;
ScoresDatabase = NULL;
}
}
const wxString theDatabaseFile = wxGetCwd() + wxT("/scores.db");