| 12
 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
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 
 |  
Private Class ContactInfo
        Public NomComplet As String
        Public BtnSup As ImageButton = Nothing '<----- C'est ce bouton
    End Class
Dim dicInvite As Dictionary(Of Guid, ContactInfo)
    Dim strdicInvite As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
strdicInvite = "dicInvite" & ConnectedUser.IDContact.ToString
 If Page.IsPostBack Then
For Each ContInfo As KeyValuePair(Of Guid, ContactInfo) In dicInvite
                        If ContInfo.Value.BtnSup IsNot Nothing Then AddHandler ContInfo.Value.BtnSup.Click, AddressOf Me.btnDelInvite_Click
                    Next
                    'Si les controles n'existe pas les construire pour avoir l'évènement sur les boutons
                    Try
                        ConstruirePlanning() 
                    Catch ex As Exception
                    End Try
end If
End Sub
Private Sub ConstruirePlanning()
        'Vider le placeHolder car avec le Load se construit 2X l'un derière l'autre
        Planning.Controls.Clear()
        Dim MaTable As HtmlTable = New HtmlTable
        MaTable.Attributes.Add("class", "TBL")
        Dim MaRow1 As HtmlTableRow = New HtmlTableRow
        Dim MaCell1 As HtmlTableCell = New HtmlTableCell
        'Construction de la première ligne
        MaRow1.Attributes.Add("class", "ListeEntete")
        '1ere cellule vide
        MaCell1.Width = 60
        MaRow1.Controls.Add(MaCell1)
        'Ajouter nom/Suppression
        For Each ContInfo As KeyValuePair(Of Guid, ContactInfo) In dicInvite
            Dim MaCell As HtmlTableCell = New HtmlTableCell
                MaCell.Align = "center"
....
                'Nouvelle ligne
                MaCell.Controls.Add(New LiteralControl(" "))
                'Bouton suppression
                Dim btnsupp As New ImageButton
                btnsupp.ImageUrl = "~/images/cancel.gif"
                btnsupp.CommandArgument = ContInfo.Key.ToString
                btnsupp.ID = "btnSupInv" & ContInfo.Key.ToString
                AddHandler btnsupp.Click, AddressOf Me.btnDelInvite_Click 'Rattaché le btn à l'evt a déclencher
                MaCell.Controls.Add(btnsupp)
                ContInfo.Value.BtnSup = btnsupp 'Mise dans le dictionnaire pour mémorisation et régération sue postback
                'Vérification de suppression
                Dim SurSupp As New AjaxControlToolkit.ConfirmButtonExtender
                SurSupp.ConfirmText = "Voulez vous vraiment supprimer ?"
                SurSupp.TargetControlID = "btnSupInv" & ContInfo.Key.ToString
                MaCell.Controls.Add(SurSupp)
                'Nouvelle ligne
                MaCell.Controls.Add(New LiteralControl("<BR />"))
            'Nom/Fonction
            lblnom.Text = ContInfo.Value.NomComplet
            MaCell.Controls.Add(lblnom)
            MaRow1.Controls.Add(MaCell)
        Next
        MaTable.Controls.Add(MaRow1)
        'Pour chaque horaire : controler chaque contact
        For Each Hor As DataRowView In dtvHoraire
            Dim MaRow As HtmlTableRow = New HtmlTableRow
            Dim MaCell As HtmlTableCell = New HtmlTableCell
            Dim heure As Date = CDate("##/##/##" & Hor("Libelle"))
....
            MaRow.Controls.Add(MaCell)
            'Mise en couleur des cellules
            'pour indiquer si contact dispo ou non
            Dim NonDispo As Boolean = True
            For Each ContInfo As KeyValuePair(Of Guid, ContactInfo) In dicInvite
                Dim MaCellDispo As New HtmlTableCell
                   ...
                MaRow.Controls.Add(MaCellDispo)
            Next
            MaTable.Controls.Add(MaRow)
        Next
        Planning.Controls.Add(MaTable)
    End Sub
'Au dessus du placeholder : une liste de personne a inviter avec un bouton de validation
    Protected Sub btnAddInvite_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnAddInvite.Click
        Dim IdInvit As Guid = New Guid(lstContactAInviter.SelectedValue)
        'Ajout dans la liste locale des invités
        dicInvite = CType(Utils.GetObjectFromCache(strdicInvite), Dictionary(Of Guid, ContactInfo))
        InsertDic(IdInvit)
        Utils.SetObjectToCache(strdicInvite, dicInvite, True, False, False)
        ConstruirePlanning()
    End Sub
    Protected Sub btnDelInvite_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        'Récupérer argument passer en paramètre
        Dim IdInv As Guid = New Guid(CType(sender, ImageButton).CommandArgument)
        'Récupérer le dictionnaire
        dicInvite = CType(Utils.GetObjectFromCache(strdicInvite), Dictionary(Of Guid, ContactInfo))
        'Retirer du dictionnaire
        dicInvite.Remove(IdInv)
        'Remettre en mémoire le dictionnaire mis à jour
        Utils.SetObjectToCache(strdicInvite, dicInvite, True, False, False)
        ConstruirePlanning()
    End Sub
 Private Sub InsertDic(ByVal IdContact As Guid)
        Dim MonContactInfo As New ContactInfo
....
                   MonContactInfo.NomComplet = "blabla"
            dicInvite.Add(IdContact, MonContactInfo)
    End Sub | 
Partager