Browse Source

Modif de bdd :

- utilisation de wxFFile à la place de FILE* pour l'import
- check pour le LF de trop dans le csv lors de l'import
- correction d'une erreur dans la construction de la requête SQL
- suppression des attributs de cellule et déplacement vers la création de la grille, par colonne

Correction du retour au background par défaut pour les lignes validées
master
Maxime Wack 11 years ago
parent
commit
e40565fa1e
7 changed files with 81 additions and 77 deletions
  1. +32
    -31
      CosMoS/bdd.cpp
  2. +5
    -2
      CosMoS/bdd.h
  3. +1
    -1
      CosMoS/cosmos.cpp
  4. +31
    -5
      CosMoS/cosmosGUI.cpp
  5. +3
    -0
      CosMoS/cosmosGUI.h
  6. +1
    -0
      Sante_Pub.workspace
  7. +8
    -38
      Sante_Pub.workspace.session

+ 32
- 31
CosMoS/bdd.cpp View File

@@ -43,15 +43,21 @@ void class_bdd::importer(const wxString& filename)
rc = 0;
int size = 0;
int progress = 0; //indicateurs de progression
char c;
//char c;
wxUniChar c;
wxString fichier;
bool inquote = false; //guillemets
bool firstline = true;
wxString item[23];
FILE * importfile = fopen(_C(filename), "r");
/*FILE * importfile = fopen(_C(filename), "r");
fseek(importfile, 0, SEEK_END);
size = ftell(importfile);
rewind(importfile);
rewind(importfile);*/
wxFFile* importfile = new wxFFile();
importfile->Open(filename);
importfile->ReadAll(&fichier);
size = fichier.length() + 1;
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);
@@ -63,10 +69,13 @@ void class_bdd::importer(const wxString& filename)
item[i]="";
do
{
c = fgetc(importfile);
//c = fgetc(importfile);
c = fichier[progress];
progress++;
if (c == '"')
{
inquote = (!inquote) ? true : false;
}
if (c != '"')
item[i] << c;
}while (((c != ';') && (!inquote)) || inquote); //boucle pour un item, se finit par un ';' sauf entre guillemets
@@ -75,11 +84,12 @@ void class_bdd::importer(const wxString& filename)
item[22]="";
do
{
c = fgetc(importfile);
//c = fgetc(importfile);
c = fichier[progress];
progress++;
if ((c != '\n') && (c != EOF))
if ((c != '\n') && (c != '\0')) //EOF->\0
item[22] << c;
}while ((c != '\n') && (c != EOF)); //dernier item de la ligne, se finit si retour ou EOF
}while ((c != '\n') && (c != '\0')); //dernier item de la ligne, se finit si retour ou EOF
if (!firstline)
{
@@ -89,15 +99,15 @@ void class_bdd::importer(const wxString& filename)
if (item[1].IsSameAs("")) //n_dossier
requete << "NULL, ";
else
requete << item[1] << ", "
<< "\"" << 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
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 << "1, ";
else
@@ -120,9 +130,12 @@ void class_bdd::importer(const wxString& filename)
sqlite3_exec(db, "ROLLBACK TO before_import;", NULL, NULL, NULL);
break;
}
if (fichier[progress] == '\0')
break;
}while (c != EOF);
fclose(importfile);
}while (c != '\0');
//fclose(importfile);
importfile->Close();
progress_dialog.Update(size);
sqlite3_exec(db, "RELEASE before_import;", NULL, NULL, NULL);
if (rc)
@@ -151,41 +164,29 @@ void class_bdd::updategrid()
return;
}
else
sqlite3_reset(stmt); //retour à la première ligne, celle-ci étant lue pour vérifier la non vacuité
sqlite3_reset(stmt); //retour à la première ligne, celle-ci étant lue juste avant pour vérifier la non vacuité
while (sqlite3_step(stmt) == SQLITE_ROW)
{
gridptr->AppendRows();
gridptr->SetCellValue(nligne, 4, _itoW(sqlite3_column_int(stmt, 1))); //n_dossier
//gridptr->SetReadOnly(nligne, 4);
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
//gridptr->SetReadOnly(nligne, 12);
//gridptr->SetCellRenderer(nligne, 12, new wxGridCellDateTimeRenderer);
gridptr->SetCellValue(nligne, 13, _itoW(sqlite3_column_int(stmt, 0))); //id, caché
//gridptr->SetReadOnly(nligne, 13);
nligne++;
}
sqlite3_finalize(stmt);
wxGridCellBoolEditor* bool_editor = new wxGridCellBoolEditor();
bool_editor->UseStringValues("1", "0");
wxGridCellBoolRenderer* bool_renderer = new wxGridCellBoolRenderer();
nligne = 0;
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
//gridptr->SetReadOnly(nligne, 0);
bool publie = false;
for (int i=1; i<4; i++)
{
gridptr->SetCellEditor(nligne, i, bool_editor);
gridptr->SetCellRenderer(nligne, i, bool_renderer);
gridptr->SetCellValue(nligne, i, _itoW(sqlite3_column_int(stmt, i))); //publi, publi_CHU, cs_associe
if (sqlite3_column_int(stmt, i) == 1)
publie = true;
//gridptr->SetCellAlignment(nligne, i, wxALIGN_CENTER, wxALIGN_CENTER); //aligner les checkbox au milieu
}
if (publie)
for (int i=0; i<13; i++)


+ 5
- 2
CosMoS/bdd.h View File

@@ -2,7 +2,8 @@
#define __bdd__

#include <wx/filefn.h>
#include <cstdio>
//#include <cstdio>
#include <wx/ffile.h>
#include <wx/msgdlg.h>
#include <wx/progdlg.h>
#include <wx/grid.h>
@@ -12,12 +13,14 @@
#ifdef __WXGTK__
#define slash "/"
#define _C(string) string.fn_str() // wxString -> char*
#define _W(string) string // char* -> wxString
#elif defined( __WXMSW__ )
#define slash "\\"
#define _C(string) (const char*) string.c_str() // wxString -> char*
#define _W(string) wxString::FromAscii(string) // char* -> wxString
#endif
#define _itoW(integer) wxString::Format("%i",integer) // int -> wxString
#define _W(string) wxString::FromAscii(string) // char* -> wxString

class class_bdd
{


+ 1
- 1
CosMoS/cosmos.cpp View File

@@ -85,7 +85,7 @@ void cosmos::OnCellChange( wxGridEvent& event )
if (publie)
grid_Consults->SetCellBackgroundColour(row, i, *wxGREEN);
else
grid_Consults->SetCellBackgroundColour(row, i, *wxWHITE);
grid_Consults->SetCellBackgroundColour(row, i, grid_Consults->GetDefaultCellBackgroundColour());
grid_Consults->ForceRefresh();
}
else //corrections


+ 31
- 5
CosMoS/cosmosGUI.cpp View File

@@ -120,12 +120,38 @@ cosmosGUI::cosmosGUI( wxWindow* parent, wxWindowID id, const wxString& title, co
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);
// Editeur pour les cellules à checkbox, avec affectation des valeurs pour vrai et faux
bool_editor = new wxGridCellBoolEditor();
bool_editor->UseStringValues("1", "0");
bool_renderer = new wxGridCellBoolRenderer();
// Attributs pour les colonnes bool (1,2,3)
col_bool = new wxGridCellAttr();
col_bool->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
col_bool->SetEditor(bool_editor);
col_bool->SetRenderer(bool_renderer);
// Attributs pour les colonnes en lecture seule (0,4,13)
col_RO = new wxGridCellAttr();
col_RO->SetReadOnly();
col_RO->SetRenderer(new wxGridCellNumberRenderer);
col_RO->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
// Attributs pour la colonne de dates (12)
col_date = new wxGridCellAttr();
col_date->SetReadOnly();
col_date->SetRenderer(new wxGridCellDateTimeRenderer);
col_date->SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
// Application des attributs aux colonnes
grid_Consults->SetColAttr(1, col_bool);
grid_Consults->SetColAttr(2, col_bool);
grid_Consults->SetColAttr(3, col_bool);
grid_Consults->SetColAttr(0, col_RO);
grid_Consults->SetColAttr(4, col_RO);
grid_Consults->SetColAttr(13, col_RO);
grid_Consults->SetColAttr(12, col_date);
// Rows
grid_Consults->EnableDragRowSize( true );


+ 3
- 0
CosMoS/cosmosGUI.h View File

@@ -41,6 +41,9 @@ class cosmosGUI : public wxFrame
wxToolBar* toolbar;
wxSearchCtrl* searchctrl;
wxGrid* grid_Consults;
wxGridCellAttr* col_bool, *col_RO, *col_date;
wxGridCellBoolEditor* bool_editor;
wxGridCellBoolRenderer* bool_renderer;
// Virtual event handlers, overide them in your derived class
virtual void OnQuit( wxCloseEvent& event ) { event.Skip(); }


+ 1
- 0
Sante_Pub.workspace View File

@@ -6,6 +6,7 @@
<Project Name="testsqlite" Path="testsqlite/testsqlite.project" Active="No"/>
<Environment>
<![CDATA[
]]>
</Environment>
<BuildMatrix>


+ 8
- 38
Sante_Pub.workspace.session View File

@@ -1,48 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<Session Name="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace">
<?xml version="1.0" encoding="utf-8"?>
<Session Name="/home/satamaxx/Programmes/Sante_Pub/Sante_Pub.workspace">
<int Value="1" Name="m_selectedTab"/>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\Sante_Pub.workspace" Name="m_workspaceName"/>
<wxString Value="/home/satamaxx/Programmes/Sante_Pub/Sante_Pub.workspace" Name="m_workspaceName"/>
<TabInfoArray Name="TabInfoArray">
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.h" Name="FileName"/>
<wxString Value="/home/satamaxx/Programmes/Sante_Pub/CosMoS/bdd.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="17" Name="CurrentLine"/>
<int Value="9" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\cosmos.cpp" Name="FileName"/>
<int Value="48" Name="FirstVisibleLine"/>
<int Value="90" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\config.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="17" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\config.cpp" Name="FileName"/>
<int Value="27" Name="FirstVisibleLine"/>
<int Value="1" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.h" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="34" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\bdd.cpp" Name="FileName"/>
<int Value="160" Name="FirstVisibleLine"/>
<int Value="181" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
<TabInfo>
<wxString Value="G:\Commun\Etudiants\Maxime W\Projets\CosMoS\optionsGUI.cpp" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
<int Value="7" Name="CurrentLine"/>
<wxString Value="/home/satamaxx/Programmes/Sante_Pub/CosMoS/bdd.cpp" Name="FileName"/>
<int Value="42" Name="FirstVisibleLine"/>
<int Value="60" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
</TabInfo>
</TabInfoArray>


Loading…
Cancel
Save