IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Silverlight Discussion :

Validation des données sur un projet non RIA


Sujet :

Silverlight

  1. #1
    Membre habitué Avatar de Mozofeuk
    Inscrit en
    Novembre 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 326
    Points : 133
    Points
    133
    Par défaut Validation des données sur un projet non RIA
    Bonjour,

    Voila j'aurai voulu savoir savoir si il était possible de mettre en place un système de validation des données mais sans utilisations de RIA service (dans un datagrid par exemple) ?


    Cordialement MoZo

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Avec les ValidationRules ?

  3. #3
    Rédacteur
    Avatar de The_badger_man
    Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2005
    Messages
    2 745
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2005
    Messages : 2 745
    Points : 8 538
    Points
    8 538
    Les règles du forum
    Le trio magique : FAQ + Cours + fonction rechercher
    Mes articles
    Pas de questions par messages privés svp

    Software is never finished, only abandoned.

  4. #4
    Membre habitué Avatar de Mozofeuk
    Inscrit en
    Novembre 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 326
    Points : 133
    Points
    133
    Par défaut
    Merci de vos réponse, mais en fait j'ai peur de ne pas trop comprendre :

    J'utilise un service WCF qui exécute une requête sur ma base de données afin de remplir mon datagrid comme ceci :

    Service :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    [OperationContract]
            public List<Contact> Get_ListeContacts()
            {
                PlateformeCommercialDataClassesDataContext dc = new PlateformeCommercialDataClassesDataContext();
                var ListeDesContacts = (from Contact in dc.Contacts select Contact).ToList();
                return ListeDesContacts;
            }
    ds la page de mon Datagrid :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    void Serv_Get_ListeContactsCompleted(object sender, Get_ListeContactsCompletedEventArgs e)
            {
                MonDataGrid.ItemsSource = e.Result;
            }
    xaml :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     <data:DataGrid Grid.Row="0" AutoGenerateColumns="False" HeadersVisibility="All" x:Name="MonDatagrid" ColumnWidth="85" RowHeight="30" CanUserResizeColumns="True" Width="Auto" Height="Auto" IsEnabled="True" Visibility="Visible" Margin="0,21,0,8">
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Header="ID" Binding="{Binding    Path=Contact_ID, Mode=TwoWay}" Width="19" />
                    <data:DataGridTextColumn Header="Nom" Binding="{Binding    Path=Contact_Nom, Mode=TwoWay}" Width="120" />
                    <data:DataGridTextColumn Header="Prénom" Binding="{Binding    Path=Contact_Prenom, Mode=TwoWay}" Width="120" />
                    <data:DataGridTextColumn Header="Strucure" Binding="{Binding    Path=Contact_Structure, Mode=TwoWay}" Width="120" />
                    <data:DataGridTextColumn Header="Fonction" Binding="{Binding    Path=Contact_Fonction, Mode=TwoWay}" Width="120" />
                    <data:DataGridTextColumn Header="Coordonnées" Binding="{Binding    Path=Contact_Coordonnees, Mode=TwoWay}" Width="120" />
       </data:DataGrid.Columns>
            </data:DataGrid>
    Je ne comprend pas trop a quel endroit je doit modifer les "setter" (get/set) ? Est-ce dans ma classe LinQ to SQL (pourtant situé coté serveur) ?

  5. #5
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Software Engineer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Je suis tombé sur ça hier, mais j'ai pas lu dans le détail, je sais pas si ça correspond à ce que tu veux
    http://wildermuth.com/2009/09/28/Int...roject_Niagara
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  6. #6
    Membre actif
    Profil pro
    Inscrit en
    Juillet 2009
    Messages
    159
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2009
    Messages : 159
    Points : 259
    Points
    259
    Par défaut
    Hello,

    Il te faut mettre en place une couche intermédiaire entre le proxy client WCF généré coté Silverlight et le binding dans ta grille.

    Je serais donc tenté de t'inciter à utiliser le pattern MVVM.

    1 - Construit un modèle intermédiare (ViewModel) pour tes vues alimenté par les objets venant de ton service WCF
    2 - Enrichie ce modèle pour qu'il lève une exception de validation sur le setter
    2 - Utilise le binding de ta vue sur ce ViewModel et tu auras un résultat similaire à ce que propose .NET RIA Services out of the box.

    Si le sujet t'intéresse et que tu es libre demain, viens à la journée Industrialisation des développements N-tiers : http://blogs.msdn.com/mitsufu/archiv...lverlight.aspx

    Bye,

    David Rousset
    Microsoft France

  7. #7
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Ce qui serait top, c'est sur Silverlight dispose de IDataErrorInfo mais ce n'est pas disponible à l'heure actuelle....

  8. #8
    Membre habitué Avatar de Mozofeuk
    Inscrit en
    Novembre 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 326
    Points : 133
    Points
    133
    Par défaut
    Merci beaucoup de vos réponses,

    Je vais essayer la methode de davrous et je posterais du code si j'arrive a le faire. Encore merci a tous !!

    Cordialement MoZo

  9. #9
    Membre habitué Avatar de Mozofeuk
    Inscrit en
    Novembre 2007
    Messages
    326
    Détails du profil
    Informations forums :
    Inscription : Novembre 2007
    Messages : 326
    Points : 133
    Points
    133
    Par défaut
    J'ai réussi a implémenter la validation des données en m'inspirant de vos réponses (particulièrement de davrous) donc merci a tous pour votre aide :

    1 ) Construit un modèle intermédiare (ViewModel) pour tes vues alimenté par les objets venant de ton service WCF :

    j'ai donc créer une classe ContactValidate (coté client) qui possède les mêmes attribut que ma classe Contact(coté serveur) représentant les données de ma base.

    Donc a chaque fois que je doit binder mes données je trasforme Mon Contact en un ContactValidate comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    public ContactValidate(Contact _LeContact)
            {
                Contact_ID = _LeContact.Contact_ID;
                Contact_Nom = _LeContact.Contact_Nom;
                Contact_Prenom = _LeContact.Contact_Prenom;
                Contact_Structure = _LeContact.Contact_Structure;
                Contact_Fonction = _LeContact.Contact_Fonction;
                Contact_Coordonnees = _LeContact.Contact_Coordonnees;
                Contact_Problematique = _LeContact.Contact_Problematique;
            }
    J'instancie un ContactValidate a l'aide d'un Contact passer en parametre.

    2 ) Enrichie ce modèle pour qu'il lève une exception de validation sur le setter

    j'ai donc enrichie les setter de ma classe ContactValidate :

    (ds ma classe ContactValidate.cs :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
     private string contact_Nom;
            public string Contact_Nom
            {
                get
                {
                    return this.contact_Nom;
                }
                set
                {
                    this.contact_Nom = value;
                    if (value.Length>5)
                    {
                        throw new InvalidDataException("Bad length on that string");
                    }
                    FirePropertyChanged("Contact_Nom");
                }
            }
     
    void FirePropertyChanged(string property)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(property));
                }
            }
     
    //je l'ai mis là mais peut etre mis dans une classe a part entiere
    public class InvalidDataException : Exception
        {
            public InvalidDataException(string msg)
                : base(msg)
            {
            }
        }
    Dans ma Page.xaml.cs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    private void OnValidationError(object sender, ValidationErrorEventArgs e)
            {
                switch (e.Action)
                {
                    case ValidationErrorEventAction.Added:
                        Exception ex = e.Error.Exception;
                        break;
                    case ValidationErrorEventAction.Removed:
                        break;
                    default:
                        break;
                }
            }
    et enfin ma page.xaml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
    <controls:ChildWindow xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="PlateformeContactCommerciaux.Controls.DetailContactChildWindow"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
               xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
               xmlns:local="clr-namespace:PlateformeContactCommerciaux.Classes"
               Width="900" Height="500" 
               Title="Détail du Contact">
     
        <Grid x:Name="LayoutRoot" Margin="2" ShowGridLines="False" BindingValidationError="OnValidationError">
        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="130"></ColumnDefinition>
                            <ColumnDefinition Width="180"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="30"></RowDefinition>
                            <RowDefinition Height="40"></RowDefinition>
                            <RowDefinition Height="25"></RowDefinition>
                        </Grid.RowDefinitions>
     
                        <TextBlock Height="25" Grid.Row="0" Grid.Column="0" Text="Nom :"></TextBlock>
                        <TextBlock Height="25" Grid.Row="1" Grid.Column="0" Text="Prenom :"></TextBlock>
                        <TextBlock Height="25" Grid.Row="2" Grid.Column="0" Text="Structure :"></TextBlock>
                        <TextBlock Height="25" Grid.Row="3" Grid.Column="0" Text="Fonction :"></TextBlock>
                        <TextBlock Height="40" Grid.Row="4" Grid.Column="0" Text="Coordonnées :"></TextBlock>
                        <TextBlock Height="25" Grid.Row="5" Grid.Column="0" Text="Problématique :" VerticalAlignment="Bottom"></TextBlock>
     
                        <TextBox Height="25" Grid.Row="0" Grid.Column="1" x:Name="Tb_Nom"  Text="{Binding Contact_Nom,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox>
                        <TextBox Height="25" Grid.Row="1" Grid.Column="1" x:Name="Tb_Prenom"  Text="{Binding Contact_Prenom,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox>
                        <TextBox Height="25" Grid.Row="2" Grid.Column="1" x:Name="Tb_Structure"  Text="{Binding Contact_Structure,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox>
                        <TextBox Height="25" Grid.Row="3" Grid.Column="1" x:Name="Tb_Fonction"  Text="{Binding Contact_Fonction,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox>
                        <TextBox Height="25" Grid.Row="4" Grid.Column="1" x:Name="Tb_Coordonnées"  Text="{Binding Contact_Coordonnees,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}"></TextBox>
                </Grid>
    Merci a tous de votre aide, Cordialement MoZo

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2010] Validation des Données sur le nombre de caractère
    Par antonysansh dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 15/05/2015, 10h02
  2. [PHP-JS] validation des données
    Par emma des bois dans le forum Langage
    Réponses: 6
    Dernier message: 10/02/2006, 15h28
  3. Remonter des donnes sur ACCESS
    Par pierre bunel dans le forum Access
    Réponses: 1
    Dernier message: 22/12/2005, 17h03
  4. Récupérer des données sur une page HTML
    Par rupeni dans le forum VB 6 et antérieur
    Réponses: 11
    Dernier message: 18/11/2005, 17h22
  5. dbgrid AND validation des données
    Par samlerouge dans le forum Bases de données
    Réponses: 10
    Dernier message: 11/06/2004, 23h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo