using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data.SqlClient; namespace SuiviClient_Distrib_Info{ public class NouvelleIntervention : System.Windows.Forms.Form{ private System.Windows.Forms.TextBox NumInter; private System.Windows.Forms.Label label1; private System.Windows.Forms.ComboBox NomClient; private System.Windows.Forms.ComboBox NomContact; private System.Windows.Forms.TextBox telContact; private System.Data.SqlClient.SqlConnection sqlConnection1; private System.Windows.Forms.ComboBox NomMachine; private System.Windows.Forms.TextBox NomUtMachine; private System.Windows.Forms.TextBox ConfigMachine; private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; private System.Data.SqlClient.SqlCommand sqlSelectCommand1; private System.Data.SqlClient.SqlCommand sqlInsertCommand1; private System.Windows.Forms.DateTimePicker DatePrisEnCharge; private System.Windows.Forms.TextBox RaisonInter; private System.Windows.Forms.ComboBox Dépositaire; private System.Windows.Forms.ComboBox Réceptionneur; private System.Windows.Forms.Button Imprimer; ///<summary> /// Variable nécessaire au concepteur. ///</summary> private System.ComponentModel.Container components = null; public NouvelleIntervention(){ NomClient.DataSource = ds.Table["CLIENT"]; // champ à afficher dans le ComboBoxNomClient.DisplayMember = "NomClt"; // // Requis pour la prise en charge du Concepteur Windows Forms //InitializeComponent(); // // TODO : ajoutez le code du constructeur après l'appel à InitializeComponent //} ///<summary> /// Nettoyage des ressources utilisées. ///</summary> protected override void Dispose( bool disposing ){ if( disposing ){ if(components != null){ components.Dispose(); } } base.Dispose( disposing );} #region Code généré par le Concepteur Windows Form ///<summary> /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas /// le contenu de cette méthode avec l'éditeur de code. ///</summary> private void InitializeComponent(){ this.NumInter = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.NomClient = new System.Windows.Forms.ComboBox(); this.NomContact = new System.Windows.Forms.ComboBox(); this.telContact = new System.Windows.Forms.TextBox(); this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); this.NomMachine = new System.Windows.Forms.ComboBox(); this.NomUtMachine = new System.Windows.Forms.TextBox(); this.ConfigMachine = new System.Windows.Forms.TextBox(); this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(); this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); this.DatePrisEnCharge = new System.Windows.Forms.DateTimePicker(); this.RaisonInter = new System.Windows.Forms.TextBox(); this.Dépositaire = new System.Windows.Forms.ComboBox(); this.Réceptionneur = new System.Windows.Forms.ComboBox(); this.Imprimer = new System.Windows.Forms.Button(); this.SuspendLayout(); // // NumInter // this.NumInter.Location = new System.Drawing.Point(24, 8); this.NumInter.Name = "NumInter"; this.NumInter.Size = new System.Drawing.Size(80, 20); this.NumInter.TabIndex = 0; this.NumInter.Text = "textBox1"; this.NumInter.TextChanged += new System.EventHandler( this.NumInter_TextChanged); // // label1 // this.label1.Location = new System.Drawing.Point(8, 48); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(56, 16); this.label1.TabIndex = 1; this.label1.Text = "CLIENT :"; // // NomClient // this.NomClient.Location = new System.Drawing.Point(24, 72); this.NomClient.Name = "NomClient"; this.NomClient.Size = new System.Drawing.Size(80, 21); this.NomClient.TabIndex = 2; this.NomClient.Text = "comBox1"; this.NomClient.SelectedIndexChanged += new System.EventHandler( this.NomClient_SelectedIndexChanged); // // NomContact // this.NomContact.Location = new System.Drawing.Point(176, 72); this.NomContact.Name = "NomContact"; this.NomContact.Size = new System.Drawing.Size(88, 21); this.NomContact.TabIndex = 3; this.NomContact.Text = "comboBox1"; this.NomContact.SelectedIndexChanged += new System.EventHandler( this.NomContact_SelectedIndexChanged); // // telContact // this.telContact.Location = new System.Drawing.Point(176, 104); this.telContact.Name = "telContact"; this.telContact.Size = new System.Drawing.Size(96, 20); this.telContact.TabIndex = 4; this.telContact.Text = "textBox1"; this.telContact.TextChanged += new System.EventHandler( this.telContact_TextChanged); // // sqlConnection1 // this.sqlConnection1.ConnectionString = "workstation id="DIST-5B8D87E3A9";packet size=4096;integrated security=SSPI;data s" +"ource="DIST-5B8D87E3A9";persist security info=False;initial catalog=stage_essai"; this.sqlConnection1.InfoMessage += new System.Data.SqlClient.SqlInfoMessageEventHandler( this.sqlConnection1_InfoMessage); // // NomMachine // this.NomMachine.Location = new System.Drawing.Point(24, 144); this.NomMachine.Name = "NomMachine"; this.NomMachine.Size = new System.Drawing.Size(88, 21); this.NomMachine.TabIndex = 5; this.NomMachine.Text = "comboBox1"; this.NomMachine.SelectedIndexChanged += new System.EventHandler( this.NomMachine_SelectedIndexChanged); // // NomUtMachine // this.NomUtMachine.Location = new System.Drawing.Point(176, 144); this.NomUtMachine.Name = "NomUtMachine"; this.NomUtMachine.Size = new System.Drawing.Size(96, 20); this.NomUtMachine.TabIndex = 6; this.NomUtMachine.Text = "textBox1"; this.NomUtMachine.TextChanged += new System.EventHandler( this.NomUtMachine_TextChanged); // // ConfigMachine // this.ConfigMachine.Location = new System.Drawing.Point(24, 176); this.ConfigMachine.Name = "ConfigMachine"; this.ConfigMachine.Size = new System.Drawing.Size(248, 20); this.ConfigMachine.TabIndex = 7; this.ConfigMachine.Text = "textBox1"; this.ConfigMachine.TextChanged += new System.EventHandler( this.ConfigMachine_TextChanged); // // sqlDataAdapter1 // this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1; this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1; this.sqlDataAdapter1.TableMappings.AddRange( new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "CLIENT", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("NomClt", "NomClt")})}); this.sqlDataAdapter1.RowUpdated += new System.Data.SqlClient.SqlRowUpdatedEventHandler( this.sqlDataAdapter1_RowUpdated); // // sqlInsertCommand1 // this.sqlInsertCommand1.CommandText = "INSERT INTO CLIENT(NomClt) VALUES (@NomClt); SELECT NomClt FROM CLIENT"; this.sqlInsertCommand1.Connection = this.sqlConnection1; this.sqlInsertCommand1.Parameters.Add( new System.Data.SqlClient.SqlParameter("@NomClt", System.Data.SqlDbType.VarChar, 50, "NomClt")); // // sqlSelectCommand1 // this.sqlSelectCommand1.CommandText = "SELECT NomClt FROM CLIENT"; this.sqlSelectCommand1.Connection = this.sqlConnection1; // // DatePrisEnCharge // this.DatePrisEnCharge.Location = new System.Drawing.Point(48, 208); this.DatePrisEnCharge.Name = "DatePrisEnCharge"; this.DatePrisEnCharge.Size = new System.Drawing.Size(184, 20); this.DatePrisEnCharge.TabIndex = 8; this.DatePrisEnCharge.ValueChanged += new System.EventHandler( this.DatePrisEnCharge_ValueChanged); // // RaisonInter // this.RaisonInter.Location = new System.Drawing.Point(24, 232); this.RaisonInter.Name = "RaisonInter"; this.RaisonInter.Size = new System.Drawing.Size(240, 20); this.RaisonInter.TabIndex = 9; this.RaisonInter.Text = "textBox1"; this.RaisonInter.TextChanged += new System.EventHandler( this.RaisonInter_TextChanged); // // Dépositaire // this.Dépositaire.Location = new System.Drawing.Point(16, 264); this.Dépositaire.Name = "Dépositaire"; this.Dépositaire.Size = new System.Drawing.Size(88, 21); this.Dépositaire.TabIndex = 10; this.Dépositaire.Text = "comboBox1"; this.Dépositaire.SelectedIndexChanged += new System.EventHandler( this.Dépositaire_SelectedIndexChanged); // // Réceptionneur // this.Réceptionneur.Location = new System.Drawing.Point(160, 264); this.Réceptionneur.Name = "Réceptionneur"; this.Réceptionneur.Size = new System.Drawing.Size(96, 21); this.Réceptionneur.TabIndex = 11; this.Réceptionneur.Text = "comboBox1"; // // Imprimer // this.Imprimer.Location = new System.Drawing.Point(88, 296); this.Imprimer.Name = "Imprimer"; this.Imprimer.Size = new System.Drawing.Size(96, 24); this.Imprimer.TabIndex = 12; this.Imprimer.Text = "Imprimer"; this.Imprimer.Click += new System.EventHandler( this.Imprimer_Click); // // NouvelleIntervention // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(312, 334); this.Controls.Add( this.Imprimer); this.Controls.Add( this.Réceptionneur); this.Controls.Add( this.Dépositaire); this.Controls.Add( this.RaisonInter); this.Controls.Add( this.DatePrisEnCharge); this.Controls.Add( this.NomClient); this.Controls.Add( this.ConfigMachine); this.Controls.Add( this.NomUtMachine); this.Controls.Add( this.NomMachine); this.Controls.Add( this.telContact); this.Controls.Add( this.NomContact); this.Controls.Add( this.label1); this.Controls.Add( this.NumInter); this.Name = "NouvelleIntervention"; this.Text = "Nouvelle Intervention"; this.ResumeLayout( false);} #endregion private void sqlConnection1_InfoMessage( object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e){ SqlConnection connection; SqlCommand command; SqlDataReader rader; connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=stage_essai;Integrated Security=SSPI");command = new SqlCommand("SELECT * FROM CLIENT", connection);connection.Open(); try{ rader = command.ExecuteReader(); try{ while (rader.Read())NomClient.Items.Add(rader["NumClt"]); } finally{ rader.Close(); } } finally{ connection.Close(); } } private void NumInter_TextChanged( object sender, System.EventArgs e){ NumInter.Text = DateTime.Today.ToShortDateString() + "-001"; NumInter.Text = "+1"; Console.WriteLine = NumInter.Text; } private void NomClient_SelectedIndexChanged( object sender, System.EventArgs e){ } private void NomContact_SelectedIndexChanged( object sender, System.EventArgs e){ } private void telContact_TextChanged( object sender, System.EventArgs e){ } private void NomMachine_SelectedIndexChanged( object sender, System.EventArgs e){ } private void NomUtMachine_TextChanged( object sender, System.EventArgs e){ } private void ConfigMachine_TextChanged( object sender, System.EventArgs e){ } private void DatePrisEnCharge_ValueChanged( object sender, System.EventArgs e){ } private void RaisonInter_TextChanged( object sender, System.EventArgs e){ } private void Dépositaire_SelectedIndexChanged( object sender, System.EventArgs e){ } private void Imprimer_Click( object sender, System.EventArgs e){ } private void sqlDataAdapter1_RowUpdated( object sender, System.Data.SqlClient.SqlRowUpdatedEventArgs e){ } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic NouvelleIntervention(){ // // Requis pour la prise en charge du Concepteur Windows Forms //InitializeComponent(); SqlConnection connection; SqlCommand command; SqlDataReader rader; connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=stage_essai;Integrated Security=SSPI");command = new SqlCommand("SELECT NomClt FROM CLIENT", connection);connection.Open(); try{ rader = command.ExecuteReader(); try{ while (rader.Read()) NomClient.Items.Add(rader["NomClt"]); //NomClient.Items.Add(Convert.ToString(rader["NumClt"]));} finally{ rader.Close(); } } finally{ connection.Close(); } // // TODO : ajoutez le code du constructeur après l'appel à InitializeComponent //}
je souhaiterais avoir 2 combo dont la première est "NomClient" et la deuxième s'appelle "NomContact". J'aimerais que "NomContact" se remplisse selon "NomClient". EX : NomCLT fr gh Si je choissit fr, j'aimerais que "NomContact" m'affiche les nom des contacts correspondant a fr. Comment puis-je réaliser cela?? En sachant que le "NumClt" est dans la table "CLIENT" et le "NomContact" se situe dans la table "CONTACT". Puis l'identifiant de "NumClt" se situe dans la table "CONTACT" en tant que clé étrangére.