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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer;
using Microsoft.VisualBasic;
using Microsoft.CSharp;
using System.Diagnostics;
using System.Data;
using System.Net;
namespace IMR
{
class ProgramCSV // Début Programme
{
// Fonction Main
static void Main(string[] args)
{
// On apelle les deux .exe dans notre main
Integration c = new Integration();
c.UnixToDos();
c.CsvToSql("");
Console.WriteLine(" L'intégration a été effectuée avec succés à la base de données ");
Console.ReadKey();
}
}
public class ftp
{
private string host = null;
private string user = null;
private string pass = null;
private FtpWebRequest ftpRequest = null;
private FtpWebResponse ftpResponse = null;
private Stream ftpStream = null;
private int bufferSize = 2048;
/* Construct Object */
public ftp(string hostIP, string userName, string password) { host = hostIP; user = userName; pass = password; }
public void Download(string remoteFile, string localFile)
{
try
{
// Création de requête FTP
ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
// Connexion avec les log au server FTP de l'INPI
ftpRequest.Credentials = new NetworkCredential(user, pass);
// Requête de téléchargement d'un fichier
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
}
catch ( Exception ex ) {
}
}
}
public class Integration
{
public void UnixToDos() //la fonction permettant de convertir de Unix à Dos
{
string strCmdText;
DirectoryInfo dir = new DirectoryInfo("U:/FichiersINPI/IMR_Donnees_Saisies/tc/flux/2017/06/01/0101");
Console.WriteLine("Recherche de fichier .csv :"); //Fonction de recherche de tout les fichiers .csv
foreach (var Fi in Directory.GetFiles("U:/FichiersINPI/IMR_Donnees_Saisies/tc/flux/2017/06/01/0101", "*.csv", SearchOption.AllDirectories)) //On précise qu'on veut tout les répértoires
{
Console.WriteLine(Fi);
Console.WriteLine(DateTime.Now);
strCmdText = ("/C Unix2Dos " + Fi ); // On applique la commande pour chaque fichier CSV du repertoire
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Console.WriteLine("Conversion effectuée !");
}
}
public void CsvToSql(string strCmdText) // la méthode permettant d'entrer les données du CSV à la table SQL
{
DirectoryInfo dir = new DirectoryInfo("U:/FichiersINPI/IMR_Donnees_Saisies/tc/flux/2017/06/01/0101");
Console.WriteLine("Recherche de fichier .csv :"); //Fonction de recherche des csv convertis précédemment
foreach (var Fi in Directory.GetFiles("U:/FichiersINPI/IMR_Donnees_Saisies/tc/flux/2017/06/01/0101", "*.csv", SearchOption.AllDirectories)) //On précise qu'on veut tout les répértoires
{
Console.WriteLine(Fi);
Console.WriteLine(DateTime.Now); // On écrit les fichiers indexés
if (_CompareFileName(Fi, "1_PM.csv")) // Boucle If pour les 13 types de fichiers
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..PM /force"); //Personne Morale
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi, "2_PM_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..PM_EVT /force"); //Evenement Personne Morale
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "3_PP.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..PP /force"); // Personne Physique
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi, "4_PP_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..PP_EVT /force"); //Evenement Personne Physique
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi, "5_rep.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Rep /force"); // Représentants
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "6_rep_nouveau_modifie_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Rep_new /force"); // Modification relative aux représentants
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "7_rep_partant_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Rep_supression /force"); // Supression d'un représentant
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "8_ets.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Ets /force"); // Etablissements
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "9_ets_nouveau_modifie_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Ets_modification /force"); // Modification relative aux établissements
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "10_ets_supprime_EVT.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Ets_supression /force"); // Supression d'un établissement
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "11_obs .csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Obs /force"); // Observation
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "12_actes.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Acte /force"); // Actes
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else if (_CompareFileName(Fi , "13_comptes_annuels.csv"))
{
strCmdText = ("/C Csv2Sql_new " + Fi + " IMR_INPI..Compte_annuel /force"); //Comptes annuels
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
}
else // On conclue la boucle par un catch qui arrête le traitement automatique en cas d'erreur ( Table pas assez large , fichier corrompu .. )
{
Console.WriteLine("Aucun fichier de ce type est traitable !");
}
Console.WriteLine("Intégration effectuée sur les 13 types de fichiers !"); // Confirmation du traitement des 13 types de fichiers reçus
}
//Se Renseigner sur les tests unitaires */
}
bool _CompareFileName(string fileName, string id) //Fonction de comparaison des chaines de caractéres des .csv SUBSTRING
{
if (fileName.Substring(fileName.Length - id.Length, id.Length) == id)
return true;
else
return false;
}
}
// Fin Programme
} |
Partager