DevInformatique Ralis par HACHIMI SAFAE Module N 17

  • Slides: 13
Download presentation
Dev-Informatique Réalisé par : HACHIMI SAFAE

Dev-Informatique Réalisé par : HACHIMI SAFAE

Module N° 17 : CRÉATION ET DÉPLOIEMENT D’APPLICATION CLIENT /SERVEUR CHAPITRE 5 : MODE

Module N° 17 : CRÉATION ET DÉPLOIEMENT D’APPLICATION CLIENT /SERVEUR CHAPITRE 5 : MODE DÉCONNECTÉ (DATASET, DATAADAPTER ) EXERCICE 1 : § Dans cet atelier vous allez utiliser les objets du mode déconnecté Dataset – dataadapter – Command. Builder -Data. Adapter § Créer l’interface ci-dessous :

CORRECTION EX 1: using System. Data. Sql. Client; namespace TDI_TP { public partial class

CORRECTION EX 1: using System. Data. Sql. Client; namespace TDI_TP { public partial class Form 1 : Form { Sql. Connection con = new Sql. Connection( "Data Source=. ; Initial Catalog=GST_STAGIAIRE; Integrated Security=True"); int cpt=0; Data. Set DS = new Data. Set(); Sql. Data. Adapter DA; Sql. Command. Builder CB = new Sql. Command. Builder();

public Form 1() { Initialize. Component(); } public void Valider() { Data. Set changes

public Form 1() { Initialize. Component(); } public void Valider() { Data. Set changes = DS. Get. Changes(); if (changes != null)// il y a des chgt { DA. Update(changes, ‘’STAGIAIRE"); DS. Accept. Changes(); } }

public void afficher(int i) { text. Box 1. Text = DS. Tables[0]. Rows[i][0]. To.

public void afficher(int i) { text. Box 1. Text = DS. Tables[0]. Rows[i][0]. To. String(); text. Box 2. Text = DS. Tables[0]. Rows[i][1]. To. String(); } public void Form 1_Load(object sender, Event. Args e) { DA = new Sql. Data. Adapter("select * from STAGIAIRE", con); DA. Fill. Schema(DS, Schema. Type. Source, ‘’STAGIAIRE"); CB. Data. Adapter = DA ; DA. Fill(ds, "client"); }

public void button. Premier_Click(object sender, Event. Args e) { cpt = 0; afficher(cpt); }

public void button. Premier_Click(object sender, Event. Args e) { cpt = 0; afficher(cpt); }

public void button. Suivant_Click(object sender, Event. Args e) try { cpt += 1; //

public void button. Suivant_Click(object sender, Event. Args e) try { cpt += 1; // Positioner le curseur dans la position suivante afficher(cpt); } catch(Index. Out. Of. Range. Exception ) { Message. Box. Show("Vous avez atteint la fin"); cpt = DS. Tables[“STAGIAIRE"]. Rows. Count - 1; } }

public void button. Precedent_Click(object sender, Event. Args e) { try { cpt -= 1;

public void button. Precedent_Click(object sender, Event. Args e) { try { cpt -= 1; // Positioner le curseur dans la position précédente afficher(cpt); } catch (Index. Out. Of. Range. Exception) { Message. Box. Show("Vous avez atteint le début"); cpt = 0; } }

public void buttondernier_Click(object sender, Event. Args e) { cpt = DS. Tables[‘’STAGIAIRE"]. Rows. Count

public void buttondernier_Click(object sender, Event. Args e) { cpt = DS. Tables[‘’STAGIAIRE"]. Rows. Count - 1; // Positioner le curseur dans la fin afficher(cpt); }

public void button. Ajouter_Click(object sender, Event. Args e) { Data. Row ligne = DS.

public void button. Ajouter_Click(object sender, Event. Args e) { Data. Row ligne = DS. Tables[0]. Rows. Find(text. Box 1. Text); if (ligne == null) { Data. Row nouvelle. Ligne = DS. Tables[0]. New. Row(); nouvelle. Ligne[0] = text. Box 1. Text; nouvelle. Ligne[1] = text. Box 2. Text; DS. Tables[0]. Rows. Add(nouvelle. Ligne); Valider(); } else { Message. Box. Show(‘’Stagiaire déja existant"); } }

public void button. Modifier_Click(object sender, Event. Args e) { Data. Row ligne = DS.

public void button. Modifier_Click(object sender, Event. Args e) { Data. Row ligne = DS. Tables[0]. Rows. Find(text. Box 1. Text); if (ligne != null) { ligne. Begin. Edit(); ligne[0] = text. Box 1. Text; ligne[1] = text. Box 2. Text; ligne. End. Edit (); Valider(); } else { Message. Box. Show(‘’ Stagiaire inexistant"); } }

public void button. Supprimer_Click(object sender, Event. Args e) {//recherché le client à l’aide de

public void button. Supprimer_Click(object sender, Event. Args e) {//recherché le client à l’aide de find Data. Row ligne = DS. Tables[0]. Rows. Find(text. Box 1. Text); if (ligne != null) { ligne. Delete(); Valider(); } else { Message. Box. Show(‘’Stagiaire inexistant"); } }

DEV-INFORMATIQUE MERCI POUR VOTRE ATTENTION

DEV-INFORMATIQUE MERCI POUR VOTRE ATTENTION