Bonjour à tous, j'ai besion d'aide..j'ai réalisé un programmae qui permet de lire des fichiers et de mettre à jour certaines tables de ma base de données...
Mais le tratiemment est long et par conséquent j'ai beqsion de mettre un control progressBar qui comme un préloader fera patienter...
Voici le code...
>>>>>>>>>>>>>>>>>>>>>>>>
using System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.OleDb;
using
System.IO;
using
System.Timers;
namespace
UpDateDB_TTS{
public
partial
class
UpDate_TTS
:
Form
{
public
UpDate_TTS(){
InitializeComponent();
}
///
***************************************************************************************************
///
Détection de coupures de site//////////////////////////////////////////////
///
// Déclarations des champs de collecte de site en vue de la détection des coupures de site
///
///
public
int
ID_rdSite;
public
string
Code_Site;
public
string
VCode_Site;
//valeur précédente du code_site
public
int
nbr_Cell;
// nombre de cellules
public
int
compt_Cell = 0;
//compteur pour nombre de cellules
public
int
n_BSS;
//numéro de la BSC
public
string
mangObjInst_site;
// chemin du site
public
string
mangObjInst_site2;
//Chemin de rack faisant parti du site
public
string
mangObjInst_siteBis;
//nomenclature en cours
public
string
VmangObjInst_siteBis;
//nomenclature précédente
public
string
mangObjInst_siteBis_2;
public
string
mangObjInst_siteBis_3;
public
String
linex_1;
//récupère les lignes dun filchier
public
String
linex_3;
public
string
cSite;
public
string
pathFile;
//public string VSiteName;//contrôle le nom pour ne pas avoir de doublon de nom
public
int
i;
public
int
compt_1 = 0;
public
int
compt_2 = 0;
///
compteurs interne du traitement2
public
int
compt_3 = 0;
public
int
compt_5 = 0;
public
int
compt_Cellbis;
public
bool
arret =
false
;
///
///
Méthodes pour le traitement et la mise à jour des tables Site, et Cellules. Et pour la détection des coupures de sites.
///
////////////////////// Métohdes du traitement2///////////////////////////////////////////////////////////
public
void
collectSite_OnSBSFile_(){
cleaner_DB();
compt_1 = 0;
bool
finish =
false
;
///
Pass the file path and file name to the StreamReader constructor
///
StreamReader sr = new StreamReader();
for
(i = 1; i < 23; i++){
n_BSS = i;
pathFile =
"E:\\DataFile\\dg_20081015\\SBS_"
+ i +
".ASC"
;
StreamReader
sr =
new
StreamReader
(pathFile);
//parcourir le fichier
//try
//{
//Continue to read until you reach end of file
while
((linex_1 = sr.ReadLine()) !=
null
& !finish){
compt_1 += 1;
if
(compt_1 >= 10){
if
(linex_1.Contains(
"CREATE BTS:"
)){
collect_mangObjInst_site();
collect_code_site();
Count_Cell();
nbr_Cell = compt_Cell;
test_site();
VmangObjInst_siteBis = mangObjInst_siteBis;
VCode_Site = Code_Site;
compt_Cell = 0;
}
else
{
goto
aller;}
}
aller: ;
}
sr.Close();
//close the file
}
finish =
true
;
//arret du parcour de fichier
//}
//catch (Exception e)
//{
// // MessageBox.Show("La programme a rencontré un problème et doit fermer","", MessageBoxButtons.OK, MessageBoxIcon.Error);
// //Close();
//}
//finally
//{
//}
//intraitemt = true;
}
public
void
collect_mangObjInst_site(){
int
pos_1 = linex_1.IndexOf(
"="
);linex_1 = linex_1.Substring(pos_1 + 1, linex_1.Length - pos_1 - 1);
int
pos_2 = linex_1.IndexOf(
"/"
);mangObjInst_siteBis = linex_1.Substring(0, pos_2);
mangObjInst_site =
"BSS:"
+ i +
"/"
+ mangObjInst_siteBis;}
public
void
collect_code_site(){
int
pos_1 = linex_1.IndexOf(
","
);linex_1 = linex_1.Substring(pos_1 + 1, linex_1.Length - pos_1 - 1);
int
pos_2 = linex_1.IndexOf(
","
);linex_1 = linex_1.Substring(0, pos_2 - 1);
int
pos_3 = linex_1.IndexOf(
"-"
);linex_1 = linex_1.Substring(pos_3 + 1, linex_1.Length - pos_3 - 1);
int
pos_4 = linex_1.IndexOf(
"-"
);linex_1 = linex_1.Substring(pos_4 + 1, linex_1.Length - pos_4 - 1);
int
pos_5 = linex_1.IndexOf(
"-"
);linex_1 = linex_1.Substring(pos_5 + 1, linex_1.Length - pos_5 - 1);
cSite = linex_1;
string
nCodeSite =
"CI00000"
;
int
nstring_cSite cSite.Length;nCodeSite nCodeSite.Substring(0, nCodeSite.Length - nstring_cSite);
nCodeSite = nCodeSite + cSite;
Code_Site = nCodeSite;
}
public
void
collectID_rdSite()
// méthode de collecte et de gestion de l'incrémentation du ID d'enregistrement
{
comptNbreSite();
ID_rdSite = 0;
ID_rdSite = compt_2 + 1;
compt_2 = 0;
}
public
void
updateSite(){
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"Update T_reportSiteSBS set mangObjInst_site2='"
+ mangObjInst_site2 +
"' where ID_rdSite='"
+ ID_rdSite +
"'; "
;cmd.ExecuteNonQuery();
}
public
void
updateSite2(){
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"Update T_reportSiteSBS set nbr_Cell='"
+ nbr_Cell +
"' where ID_rdSite='"
+ ID_rdSite +
"'; "
;cmd.ExecuteNonQuery();
}
public
void
test_site()
// recupère le nombre de site
{
if
(Code_Site != VCode_Site){
mangObjInst_site2 =
""
;insertSite();
}
else
if
(Code_Site == VCode_Site && mangObjInst_siteBis != VmangObjInst_siteBis){
nbr_Cell += 1;
mangObjInst_site2 =
"BSS:"
+ i +
"/"
+ mangObjInst_siteBis;research_sitebis();
nbr_Cell += compt_Cellbis;
updateSite();
//méthode de mise à jour de la dernière ligne
updateSite2();
}
else
{
int
val = 0;val += 1;
}
}
public
void
research_sitebis(){
compt_Cellbis = 0;
bool
finish =
false
;
StreamReader
sr =
new
StreamReader
(pathFile);
//parcourir le fichier
while
((linex_3 = sr.ReadLine()) !=
null
& !finish){
compt_5 += 1;
if
(compt_5 >= 10){
if
(linex_3.Contains(
"CREATE BTS:NAME="
+ mangObjInst_siteBis)){
mangObjInst_siteBis =
"CREATE BTS:NAME="
+ mangObjInst_siteBis;collect_mangObjInst_siteBis_();
if
(mangObjInst_siteBis == mangObjInst_siteBis_3){
if
(linex_3.Contains(cSite)){
compt_Cellbis ++;
}
else
{
goto
aller;}
}
}
}
aller: ;
}
finish =
true
;sr.Close();
}
public
void
collect_mangObjInst_siteBis_()
// pour récupérer le mangObjInts pour un e comparaison
{
int
pos_1 = linex_3.IndexOf(
"="
);linex_1 = linex_3.Substring(pos_1 + 1, linex_3.Length - pos_1 - 1);
int
pos_2 = linex_3.IndexOf(
"/"
);mangObjInst_siteBis_3 = linex_3.Substring(0, pos_2);
mangObjInst_siteBis_2=
"BSS:"
+ i +
"/"
+ mangObjInst_siteBis_3;}
public
void
collect_mangObjInst_siteBis()
// pour récupérer le mangObjInts pour un e comparaison
{
int
pos_1 = linex_1.IndexOf(
"="
);linex_1 = linex_1.Substring(pos_1 + 1, linex_1.Length - pos_1 - 1);
int
pos_2 = linex_1.IndexOf(
"/"
);mangObjInst_siteBis_3 = linex_1.Substring(0, pos_2);
mangObjInst_siteBis_2 =
"BSS:"
+ i +
"/"
+ mangObjInst_siteBis_3;}
public
void
Count_Cell(){
bool
finish =
false
;
StreamReader
sr =
new
StreamReader
(pathFile);
//parcourir le fichier
while
((linex_1 = sr.ReadLine()) !=
null
& !finish){
compt_3 += 1;
if
(compt_3 >= 10){
if
(linex_1.Contains(
"CREATE BTS:NAME="
+ mangObjInst_siteBis)){
collect_mangObjInst_siteBis();
if
(mangObjInst_siteBis == mangObjInst_siteBis_3){
if
(linex_1.Contains(cSite)){
compt_Cell++;
}
else
{
goto
aller;}
}
}
}
aller: ;
}
finish =
true
;sr.Close();
}
public
void
comptNbreSite()
///
compte le nombre d'entrée qu'il ya dans la table T_alarmeActiveBTS
{
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"select* from T_reportSiteSBS order by ID_rdSite DESC;"
;
//exécution de la procédure stockée
IDataReader
lecteur = cmd.ExecuteReader();
while
(lecteur.Read()){
compt_2++;
}
}
public
void
insertSite(){
collectID_rdSite();
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"insert into T_reportSiteSBS(ID_rdSite , Code_Site , n_BSS , mangObjInst_site,mangObjInst_site2,nbr_Cell) VALUES ( '"
+ ID_rdSite +
"','"
+ Code_Site +
"','"
+ n_BSS +
"','"
+ mangObjInst_site +
"','"
+ mangObjInst_site2 +
"','"
+ nbr_Cell +
"')"
;cmd.ExecuteNonQuery();
}
public
void
cleaner_DB()
//nettoyage de la base de données
{
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"delete from T_reportSiteSBS;"
;cmd.ExecuteNonQuery();
}
///
///
Phase de mise à jour de la BD des sites avec leurs noms***************************************************
///
///
public
String
linex_2;
//récupère les lignes dun filchier
//public string SiteName;//nom du site
public
int
ID_redSite;
public
string
CodeSite;
public
int
BSS;
public
String
SitemangObjInst;
//nomclature du site
public
String
SitemangObjInst2;
//nomclature du site
public
string
SiteObjName;
//nom du site
public
int
nbrCell;
public
int
compt_4 = 0;
public
void
upDateSite_()
//méthode de mise à jour de la table T_Site
{
rEsetRecord();
select_SiteSBS();
}
public
void
rEsetRecord(){
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"delete from T_Site;"
;cmd.ExecuteNonQuery();
}
public
void
select_SiteSBS(){
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"select* from T_reportSiteSBS;"
;
//exécution de la procédure stockée
IDataReader
lecteur = cmd.ExecuteReader();
while
(lecteur.Read()){
CodeSite = lecteur[
"Code_Site"
].ToString();BSS = (
int
)lecteur[
"n_BSS"
];SitemangObjInst = lecteur[
"mangObjInst_site"
].ToString();SitemangObjInst2 = lecteur[
"mangObjInst_site2"
].ToString();nbrCell = (
int
)lecteur[
"nbr_Cell"
];
collect_ObjName_Site();
insertT_Site();
}
}
public
void
comptNbreSitebis()
///
compte le nombre d'entrée qu'il ya dans la table T_alarmeActiveBTS
{
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"select* from T_Site;"
;
//exécution de la procédure stockée
IDataReader
lecteur = cmd.ExecuteReader();
while
(lecteur.Read()){
compt_4++;
}
}
public
void
collectID_redSite()
// méthode de collecte et de gestion de l'incrémentation du ID d'enregistrement
{
comptNbreSitebis();
ID_redSite = 0;
ID_redSite = compt_4 + 1;
compt_4 = 0;
}
public
void
insertT_Site(){
collectID_redSite();
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"insert into T_Site(ID_redSite , CodeSite , BSS , SitemangObjInst,SitemangObjInst2,nbrCell, SiteObjName) VALUES ( '"
+ ID_redSite +
"','"
+ CodeSite +
"','"
+ BSS +
"','"
+ SitemangObjInst +
"','"
+ SitemangObjInst2 +
"','"
+ nbrCell +
"','"
+ SiteObjName +
"')"
;cmd.ExecuteNonQuery();
}
public
void
collect_ObjName_Site()
//pour récupérer le nom du site
{
collect_ObjName_();
SiteObjName = linex_2;
}
public
void
collect_ObjName_()
///
pour récupérer le nom du site
{
string
pathFile_1 =
"E:\\DataFile\\symb_20081015\\symbolicNameFile_20081015.txt"
;
///
chemin d'accèss du symbolicNameFile
bool
finish =
false
;
StreamReader
sr =
new
StreamReader
(pathFile_1);
///
parcourir le fichier
while
((linex_2 = sr.ReadLine()) !=
null
& !finish){
if
(linex_2.Contains(SitemangObjInst)){
int
pos_1 = linex_2.IndexOf(
";"
);linex_2 = linex_2.Substring(pos_1 + 1, linex_2.Length - pos_1 - 1);
if
(linex_2.Contains(
"-"
)){
int
pos_2 = linex_2.IndexOf(
"-"
);linex_2 = linex_2.Substring(0, pos_2);
if
(linex_2.Contains(
"DCS"
)){
string
nDCS =
"DCS"
;
int
nbrDCS nDCS.Length;linex_2 linex_2.Substring(0, linex_2.Length - nbrDCS);
break
;}
else
if
(linex_2.Contains(
"GSM"
)){
string
nDCS =
"GSM"
;
int
nbrDCS nDCS.Length;linex_2 linex_2.Substring(0, linex_2.Length - nbrDCS);
break
;}
break
;}
else
if
(linex_2.Contains(
"_"
)){
int
pos_2 = linex_2.IndexOf(
"_"
);linex_2 = linex_2.Substring(0, pos_2);
if
(linex_2.Contains(
"DCS"
)){
string
nDCS =
"DCS"
;
int
nbrDCS nDCS.Length;linex_2 linex_2.Substring(0, linex_2.Length - nbrDCS);
break
;}
else
if
(linex_2.Contains(
"GSM"
)){
string
nDCS =
"GSM"
;
int
nbrDCS nDCS.Length;linex_2 linex_2.Substring(0, linex_2.Length - nbrDCS);
break
;}
break
;}
else
if
(linex_2.Contains(
"DCS"
)){
int
pos_2 = linex_2.IndexOf(
"D"
);linex_2 = linex_2.Substring(0, pos_2);
break
;}
else
if
(linex_2.Contains(
"GSM"
)){
string
nDCS =
"G"
;
int
nbrDCS nDCS.Length;linex_2 linex_2.Substring(0, linex_2.Length - nbrDCS);
break
;}
break
;}
else
{
goto
aller;}
aller: ;
}
finish =
true
;sr.Close();
}
///
******************************Traitement pour compter le nombre de TRX*****************************************************************
///
public
int
_ID_rdSite;
//recupère l'ID;
public
string
_SitemangObjInst;
public
string
_SitemangObjInst2;
public
int
_nBss;
public
string
_ChoixSite;
public
int
compt_6 = 0;
public
int
compt_TRX = 0;
public
int
nbrTRX;
public
String
linex_4;
public
void
CalculTRX()
//
{
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"select* from T_reportSiteSBS;"
;
//exécution de la procédure stockée
IDataReader
lecteur = cmd.ExecuteReader();
while
(lecteur.Read()){
_ID_rdSite = (
int
)lecteur[
"ID_rdSite"
];_nBss = (
int
)lecteur[
"n_BSS"
];_SitemangObjInst = lecteur[
"mangObjInst_site"
].ToString();_SitemangObjInst2 = lecteur[
"mangObjInst_site2"
].ToString();
bringObjInst();
if
(_SitemangObjInst2 !=
""
){
bringObjInst2();
}
nbrTRX = compt_TRX;
// on ajoute le nombre de TRX
updateT_Site();
compt_TRX = 0;
}
}
public
void
bringObjInst(){
int
pos_1 = _SitemangObjInst.IndexOf(
"/"
);_SitemangObjInst = _SitemangObjInst.Substring(pos_1 + 1, _SitemangObjInst.Length - pos_1 - 1);
_ChoixSite = _SitemangObjInst;
LireFichier();
}
public
void
bringObjInst2(){
int
pos_1 = _SitemangObjInst.IndexOf(
"/"
);_SitemangObjInst2 = _SitemangObjInst2.Substring(pos_1 + 1, _SitemangObjInst2.Length - pos_1 - 1);
_ChoixSite = _SitemangObjInst2;
LireFichier();
}
public
void
LireFichier(){
string
pathFile_1;pathFile_1 =
"E:\\DataFile\\dg_20081015\\SBS_"
+ _nBss +
".ASC"
;
bool
finish =
false
;
StreamReader
sr =
new
StreamReader
(pathFile_1);
//parcourir le fichier
while
((linex_4 = sr.ReadLine()) !=
null
& !finish){
compt_6 += 1;
if
(compt_6 >= 100){
if
(linex_4.Contains(
"CREATE TRX:NAME="
+ _ChoixSite +
"/"
)){
//collect_mangObjInst_siteBis();
compt_TRX++;
}
else
{
goto
aller;}
}
aller: ;
}
finish =
true
;sr.Close();
}
public
void
updateT_Site(){
//connexion à la base de données
OleDbConnection
lien =
new
OleDbConnection
();
//Définition de la chaîne de connexion
lien.ConnectionString =
@"Provider=SQLOLEDB;Data Source=PC-DT-52;Integrated Security=SSPI;Initial Catalog=db_collectAlarm"
;
//Ouvrir la connexion
lien.Open();
//création de la commande
OleDbCommand
cmd =
new
OleDbCommand
();cmd.Connection = lien;
cmd.CommandType =
CommandType
.Text;cmd.CommandText =
"Update T_Site set nbrTRX='"
+ nbrTRX +
"' where ID_redSite='"
+ _ID_rdSite +
"'; "
;cmd.ExecuteNonQuery();
}
private
void
cmd_lancer_Click(
object
sender,
EventArgs
e)
//cette commande lancer le pocessus de mise à jour
{
collectSite_OnSBSFile_();
upDateSite_();
CalculTRX();
timer_updt.Start();
}
private
void
cmd_arret_Click(
object
sender,
EventArgs
e)
//cette commande arrête le processus de mise à jour
{
arret =
true
;
if
(arret){
collectSite_OnSBSFile_();
upDateSite_();
CalculTRX();
timer_updt.Stop();
}
}
private
void
cmd_fermer_Click(
object
sender,
EventArgs
e)
//cette commande ferme l'application
{
Close();
}
private
void
timer_updt_Tick(
object
sender,
EventArgs
e)
// c'est le timer qui excute le processus à intervalle de temps.
{
collectSite_OnSBSFile_();
upDateSite_();
CalculTRX();
}
}
}
>>>>>>>>>>>>>>>>>>>>>>>>
voyez et aidez moi merci d'avance.....
Afficher la suite