Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

ADO.NET: Liaison de données multiple avec une Base de données XML

Recherche,dans,la,base,de,données:,non,édité
{filelink=16134}

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
 
namespace Base_de_Données
{
 
    public class LiaisonMultiple : System.Windows.Forms.Form
    {
        /* Liaison des Données avec ADO.Net
         *  Afficher les information de
         *  L'entreprise Séléctionnée
         *  dans le ComboBox.
         *  Base de données XML
         *
         *     */
        internal System.Windows.Forms.GroupBox GroupBox1;
        internal System.Windows.Forms.Label lblAdresse;
        internal System.Windows.Forms.Label lblNomContact;
        internal System.Windows.Forms.Label lblTel;
        internal System.Windows.Forms.Button btnSuiv;
        internal System.Windows.Forms.Button btnPrec;
        internal System.Windows.Forms.ComboBox cmbEntreprise;
        internal System.Windows.Forms.Label lblPays;
 
        private System.ComponentModel.Container components = null;
 
        public LiaisonMultiple()
        {
 
            InitializeComponent();
 
        }
 
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
 
        #region Windows Form Designer generated code
 
        private void InitializeComponent()
        {
            this.GroupBox1 = new System.Windows.Forms.GroupBox();
            this.lblAdresse = new System.Windows.Forms.Label();
            this.lblNomContact = new System.Windows.Forms.Label();
            this.lblTel = new System.Windows.Forms.Label();
            this.btnSuiv = new System.Windows.Forms.Button();
            this.btnPrec = new System.Windows.Forms.Button();
            this.cmbEntreprise = new System.Windows.Forms.ComboBox();
            this.lblPays = new System.Windows.Forms.Label();
            this.GroupBox1.SuspendLayout();
            this.SuspendLayout();
            //
            // GroupBox1
            //
            this.GroupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.GroupBox1.Controls.Add(this.lblPays);
            this.GroupBox1.Controls.Add(this.lblAdresse);
            this.GroupBox1.Controls.Add(this.lblNomContact);
            this.GroupBox1.Controls.Add(this.lblTel);
            this.GroupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.GroupBox1.Location = new System.Drawing.Point(18, 47);
            this.GroupBox1.Name = "GroupBox1";
            this.GroupBox1.Size = new System.Drawing.Size(312, 168);
            this.GroupBox1.TabIndex = 10;
            this.GroupBox1.TabStop = false;
            //
            // lblAdresse
            //
            this.lblAdresse.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lblAdresse.Location = new System.Drawing.Point(6, 98);
            this.lblAdresse.Name = "lblAdresse";
            this.lblAdresse.Size = new System.Drawing.Size(130, 24);
            this.lblAdresse.TabIndex = 6;
            //
            // lblNomContact
            //
            this.lblNomContact.Location = new System.Drawing.Point(168, 16);
            this.lblNomContact.Name = "lblNomContact";
            this.lblNomContact.Size = new System.Drawing.Size(136, 32);
            this.lblNomContact.TabIndex = 5;
            //
            // lblTel
            //
            this.lblTel.Location = new System.Drawing.Point(8, 16);
            this.lblTel.Name = "lblTel";
            this.lblTel.Size = new System.Drawing.Size(140, 32);
            this.lblTel.TabIndex = 4;
            //
            // btnSuiv
            //
            this.btnSuiv.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnSuiv.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnSuiv.Location = new System.Drawing.Point(238, 227);
            this.btnSuiv.Name = "btnSuiv";
            this.btnSuiv.Size = new System.Drawing.Size(92, 28);
            this.btnSuiv.TabIndex = 9;
            this.btnSuiv.Text = "Suiv >>";
            this.btnSuiv.Click += new System.EventHandler(this.cmdNext_Click);
            //
            // btnPrec
            //
            this.btnPrec.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.btnPrec.Enabled = false;
            this.btnPrec.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.btnPrec.Location = new System.Drawing.Point(18, 227);
            this.btnPrec.Name = "btnPrec";
            this.btnPrec.Size = new System.Drawing.Size(92, 28);
            this.btnPrec.TabIndex = 8;
            this.btnPrec.Text = "<< Prec";
            this.btnPrec.Click += new System.EventHandler(this.cmdPrev_Click);
            //
            // cmbEntreprise
            //
            this.cmbEntreprise.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbEntreprise.Location = new System.Drawing.Point(14, 11);
            this.cmbEntreprise.Name = "cmbEntreprise";
            this.cmbEntreprise.Size = new System.Drawing.Size(316, 21);
            this.cmbEntreprise.TabIndex = 7;
            //
            // lblPays
            //
            this.lblPays.AutoSize = true;
            this.lblPays.Location = new System.Drawing.Point(176, 98);
            this.lblPays.Name = "lblPays";
            this.lblPays.Size = new System.Drawing.Size(316, 21);
            this.lblPays.Size = new System.Drawing.Size(130, 13);
            this.lblPays.TabIndex = 7;
            this.lblPays.Text = "                                         ";
            //
            // LiaisonMultiple
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(344, 266);
            this.Controls.Add(this.GroupBox1);
            this.Controls.Add(this.btnSuiv);
            this.Controls.Add(this.btnPrec);
            this.Controls.Add(this.cmbEntreprise);
            this.Name = "LiaisonMultiple";
            this.Text = "Liaison de données en Utilisant XML";
            this.Load += new System.EventHandler(this.LiaisonMultiple_Load);
            this.GroupBox1.ResumeLayout(false);
            this.GroupBox1.PerformLayout();
            this.ResumeLayout(false);
 
        }
        #endregion
 
        private BindingManagerBase storeBinding;
 
        private void LiaisonMultiple_Load(object sender, System.EventArgs e)
        {
            DataSet dsStore = new DataSet();
 
            // Lire le schéma et la base de données XML
            dsStore.ReadXmlSchema(Application.StartupPath + @"Clients.xsd");
            dsStore.ReadXml(Application.StartupPath + @"Clients.xml");
 
            cmbEntreprise.DataSource = dsStore.Tables["Clients"];
            cmbEntreprise.DisplayMember = "Entreprise";
 
            lblTel.DataBindings.Add("Text",
                dsStore.Tables["Clients"], "Tel");
            lblNomContact.DataBindings.Add("Text",
                dsStore.Tables["Clients"], "Nom-Contact");
            lblAdresse.DataBindings.Add("Text",
                dsStore.Tables["Clients"], "Adresse");
            lblPays.DataBindings.Add("Text",
            dsStore.Tables["Clients"], "Pays");
            storeBinding = this.BindingContext[dsStore.Tables["Clients"]];
            storeBinding.PositionChanged += new EventHandler(Binding_PositionChanged);
        }
 
        [STAThread]
        static void Main()
        {
            Application.Run(new LiaisonMultiple());
        }
 
        private void cmdNext_Click(object sender, System.EventArgs e)
        {
                storeBinding.Position++;
        }
 
        private void cmdPrev_Click(object sender, System.EventArgs e)
        {
                storeBinding.Position--;
        }
 
        private void Binding_PositionChanged(object sender, System.EventArgs e)
        {
            if (storeBinding.Position == storeBinding.Count - 1)
            {
                btnSuiv.Enabled = false;
            }
            else
            {
                btnSuiv.Enabled = true;
            }
 
            if (storeBinding.Position == 0)
            {
                btnPrec.Enabled = false;
            }
            else
            {
                btnPrec.Enabled = true;
            }
        }
 
    }
}

No comments yet.

Leave a Comment