- fenêtre spécifique fonctionnelle (modification et suppression) - clic sur label (X) pour supprimer - mise à jour de la grille après modification - autocorrections pour prénoms (XX, xy, etc…) et responsables (Dr., Pr., etc…)master
@@ -11,7 +11,6 @@ class_bdd::class_bdd(const wxString& path_in, wxGrid* gridptr) | |||
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() | |||
@@ -34,8 +33,6 @@ void class_bdd::createEmpty(const wxString& path) | |||
wxMessageBox(_T("Erreur lors de la création de la base de données"), "Erreur", wxICON_ERROR | wxOK); | |||
exit(0); | |||
} | |||
wxMessageBox(_T("La base de données est vide,\nveuillez importer des données !")); | |||
} | |||
void class_bdd::importer(const wxString& filename) | |||
@@ -95,24 +92,24 @@ void class_bdd::importer(const wxString& filename) | |||
{ | |||
//Insertion dans la table de consults | |||
wxString requete = "INSERT OR REPLACE INTO Consult (id, n_dossier, nom, prenom, responsable, consultant, theme, etablissement, travail, date_cs, publi_prevue, service) VALUES ("; | |||
requete << item[0] << ", "; //numéro travail -> id PRIMARY KEY | |||
requete << item[0] << ", "; //numéro travail -> id PRIMARY KEY | |||
if (item[1].IsSameAs("")) //n_dossier | |||
requete << "NULL, "; | |||
else | |||
requete << item[1] << ", "; | |||
requete << "\"" << item[3] << "\", " //Nom | |||
<< "\"" << item[4] << "\", " //Prénom | |||
<< "\"" << item[19] << "\", " //Responsable | |||
<< "\"" << item[20] << "\", " //Consultant | |||
<< "\"" << item[13] << "\", " //Thème | |||
<< "\"" << item[7] << "\", " //Etablissement | |||
<< "\"" << item[12] << "\", " //Type travail | |||
<< "\"" << item[21] << "\", "; //Date_cs | |||
if (item[18].IsSameAs("VRAI", false)) //Publi prévue | |||
requete << "\"" << item[3] << "\", " //Nom | |||
<< "\"" << item[4] << "\", " //Prénom | |||
<< "\"" << item[19] << "\", " //Responsable | |||
<< "\"" << item[20] << "\", " //Consultant | |||
<< "\"" << item[13] << "\", " //Thème | |||
<< "\"" << item[7] << "\", " //Etablissement | |||
<< "\"" << item[12] << "\", " //Type travail | |||
<< "\"" << item[21] << "\", "; //Date_cs | |||
if (item[18].IsSameAs("VRAI", false)) //Publi prévue | |||
requete << "1, "; | |||
else | |||
requete << "0, "; | |||
requete << "\"" << item[6] << "\"" //Service | |||
requete << "\"" << item[6] << "\"" //Service | |||
<< ");"; | |||
rc += sqlite3_exec(db, requete, NULL, NULL, NULL); | |||
@@ -156,7 +153,7 @@ void class_bdd::updategrid() | |||
stmt = NULL; | |||
if (gridptr->GetNumberRows() != 0) | |||
gridptr->DeleteRows(0, gridptr->GetNumberRows()); //reset de la grille | |||
sqlite3_prepare_v2(db, "SELECT * FROM Consult", -1, &stmt, NULL); //import depuis Consult | |||
rc = sqlite3_prepare_v2(db, "SELECT * FROM Consult;", -1, &stmt, NULL); //import depuis Consult | |||
if (sqlite3_step(stmt) == SQLITE_DONE) //Si la bdd est vide | |||
{ | |||
wxEndBusyCursor(); | |||
@@ -169,15 +166,47 @@ void class_bdd::updategrid() | |||
{ | |||
gridptr->AppendRows(); | |||
gridptr->SetCellValue(nligne, 4, _itoW(sqlite3_column_int(stmt, 1))); //n_dossier | |||
for (int i=2; i<10; i++) | |||
gridptr->SetCellValue(nligne, i+3, _W(sqlite3_column_text(stmt, i))); //nom, prénom, responsable, consultant, theme, etablissement, travail, date | |||
for (int i=2; i<10; i++) //nom, prénom, responsable, consultant, theme, etablissement, travail, date | |||
{ | |||
wxString orig = _W(sqlite3_column_text(stmt, i)); | |||
rc = sqlite3_prepare_v2(db, "SELECT dest FROM Correc WHERE orig=\"" + orig + "\";", -1, &stmt_correc, NULL); //fetch d'une éventuelle correction | |||
if (sqlite3_step(stmt_correc) == SQLITE_DONE) | |||
gridptr->SetCellValue(nligne, i+3, orig); | |||
else | |||
{ | |||
gridptr->SetCellValue(nligne, i+3, _W(sqlite3_column_text(stmt_correc, 0))); | |||
//gridptr->SetCellBackgroundColour(nligne, i+3, *wxYELLOW); | |||
} | |||
sqlite3_finalize(stmt_correc); | |||
} | |||
// autocorrection prenoms | |||
wxString prenom = gridptr->GetCellValue(nligne, 6); | |||
if (prenom.IsSameAs("xxx", false) || prenom.IsSameAs("xx", false) || prenom.IsSameAs("zzz", false) || prenom.IsSameAs("zz", false) || prenom.IsSameAs("yy", false) || prenom.IsSameAs("xy", false)) | |||
gridptr->SetCellValue(nligne, 6, ""); | |||
// autocorrection responsables | |||
wxString resp = gridptr->GetCellValue(nligne, 7); | |||
resp.Replace("Mr. Le Pr. ", "", true); | |||
resp.Replace("Mme Le Dr. ", "", true); | |||
resp.Replace("Mme Le Pr. ", "", true); | |||
resp.Replace("Mr. ", "", true); | |||
resp.Replace("Dr. ", "", true); | |||
resp.Replace("Pr. ", "", true); | |||
resp.Replace("Pr ", "", true); | |||
resp.Replace("Mme ", "", true); | |||
resp.Replace("Melle ", "", true); | |||
gridptr->SetCellValue(nligne, 7, resp); | |||
gridptr->SetCellValue(nligne, 13, _itoW(sqlite3_column_int(stmt, 0))); //id, caché | |||
/*wxColour lightgreen(230, 255, 230); //TODO: gestion des couleurs dans la config ? | |||
if (sqlite3_column_int(stmt, 10)) | |||
for (int j=0; j<13; j++) | |||
gridptr->SetCellBackgroundColour(nligne, j, lightgreen); //coloration des publis prévues*/ | |||
nligne++; | |||
} | |||
sqlite3_finalize(stmt); | |||
nligne = 0; | |||
sqlite3_prepare_v2(db, "SELECT * FROM Result", -1, &stmt, NULL); //import depuis Result | |||
sqlite3_prepare_v2(db, "SELECT * FROM Result;", -1, &stmt, NULL); //import depuis Result | |||
while (sqlite3_step(stmt) == SQLITE_ROW) | |||
{ | |||
gridptr->SetCellValue(nligne, 0, _itoW(sqlite3_column_int(stmt, 4))); //nb_results | |||
@@ -207,12 +236,85 @@ void class_bdd::modresultbool(const wxString& id, int col, const wxString& val) | |||
wxString requete = "UPDATE Result SET "; | |||
switch (col) | |||
{ | |||
case 1: requete << "publi="; break; | |||
case 2: requete << "publi_CHU="; break; | |||
case 3: requete << "cs_associe="; break; | |||
case 1: requete << "publi"; break; | |||
case 2: requete << "publi_CHU"; break; | |||
case 3: requete << "cs_associe"; break; | |||
} | |||
requete << val | |||
requete << "=" << val | |||
<< " WHERE id=" | |||
<< id; | |||
<< id << ";"; | |||
rc = sqlite3_exec(db, requete, NULL, NULL, NULL); | |||
if (rc) | |||
wxMessageBox("Erreur lors de la mise à jour de la valeur", "Erreur", wxOK | wxICON_ERROR); | |||
} | |||
int class_bdd::nbcorrections() | |||
{ | |||
int count = 0; | |||
sqlite3_prepare_v2(db, "SELECT * FROM Correc;", -1, &stmt, NULL); | |||
while (sqlite3_step(stmt) == SQLITE_ROW) | |||
count++; | |||
sqlite3_finalize(stmt); | |||
return count; | |||
} | |||
wxString* class_bdd::getcorrecorig() | |||
{ | |||
wxString* retour = new wxString[nbcorrections()]; | |||
sqlite3_prepare_v2(db, "SELECT * FROM Correc;", -1, &stmt, NULL); | |||
for (int i=0; sqlite3_step(stmt) == SQLITE_ROW; i++) | |||
retour[i] = _W(sqlite3_column_text(stmt, 0)); | |||
sqlite3_finalize(stmt); | |||
return retour; | |||
} | |||
wxString* class_bdd::getcorrecdest() | |||
{ | |||
wxString* retour = new wxString[nbcorrections()]; | |||
sqlite3_prepare_v2(db, "SELECT * FROM Correc;", -1, &stmt, NULL); | |||
for (int i=0; sqlite3_step(stmt) == SQLITE_ROW; i++) | |||
retour[i] = _W(sqlite3_column_text(stmt, 1)); | |||
sqlite3_finalize(stmt); | |||
return retour; | |||
} | |||
void class_bdd::addcorrection(const wxString& id, int col, const wxString& dest) | |||
{ | |||
rc = 0; | |||
wxString requete = "SELECT * FROM Consult WHERE id=" + id + ";"; | |||
sqlite3_prepare_v2(db, requete, -1, &stmt, NULL); | |||
sqlite3_step(stmt); | |||
wxString orig = _W(sqlite3_column_text(stmt, col-3)); | |||
sqlite3_finalize(stmt); | |||
modcorrection(orig, dest); | |||
} | |||
void class_bdd::modcorrection(const wxString& orig, const wxString& dest) | |||
{ | |||
wxString requete = "INSERT OR REPLACE INTO Correc VALUES (\"" + orig + "\",\"" + dest + "\");"; | |||
sqlite3_exec(db, requete, NULL, NULL, NULL); | |||
// Mise à jour de la grille | |||
for (int i=0; i<gridptr->GetNumberRows(); i++) | |||
{ | |||
requete = "SELECT * FROM Consult WHERE id=" + gridptr->GetCellValue(i, 13) + ";"; | |||
sqlite3_prepare_v2(db, requete, -1, &stmt, NULL); | |||
sqlite3_step(stmt); | |||
for (int j=5; j<11; j++) | |||
{ | |||
wxString table_orig = _W(sqlite3_column_text(stmt, j - 3)); | |||
if (table_orig == orig) | |||
gridptr->SetCellValue(i, j, dest); | |||
} | |||
sqlite3_finalize(stmt); | |||
} | |||
// Suppression d'une correction si on revient à l'original | |||
if (dest == orig) | |||
delcorrection(orig); | |||
} | |||
void class_bdd::delcorrection(const wxString& orig) | |||
{ | |||
sqlite3_exec(db, "DELETE FROM Correc WHERE orig=\"" + orig + "\";", NULL, NULL, NULL); | |||
} |
@@ -26,7 +26,7 @@ class class_bdd | |||
{ | |||
private: | |||
sqlite3* db; | |||
sqlite3_stmt* stmt; | |||
sqlite3_stmt* stmt, *stmt_correc; | |||
int rc; | |||
wxGrid* gridptr; | |||
@@ -38,6 +38,12 @@ class class_bdd | |||
void exporter(const wxString& filename); | |||
void updategrid(); | |||
void modresultbool(const wxString& id, int col, const wxString& val); | |||
int nbcorrections(); | |||
wxString* getcorrecorig(); | |||
wxString* getcorrecdest(); | |||
void addcorrection(const wxString& id, int col, const wxString& dest); | |||
void modcorrection(const wxString& orig, const wxString& dest); | |||
void delcorrection(const wxString& orig); | |||
}; | |||
@@ -1,36 +1,50 @@ | |||
#include "correc.h" | |||
correc::correc( wxWindow* parent ) | |||
correc::correc( wxWindow* parent, class_bdd* bdd ) | |||
: | |||
dialog_correc( parent ) | |||
{ | |||
grid_Correcs->AppendRows(25); | |||
grid_Correcs->SetCellValue(0, 0, "Texte\noriginal"); | |||
grid_Correcs->SetCellValue(0, 1, "Correction"); | |||
grid_Correcs->SetCellValue(0, 2, "X"); | |||
this->bdd = bdd; | |||
} | |||
void correc::update() | |||
{ | |||
int nbcorrec = bdd->nbcorrections(); | |||
if (grid_Correcs->GetNumberRows() != 0) | |||
grid_Correcs->DeleteRows(0, grid_Correcs->GetNumberRows()); //reset de la grille | |||
grid_Correcs->AppendRows(nbcorrec); | |||
wxString* correcorig = bdd->getcorrecorig(); | |||
wxString* correcdest = bdd->getcorrecdest(); | |||
for (int i=0; i<nbcorrec; i++) | |||
{ | |||
grid_Correcs->SetRowLabelValue(i, "X"); | |||
grid_Correcs->SetCellValue(i, 0, correcorig[i]); | |||
grid_Correcs->SetCellValue(i, 1, correcdest[i]); | |||
} | |||
grid_Correcs->AutoSizeRows(false); | |||
grid_Correcs->AutoSizeColumns(false); | |||
grid_Correcs->Fit(); | |||
Fit(); | |||
delete[] correcorig; | |||
delete[] correcdest; | |||
} | |||
void correc::OnCellChange( wxGridEvent& event ) | |||
{ | |||
// TODO: Implement OnCellChange | |||
int row = event.GetRow(); | |||
bdd->modcorrection(grid_Correcs->GetCellValue(row, 0), grid_Correcs->GetCellValue(row, 1)); | |||
} | |||
void correc::OnCellLeftClick( wxGridEvent& event ) | |||
void correc::OnLabelLeftClick( wxGridEvent& event ) | |||
{ | |||
// TODO: Implement OnCellLeftClick | |||
if (event.GetCol() == 2) | |||
event.Skip(); | |||
else | |||
if (event.GetRow() != -1) | |||
{ | |||
wxString orig = grid_Correcs->GetCellValue(event.GetRow(), 0); | |||
bdd->modcorrection(orig, orig); | |||
grid_Correcs->DeleteRows(event.GetRow(), 1, false); | |||
} | |||
} | |||
void correc::OnOk( wxCommandEvent& event ) | |||
{ | |||
// TODO: Implement OnOk | |||
Close(); | |||
} |
@@ -7,21 +7,24 @@ Subclass of dialog_correc, which is generated by wxFormBuilder. | |||
*/ | |||
#include "correcGUI.h" | |||
#include "bdd.h" | |||
//// end generated include | |||
/** Implementing dialog_correc */ | |||
class correc : public dialog_correc | |||
{ | |||
protected: | |||
// Handlers for dialog_correc events. | |||
void OnCellChange( wxGridEvent& event ); | |||
void OnCellLeftClick( wxGridEvent& event ); | |||
void OnOk( wxCommandEvent& event ); | |||
public: | |||
/** Constructor */ | |||
correc( wxWindow* parent ); | |||
//// end generated class members | |||
protected: | |||
class_bdd* bdd; | |||
// Handlers for dialog_correc events. | |||
void OnCellChange( wxGridEvent& event ); | |||
void OnLabelLeftClick( wxGridEvent& event ); | |||
void OnOk( wxCommandEvent& event ); | |||
public: | |||
/** Constructor */ | |||
correc( wxWindow* parent, class_bdd* bdd ); | |||
void update(); | |||
//// end generated class members | |||
}; | |||
@@ -19,7 +19,7 @@ dialog_correc::dialog_correc( wxWindow* parent, wxWindowID id, const wxString& t | |||
grid_Correcs = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); | |||
// Grid | |||
grid_Correcs->CreateGrid( 0, 3 ); | |||
grid_Correcs->CreateGrid( 0, 2 ); | |||
grid_Correcs->EnableEditing( true ); | |||
grid_Correcs->EnableGridLines( true ); | |||
grid_Correcs->EnableDragGridSize( true ); | |||
@@ -28,18 +28,15 @@ dialog_correc::dialog_correc( wxWindow* parent, wxWindowID id, const wxString& t | |||
// Columns | |||
grid_Correcs->SetColSize( 0, 114 ); | |||
grid_Correcs->SetColSize( 1, 82 ); | |||
grid_Correcs->SetColSize( 2, 80 ); | |||
grid_Correcs->EnableDragColMove( false ); | |||
grid_Correcs->EnableDragColSize( true ); | |||
grid_Correcs->SetColLabelSize( 30 ); | |||
grid_Correcs->SetColLabelValue( 0, wxT("Texte d'origine") ); | |||
grid_Correcs->SetColLabelValue( 1, wxT("Correction") ); | |||
grid_Correcs->SetColLabelValue( 2, wxT("Supprimer") ); | |||
grid_Correcs->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); | |||
// Rows | |||
grid_Correcs->EnableDragRowSize( true ); | |||
grid_Correcs->SetRowLabelSize( 0 ); | |||
grid_Correcs->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); | |||
grid_Correcs->SetDefaultEditor(new wxGridCellTextEditor); | |||
@@ -50,16 +47,7 @@ dialog_correc::dialog_correc( wxWindow* parent, wxWindowID id, const wxString& t | |||
col_orig->SetAlignment(wxALIGN_LEFT, wxALIGN_CENTRE); | |||
col_orig->SetRenderer(new wxGridCellStringRenderer); | |||
col_suppr = new wxGridCellAttr(); | |||
col_suppr->SetReadOnly(); | |||
col_suppr->SetAlignment(wxALIGN_CENTRE, wxALIGN_CENTRE); | |||
wxFont font; | |||
col_suppr->SetFont(font.Bold()); | |||
col_suppr->SetTextColour(*wxRED); | |||
col_suppr->SetBackgroundColour(*wxLIGHT_GREY); | |||
grid_Correcs->SetColAttr(0, col_orig); | |||
grid_Correcs->SetColAttr(2, col_suppr); | |||
// Label Appearance | |||
@@ -77,7 +65,7 @@ dialog_correc::dialog_correc( wxWindow* parent, wxWindowID id, const wxString& t | |||
// Connect Events | |||
grid_Correcs->Connect( wxEVT_GRID_CELL_CHANGE, wxGridEventHandler( dialog_correc::OnCellChange ), NULL, this ); | |||
grid_Correcs->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( dialog_correc::OnCellLeftClick ), NULL, this ); | |||
grid_Correcs->Connect( wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEventHandler( dialog_correc::OnLabelLeftClick ), NULL, this ); | |||
bouton_ok->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( dialog_correc::OnOk ), NULL, this ); | |||
} | |||
@@ -85,7 +73,7 @@ dialog_correc::~dialog_correc() | |||
{ | |||
// Disconnect Events | |||
grid_Correcs->Disconnect( wxEVT_GRID_CELL_CHANGE, wxGridEventHandler( dialog_correc::OnCellChange ), NULL, this ); | |||
grid_Correcs->Disconnect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( dialog_correc::OnCellLeftClick ), NULL, this ); | |||
grid_Correcs->Disconnect( wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEventHandler( dialog_correc::OnLabelLeftClick ), NULL, this ); | |||
bouton_ok->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( dialog_correc::OnOk ), NULL, this ); | |||
} |
@@ -35,7 +35,7 @@ class dialog_correc : public wxDialog | |||
// Virtual event handlers, overide them in your derived class | |||
virtual void OnCellChange( wxGridEvent& event ) { event.Skip(); } | |||
virtual void OnCellLeftClick( wxGridEvent& event ) { event.Skip(); } | |||
virtual void OnLabelLeftClick( wxGridEvent& event ) { event.Skip(); } | |||
virtual void OnOk( wxCommandEvent& event ) { event.Skip(); } | |||
@@ -14,7 +14,8 @@ cosmosGUI( parent ) | |||
} | |||
bdd = new class_bdd(configuration->GetDbpath(), grid_Consults); | |||
fenetre_corrections = new correc(this); | |||
bdd->updategrid(); | |||
fenetre_corrections = new correc(this, bdd); | |||
} | |||
void cosmos::OnImport( wxCommandEvent& event ) | |||
@@ -55,7 +56,7 @@ void cosmos::OnOptionsRche( wxCommandEvent& event ) | |||
void cosmos::OnCorrections( wxCommandEvent& event ) | |||
{ | |||
// TODO: Implement OnCorrections | |||
fenetre_corrections->update(); | |||
fenetre_corrections->ShowModal(); | |||
} | |||
@@ -93,7 +94,7 @@ void cosmos::OnCellChange( wxGridEvent& event ) | |||
} | |||
else //corrections | |||
{ | |||
bdd->addcorrection(grid_Consults->GetCellValue(row, 13), col, grid_Consults->GetCellValue(row, col)); | |||
} | |||
} | |||
@@ -132,10 +132,10 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co | |||
col_bool->SetEditor(bool_editor); | |||
col_bool->SetRenderer(bool_renderer); | |||
// Attributs pour les colonnes en lecture seule (0,4,13) | |||
// Attributs pour les colonnes en lecture seule (0,4,11,13) | |||
col_RO = new wxGridCellAttr(); | |||
col_RO->SetReadOnly(); | |||
col_RO->SetRenderer(new wxGridCellNumberRenderer); | |||
//col_RO->SetRenderer(new wxGridCellNumberRenderer); | |||
col_RO->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER); | |||
// Attributs pour la colonne de dates (12) | |||
@@ -150,6 +150,7 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co | |||
grid_Consults->SetColAttr(3, col_bool); | |||
grid_Consults->SetColAttr(0, col_RO); | |||
grid_Consults->SetColAttr(4, col_RO); | |||
grid_Consults->SetColAttr(11, col_RO); | |||
grid_Consults->SetColAttr(13, col_RO); | |||
grid_Consults->SetColAttr(12, col_date); | |||
@@ -7,6 +7,7 @@ | |||
<Environment> | |||
<![CDATA[ | |||
]]> | |||
</Environment> | |||
<BuildMatrix> | |||