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 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
Imports Microsoft.VisualBasic
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.IO
Imports AdresseLivraison
Imports Param
Public Class ImpressionBL
'Document d'impression
Private _Doc As New PrintDocument
'Police d'écriture de base
Private _Font As New Font("Verdana", 10)
'Pinceau pour écrire
Private _Brush As New SolidBrush(Color.Black)
'Tableau des BLs à imprimer
Private BLtoPrint As InfoBL
'Curseur d'impression
Private curs As Integer = 0
'Page courante
Private curPageBL As Integer = 1
'Nombre total de Page
Private totPageBL As Integer = 0
'Ligne courante du BL
Private curLig As Integer = 0
'Poids total pour le BL
Private poidsTotalBL As Double = 0.0
'Prix total transport pour le BL
Private transpTotalBL As Double = 0.0
'Paramaètres
Private Parametre As Param
'Numéro de dépôt
Private numDepot As Integer
'Variation de marges en fonction de l'imprimante de dépôt utilisée
Private varMarge As Integer = 0
'Police d'écriture
'VERDANA
Dim font6bold As New Font("Verdana", 6, FontStyle.Bold)
Dim font6 As New Font("Verdana", 6, FontStyle.Regular)
Dim font7bold As New Font("Verdana", 7, FontStyle.Bold)
Dim font7boldU As New Font("Verdana", 7, FontStyle.Bold Or FontStyle.Underline)
Dim font7 As New Font("Verdana", 7, FontStyle.Regular)
Dim font8bold As New Font("Verdana", 8, FontStyle.Bold)
Dim font8boldU As New Font("Verdana", 8, (FontStyle.Bold Or FontStyle.Underline))
Dim font8 As New Font("Verdana", 8, FontStyle.Regular)
Dim font10bold As New Font("Verdana", 10, FontStyle.Bold)
Dim font10boldU As New Font("Verdana", 10, FontStyle.Bold Or FontStyle.Underline)
Dim font12bold As New Font("Verdana", 12, FontStyle.Bold)
Dim font12boldU As New Font("Verdana", 12, FontStyle.Bold Or FontStyle.Underline)
'ARIAL
Dim font20bold As New Font("Arial", 20, FontStyle.Bold)
Dim font24bold As New Font("Arial", 24, FontStyle.Bold)
'CODE BARRE
Dim fontCodeBarre As New Font("Code 39 v1", 40)
'Constructeur
Public Sub New(ByVal depot As Integer)
'Depot d'impression
numDepot = depot
'Initialisation des paramètres du document
With Me._Doc.DefaultPageSettings
.Landscape = False
.Color = False
.Margins = New Margins(0, 0, 0, 0)
End With
'Lecture du fichier de paramètre
Parametre = New Param
If (numDepot = 1) Then
Me._Doc.PrinterSettings.PrinterName = Parametre.NamePrint1
Else
Me._Doc.PrinterSettings.PrinterName = Parametre.NamePrint2
End If
'Prepare le handle d'impression
AddHandler _Doc.PrintPage, AddressOf _Doc_PrintPage
End Sub
'Mise en page du document et impression
Private Sub _Doc_PrintPage(ByVal send As Object, ByVal ev As PrintPageEventArgs)
Dim X As Integer = 0
Dim Y As Integer = 0
'Récupérer l'élément graphique
Dim graph As Graphics = ev.Graphics
'Définition du point 0,0
Dim XBase As Integer = CInt(ev.MarginBounds.Left)
Dim YBase As Integer = CInt(ev.MarginBounds.Top)
printBL(XBase, YBase, graph, BLtoPrint, ev)
End Sub
'Impression des BLs
Private Sub printBL(ByVal X As Integer, ByVal Y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL, ByVal ev As PrintPageEventArgs)
'Calcul du nombre de pages total à imprimer
Dim ligDebutSaisieDetail As Integer = 510
Dim ligDebutPiedPage As Integer = 1040
Dim tailleLigDetail As Integer = 15
Dim nbTotalLigDetail As Integer = BL.ligneBL.Length
Dim maxLigPerPage As Integer = ((ligDebutPiedPage - ligDebutSaisieDetail) / tailleLigDetail)
If (BL.ligneBL.Length > maxLigPerPage) Then
totPageBL = CInt((maxLigPerPage / nbTotalLigDetail) + 0.9999)
Else
totPageBL = 1
End If
'Affichage du titre
writeTitreBL(X, Y, graph, BL)
'Affichage information BL / Livraison
writeInfoBLivr(X, Y, graph, BL)
'Affichage du code barre
writeCodeBarre(X, Y, graph, BL)
'Affichage Adresse de livraison
writeAdrLivrBL(X, Y, graph, BL)
'Affichage info compte payeur
writeInfoCptPay(X, Y, graph, BL)
'Affichage commentaire
writeCommentBL(X, Y, graph, BL)
'Affichage détail du BL
writeLigBL(X, Y, graph, BL)
If (curPageBL < totPageBL) Then
curPageBL = curPageBL + 1
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub
'Mise en place du titre d'un BL
Private Sub writeTitreBL(ByVal X As Integer, ByVal Y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
Dim i As Integer = 0
Dim img As Image
graph.DrawString("BON DE LIVRAISON", font24bold, _Brush, New PointF(X + 15, Y), New StringFormat())
graph.DrawString("N° dans la série : ", font12bold, _Brush, New Point(X + 20, Y + 45), New StringFormat())
graph.DrawString(BL.numInSerie, font20bold, _Brush, New Point(X + 200, Y + 40), New StringFormat())
For i = 0 To (BL.tabZones.Count - 1)
If (BL.tabZones(i) = 0) Then
img = Image.FromFile(HttpContext.Current.Server.MapPath(Parametre.ImgPath & "\chkVide.png"))
Else
img = Image.FromFile(HttpContext.Current.Server.MapPath(Parametre.ImgPath & "\chkPlein.png"))
End If
graph.DrawImage(img, X + 500 + (i * 40), Y + 5, 25, 25)
Next
End Sub
'Mise en place du code barre
Private Sub writeCodeBarre(ByVal X As Integer, ByVal Y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
graph.DrawString("*" + BL.NumBL + "*", fontCodeBarre, _Brush, New PointF(X + 25, Y + 230), New StringFormat())
End Sub
'Mise en place de l'adresse de livraison d'un BL
Private Sub writeAdrLivrBL(ByVal X As Integer, ByVal Y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
graph.DrawString("ADRESSE DE LIVRAISON", font10bold, _Brush, New PointF(X + 520, Y + 85), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, Y + 80, 325, 30))
graph.DrawString("N° compte client : " + BL.AdrLivr.compteClient, font8bold, _Brush, New Point(X + 460, Y + 115), New StringFormat())
graph.DrawString(BL.AdrLivr.intitule, font8bold, _Brush, New Point(X + 460, Y + 130), New StringFormat())
graph.DrawString(BL.AdrLivr.adresse, font8, _Brush, New Point(X + 460, Y + 145), New StringFormat())
graph.DrawString(BL.AdrLivr.complement, font8, _Brush, New Point(X + 460, Y + 160), New StringFormat())
graph.DrawString(BL.AdrLivr.CP + " " + BL.AdrLivr.ville, font8, _Brush, New Point(X + 460, Y + 175), New StringFormat())
graph.DrawString("Tél. : " + BL.AdrLivr.telephone + " Fax : " + BL.AdrLivr.fax, font8, _Brush, New Point(X + 460, Y + 195), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, Y + 110, 325, 105))
End Sub
'Mise en place des info BL / Livraison
Private Sub writeInfoBLivr(ByVal X As Integer, ByVal y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
graph.DrawString(Date.Now.ToString(), font7boldU, _Brush, New PointF(X + 450, y + 225), New StringFormat())
graph.DrawString("Page " & curPageBL & "/" & totPageBL, font7, _Brush, New PointF(X + 720, y + 225), New StringFormat())
graph.DrawString("N° du BL", font8bold, _Brush, New PointF(X + 470, y + 258), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, y + 250, 108, 30))
graph.DrawString("Date", font8bold, _Brush, New PointF(X + 588, y + 258), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 558, y + 250, 108, 30))
graph.DrawString("Départ", font8bold, _Brush, New PointF(X + 696, y + 258), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 666, y + 250, 109, 30))
graph.DrawString(BL.NumBL, font8, _Brush, New PointF(X + 470, y + 288), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, y + 280, 108, 30))
graph.DrawString(BL.DateBL, font8, _Brush, New PointF(X + 578, y + 288), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 558, y + 280, 108, 30))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 666, y + 280, 109, 30))
graph.DrawString("Référence : " + BL.refBL, font8, _Brush, New PointF(X + 470, y + 318), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, y + 310, 325, 30))
graph.DrawString("Expédition : ", font8, _Brush, New PointF(X + 470, y + 348), New StringFormat())
graph.DrawString(BL.typeExpe, font12boldU, _Brush, New PointF(X + 540, y + 344), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 450, y + 340, 325, 30))
End Sub
'Mise en place des info compte payeur
Private Sub writeInfoCptPay(ByVal X As Integer, ByVal y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
graph.DrawString(BL.cptPay.compte + " " + BL.cptPay.libelle + " " + BL.cptPay.codePostal, font7bold, _Brush, New PointF(X + 20, y + 330), New StringFormat())
graph.DrawString("Représentant : " + BL.cptPay.represent, font7, _Brush, New PointF(X + 20, y + 350), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 15, y + 325, 350, 45))
End Sub
'Mise en place du comment BL
Private Sub writeCommentBL(ByVal X As Integer, ByVal y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
graph.DrawString(BL.comment, font7bold, _Brush, New PointF(X + 20, y + 395), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 15, y + 390, 760, 45))
End Sub
'Mise en place des lignes du BL
Private Sub writeLigBL(ByVal X As Integer, ByVal Y As Integer, ByVal graph As Graphics, ByVal BL As InfoBL)
Dim lastLigCadre As Integer = 0
graph.DrawString("Ref", font8bold, _Brush, New PointF(X + 25, Y + 470), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 15, Y + 455, 80, 45))
graph.DrawString("Qté", font8bold, _Brush, New PointF(X + 120, Y + 470), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 95, Y + 455, 80, 45))
graph.DrawString("Empl.", font8bold, _Brush, New PointF(X + 195, Y + 470), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 175, Y + 455, 80, 45))
graph.DrawString("N° de Commande", font8bold, _Brush, New PointF(X + 265, Y + 470), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 255, Y + 455, 130, 45))
graph.DrawString("Désignation", font8bold, _Brush, New PointF(X + 390, Y + 470), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 385, Y + 455, 300, 45))
graph.DrawString("Montant HT", font8bold, _Brush, New PointF(X + 692, Y + 465), New StringFormat())
graph.DrawString("Transport", font8bold, _Brush, New PointF(X + 697, Y + 475), New StringFormat())
graph.DrawRectangle(Pens.Black, New Rectangle(X + 685, Y + 455, 90, 45))
Dim i As Integer
Dim ligWritten As Integer = 0
For i = curLig To (BL.ligneBL.Count - 1)
If ((Y + 510 + (ligWritten * 15)) >= 1040) Then
curLig = i
Exit For
End If
graph.DrawString(BL.ligneBL(i).ref, font8, _Brush, New PointF(X + 25, Y + 510 + (ligWritten * 15)), New StringFormat())
graph.DrawString(BL.ligneBL(i).quantite, font8, _Brush, New PointF(X + 100, Y + 510 + (ligWritten * 15)), New StringFormat())
graph.DrawString(BL.ligneBL(i).emplacement, font8, _Brush, New PointF(X + 180, Y + 510 + (ligWritten * 15)), New StringFormat())
graph.DrawString(BL.ligneBL(i).numCom, font8, _Brush, New PointF(X + 260, Y + 510 + (ligWritten * 15)), New StringFormat())
graph.DrawString(BL.ligneBL(i).design, font8, _Brush, New PointF(X + 390, Y + 510 + (ligWritten * 15)), New StringFormat())
If (BL.ligneBL(i).ref = "01") Then
graph.DrawString(BL.ligneBL(i).PrixU, font8, _Brush, New PointF(X + 690, Y + 510 + (ligWritten * 15)), New StringFormat())
transpTotalBL = transpTotalBL + CDbl(BL.ligneBL(i).montant)
End If
poidsTotalBL = poidsTotalBL + (BL.ligneBL(i).Poids)
ligWritten = ligWritten + 1
Next
'Affichage des totaux en dernière page
If (curPageBL = totPageBL) Then
graph.DrawString("POIDS NET TOTAL/KG : " & poidsTotalBL.ToString("0.00"), font8bold, _Brush, New PointF(X + 390, Y + 510 + (ligWritten * 15)), New StringFormat())
graph.DrawString(transpTotalBL.ToString("0.00") & " ", font8bold, _Brush, New PointF(X + 690, Y + 510 + (ligWritten * 15)), New StringFormat())
lastLigCadre = (ligWritten * 15) + 25
Else
lastLigCadre = (ligWritten * 15) + 15
End If
'Affichage du cadre
graph.DrawRectangle(Pens.Black, New Rectangle(X + 15, Y + 500, 80, lastLigCadre))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 95, Y + 500, 80, lastLigCadre))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 175, Y + 500, 80, lastLigCadre))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 255, Y + 500, 130, lastLigCadre))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 385, Y + 500, 300, lastLigCadre))
graph.DrawRectangle(Pens.Black, New Rectangle(X + 685, Y + 500, 90, lastLigCadre))
End Sub
'Lancement de l'impression
Public Function imprimer(ByVal BL As InfoBL) As Boolean
BLtoPrint = BL
Try
_Doc.Print()
Return True
Catch ex As Exception
Dim ret = _Doc.PrinterSettings.IsValid
Dim v As New PrinterSettings
If (ret) Then
My.Response.Write("L'impression n'a pas pu être effectuée correctement même si tous les paramètres sont valides, erreur : " & ex.Message)
Else
My.Response.Write("L'impression n'a pas pu être effectuée correctement car les paramètres sont invalides, erreur : " & ex.Message)
End If
Return False
End Try
End Function
End Class |
Partager