@@ -1,7 +1,8 @@ | |||
#include "bdd.h" | |||
class_bdd::class_bdd(const wxString& path_in) | |||
class_bdd::class_bdd(const wxString& path_in, wxGrid* gridptr) | |||
{ | |||
this->gridptr = gridptr; | |||
path = path_in + slash + "cosmos.db"; | |||
if (!wxFileExists(path)) | |||
createEmpty(); | |||
@@ -10,6 +11,7 @@ class_bdd::class_bdd(const wxString& path_in) | |||
wxMessageBox(_T("Erreur lors de l'ouverture de la base de données"), "Erreur", wxICON_ERROR | wxOK); | |||
exit(0); | |||
} | |||
else updategrid(); | |||
} | |||
class_bdd::~class_bdd() | |||
@@ -22,7 +24,7 @@ void class_bdd::createEmpty() | |||
rc = 0; | |||
rc += sqlite3_open_v2(_C(path), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); | |||
rc += sqlite3_exec(db, "CREATE TABLE Consult(id INTEGER PRIMARY KEY ASC, n_dossier INTEGER, nom VARCHAR(50), prenom VARCHAR(50), responsable VARCHAR(100), consultant VARCHAR(50), theme TEXT, etablissement VARCHAR(100), travail VARCHAR(50), date_cs DATE, publi_prevue BOOLEAN);", NULL, NULL, NULL); | |||
rc += sqlite3_exec(db, "CREATE TABLE Result(id INTEGER PRIMARY KEY ASC, publi BOOLEAN DEFAULT 0, cs_associe BOOLEAN DEFAULT 0, publi_CHU BOOLEAN DEFAULT 0, nb_result INTEGER DEFAULT 0, id_result TEXT DEFAULT \"\");", NULL, NULL, NULL); | |||
rc += sqlite3_exec(db, "CREATE TABLE Result(id INTEGER PRIMARY KEY ASC, publi BOOLEAN DEFAULT 0, publi_CHU BOOLEAN DEFAULT 0, cs_associe BOOLEAN DEFAULT 0, nb_result INTEGER DEFAULT 0, id_result TEXT DEFAULT \"\");", NULL, NULL, NULL); | |||
rc += sqlite3_exec(db, "CREATE TABLE Publi(id INTEGER PRIMARY KEY, titre TEXT, auteurs TEXT, lien VARCHAR(50), date_publi DATE);", NULL, NULL, NULL); | |||
rc += sqlite3_exec(db, "CREATE TABLE Correc(orig TEXT PRIMARY KEY, dest TEXT);", NULL, NULL, NULL); | |||
if (rc) | |||
@@ -34,7 +36,7 @@ void class_bdd::createEmpty() | |||
wxMessageBox(_T("La base de données est vide,\nveuillez importer des données !")); | |||
} | |||
void class_bdd::import(const wxString& filename) | |||
void class_bdd::importer(const wxString& filename) | |||
{ | |||
rc = 0; | |||
int size = 0; | |||
@@ -44,8 +46,8 @@ void class_bdd::import(const wxString& filename) | |||
fseek(importfile, 0, SEEK_END); | |||
size = ftell(importfile); | |||
rewind(importfile); | |||
wxProgressDialog progress_dialog("Import", "Import de la base...", size); | |||
sqlite3_exec(db, "SAVEPOINT before_import;", NULL, NULL, NULL); | |||
wxProgressDialog progress_dialog("Import", "Import de la base...", size, NULL, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_ELAPSED_TIME | wxPD_REMAINING_TIME | wxPD_CAN_ABORT); | |||
char c; | |||
bool inquote = false; | |||
bool firstline = true; | |||
@@ -107,11 +109,66 @@ void class_bdd::import(const wxString& filename) | |||
rc += sqlite3_exec(db, requete, NULL, NULL, NULL); | |||
} | |||
firstline = false; | |||
progress_dialog.Update(progress); | |||
if (!progress_dialog.Update(progress)) | |||
{ | |||
wxMessageBox(_T("Aucune nouvelle donnée n'a été ajoutée"), "Attention !"); | |||
sqlite3_exec(db, "ROLLBACK TO before_import;", NULL, NULL, NULL); | |||
break; | |||
} | |||
}while (c != EOF); | |||
fclose(importfile); | |||
progress_dialog.Update(size); | |||
sqlite3_exec(db, "RELEASE before_import;", NULL, NULL, NULL); | |||
if (rc) | |||
wxMessageBox("Erreur lors de l'import", "Erreur", wxOK | wxICON_ERROR); | |||
updategrid(); | |||
} | |||
void class_bdd::exporter(const wxString& filename) | |||
{ | |||
} | |||
void class_bdd::updategrid() | |||
{ | |||
wxBeginBusyCursor(); | |||
rc = 0; | |||
int nbligne = 0; | |||
stmt = NULL; | |||
gridptr->DeleteRows(0, gridptr->GetNumberRows()); | |||
sqlite3_prepare_v2(db, "SELECT * FROM Consult", -1, &stmt, NULL); | |||
while (sqlite3_step(stmt) == SQLITE_ROW) | |||
{ | |||
gridptr->AppendRows(); | |||
gridptr->SetCellValue(nbligne, 4, wxString::Format("%i",sqlite3_column_int(stmt, 1))); | |||
gridptr->SetReadOnly(nbligne, 4); | |||
for (int i=2; i<10; i++) | |||
gridptr->SetCellValue(nbligne, i+3, wxString::FromAscii(sqlite3_column_text(stmt, i))); | |||
gridptr->SetReadOnly(nbligne, 12); | |||
gridptr->SetCellRenderer(nbligne, 12, new wxGridCellDateTimeRenderer); | |||
nbligne++; | |||
} | |||
sqlite3_finalize(stmt); | |||
nbligne = 0; | |||
sqlite3_prepare_v2(db, "SELECT * FROM Result", -1, &stmt, NULL); | |||
while (sqlite3_step(stmt) == SQLITE_ROW) | |||
{ | |||
gridptr->SetCellValue(nbligne, 0, wxString::Format("%i",sqlite3_column_int(stmt, 4))); | |||
gridptr->SetReadOnly(nbligne, 0); | |||
for (int i=1; i<4; i++) | |||
{ | |||
if (sqlite3_column_int(stmt, i) == 1) | |||
gridptr->SetCellValue(nbligne, i, "1"); | |||
else | |||
gridptr->SetCellValue(nbligne, i, ""); | |||
} | |||
nbligne++; | |||
} | |||
sqlite3_finalize(stmt); | |||
gridptr->AutoSizeColumns(false); | |||
gridptr->AutoSizeRows(false); | |||
wxEndBusyCursor(); | |||
} |
@@ -5,6 +5,8 @@ | |||
#include <cstdio> | |||
#include <wx/msgdlg.h> | |||
#include <wx/progdlg.h> | |||
#include <wx/grid.h> | |||
#include <wx/utils.h> | |||
#include <sqlite3.h> | |||
#ifdef __WXGTK__ | |||
@@ -22,12 +24,15 @@ class class_bdd | |||
sqlite3_stmt* stmt; | |||
int rc; | |||
wxString path; | |||
wxGrid* gridptr; | |||
void createEmpty(); | |||
public: | |||
class_bdd(const wxString& path_in); | |||
class_bdd(const wxString& path_in, wxGrid* gridptr); | |||
~class_bdd(); | |||
void import(const wxString& filename); | |||
void importer(const wxString& filename); | |||
void exporter(const wxString& filename); | |||
void updategrid(); | |||
}; | |||
@@ -13,7 +13,7 @@ cosmosGUI( parent ) | |||
fenetre_options->ShowModal(); | |||
} | |||
bdd = new class_bdd(configuration->GetDbpath()); | |||
bdd = new class_bdd(configuration->GetDbpath(), grid_Consults); | |||
} | |||
void cosmos::OnImport( wxCommandEvent& event ) | |||
@@ -23,7 +23,7 @@ void cosmos::OnImport( wxCommandEvent& event ) | |||
if (opendialog->ShowModal() == wxID_CANCEL) | |||
return; | |||
else | |||
bdd->import(opendialog->GetPath()); | |||
bdd->importer(opendialog->GetPath()); | |||
delete opendialog; | |||
} | |||
@@ -65,3 +65,13 @@ void cosmos::OnOptionsProg( wxCommandEvent& event ) | |||
{ | |||
fenetre_options->Show(true); | |||
} | |||
void cosmos::OnCellChange( wxGridEvent& event ) | |||
{ | |||
// TODO: Implement OnCellChange | |||
} | |||
void cosmos::OnCellDbClick( wxGridEvent& event ) | |||
{ | |||
// TODO: Implement OnCellDbClick | |||
} |
@@ -79,7 +79,7 @@ | |||
<event name="OnSetFocus"></event> | |||
<event name="OnSize"></event> | |||
<event name="OnUpdateUI"></event> | |||
<object class="wxMenuBar" expanded="1"> | |||
<object class="wxMenuBar" expanded="0"> | |||
<property name="bg"></property> | |||
<property name="context_help"></property> | |||
<property name="context_menu">1</property> | |||
@@ -128,7 +128,7 @@ | |||
<event name="OnSetFocus"></event> | |||
<event name="OnSize"></event> | |||
<event name="OnUpdateUI"></event> | |||
<object class="wxMenu" expanded="1"> | |||
<object class="wxMenu" expanded="0"> | |||
<property name="label">Fichier</property> | |||
<property name="name">menu_Fichier</property> | |||
<property name="permission">protected</property> | |||
@@ -182,11 +182,11 @@ | |||
<event name="OnUpdateUI"></event> | |||
</object> | |||
</object> | |||
<object class="wxMenu" expanded="1"> | |||
<object class="wxMenu" expanded="0"> | |||
<property name="label">Edition</property> | |||
<property name="name">menu_Edit</property> | |||
<property name="permission">protected</property> | |||
<object class="wxMenuItem" expanded="1"> | |||
<object class="wxMenuItem" expanded="0"> | |||
<property name="bitmap">icons/optionsgales.png; Load From File</property> | |||
<property name="checked">0</property> | |||
<property name="enabled">1</property> | |||
@@ -208,7 +208,7 @@ | |||
<property name="permission">protected</property> | |||
</object> | |||
</object> | |||
<object class="wxToolBar" expanded="1"> | |||
<object class="wxToolBar" expanded="0"> | |||
<property name="bg"></property> | |||
<property name="bitmapsize"></property> | |||
<property name="context_help"></property> | |||
@@ -400,8 +400,8 @@ | |||
<property name="flag">wxALL|wxEXPAND</property> | |||
<property name="proportion">1</property> | |||
<object class="wxGrid" expanded="0"> | |||
<property name="autosize_cols">0</property> | |||
<property name="autosize_rows">0</property> | |||
<property name="autosize_cols">1</property> | |||
<property name="autosize_rows">1</property> | |||
<property name="bg"></property> | |||
<property name="cell_bg"></property> | |||
<property name="cell_font"></property> | |||
@@ -410,16 +410,16 @@ | |||
<property name="cell_vert_alignment">wxALIGN_TOP</property> | |||
<property name="col_label_horiz_alignment">wxALIGN_CENTRE</property> | |||
<property name="col_label_size">30</property> | |||
<property name="col_label_values">"Publication ?" "Consultant associé ?" "Publication CHU ?" "N° Dossier" "Nom(s) demandeur(s)" "Prénom(s) demandeur(s)" "Nom(s) responsable(s)" "Thème" "Date dernière consultation" "Résultats"</property> | |||
<property name="col_label_values">"Resultats" "Publi ?" "Publi CHU ?" "Consultant associé ?" "N° Dossier" "Nom(s) demandeur(s)" "Prénom(s) demandeur(s)" "Nom(s) responsable(s)" "Consultant" "Thème" "Etablissement" "Travail" "Date consultation"</property> | |||
<property name="col_label_vert_alignment">wxALIGN_CENTRE</property> | |||
<property name="cols">10</property> | |||
<property name="column_sizes">83,125,107,68,135,154,139,49,161,64</property> | |||
<property name="cols">13</property> | |||
<property name="column_sizes">64,46,72,125,68,135,154,139,71,49,90,49,110</property> | |||
<property name="context_help"></property> | |||
<property name="context_menu">1</property> | |||
<property name="drag_col_move">0</property> | |||
<property name="drag_col_size">1</property> | |||
<property name="drag_grid_size">1</property> | |||
<property name="drag_row_size">0</property> | |||
<property name="drag_row_size">1</property> | |||
<property name="editing">1</property> | |||
<property name="enabled">1</property> | |||
<property name="fg"></property> | |||
@@ -457,9 +457,9 @@ | |||
<event name="OnChar"></event> | |||
<event name="OnEnterWindow"></event> | |||
<event name="OnEraseBackground"></event> | |||
<event name="OnGridCellChange"></event> | |||
<event name="OnGridCellChange">OnCellChange</event> | |||
<event name="OnGridCellLeftClick"></event> | |||
<event name="OnGridCellLeftDClick"></event> | |||
<event name="OnGridCellLeftDClick">OnCellDbClick</event> | |||
<event name="OnGridCellRightClick"></event> | |||
<event name="OnGridCellRightDClick"></event> | |||
<event name="OnGridCmdCellChange"></event> | |||
@@ -11,8 +11,6 @@ Subclass of cosmosGUI, which is generated by wxFormBuilder. | |||
#include "bdd.h" | |||
#include "config.h" | |||
//// end generated include | |||
/** Implementing cosmosGUI */ | |||
class cosmos : public cosmosGUI | |||
{ | |||
@@ -29,6 +27,8 @@ protected: | |||
void OnOptionsProg( wxCommandEvent& event ); | |||
void OnCorrections( wxCommandEvent& event ); | |||
void OnSearch( wxCommandEvent& event ); | |||
void OnCellChange( wxGridEvent& event ); | |||
void OnCellDbClick( wxGridEvent& event ); | |||
public: | |||
/** Constructor */ | |||
cosmos( wxWindow* parent ); | |||
@@ -78,47 +78,61 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co | |||
grid_Consults = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); | |||
// Grid | |||
grid_Consults->CreateGrid( 0, 10 ); | |||
grid_Consults->CreateGrid( 0, 13); | |||
grid_Consults->EnableEditing( true ); | |||
grid_Consults->EnableGridLines( true ); | |||
grid_Consults->EnableDragGridSize( true ); | |||
grid_Consults->SetMargins( 0, 0 ); | |||
// Columns | |||
grid_Consults->SetColSize( 0, 83 ); | |||
grid_Consults->SetColSize( 1, 125 ); | |||
grid_Consults->SetColSize( 2, 107 ); | |||
grid_Consults->SetColSize( 3, 68 ); | |||
grid_Consults->SetColSize( 4, 135 ); | |||
grid_Consults->SetColSize( 5, 154 ); | |||
grid_Consults->SetColSize( 6, 139 ); | |||
grid_Consults->SetColSize( 7, 49 ); | |||
grid_Consults->SetColSize( 8, 161 ); | |||
grid_Consults->SetColSize( 9, 64 ); | |||
grid_Consults->SetColSize( 0, 64 ); | |||
grid_Consults->SetColSize( 1, 46 ); | |||
grid_Consults->SetColSize( 2, 72 ); | |||
grid_Consults->SetColSize( 3, 125 ); | |||
grid_Consults->SetColSize( 4, 68 ); | |||
grid_Consults->SetColSize( 5, 135 ); | |||
grid_Consults->SetColSize( 6, 154 ); | |||
grid_Consults->SetColSize( 7, 139 ); | |||
grid_Consults->SetColSize( 8, 71 ); | |||
grid_Consults->SetColSize( 9, 49 ); | |||
grid_Consults->SetColSize( 10, 90 ); | |||
grid_Consults->SetColSize( 11, 49 ); | |||
grid_Consults->SetColSize( 12, 110 ); | |||
grid_Consults->EnableDragColMove( false ); | |||
grid_Consults->EnableDragColSize( true ); | |||
grid_Consults->SetColLabelSize( 30 ); | |||
grid_Consults->SetColLabelValue( 0, "Publication ?" ); | |||
grid_Consults->SetColLabelValue( 1, _T("Consultant associé ?") ); | |||
grid_Consults->SetColLabelValue( 2, "Publication CHU ?" ); | |||
grid_Consults->SetColLabelValue( 3, _T("N° Dossier") ); | |||
grid_Consults->SetColLabelValue( 4, "Nom(s) demandeur(s)" ); | |||
grid_Consults->SetColLabelValue( 5, _T("Prénom(s) demandeur(s)") ); | |||
grid_Consults->SetColLabelValue( 6, "Nom(s) responsable(s)" ); | |||
grid_Consults->SetColLabelValue( 7, _T("Thème") ); | |||
grid_Consults->SetColLabelValue( 8, _T("Date dernière consultation") ); | |||
grid_Consults->SetColLabelValue( 9, _T("Résultats") ); | |||
grid_Consults->SetColLabelValue( 0, wxT("Resultats") ); | |||
grid_Consults->SetColLabelValue( 1, wxT("Publi ?") ); | |||
grid_Consults->SetColLabelValue( 2, wxT("Publi CHU ?") ); | |||
grid_Consults->SetColLabelValue( 3, wxT("Consultant associé ?") ); | |||
grid_Consults->SetColLabelValue( 4, wxT("N° Dossier") ); | |||
grid_Consults->SetColLabelValue( 5, wxT("Nom(s) demandeur(s)") ); | |||
grid_Consults->SetColLabelValue( 6, wxT("Prénom(s) demandeur(s)") ); | |||
grid_Consults->SetColLabelValue( 7, wxT("Nom(s) responsable(s)") ); | |||
grid_Consults->SetColLabelValue( 8, wxT("Consultant") ); | |||
grid_Consults->SetColLabelValue( 9, wxT("Thème") ); | |||
grid_Consults->SetColLabelValue( 10, wxT("Etablissement") ); | |||
grid_Consults->SetColLabelValue( 11, wxT("Travail") ); | |||
grid_Consults->SetColLabelValue( 12, wxT("Date consultation") ); | |||
grid_Consults->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); | |||
grid_Consults->SetDefaultEditor(new wxGridCellAutoWrapStringEditor); | |||
grid_Consults->SetDefaultRenderer(new wxGridCellStringRenderer); | |||
grid_Consults->SetColFormatNumber(0); | |||
grid_Consults->SetColFormatBool(1); | |||
grid_Consults->SetColFormatBool(2); | |||
grid_Consults->SetColFormatBool(3); | |||
grid_Consults->SetColFormatNumber(4); | |||
// Rows | |||
grid_Consults->EnableDragRowSize( false ); | |||
grid_Consults->EnableDragRowSize( true ); | |||
grid_Consults->SetRowLabelSize( 80 ); | |||
grid_Consults->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); | |||
// Label Appearance | |||
// Cell Defaults | |||
grid_Consults->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); | |||
grid_Consults->SetDefaultCellAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); | |||
bSizer2->Add( grid_Consults, 1, wxALL|wxEXPAND, 5 ); | |||
this->SetSizer( bSizer2 ); | |||
@@ -138,6 +152,8 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co | |||
this->Connect( wxID_FIND, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( cosmosGUI::OnOptionsRche ) ); | |||
this->Connect( wxID_DUPLICATE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( cosmosGUI::OnCorrections ) ); | |||
searchctrl->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( cosmosGUI::OnSearch ), NULL, this ); | |||
grid_Consults->Connect( wxEVT_GRID_CELL_CHANGE, wxGridEventHandler( cosmosGUI::OnCellChange ), NULL, this ); | |||
grid_Consults->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( cosmosGUI::OnCellDbClick ), NULL, this ); | |||
} | |||
cosmosGUI::~cosmosGUI() | |||
@@ -154,5 +170,7 @@ cosmosGUI::~cosmosGUI() | |||
this->Disconnect( wxID_FIND, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( cosmosGUI::OnOptionsRche ) ); | |||
this->Disconnect( wxID_DUPLICATE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( cosmosGUI::OnCorrections ) ); | |||
searchctrl->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( cosmosGUI::OnSearch ), NULL, this ); | |||
grid_Consults->Disconnect( wxEVT_GRID_CELL_CHANGE, wxGridEventHandler( cosmosGUI::OnCellChange ), NULL, this ); | |||
grid_Consults->Disconnect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( cosmosGUI::OnCellDbClick ), NULL, this ); | |||
} |
@@ -52,7 +52,8 @@ class cosmosGUI : public wxFrame | |||
virtual void OnOptionsRche( wxCommandEvent& event ) { event.Skip(); } | |||
virtual void OnCorrections( wxCommandEvent& event ) { event.Skip(); } | |||
virtual void OnSearch( wxCommandEvent& event ) { event.Skip(); } | |||
virtual void OnCellChange( wxGridEvent& event ) { event.Skip(); } | |||
virtual void OnCellDbClick( wxGridEvent& event ) { event.Skip(); } | |||
public: | |||
@@ -26,7 +26,8 @@ int main(int argc, char **argv) | |||
exit(0); | |||
} | |||
if ((rc = sqlite3_step(stmt)) == SQLITE_DONE) //SQLITE_ROW si une nouvelle ligne est chopable, traiter la courante avec int/char* sqlite3_column_int/text(stmt, n_col); | |||
if ((rc = sqlite3_step(stmt)) == SQLITE_DONE) //SQLITE_ROW si une nouvelle ligne est chopable, | |||
//traiter la courante avec int/char* sqlite3_column_int/text(stmt, n_col); | |||
//int sqlite_column_count(stmt) retourne nb_col (0 si stmt sans retour de data) | |||
//int sqlite_column_type(stmt, n_col) retourne le type SQLITE_INTEGER/FLOAT/TEXT/BLOB/NULL | |||
printf("Step OK\n"); | |||