Debutant

Jideone Messages postés 9 Date d'inscription dimanche 13 mai 2007 Statut Membre Dernière intervention 5 octobre 2010 - 29 août 2007 à 12:25
cs_rodcobalt22 Messages postés 193 Date d'inscription dimanche 10 février 2002 Statut Membre Dernière intervention 16 février 2016 - 29 août 2007 à 12:42
SALut tout le monde,
J ai 2 Programmes et je veux les reunir en un seul!
-Le premier lit un fichier  comprenant des usernames et des numeros de telephones
- le deuxieme fait une recherche dans une base donnees  ou tous les users sont repertories et si un user est identifie    il se voit attribue un numero de telephone

Je vous fais parvenir les deux codes :

3 réponses

Jideone Messages postés 9 Date d'inscription dimanche 13 mai 2007 Statut Membre Dernière intervention 5 octobre 2010
29 août 2007 à 12:27
Premier code :

using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.DirectoryServices;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;

namespace fichier
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.DataGrid dataGrid1;
        //private System.Windows.Forms.TextBox textBox1;

        //<summary>
        // required designer variable.

        private System.ComponentModel.Container components = null;
        public Form1()
        {
            // required for windows Form Designer support

            InitializeComponent();

            // TODO Add any constructor code after InitializeComponent call
        }

        // clean up any resources being used

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        #region Windows Form Designer generated code

        // required method for designer support - do not modify
        // the contents of this method with the code editor.

        private void InitializeComponent()
        {
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.SuspendLayout();

            // datagrid1

            this.dataGrid1.DataMember = "";
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(8, 40);
            this.dataGrid1.Name = "datgrid1";
            this.dataGrid1.Size = new System.Drawing.Size(400, 400);
            this.dataGrid1.TabIndex = 0;

            // Form1

            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(680, 425);
            //this.Controls.Add(this.textBox1);
            this.Controls.Add(this.dataGrid1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.ResumeLayout(false);
        }

        #endregion
        // the main entry point for the application
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
        private void Form1_Load(object sender, System.EventArgs e)
        {

            // on crée une table
            DataTable dt = new DataTable("test");
            // on crée des colonnes
            dt.Columns.Add("TelephoneNumber", System.Type.GetType("System.Int32"));
            dt.Columns.Add("User", System.Type.GetType("System.String"));
            StreamReader fichier = File.OpenText(@"h:\\export.txt");
            while (fichier.Peek() >= 0)
            {
                // on lit une ligne et on ajoute
                string ligne = fichier.ReadLine();
                string[] vals = ligne.Split(';');
                DataRow dr = dt.NewRow();
                try
                {
                    dr["TelephoneNumber"] = int.Parse(vals[0]);
                    dr["User"] = vals[1];
                    dt.Rows.Add(dr);
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString());
                    Console.ReadLine();
                }
              
            }

            // on genere le tableau
            dataGrid1.DataSource = dt;
        }
       
    }
}

Deuxieme codes :

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.DirectoryServices;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;

namespace TestAD
{

    class Program
    {

        public static void Main(string[] args)
        {

                DirectoryEntry deUser = new DirectoryEntry("LDAP://ou=User, ou=User Office, ou=User, DC=hte,DC=intra", "don", "mamanetpapa");

                DirectorySearcher searchEmploye = new DirectorySearcher(deUser);

                searchEmploye.Filter = "(objectClass=user)";

                // Display all Employe

                foreach (SearchResult unResultat in searchEmploye.FindAll())
                {

                    DirectoryEntry unEmploye = unResultat.GetDirectoryEntry();

                }

                // Modification of the telephoneNumber

                foreach (SearchResult unResultat in searchEmploye.FindAll())
                {

                    DirectoryEntry unEmploye = unResultat.GetDirectoryEntry();

                    if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "sg")
                    {

                        // Changing the telephoneNumber

                        unEmploye.Properties["telephoneNumber"].Value = "110";

                        // Commit the modification

                        unEmploye.CommitChanges();

                    }
                    else
                    {
                        if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "sas")
                        {

                            unEmploye.Properties["telephoneNumber"].Value = "111";
                            unEmploye.CommitChanges();
                        }

                        else
                        {
                            if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "sap")
                            {

                                unEmploye.Properties["telephoneNumber"].Value = "112";
                                unEmploye.CommitChanges();
                            }
                            else
                            {
                                if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "ab")
                                {

                                    unEmploye.Properties["telephoneNumber"].Value = "113";
                                    unEmploye.CommitChanges();
                                }
                                else
                                {
                                    if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "ah")
                                    {

                                        unEmploye.Properties["telephoneNumber"].Value = "114";
                                        unEmploye.CommitChanges();
                                    }
                                    else
                                    {
                                        if (unEmploye.Properties["SAMAccountName"].Value.ToString() == "wst")
                                        {

                                            unEmploye.Properties["telephoneNumber"].Value = "115";
                                            unEmploye.CommitChanges();
                                        }

                                    }
                                }
                            }
                        }
                    }

                }

            }
           

            }

        }

 

  

MERCI D'AVENCE
0
cs_Pedrosa Messages postés 42 Date d'inscription lundi 3 juillet 2006 Statut Membre Dernière intervention 2 juin 2008
29 août 2007 à 12:41
Merci pour ton code.

Ce serait gentil de nous faire un ZIP.

Merci.
0
cs_rodcobalt22 Messages postés 193 Date d'inscription dimanche 10 février 2002 Statut Membre Dernière intervention 16 février 2016
29 août 2007 à 12:42
D'accord et quelle difficulté rencontres tu ?
Car là j'ai l'impression (Peut être mauvaise) que tu nous confie tout simplement le boulot, c'est pas très sympas ça !
Informe moi de tes difficultés (si je me trompe) ou alors justifie toi plus sur le soucis
0
Rejoignez-nous