woot6768
Messages postés
393
Date d'inscription
mercredi 8 mars 2006
Statut
Membre
Dernière intervention
23 mars 2007
6 juil. 2006 à 15:47
Bon ben je vous met le code, je ne met pas les collections, je ne met que les fonctions :
public
partial
class
Form1 :
Form{
//Déclaration des variables nécéssaires au programme :
public
string[,] correspondance =
new
string[52, 2];
//Tableu des correspondances à effectuer.
public
int nb_correspondances;
//Nombre de correspondances au total.
public
const
int limite_autres = 41;
//Limite des autres.
private
Collection<
string> exclus;
//Collection des mots exclus.
public
OdbcConnection connection2 =
new
OdbcConnection();
//Création de la connection à la seconde base.
public
string chaineDeConnection2 =
"DSN=Contacts";
//Chaine de connection à la seconde base.
public Form1(){
InitializeComponent();
}
private
void Form1_Load_1(
object sender,
EventArgs e){}
//Ôtes les éléments inutiles :
public
void NettoyeProprietaire(){
InitialiserCorrespondances();
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET CIVILITY='{0}', FULLNAME='{1}', FIRSTNAME='{2}', LASTNAME='{3}' WHERE CONTACTSYNCID= {4} ";
string req =
"SELECT CIVILITY, FULLNAME, FIRSTNAME, LASTNAME, CONTACTSYNCID FROM M9004_CONTACTSYNC ";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusP = GetExclusAutresProprietaire;
string CIV;
string FULL;
string FIRST;
string LAST;
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
CIV "";FULL
"";FIRST "";LAST
"";ADODB.
Field field1 = Recordset.Fields[
"CIVILITY"];
if (field1.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"CIVILITY"]).Length > 0){
CIV = Recordset.Fields[
"CIVILITY"].Value.ToString();CIV = (CleanEspaces(CIV)).Trim();
CIV = Cleanup((Recordset.Fields[
"CIVILITY"].Value).ToString(), limite_autres);CIV = EpurerNom(CIV, exclusP);
}
}
ADODB.
Field field2 = Recordset.Fields[
"FULLNAME"];
if (field2.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"FULLNAME"]).Length > 0){
FULL = Recordset.Fields[
"FULLNAME"].Value.ToString();FULL = (CleanEspaces(FULL)).Trim();
FULL = Cleanup((Recordset.Fields[
"FULLNAME"].Value).ToString(), limite_autres);}
}
ADODB.
Field field3 = Recordset.Fields[
"FIRSTNAME"];
if (field3.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"FIRSTNAME"]).Length > 0){
FIRST = Recordset.Fields[
"FIRSTNAME"].Value.ToString();FIRST = (CleanEspaces(FIRST)).Trim();
FIRST = Cleanup((Recordset.Fields[
"FIRSTNAME"].Value).ToString(), limite_autres);}
}
ADODB.
Field field4 = Recordset.Fields[
"LASTNAME"];
if (field4.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"LASTNAME"]).Length > 0){
LAST = Recordset.Fields[
"LASTNAME"].Value.ToString();LAST = (CleanEspaces(LAST)).Trim();
LAST = Cleanup((Recordset.Fields[
"LASTNAME"].Value).ToString(), limite_autres);}
}
lineCmd =
String.Format(lineCmd, CIV.Trim(), FULL.Trim(), FIRST.Trim(), LAST.Trim(), Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
Recordset.Close();
MessageBox.Show(
"Fonction NettoyeProprietaire() terminée.");}
//Supprimme le champs INITIALS qui n'est pas nécéssaire ici :
public
void NettoyeInitialles(){
InitialiserCorrespondances();
string INI;
string req =
"SELECT INITIALS, CONTACTSYNCID FROM M9004_CONTACTSYNC";
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET INITIALS='{0}' WHERE CONTACTSYNCID = {1} ";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusI = ExclusInitialles;
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
INI = Recordset.Fields[
"INITIALS"].Value.ToString();INI = INI.ToUpper();
INI = Cleanup((Recordset.Fields[
"INITIALS"].Value).ToString(), limite_autres);
//INI EpurerNom(INI, exclusI);lineCmd
String.Format(lineCmd, INI, Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
Recordset.Close();
MessageBox.Show(
"Fonction NettoyeInitialles() terminée.");}
//Nettoie le titre de la profession :
public
void NettoyeTitre(){
InitialiserCorrespondances();
string chaine;
string lineCmd "UPDATE M9004_CONTACTSYNC SET TITLE '{0}' WHERE CONTACTSYNCID = {1}";
string req =
"SELECT TITLE ,CONTACTSYNCID FROM M9004_CONTACTSYNC";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusC = GetExclusCommunes;
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
chaine =
"";ADODB.
Field field = Recordset.Fields[
"TITLE"];
if (field.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"TITLE"]).Length > 0){
chaine = Recordset.Fields[
"TITLE"].Value.ToString();chaine = (CleanEspaces(chaine)).Trim();
chaine = Cleanup((Recordset.Fields[
"TITLE"].Value).ToString(), limite_autres);chaine = EpurerNom(chaine, exclusC);
}
}
lineCmd =
String.Format(lineCmd, chaine.Trim(), Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
MessageBox.Show(
"Fonction NettoyeTitre() terminée.");Recordset.Close();
}
//Nettoie le nom de l'entreprise :
public
void NettoyeEntreprise(){
InitialiserCorrespondances();
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET COMPANYFULLNAME='{0}' WHERE CONTACTSYNCID={1}";
string req =
"SELECT CONTACTSYNCID, COMPANYFULLNAME FROM M9004_CONTACTSYNC ORDER BY CONTACTSYNCID ASC";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusC = GetExclusCommunes;
string COMPANY;
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
COMPANY =
"";ADODB.
Field field = Recordset.Fields[
"COMPANYFULLNAME"];
if (field.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"COMPANYFULLNAME"]).Length > 0){
COMPANY = Recordset.Fields[
"COMPANYFULLNAME"].Value.ToString();COMPANY = (CleanEspaces(COMPANY)).Trim();
COMPANY = Cleanup((Recordset.Fields[
"COMPANYFULLNAME"].Value).ToString(), limite_autres);COMPANY = EpurerNom(COMPANY, exclusC);
}
}
lineCmd =
String.Format(lineCmd, COMPANY.Trim(), Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
MessageBox.Show(
"Fonction NettoyeEntreprise() terminée.");Recordset.Close();
}
//Nettoie les adresses :
public
void NettoyeAdresse(){
InitialiserCorrespondances();
string req =
"SELECT ADDRESS1, ADDRESS2, ADDRESS3, CONTACTSYNCID FROM M9004_CONTACTSYNC";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusV = GetExclusAutresVoies;
int i;
string ADD1;
string ADD2;
string ADD3;
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET ADDRESS1='{0}', ADDRESS2='{1}', ADDRESS3='{2}' WHERE CONTACTSYNCID= {3} ";
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
ADD1 "";ADD2
"";ADD3 =
"";ADODB.
Field field1 = Recordset.Fields[
"ADDRESS1"];
if (field1.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"ADDRESS1"]).Length > 0){
ADD1 = Cleanup((Recordset.Fields[
"ADDRESS1"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= ADD1.Length; i++){
ADD1 = RemplaceChar(ADD1, i.ToString(),
" ");}
ADD1 = EpurerNom(ADD1, exclusV);
ADD1 = (CleanEspaces(ADD1)).Trim();
}
}
ADODB.
Field field2 = Recordset.Fields[
"ADDRESS2"];
if (field2.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"ADDRESS2"]).Length > 0){
ADD2 = Cleanup((Recordset.Fields[
"ADDRESS2"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= ADD2.Length; i++){
ADD2 = RemplaceChar(ADD2, i.ToString(),
" ");}
ADD2 = EpurerNom(ADD2, exclusV);
ADD2 = (CleanEspaces(ADD2)).Trim();
}
}
ADODB.
Field field3 = Recordset.Fields[
"ADDRESS3"];
if (field3.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"ADDRESS3"]).Length > 0){
ADD3 = Cleanup((Recordset.Fields[
"ADDRESS3"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= ADD3.Length; i++){
ADD3 = RemplaceChar(ADD3, i.ToString(),
" ");}
ADD3 = EpurerNom(ADD3, exclusV);
ADD3 = (CleanEspaces(ADD3)).Trim();
}
}
lineCmd =
String.Format(lineCmd, ADD1.Trim(), ADD2.Trim(), ADD3.Trim(), Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
MessageBox.Show(
"Fonction NettoyeAdresse() terminée.");Recordset.Close();
}
//Nettoie la commune :
public
void NettoyeCommune(){
InitialiserCorrespondances();
string req =
"SELECT CITY, COUNTY, COUNTRY, CONTACTSYNCID FROM M9004_CONTACTSYNC";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
Collection<
string> exclusV = GetExclusAutresVoies;
int i;
string CIT;
string COUNT;
string COUNTR;
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET CITY='{0}', COUNTY='{1}', COUNTRY='{2}', WHERE CONTACTSYNID= {3} ";
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
CIT "";COUNT
"";COUNTR =
"";ADODB.
Field field1 = Recordset.Fields[
"CITY"];
if (field1.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"CITY"]).Length > 0){
CIT = Cleanup((Recordset.Fields[
"CITY"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= CIT.Length; i++){
CIT = RemplaceChar(CIT, i.ToString(),
" ");}
CIT = EpurerNom(CIT, exclusV);
CIT = (CleanEspaces(CIT)).Trim();
}
}
ADODB.
Field field2 = Recordset.Fields[
"COUNTY"];
if (field2.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"COUNTY"]).Length > 0){
COUNT = Cleanup((Recordset.Fields[
"COUNTY"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= COUNT.Length; i++){
COUNT = RemplaceChar(COUNT, i.ToString(),
" ");}
COUNT = EpurerNom(COUNT, exclusV);
COUNT = (CleanEspaces(COUNT)).Trim();
}
}
ADODB.
Field field3 = Recordset.Fields[
"COUNTRY"];
if (field3.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"COUNTRY"]).Length > 0){
COUNTR = Cleanup((Recordset.Fields[
"COUNTRY"].Value).ToString(), limite_autres);i = 0;
for (i = 0; i <= COUNTR.Length; i++){
COUNTR = RemplaceChar(COUNTR, i.ToString(),
" ");}
COUNTR = EpurerNom(COUNTR, exclusV);
COUNTR = (CleanEspaces(COUNTR)).Trim();
}
}
lineCmd =
String.Format(lineCmd, CIT, COUNT, COUNTR, Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
MessageBox.Show(
"Fonction NettoyeCommune() terminée.");Recordset.Close();
}
//Nettoie les différents numéros :
public
void NettoyeTelephone(){
InitialiserCorrespondances();
string req =
"SELECT CONTACTSYNCID, PHONE, MOBILE, FAX FROM M9004_CONTACTSYNC";ADODB.
Recordset Recordset =
new ADODB.
Recordset();Recordset.Open(req, chaineDeConnection2, ADODB.
CursorTypeEnum.adOpenKeyset, ADODB.
LockTypeEnum.adLockOptimistic, -1);
string lineCmd =
"UPDATE M9004_CONTACTSYNC SET PHONE='{0}', MOBILE='{1}', FAX='{2}' WHERE CONTACTSYNCID= {3} ";
string PHO;
string MOB;
string FAX;
if (Recordset.RecordCount > 0){
Recordset.MoveFirst();
while (!(Recordset.EOF)){
PHO "";MOB
"";FAX =
"";ADODB.
Field field1 = Recordset.Fields[
"PHONE"];
if (field1.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"PHONE"]).Length > 0){
PHO = FormatNumeros((Recordset.Fields[
"PHONE"]).ToString());PHO = (CleanEspaces(PHO)).Trim();
}
}
ADODB.
Field field2 = Recordset.Fields[
"MOBILE"];
if (field2.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"MOBILE"]).Length > 0){
MOB = FormatNumeros((Recordset.Fields[
"MOBILE"]).ToString());MOB = (CleanEspaces(MOB)).Trim();
}
}
ADODB.
Field field3 = Recordset.Fields[
"FAX"];
if (field3.Value !=
DBNull.Value){
if (
Convert.ToString(Recordset.Fields[
"FAX"]).Length > 0){
FAX = FormatNumeros((Recordset.Fields[
"FAX"]).ToString());FAX = (CleanEspaces(FAX)).Trim();
}
}
lineCmd =
String.Format(lineCmd, PHO, MOB, FAX, Recordset.Fields[
"CONTACTSYNCID"].Value);
OdbcCommand cmd =
new
OdbcCommand(lineCmd, connection2);cmd.ExecuteNonQuery();
Recordset.MoveNext();
}
}
MessageBox.Show(
"Fonction NettoyeTelephone() terminée.");Recordset.Close();
}
public
string Cleanup(
string label,
int limite){
//Remplace les caractères parasites (définis dans le module correspondances) par leurs caractères de remplacement :limite = 0;
string Nom;Nom = (label.ToUpper()).Trim();
int i;
int max;
if (limite 0)max nb_correspondances - 1;
elsemax = limite - 1;
for (i = 0; i >= max; i++){
Nom = RemplaceChar(Nom, correspondance[i, 0], correspondance[i, 1]);
}
//supprimer les éventuels espaces superflus :Nom = CleanEspaces(Nom);
return Nom.Trim();}
public
string EpurerNom(
string Nom,
Collection<
string> rejets){
//Epurer une chaîne en supprimant les mots exclus ainsi que les espaces superflus :
string chaîne;chaîne = Nom;
foreach (
string motRejete
in rejets){
int x;
bool ok;ok =
true;
while (ok){
x = chaîne.IndexOf(motRejete);
if (x > -1)chaîne = chaîne.Substring(0, x) + chaîne.Substring(x + motRejete.Length);
elseok =
false;}
}
return CleanEspaces(chaîne);}
public
string RemplaceChar(
string label,
string aRemplacer,
string remplacement){
//Dans une chaîne, remplace toutes les occurences d'un caractère par une chaîne :
string chaîne;chaîne = label;
int x;
bool ok;ok =
true;
while (ok){
x = chaîne.IndexOf(aRemplacer);
if (x > 0)chaîne = chaîne.Substring(0, x) + remplacement + chaîne.Substring(x);
elseok =
false;}
return chaîne;}
public
string CleanEspaces(
string label){
//Dans une chaîne, ne laisse subsister que les espaces simples :
string chaîne;chaîne = label;
int x;
bool ok;ok =
true;
while (ok){
x = chaîne.IndexOf(chaîne);
if (x > 0){
chaîne = chaîne.Substring(0, x) + chaîne.Substring(x);
}
elseok =
false;}
return chaîne;}
public
bool IsNumeric(
string chaîne){
foreach (
char c
in chaîne){
if (!
char.IsNumber(c))
return
false;}
return
true;}
public
string FormatNumeros(
string chaîne){
string retour;retour = RemplaceChar(chaîne,
".",
"");retour = RemplaceChar(chaîne,
" ",
"");
if (!(IsNumeric(retour))){
retour =
"";}
else{
if (retour.Length == 9){
if (retour.Substring(0, 0) !"0")retour 0 + retour;
}
}
return retour;}
private
void Form1_FormClosed(
object sender,
FormClosedEventArgs e){
//Fermeture de la connection à la seconde base :connection2.Close();
}
private
void cmdArreter_Click(
object sender,
EventArgs e){
this.Close();}
private
void cmdDemarrer_Click(
object sender,
EventArgs e){
File.Copy(
"C:\\Documents and Settings\\Administrateur\\Mes documents\\Wouter Tjon Stage\\Contacts.mdb",
"C:\\Documents and Settings\\Administrateur\\Mes documents\\Wouter Tjon Stage\\ProjetrecoupementContacts\\Contacts.mdb",
true);
//Affectation de la chaine de connection à la connection à la seconde base :connection2.ConnectionString = chaineDeConnection2;
// On mets le timeout au minimun (pour éviter d'attendre X secondes si erreur) :connection2.ConnectionTimeout = 1;
try{
//Ouverture de la connection à la seconde base :connection2.Open();
}
catch (
OdbcException exception){
MessageBox.Show(exception.ToString());
return;}
MessageBox.Show(
"Copie de la table effectuer.",
"Copie de la table");NettoyeProprietaire();
NettoyeInitialles();
NettoyeTitre();
NettoyeEntreprise();
NettoyeAdresse();
NettoyeCommune();
NettoyeTelephone();
}
}
Voilà, c'est fini!
Bon le code n'est pas encore commenté, c'est vrai, mais je commente toujours quand le code est terminée et qu'il fonctionne.
_________________________________________________________________________
Woot