Browse Source

Ajout enregistrement service d'origine dans la base (sans l'afficher)

Ajout de commentaires.
Modification de wxGridBoolEditor pour accepter "1" pour TRUE et "0" pour FALSE (facilite l'import et la modification de la base)
Ajout coloration si publication (autant à l'import qu'à la modification dans le programme)
Enregistrement des actions sur les checkboxes dans la base.
master
Maxime Wack 11 years ago
parent
commit
0c6babf745
7 changed files with 128 additions and 81 deletions
  1. +82
    -50
      CosMoS/bdd.cpp
  2. +2
    -2
      CosMoS/bdd.h
  3. +1
    -1
      CosMoS/config.cpp
  4. +3
    -2
      CosMoS/config.h
  5. +18
    -1
      CosMoS/cosmos.cpp
  6. +3
    -6
      CosMoS/cosmosGUI.cpp
  7. +19
    -19
      Sante_Pub.workspace.session

+ 82
- 50
CosMoS/bdd.cpp View File

@@ -3,9 +3,9 @@
class_bdd::class_bdd(const wxString& path_in, wxGrid* gridptr)
{
this->gridptr = gridptr;
path = path_in + slash + "cosmos.db";
wxString path = path_in + slash + "cosmos.db";
if (!wxFileExists(path))
createEmpty();
createEmpty(path);
else if ((rc=sqlite3_open_v2(_C(path), &db, SQLITE_OPEN_READWRITE, NULL)) != SQLITE_OK)
{
wxMessageBox(_T("Erreur lors de l'ouverture de la base de données"), "Erreur", wxICON_ERROR | wxOK);
@@ -19,11 +19,11 @@ class_bdd::~class_bdd()
sqlite3_close(db); //check RC (busy ?)
}

void class_bdd::createEmpty()
void class_bdd::createEmpty(const wxString& path)
{
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 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, service VARCHAR(100));", 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);
@@ -39,22 +39,24 @@ void class_bdd::createEmpty()
void class_bdd::importer(const wxString& filename)
{
rc = 0;
int size = 0;
int progress = 0;
int size = 0;
int progress = 0; //indicateurs de progression
char c;
bool inquote = false; //guillemets
bool firstline = true;
wxString item[23];
FILE * importfile = fopen(_C(filename), "r");
fseek(importfile, 0, SEEK_END);
size = ftell(importfile);
rewind(importfile);
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;
wxString item[23];
do
{
for (int i=0; i<22; i++)
for (int i=0; i<22; i++) //boucle pour les 21 premiers items
{
item[i]="";
do
@@ -62,15 +64,10 @@ void class_bdd::importer(const wxString& filename)
c = fgetc(importfile);
progress++;
if (c == '"')
{
if (!inquote)
inquote = true;
else
inquote = false;
}
inquote = (!inquote) ? true : false;
if (c != '"')
item[i] << c;
}while (((c != ';') && (!inquote)) || inquote);
}while (((c != ';') && (!inquote)) || inquote); //boucle pour un item, se finit par un ';' sauf entre guillemets
item[i] = item[i].BeforeLast(wxUniChar(';'));
}
item[22]="";
@@ -80,35 +77,40 @@ void class_bdd::importer(const wxString& filename)
progress++;
if ((c != '\n') && (c != EOF))
item[22] << c;
}while ((c != '\n') && (c != EOF));
}while ((c != '\n') && (c != EOF)); //dernier item de la ligne, se finit si retour ou EOF
if (!firstline)
{
wxString requete = "INSERT OR REPLACE INTO Consult (id, n_dossier, nom, prenom, responsable, consultant, theme, etablissement, travail, date_cs, publi_prevue) VALUES (";
requete << item[0] + ", ";
if (item[1].IsSameAs(""))
//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
if (item[1].IsSameAs("")) //n_dossier
requete << "NULL, ";
else
requete << item[1] + ", ";
requete << "\"" + item[3] + "\", ";
requete << "\"" + item[4] + "\", ";
requete << "\"" + item[19] + "\", ";
requete << "\"" + item[20] + "\", ";
requete << "\"" + item[13] + "\", ";
requete << "\"" + item[7] + "\", ";
requete << "\"" + item[12] + "\", ";
requete << "\"" + item[21] + "\", ";
if (item[18].IsSameAs("VRAI", false))
requete << "1";
requete << "\"" + item[3] + "\", "; //Nom
requete << "\"" + item[4] + "\", "; //Prénom
requete << "\"" + item[19] + "\", "; //Responsable
requete << "\"" + item[20] + "\", "; //Consultant
requete << "\"" + item[13] + "\", "; //Thème
requete << "\"" + item[7] + "\", "; //Etablissement
requete << "\"" + item[12] + "\", "; //Type travail
requete << "\"" + item[21] + "\", "; //Date_cs
if (item[18].IsSameAs("VRAI", false)) //Publi prévue
requete << "1, ";
else
requete << "0";
requete << "0, ";
requete << "\"" + item[6] + "\""; //Service
requete << ");";
rc += sqlite3_exec(db, requete, NULL, NULL, NULL);
//Insertion dans la table de résultats
requete = "INSERT OR IGNORE INTO Result (id) VALUES (";
requete << item[0] + ");";
rc += sqlite3_exec(db, requete, NULL, NULL, NULL);
}
firstline = false;
//Annulation de l'import
if (!progress_dialog.Update(progress))
{
wxMessageBox(_T("Aucune nouvelle donnée n'a été ajoutée"), "Attention !");
@@ -134,41 +136,71 @@ void class_bdd::updategrid()
{
wxBeginBusyCursor();
rc = 0;
int nbligne = 0;
int nligne = 0;
stmt = NULL;
gridptr->DeleteRows(0, gridptr->GetNumberRows());
sqlite3_prepare_v2(db, "SELECT * FROM Consult", -1, &stmt, NULL);
gridptr->DeleteRows(0, gridptr->GetNumberRows()); //reset de la grille
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();
wxMessageBox(_T("La base de données est vide,\nveuillez importer des données !"));
return;
}
while (sqlite3_step(stmt) == SQLITE_ROW)
{
gridptr->AppendRows();
gridptr->SetCellValue(nbligne, 4, wxString::Format("%i",sqlite3_column_int(stmt, 1)));
gridptr->SetReadOnly(nbligne, 4);
gridptr->SetCellValue(nligne, 4, wxString::Format("%i",sqlite3_column_int(stmt, 1))); //n_dossier
gridptr->SetReadOnly(nligne, 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++;
gridptr->SetCellValue(nligne, i+3, wxString::FromAscii(sqlite3_column_text(stmt, i))); //nom, prénom, responsable, consultant, theme, etablissement, travail, date
gridptr->SetReadOnly(nligne, 12);
gridptr->SetCellRenderer(nligne, 12, new wxGridCellDateTimeRenderer);
nligne++;
}
sqlite3_finalize(stmt);
nbligne = 0;
sqlite3_prepare_v2(db, "SELECT * FROM Result", -1, &stmt, NULL);
nligne = 0;
sqlite3_prepare_v2(db, "SELECT * FROM Result", -1, &stmt, NULL); //import depuis Result
while (sqlite3_step(stmt) == SQLITE_ROW)
{
gridptr->SetCellValue(nbligne, 0, wxString::Format("%i",sqlite3_column_int(stmt, 4)));
gridptr->SetReadOnly(nbligne, 0);
gridptr->SetCellValue(nligne, 0, wxString::Format("%i",sqlite3_column_int(stmt, 4))); //nb_results
gridptr->SetReadOnly(nligne, 0);
bool publie = false;
for (int i=1; i<4; i++)
{
wxGridCellBoolEditor* bool_editor = new wxGridCellBoolEditor();
bool_editor->UseStringValues("1", "0");
gridptr->SetCellEditor(nligne, i, bool_editor);
gridptr->SetCellRenderer(nligne, i, new wxGridCellBoolRenderer);
gridptr->SetCellValue(nligne, i, wxString::Format("%i", sqlite3_column_int(stmt, i))); //publi, publi_CHU, cs_associe
if (sqlite3_column_int(stmt, i) == 1)
gridptr->SetCellValue(nbligne, i, "1");
else
gridptr->SetCellValue(nbligne, i, "");
publie = true;
gridptr->SetCellAlignment(nligne, i, wxALIGN_CENTER, wxALIGN_CENTER); //aligner les checkbox au milieu
}
nbligne++;
if (publie)
for (int i=0; i<13; i++)
gridptr->SetCellBackgroundColour(nligne, i, *wxGREEN); //coloration des consults trouvées
nligne++;
}
sqlite3_finalize(stmt);
gridptr->AutoSizeColumns(false);
gridptr->AutoSizeRows(false);
wxEndBusyCursor();
}

void class_bdd::modresultbool(int id, int col, const wxString& val)
{
rc = 0;
wxString requete = "UPDATE Result SET ";
switch (col)
{
case 1: requete << "publi="; break;
case 2: requete << "publi_CHU="; break;
case 3: requete << "cs_associe="; break;
}
requete << val;
requete << " WHERE id=";
requete << wxString::Format("%i;", id);
rc = sqlite3_exec(db, requete, NULL, NULL, NULL);
}

+ 2
- 2
CosMoS/bdd.h View File

@@ -23,16 +23,16 @@ class class_bdd
sqlite3* db;
sqlite3_stmt* stmt;
int rc;
wxString path;
wxGrid* gridptr;
void createEmpty();
void createEmpty(const wxString& path);
public:
class_bdd(const wxString& path_in, wxGrid* gridptr);
~class_bdd();
void importer(const wxString& filename);
void exporter(const wxString& filename);
void updategrid();
void modresultbool(int id, int col, const wxString& val);
};



+ 1
- 1
CosMoS/config.cpp View File

@@ -1,5 +1,5 @@
#include "config.h"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-variable" //warnings à cause des nodes contenant du texte

config::config()
{


+ 3
- 2
CosMoS/config.h View File

@@ -15,14 +15,15 @@ protected:
bool useproxy;
wxString proxyurl;
int proxyport;
//TODO : option pour cacher les lignes identifiées
public:
config();
~config();
void createDefault();
void load();
void save();

// GETters et SETters
void SetDbpath(const wxString& dbpath) {this->dbpath = dbpath;}
void SetProxyport(int proxyport) {this->proxyport = proxyport;}
void SetProxyurl(const wxString& proxyurl) {this->proxyurl = proxyurl;}


+ 18
- 1
CosMoS/cosmos.cpp View File

@@ -68,7 +68,24 @@ void cosmos::OnOptionsProg( wxCommandEvent& event )

void cosmos::OnCellChange( wxGridEvent& event )
{
// TODO: Implement OnCellChange
//TODO : automatiser checkboxes
int row = event.GetRow();
int col = event.GetCol();
if ((col > 0) && (col < 4))
{
bdd->modresultbool(row+1, col, grid_Consults->GetCellValue(row, col));
bool publie = false;
for (int i=1; i<4; i++)
if (grid_Consults->GetCellValue(row, col).IsSameAs("1"))
publie=true;
for (int i=0; i<13; i++)
if (publie)
grid_Consults->SetCellBackgroundColour(row, i, *wxGREEN);
else
grid_Consults->SetCellBackgroundColour(row, i, *wxWHITE);
grid_Consults->ForceRefresh();
}
}
void cosmos::OnCellDbClick( wxGridEvent& event )


+ 3
- 6
CosMoS/cosmosGUI.cpp View File

@@ -88,7 +88,7 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co
grid_Consults->SetColSize( 0, 64 );
grid_Consults->SetColSize( 1, 46 );
grid_Consults->SetColSize( 2, 72 );
grid_Consults->SetColSize( 3, 125 );
grid_Consults->SetColSize( 3, 80 );
grid_Consults->SetColSize( 4, 68 );
grid_Consults->SetColSize( 5, 135 );
grid_Consults->SetColSize( 6, 154 );
@@ -104,7 +104,7 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co
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( 3, wxT("Consultant ?") );
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)") );
@@ -118,9 +118,6 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co
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);
@@ -132,7 +129,7 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co
// Label Appearance
// Cell Defaults
grid_Consults->SetDefaultCellAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
grid_Consults->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_CENTER );
bSizer2->Add( grid_Consults, 1, wxALL|wxEXPAND, 5 );
this->SetSizer( bSizer2 );


+ 19
- 19
Sante_Pub.workspace.session View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Session Name="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace">
<int Value="7" Name="m_selectedTab"/>
<int Value="9" Name="m_selectedTab"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace" Name="m_workspaceName"/>
<TabInfoArray Name="TabInfoArray">
<TabInfo>
@@ -9,16 +9,28 @@
<int Value="16" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmosGUI.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="23" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmosGUI.cpp" Name="FileName"/>
<int Value="102" Name="FirstVisibleLine"/>
<int Value="126" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="0" Name="CurrentLine"/>
<int Value="30" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.cpp" Name="FileName"/>
<int Value="6" Name="FirstVisibleLine"/>
<int Value="11" Name="CurrentLine"/>
<int Value="31" Name="FirstVisibleLine"/>
<int Value="70" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
@@ -42,25 +54,13 @@
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="3" Name="CurrentLine"/>
<int Value="16" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.cpp" Name="FileName"/>
<int Value="46" Name="FirstVisibleLine"/>
<int Value="64" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmosGUI.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="7" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmosGUI.cpp" Name="FileName"/>
<int Value="7" Name="FirstVisibleLine"/>
<int Value="27" Name="CurrentLine"/>
<int Value="128" Name="FirstVisibleLine"/>
<int Value="138" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
</TabInfoArray>


Loading…
Cancel
Save