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

Windows Forms Discussion :

Optimisation de fonction


Sujet :

Windows Forms

  1. #1
    Membre régulier

    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 80
    Points : 111
    Points
    111
    Par défaut Optimisation de fonction
    Bonjour,
    Je n'aime pas cette fonction que je n'arrive pas à améliorer pouvez vous me donner un conseil ou deux pour l'optimiser svp ? Je ne maitrise surement pas tout et je serai curieux de voir comment la simplifier ...

    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    ''' <summary>
        ''' Return True si au moins un champs obligatoire n'est pas rempli, et le colore
        ''' </summary>
        ''' <param name="lstchamps"></param>
        ''' <returns></returns>
        ''' <remarks>ED et AK 24/06/2009</remarks>
        Public Function ChampsObligatoireIsVide(ByRef lstchamps As Generic.List(Of Control)) As Boolean
            Dim bChampsVide As Boolean = False
            For Each CurControl In lstchamps
                If (TypeOf CurControl Is TextBox) Then
                    Dim tempcontrol As TextBox
                    tempcontrol = (CType(CurControl, TextBox))
                    If tempcontrol.Text = "" Then
                        tempcontrol.BackColor = Color.Orange
                        bChampsVide = True
                    Else
                        tempcontrol.BackColor = Color.NavajoWhite
                    End If
                ElseIf (TypeOf CurControl Is ComboBox) Then
                    Dim tempcontrol As ComboBox
                    tempcontrol = (CType(CurControl, ComboBox))
                    If (Trim(tempcontrol.Text) = "") Or (tempcontrol.SelectedValue Is Nothing) Then
                        tempcontrol.BackColor = Color.Orange
                        bChampsVide = True
                    Else
                        tempcontrol.BackColor = Color.NavajoWhite
                    End If
     
                ElseIf (TypeOf CurControl Is DateTimePicker) Then
                    Dim tempcontrol As DateTimePicker
                    tempcontrol = (CType(CurControl, DateTimePicker))
                    If Not IsDate(tempcontrol.Text) Then
                        tempcontrol.BackColor = Color.Orange
                        bChampsVide = True
                    Else
                        tempcontrol.BackColor = Color.NavajoWhite
                    End If
                ElseIf (TypeOf CurControl Is CheckBox) Then
                    Dim tempcontrol As CheckBox
                    tempcontrol = (CType(CurControl, CheckBox))
                    If tempcontrol.Checked = False Then
                        tempcontrol.BackColor = Color.Orange
                        bChampsVide = True
                    Else
                        tempcontrol.BackColor = Color.NavajoWhite
                    End If
                ElseIf (TypeOf CurControl Is PADatePicker) Then
                    Dim tempcontrol As PADatePicker
                    tempcontrol = (CType(CurControl, PADatePicker))
                    If (tempcontrol.Text = " / /    ") Or (Not IsDate(tempcontrol.Text)) Then
                        tempcontrol.BackColor = Color.Orange
                        bChampsVide = True
                    Else
                        tempcontrol.BackColor = Color.NavajoWhite
                    End If
                End If
     
            Next
            Return bChampsVide
        End Function
    et dans le meme genre j'ai ca aussi :
    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
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
     
        Public Sub EditablePanelAptFormGeneral(ByVal valueTrueOrFalse As Boolean)
      Dim c() As Control = {Me.Panel1, Me.Panel3, Me.Panel4, Me.pnlWPrices, Me.pnlMPrices, Me.TabST, Me.TabVST} 'Me.Panel24, Me.Panel26, Me.pnlWPrices1, Me.pnlNPrices, Me.pnlMPrices1
            Dim LstTempcontrol As New Generic.List(Of ComboBox)
            For Each i As Control In c
                For Each CurControl As Control In i.Controls
                    If (TypeOf CurControl Is TextBox) Then
                        Dim tempcontrol As TextBox
                        tempcontrol = (CType(CurControl, TextBox))
                        tempcontrol.ReadOnly = Not valueTrueOrFalse
     
                    ElseIf (TypeOf CurControl Is CheckBox) Then
                        Dim tempcontrol As CheckBox
                        tempcontrol = (CType(CurControl, CheckBox))
                        tempcontrol.AutoCheck = valueTrueOrFalse
     
                    ElseIf (TypeOf CurControl Is ComboBox) Then
                        Dim tempcontrol As ComboBox
                        tempcontrol = (CType(CurControl, ComboBox))
                        ' tempcontrol.Enabled = valueTrueOrFalse
                        If Not valueTrueOrFalse Then
                            If tempcontrol.DropDownStyle = ComboBoxStyle.DropDownList Then 'Test si le combobox est a DropDownList
                                tempcontrol.DropDownStyle = ComboBoxStyle.DropDown 'passer le combobox au style DropDown
                                SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                                LstTempcontrol.Add(tempcontrol) 'Construire une lise des combobox qui ont un style DropDownList
                            Else
                                SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                            End If
                        Else
                            For Each lst In LstTempcontrol 'parcourir la liste des combobox qui ont un style DropDownList
                                lst.DropDownStyle = ComboBoxStyle.DropDownList 'Remettre le style d'orgine des combobox
                            Next
                            SetComboReadOnly(tempcontrol, Not valueTrueOrFalse)
                        End If
                    ElseIf (TypeOf CurControl Is RadioButton) Then
                        Dim tempcontrol As RadioButton
                        tempcontrol = (CType(CurControl, RadioButton))
                        tempcontrol.AutoCheck = valueTrueOrFalse
     
                    ElseIf (TypeOf CurControl Is DateTimePicker) Then
                        Dim tempcontrol As DateTimePicker
                        tempcontrol = (CType(CurControl, DateTimePicker))
                        tempcontrol.Enabled = valueTrueOrFalse
                    ElseIf (TypeOf CurControl Is PADatePicker) Then
                        Dim tempcontrol As PADatePicker
                        tempcontrol = (CType(CurControl, PADatePicker))
                        ' tempcontrol.Enabled = valueTrueOrFalse
                        tempcontrol.Read_Only = Not valueTrueOrFalse
                    ElseIf (TypeOf CurControl Is Button) Then
                        Dim tempcontrol As Button
                        tempcontrol = (CType(CurControl, Button))
                        tempcontrol.Enabled = valueTrueOrFalse
     
                    ElseIf (TypeOf CurControl Is DataGridView) Then
                        Dim tempcontrol As DataGridView
                        tempcontrol = (CType(CurControl, DataGridView))
                        tempcontrol.ReadOnly = Not valueTrueOrFalse
     
                    ElseIf (TypeOf CurControl Is PictureBox) Then
                        Dim tempcontrol As PictureBox
                        tempcontrol = (CType(CurControl, PictureBox))
                        tempcontrol.Enabled = Not valueTrueOrFalse
     
                    End If
                Next
            Next
    end sub

  2. #2
    Expert éminent sénior Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 154
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 154
    Points : 25 072
    Points
    25 072
    Par défaut
    la seul optimisation possible serait visuelle, ou améliorer la lisibilité/maintenabilité, niveau performance y a rien à gagner (optimisation est en général utilisé pour les performances)

    sur le framework 3.5 on peut faire des choses comme ca :
    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
     
     Public Function ChampsObligatoireIsVide(ByRef lstchamps As Generic.List(Of Control)) As Boolean
            Dim auMoinsUnControlePasRempli As Boolean = False
     
            Dim dicoCtrlBienRempli As New System.Collections.Generic.Dictionary(Of System.Type, Func(Of Control, Boolean))
     
            Dim TextboxBienRempli As New Func(Of Control, Boolean)(Function(c As Control) (c.Text <> ""))
             Dim DateTimePickerBienRempli As New Func(Of Control, Boolean)(Function(c As Control) (DirectCast(c, DateTimePicker).Value IsNot Nothing))
     
     
            dicoCtrlBienRempli.Add(GetType(TextBox), TextboxBienRempli)
            dicoCtrlBienRempli.Add(GetType(DateTimePicker), DateTimePickerBienRempli)
     
            For Each c As Control In lstchamps
                If dicoCtrlBienRempli(c.GetType)(c) Then
                    c.BackColor = Color.NavajoWhite
                Else
                    c.BackColor = Color.Orange
                    auMoinsUnControlePasRempli = True
                End If
            Next
     
            Return auMoinsUnControlePasRempli
        End Function
    ca resterait à adapter vu que pour un combobox par exemple vous ne modifiez pas seulement le backcolor
    mais ca doit pouvoir diviser le nombre de lignes par 2

    enfin déjà y a pas besoin de faire une variable tempcontrol
    surtout pour tester .text !

    et y a des choses bizarres dans votre code
    - un checkbox pas coché vous le considérez comme non rempli, un checkbox en théorie on a le droit de pas le cocher
    - le datetimepicker, vous testez .text, alors que c'est .value pour la date contenue (donc pas besoin de isdate, c'est toujours un date)
    - le combobox on ne teste pas non plus .text en général
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre régulier

    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 80
    Points : 111
    Points
    111
    Par défaut
    Merci pour ces pistes... Je vais envoyer ca à mon équipe j'aime bien le coté visuel meme si ca apporte pas grand chose coté perf ;-)

    Merci

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

Discussions similaires

  1. Optimisation des fonctions?
    Par JauB dans le forum DB2
    Réponses: 5
    Dernier message: 31/01/2007, 20h47
  2. Optimiser une fonction (trouver le minimum)
    Par Noel Gallagher dans le forum C
    Réponses: 2
    Dernier message: 27/11/2006, 06h46
  3. probleme d'optimisation de fonction
    Par franc82 dans le forum C++
    Réponses: 3
    Dernier message: 31/10/2006, 09h45
  4. Optimisation de fonction
    Par Elendhil dans le forum Assembleur
    Réponses: 2
    Dernier message: 19/06/2006, 15h03
  5. Optimisation de fonction ...
    Par dark_vidor dans le forum Langage
    Réponses: 10
    Dernier message: 02/01/2006, 11h50

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