Aide en c# please!

Fermé
angelmnxxxx Messages postés 41 Date d'inscription mercredi 8 mars 2006 Statut Membre Dernière intervention 27 avril 2007 - 27 nov. 2006 à 01:27
 ansizak - 20 déc. 2007 à 22:32
Bonjour
je suis entrain de réaliser un agenda en c#;
alors ce ke g fait c ke g réalisé pour le moment une seule table Access que g nommée table1 tt simplement;
elle contient 2 champs d=une date et num=un numéro qui representera l'heure
Mon idée est ke le formulaire contiendra un dateTimePicker, un dataGrid,et un bouton

Le bouton fait avancer la date du dateTimePicker d'un jour;
Le dataGrid affiche la liste des num dont la date est celle du dateTimePicker.
a chaque fois donc qu'on appuie sur le bouton la valeur du dateTimePicker change et par conséquence celle du dataGrid aussi.

Jesper ke c clair jusque là; paske après ça se complique.

puiske je suppose ke ma table est vide et que à chaque fois qu'on change de date on fait la creation du jour ds l'agende cad on insère la date et les heures sous forme de num(ex 10/11/2006/ 8; 10/11/2006 8.
3;10/11/2006 9; 10/11/2006 9.30; 10/11/2006 10)
pour pouvoir avoir un affichage ressemblant aux pages d'un agenda.
alors lors du chargement du form on réalise une insertion ainsi qu'à chaque fois que la date du dateTimePicker change.

je sais ke c un peu n'importe quoi point de vu conception et que je répète un peu trop les memes chose mais ce n'est qu'une idée de départ.

Cependant le problème c ke mem ça, ça fonctionne pas.
en lançant mon application au début c'est correct le dataGrid contient une table avec à chaque ligne la date d'aujourd'hui et un num.
en appuyant sur le bouton g le meme affichage mais avec la date de demain ce qui est correct. Le problème survient en appuyant une 2ème fois sur le bouton il y est alors affiché 2 dates celle de demain et d'après 2main ds un meme dataGrid ce ke j'arrive pas expliker.

j'esper ke vous voyez le truc ; sinon ca serait gentil de me donner d'autres idées pour mon agenda.

voila le code (pas très au point je c ; c ke chui pa pro)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace WindowsApplication2
{
	/// <summary>
	/// Description résumée de Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Data.OleDb.OleDbConnection connection;
		private System.Data.OleDb.OleDbCommand oleDbCommand1;
        private int r;
		private int p;
		 private double d;
		private System.Windows.Forms.DateTimePicker picker;
		private System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
		private System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
		private System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
		private System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
		private System.Data.DataSet dataSet1;
		private System.Windows.Forms.DataGrid liste;
		private System.Data.OleDb.OleDbDataAdapter adapter;
		private System.Data.OleDb.OleDbCommand commande;
	    private System.Data.DataTable dataTable1;
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// Variable nécessaire au concepteur.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.connection = new System.Data.OleDb.OleDbConnection();
			this.picker = new System.Windows.Forms.DateTimePicker();
			this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
			this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
			this.adapter = new System.Data.OleDb.OleDbDataAdapter();
			this.commande = new System.Data.OleDb.OleDbCommand();
			this.dataSet1 = new System.Data.DataSet();
			this.liste = new System.Windows.Forms.DataGrid();
			this.button1 = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.liste)).BeginInit();
			this.SuspendLayout();
			// 
			// connection
			// 
			this.connection.ConnectionString = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=""C:\Documents and Settings\Administrateur\Bureau\bd1.mdb"";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1";
			// 
			// picker
			// 
			this.picker.Location = new System.Drawing.Point(216, 16);
			this.picker.Name = "picker";
			this.picker.Size = new System.Drawing.Size(192, 20);
			this.picker.TabIndex = 0;
			this.picker.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
			// 
			// adapter
			// 
			this.adapter.DeleteCommand = this.oleDbDeleteCommand1;
			this.adapter.InsertCommand = this.oleDbInsertCommand1;
			this.adapter.SelectCommand = this.oleDbSelectCommand1;
			this.adapter.UpdateCommand = this.oleDbUpdateCommand1;
			// 
			// commande
			// 
			
			
			// 
			// dataSet1
			// 
			this.dataSet1.DataSetName = "NewDataSet";
			this.dataSet1.Locale = new System.Globalization.CultureInfo("fr-FR");
			// 
			// liste
			// 
			this.liste.DataMember = "";
			this.liste.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.liste.Location = new System.Drawing.Point(112, 56);
			this.liste.Name = "liste";
			this.liste.Size = new System.Drawing.Size(408, 272);
			this.liste.TabIndex = 1;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(208, 336);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(264, 24);
			this.button1.TabIndex = 2;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(592, 366);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.liste);
			this.Controls.Add(this.picker);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.liste)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// Point d'entrée principal de l'application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{ 
		//debut insertion
				try
		 {    connection.Open();
					for(int i=8;i<19;i++) 
					{
						this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand("insert into table1(num,d) values('"+i.ToString()+"','"+picker.Value.ToShortDateString()+"');", connection);
						r=oleDbCommand1.ExecuteNonQuery();
					}
					this.d=8.3;
					do
					{string s="insert into table1(num,d) values('"+d.ToString()+"','"+picker.Value.ToShortDateString()+"');";MessageBox.Show(s);
						this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand(s,connection);
						p=oleDbCommand1.ExecuteNonQuery();
						d=d+1;
					}while(d<18);
		      
		}

				catch (Exception Erreur)
				{
					MessageBox.Show(Erreur.Message);
				}
				finally
				{
					connection.Close();
					
				}
			//fin insertion
			this.dataSet1=new DataSet();
			string rff=picker.Value.Month.ToString()+"/"+picker.Value.Day.ToString()+"/"+picker.Value.Year.ToString();
			this.commande=new OleDbCommand("select * from table1 where d=#"+rff+"#;",connection);
			adapter=new OleDbDataAdapter(commande);//la commande est exécutée
			adapter.Fill(dataSet1,"listeData");//le résultat de la commande est mis dans un dataset nommée ListeData
			dataTable1=dataSet1.Tables["ListeData"];//Le dataset listeData est récupéré dans une table
			this.liste.DataSource=dataTable1;//la liste a comme source la datatable 
			
dataSet1.Clear();
		}

		private void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
		{
			/*ebut insertion*/
			try
			{
					connection.Open();
				for(int i=8;i<19;i++) 
				{
					this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand("insert into table1(num,d) values('"+i.ToString()+"','"+picker.Value.ToShortDateString()+"');", connection);
					r=oleDbCommand1.ExecuteNonQuery();
				}
				this.d=8.3;
				do
				{
						string s="insert into table1(num,d) values('"+d.ToString()+"','"+picker.Value.ToShortDateString()+"');";MessageBox.Show(s);
					this.oleDbCommand1 = new System.Data.OleDb.OleDbCommand(s,connection);
					p=oleDbCommand1.ExecuteNonQuery();
					d=d+1;
				}while(d<18);
		      
			}
			
		

			catch (Exception Erreur)
			{
				MessageBox.Show(Erreur.Message);
			}
			finally
			{
				connection.Close();
											
			}

			//fin insertion
			
          string rff=picker.Value.Month.ToString()+"/"+picker.Value.Day.ToString()+"/"+picker.Value.Year.ToString();
            MessageBox.Show(rff);
			this.commande=new OleDbCommand("select * from table1 where d=#"+rff+"#;",connection);
			adapter=new OleDbDataAdapter(commande);//la commande est exécutée
			adapter.Fill(dataSet1,"lData");//le résultat de la commande est mis dans un dataset nommée ListeData
			dataTable1=dataSet1.Tables["lData"];//Le dataset listeData est récupéré dans une table
			this.liste.DataSource=dataTable1;//la liste a comme source la datatable 
		
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			picker.Value=picker.Value.AddDays(1);

		}
	}
}

1 réponse

Si tu écrivais du français propre, on pourrait peut-être te comprendre, voire répondre...
2