1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <locale>
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;
int rec_count = 0; //compteur donnees financieres clients
int affichageDate(string dateFormat);
struct Balanceagee // Structure stockant les informations financieres du client
{
string societe;
int compta;
string piece;
string dateEcriture;
string dateEcheance;
void dateEcrit(string);
void dateEch (string);
};
bool fonctionTriBalanceAgeeClient(const Balanceagee & a,const Balanceagee & b) //Tri des factures pas numero de compte
{
return a.compta < b.compta;
}
istream & operator >> (istream & balanceAgeeClient, Balanceagee & balClient) /*Flux fichier Balance agee envoye dans la structure Balanceagee */
{
string compta;
string piece;
// Parsage du flux par un separateur et envoi des données dans les champs de la structure
getline(balanceAgeeClient, balClient.societe, ';');
getline(balanceAgeeClient, compta, ';');
istringstream incompta(compta); // Transpytage du string en int
incompta >> balClient.compta;
getline(balanceAgeeClient, balClient.piece, ';');
getline(balanceAgeeClient, balClient.dateEcriture, ';');
getline(balanceAgeeClient, balClient.dateEcheance, ';');
return balanceAgeeClient;
}
ostream & operator << (ostream & fluxFinancier, Balanceagee const & balClient) // Affichage des donnees de la structure Balanceagee
{
fluxFinancier
<< balClient.societe << " "
<< balClient.compta << " "
<< balClient.piece << " "
<< balClient.dateEcriture << " "
<< balClient.dateEcheance << " ";
return fluxFinancier;
}
void traitementsDonneesClients() /*Lecture du fichier csv et envoie des informations dans une structure */
{
string ligne; //Une variable pour stocker les lignes lues
ifstream fichierBalAgeeClient ("balanceagee.csv");
if(fichierBalAgeeClient)
{
//L'ouverture s'est bien passée, on peut donc lire
while(getline(fichierBalAgeeClient, ligne)) //Tant qu'on n'est pas à la fin, on lit
{
Balanceagee balanceAgeeClient;
istringstream iss(lignef); // Transpytage du flux ligne pour stocker dans la structure
iss >> balanceAgeeClient;
balClient.push_back(balanceAgeeClient);
//Tri des factures pas numeros de compte
sort(balClient.begin(), balClient.end(),fonctionTriBalanceAgeeClient);
rec_count++; //compteur
}
}
else
{
cout << "ERREUR: Impossible d'ouvrir le fichier de la Balance agee." << endl;
}
fichierBalAgeeClient.close(); //On referme le fichier
//On ne peut plus écrire dans le fichier à partir d'ici
}
void afficherDonneesClient()
{
int nCompta;
cin >> nCompta;
for(int j = 0;j < rec_countB;j++)
{
while(balClient[j].compta == nCompta)
{
cout << companies[i];
}
if(i == balClient.size())
{
cout << "Il n'existe pas de donnee financiere pour ce client" << endl;
}
}
}
}
}
}
void dateEcrit(string dateFormat)
{
affichageDate(dateFormat);
}
void dateEch (string dateFormat)
{
affichageDate(dateFormat) ;
}
void affichageDate(string& dateFormat, int& d, int& m, int& y)
//fonction attend la chaîne en format jj / mm / aaaa:
{
struct tm date;
char format[10];
istringstream iss(dateFormat); // Transpytage du flux dateFormat pour stocker dans le flux iss
char delimiter = '/';
if (iss >> d >> delimiter >> m >> delimiter >> y)
{
date.tm_mday = d;
date.tm_mon = m - 1;
date.tm_year = y - 1900;
date.tm_isdst = -1;
date.tm_hour=0;
date.tm_min=0;
date.tm_sec=0;
// normaliser:
time_t time = mktime(&date);
const struct tm *norm = localtime(&time);
/* lactuelle date devrait être :
m = norm->tm_mon + 1;
d = norm->tm_mday;
y = norm->tm_year;
29/02/2013 deviendrait 01/03/2013*/
// Valider si les données normalisées est toujours le même :
return (norm->tm_mday == d &&
norm->tm_mon == m - 1 &&
norm->tm_year == y - 1900);
}
else
{
std::cout << "La date nest pas correcte" << endl;
}
strftime(format, 10, " %d/%m/%Y ", &date);
cout << format;
return 0;
}
int main()
{
traitementsDonneesClients();
afficherDonneesClient();
return 0;
} |
Partager