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

VB.NET Discussion :

Pagination d'une requete ACCESS dans un PDF


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2017
    Messages : 2
    Par défaut Pagination d'une requete ACCESS dans un PDF
    Bonjour à tous,

    Je souhaiterai faire en sorte que mes résultats de requête s'affichent sur plusieurs pages lors de la génération de mon PDF. Pour le moment mes résultats ne s'affichent que sur une seule page, et sont donc limitées en nombre.
    Voici mon code:

    Voici ma requête initiale:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Obj_Command = New OleDbCommand()
            'initialiser l'objet Command
            Obj_Command.Connection() = laConnection
            Obj_Command.CommandText = "SELECT TOP 80 LE_ID, LE_DATE, LE_COMPTE, LE_LIBELLE, LE_MONTANT, LE_NATURE, LE_JOURNAL FROM(LIGNE_ECRITURE) WHERE LE_DATE BETWEEN #" + Format("dd/mm/yyyy", dtp_deb.Text) + "# AND #" + Format("dd/mm/yyyy", dtp_fin.Text) + "# AND LE_JOURNAL = 'JDV' AND (LE_COMPTE LIKE '411%' OR LE_COMPTE='44571000' OR LE_COMPTE='70600000' OR LE_COMPTE='70700000' ) AND LE_LETTRAGE = false ORDER BY LE_DATE DESC, LE_ID DESC"
            Obj_Reader = Obj_Command.ExecuteReader()
    Ensuite je fais la mise en page de mes résultats:
    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
            While Obj_Reader.Read()
                If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                End If
                pos_y = pos_y + 20
            End While
    Et voici ma partie de code pour la création d'une deuxième feuille (et plus si nécessaire) :
    1: Je récupérer le nombre de lignes à l'aide d'une deuxième requête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
           'Instancier un objet Commande
            Obj_Command2 = New OleDbCommand()
            'initialiser l'objet Command
            Obj_Command2.Connection() = laConnection
            'requête pour affichage des articles
            Obj_Command2.CommandText = "SELECT COUNT(LIGNE_ECRITURE.LE_ID) AS Nbr FROM (LIGNE_ECRITURE) "
            Obj_Reader2 = Obj_Command2.ExecuteReader()
            Obj_Reader2.Read()
     
            Dim vente As String
            vente = Obj_Reader2.Item("LE_ID").ToString
    2: je convertis mon String en Integer:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
            Dim vente1 As Integer
            vente1 = Integer.Parse(vente)
            Obj_Reader2.Close()
     
     
            If (vente1 > 40) Then
                Dim compteur As Integer = 0
    3: J'utilise un Select Case pour déterminer le nombre de pages nécessaires:
    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
    68
    69
    70
    71
    72
    73
    74
    75
                Select Case NumPage
                    Case 1
                        While Obj_Reader.Read() And compteur <= 40
                            Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                            If (ens <> "") Then
                                compteur = compteur + 1
                                If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                                ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                    ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                    ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                    ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                                End If
                                pos_y = pos_y + 20
                            End If
     
                        End While
                        ev.HasMorePages = True
                        NumPage += 1
                        Obj_Reader.Close()
                    Case 2
                        While Obj_Reader.Read()
                            Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                            If (ens <> "") Then
                                compteur = compteur + 1
                                If (compteur > 40) Then
                                    If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                        ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                        ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                                    ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                                        ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                                        ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                                        ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                                    End If
                                    pos_y = pos_y + 20
                                End If
                            End If
                        End While
                        ev.HasMorePages = False
                        NumPage = 1
                End Select
            Else 'si nombre de ligne < 41 
                While Obj_Reader.Read()
                    Dim ens As String = Obj_Reader.Item("LE_ID").ToString
                    If (ens <> "") Then
                        If Obj_Reader.GetValue(5).ToString() = "Débit" Then
                            ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                            ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                            ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                            ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                            ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 578, ypos + pos_y)
                        ElseIf Obj_Reader.GetValue(5).ToString() = "Crédit" Then
                            ev.Graphics.DrawString(Obj_Reader.GetValue(0).ToString(), f, Brushes.Black, xpos + 6, ypos + pos_y)
                            ev.Graphics.DrawString(FormatDateTime(Obj_Reader.GetValue(1).ToString(), DateFormat.ShortDate), f, Brushes.Black, xpos + 100, ypos + pos_y)
                            ev.Graphics.DrawString(Obj_Reader.GetValue(2).ToString(), f, Brushes.Black, xpos + 194, ypos + pos_y)
                            ev.Graphics.DrawString(Obj_Reader.GetValue(3).ToString(), f, Brushes.Black, xpos + 300, ypos + pos_y)
                            ev.Graphics.DrawString(toMoney(Obj_Reader.GetValue(4).ToString()), f, Brushes.Black, xpos + 672, ypos + pos_y)
                        End If
                        pos_y = pos_y + 20
                    End If
                End While
            End If
            Obj_Reader.Close()
        End Sub
    Je reste dans une impasse et ne trouve pas comment avoir un affichage correct sur plusieurs pages. Je m'en remets à vous et votre savoir,
    Cordialement,

    Ludwig Robert

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

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 198
    Par défaut
    Le mieux c'est de charger les données dans une variable avant de lancer l'impression (genre datatable)
    Dans le printpage tu lis les données dans ta variable et tu garde l'offset dans une variable pour repartir à cet endroit
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2017
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2017
    Messages : 2
    Par défaut
    Je vous remercie pour votre attention et votre aide, votre solution semble plus simple en effet.

Discussions similaires

  1. Memorise une Requete Access dans VB6
    Par ecarbill dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 25/09/2012, 16h17
  2. Affichage dynamique d'une requete Access dans Excel
    Par alex830001 dans le forum Requêtes et SQL.
    Réponses: 2
    Dernier message: 18/06/2008, 16h54
  3. Réponses: 3
    Dernier message: 03/10/2007, 12h24
  4. Date dans une requete access toute bête
    Par quatar dans le forum Requêtes et SQL.
    Réponses: 4
    Dernier message: 29/05/2007, 17h09
  5. fonction if/then/else dans une requete Access
    Par steve38 dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 24/12/2006, 17h09

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