using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace LectureFichierTXTForms { public partial class Form1 : Form { public Form1() { InitializeComponent(); String ligne; try { /////////chemin d'accés au fichier text/////// StreamReader sr = new StreamReader("C:\\har\\cpt\\imp1.txt"); //Read the first line of text ligne = sr.ReadLine(); //Continue to read until you reach end of file while (ligne != null) { //write the lie to console window textBoxFichierTXT.Text = textBoxFichierTXT.Text + ligne +Environment.NewLine; //Read the next line ligne = sr.ReadLine(); } ////////decoupage avec split des differents lignes///////// string Fichier = textBoxFichierTXT.Text; string[] words = Fichier.ToString().Split('\n'); foreach (string word in words) { textBoxNomClient.Text = words[13].TrimEnd("".ToCharArray()); textBoxCodeSo.Text = words[3].TrimEnd("".ToCharArray()); textBoxDateEcriture.Text = words[4].Insert(2, "/").TrimEnd("".ToCharArray()); textBoxDateEcriture.Text = textBoxDateEcriture.Text.Insert(5, "/").TrimEnd("".ToCharArray()); textBoxNumFacture.Text = words[6].TrimEnd("".ToCharArray()); textBoxCodeClient.Text = words[11].TrimEnd("".ToCharArray()); textBoxDateEcheance.Text = words[15].Insert(2, "/").TrimEnd("".ToCharArray()); textBoxDateEcheance.Text = textBoxDateEcheance.Text.Insert(5, "/").TrimEnd("".ToCharArray()); textBoxDebit.Text = words[19].TrimEnd("".ToCharArray()); textBoxMontant.Text = words[20].TrimEnd("".ToCharArray()); textBoxCompteTVA.Text = words[34].TrimEnd("".ToCharArray()); textBoxCredit.Text = words[44].TrimEnd("".ToCharArray()); textBoxCompteVentes.Text = words[59].TrimEnd("".ToCharArray()); } //////fermeture du fichier///// sr.Close(); Console.ReadLine(); } //////affichage de message si erreur de nom pour le fichier////// catch (Exception e) { MessageBox.Show(e.Message); } } private void buttonChangerClient_Click(object sender, EventArgs e) { int NombreClick=0; // ICI if (buttonChan == ) // SA { // MERDE NombreClick = NombreClick + 1; // UN PEU ;) } textBox1.Text = Convert.ToString(NombreClick); String ligne; /////////chemin d'accés au fichier text/////// StreamReader sr = new StreamReader("C:\\har\\cpt\\imp1.txt"); //Read the first line of text ligne = sr.ReadLine(); //Continue to read until you reach end of file int NombreMorceaux = 0; int NombreLignes = 0; while (ligne !=null) { //write the lie to console window textBoxFichierTXT.Text = textBoxFichierTXT.Text + ligne + Environment.NewLine; //Read the next line ligne = sr.ReadLine(); //Fonction de comptage du NombreMorceaux NombreLignes++; NombreMorceaux = (NombreLignes / 25) - 3; textBox1.Text = Convert.ToString(NombreMorceaux); } //////////decoupage avec split des differents lignes///////// string Fichier = textBoxFichierTXT.Text; string MorceauxFichier = textBox2.Text; string[] lines = Fichier.Split('#'); for(int i=5+(NombreClick*3);i<NombreMorceaux;i+=3) { textBox2.Text = textBox2.Text+lines[i]; string[] words = lines[i].Split('\n'); textBoxNomClient.Text = words[11].TrimEnd("".ToCharArray()); textBoxCodeSo.Text = words[1].TrimEnd("".ToCharArray()); textBoxDateEcriture.Text = words[2].Insert(2, "/").TrimEnd("".ToCharArray()); textBoxDateEcriture.Text = textBoxDateEcriture.Text.Insert(5, "/").TrimEnd("".ToCharArray()); textBoxNumFacture.Text = words[4].TrimEnd("".ToCharArray()); textBoxCodeClient.Text = words[9].TrimEnd("".ToCharArray()); textBoxDateEcheance.Text = words[13];.Insert(2, "/").TrimEnd("".ToCharArray()); textBoxDateEcheance.Text = textBoxDateEcheance.Text.Insert(5, "/").TrimEnd("".ToCharArray()); textBoxDebit.Text = words[17].TrimEnd("".ToCharArray()); textBoxMontant.Text = words[18].TrimEnd("".ToCharArray()); i = i + 1; string[] words2 = lines[i].Split('\n'); textBoxCompteTVA.Text = words[7].TrimEnd("".ToCharArray()); textBoxCredit.Text = words2[17].TrimEnd("".ToCharArray()); i = i + 1; string[] words3 = lines[i].Split('\n'); textBoxCompteVentes.Text = words3[7].TrimEnd("".ToCharArray()); //while(buttonChangerClient !=Click ) //{ // System.Threading.Thread.Sleep(1000); //} // j'avais pensé a fair un while dand lequelle on tournée en continu //tant que l'on ne reclick pas sur le bouton mais je pense que sa //n'auré pas marché et ma condition me donne une érreur /////fermeture du fichier/// sr.Close(); } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question