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
|
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;
using projetStageInit.Class;
namespace projetStageInit
{
public partial class Palette : Form
{
private DataTable maTablePalette = null;
private int nombrePageTotal,pageCourante=1,nombreLignePage = 40,numeroPalette = -1,placemententete = 525;
private int nombreArticle = 0,indiceLigne = 0,indiceBoucle =0,margeGauchePremiereColonne = 50;
private int margeGaucheDeuxiemeColonne = 200,margeGaucheTroisiemeColonne = 700,margeGaucheQuatiremeColonne = 750;
private float x1 = 0,y1 = 200.0F,x2 = 1500.0F,y2 = 200.0F;
public Palette()
{
InitializeComponent();
}
void ButtonValiderClick(object sender, EventArgs e)
{
if(Int32.TryParse(saisieTextBox.Text,out numeroPalette) && numeroPalette>0)
{
// initialisation de la requete de l'impression
myDataSetResult = Connection.selectInBase("select a.NumPlan,a.numRepere,a.travee,a.carre,a.rack," +
"a.casier,a.etage,a.libelleArticle,e.quantite from Article a ,EntreeSortie e " +
"where a.idArticle=e.idArticle and e.idLieu=1 and a.palette='"+numeroPalette.ToString()+"'");
maTablePalette = myDataSetResult.Tables[0];
nombreArticle = maTablePalette.Rows.Count;
nombrePageTotal = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(nombreArticle)/Convert.ToDouble(nombreLignePage)));
PrintDocument document = new PrintDocument();
document.DocumentName = string.Format("Palette");
document.PrintPage += document_PrintPage;
printPreviewDialog1.Document = document;
printPreviewDialog1.Size = new System.Drawing.Size(800,700);
printPreviewDialog1.ShowDialog();
}
else
{
MessageBox.Show("Le numero de Palette doit etre un entier positif");
}
}
private void document_PrintPage(Object sender, PrintPageEventArgs e)
{
Font printFontPalette = new Font("Arial",94);
printFontPalette = new Font(printFontPalette, FontStyle.Bold);
Font printFont = new Font("Arial", 14);
indiceLigne=0;
// Entete de page
e.Graphics.DrawString("P " + numeroPalette.ToString(), printFontPalette, Brushes.Black, 30 , 32);
Pen blackPen = new Pen(Color.Black, 3);
Rectangle rect = new Rectangle(500, 100, 350, 50);
e.Graphics.DrawRectangle(blackPen, rect);
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
Font printFontentete = new Font("Arial", 14);
// travée rack casier etage
e.Graphics.DrawString("travée", printFontentete, Brushes.Black, placemententete , 70);
e.Graphics.DrawString("rack", printFontentete, Brushes.Black, placemententete + 80 , 70);
e.Graphics.DrawString("casier", printFontentete, Brushes.Black, placemententete +160 , 70);
e.Graphics.DrawString("étage", printFontentete, Brushes.Black, placemententete + 240 , 70);
printFontentete = new Font(printFontentete, FontStyle.Bold);
if(nombreArticle>0)
{
e.Graphics.DrawString(maTablePalette.Rows[0]["travee"].ToString().Trim(), printFontentete, Brushes.Black, placemententete + 10, 110);
e.Graphics.DrawString(maTablePalette.Rows[0]["rack"].ToString().Trim(), printFontentete, Brushes.Black, placemententete + 80 +10, 110);
e.Graphics.DrawString(maTablePalette.Rows[0]["casier"].ToString().Trim(), printFontentete, Brushes.Black, placemententete + 160+10 , 110);
e.Graphics.DrawString(maTablePalette.Rows[0]["etage"].ToString().Trim(), printFontentete, Brushes.Black, placemententete + 240+10 , 110);
}
else
{
e.Graphics.DrawString("PAS D'OUTIL CORRESPONDANT", printFont, Brushes.Black, placemententete , 110);
pageCourante=0;
}
e.Graphics.DrawString("N° plan", printFontentete, Brushes.Black, margeGauchePremiereColonne , 225);
e.Graphics.DrawString("Designation de l'article", printFontentete, Brushes.Black, margeGaucheDeuxiemeColonne + 10 , 225);
e.Graphics.DrawString("Rep:", printFontentete, Brushes.Black, margeGaucheTroisiemeColonne + 10 , 225);
e.Graphics.DrawString("Qté", printFontentete, Brushes.Black, margeGaucheQuatiremeColonne + 10 , 225);
for (int i = indiceBoucle; i < nombreArticle;i++)
{
e.Graphics.DrawString(maTablePalette.Rows[i]["NumPlan"].ToString().Trim(), printFont, Brushes.Black, margeGauchePremiereColonne , indiceLigne * 17 + 250);
e.Graphics.DrawString("| " + maTablePalette.Rows[i]["libelleArticle"].ToString().Trim(), printFont, Brushes.Black, margeGaucheDeuxiemeColonne , indiceLigne * 17 + 250);
e.Graphics.DrawString("| " + maTablePalette.Rows[i]["numRepere"].ToString().Trim(), printFont, Brushes.Black, margeGaucheTroisiemeColonne , indiceLigne * 17 + 250);
e.Graphics.DrawString("| " + maTablePalette.Rows[i]["quantite"].ToString().Trim(), printFont, Brushes.Black, margeGaucheQuatiremeColonne, indiceLigne * 17 + 250);
indiceLigne++; // Une fois toute les colonne ajoutées on incrémente la ligne
indiceBoucle++;
// si on a rentrer le bon nombre de ligne , on passe a la page suivante
bool pagesup = indiceBoucle % nombreLignePage == 0 && indiceBoucle!=nombreArticle;
if (e.HasMorePages = pagesup)
{
// pied de page des pages normal
x1 = 0;
y1 = 1050.0F;
x2 = 1500.0F;
y2 = y1;
// Draw line to screen.
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
e.Graphics.DrawString(pageCourante.ToString() + "/" +nombrePageTotal.ToString(), printFont, Brushes.Black, 400 , 1125);
pageCourante++;
return ;
}
}
x1 = 0;
y1 = 1100.0F;
x2 = 1500.0F;
y2 = y1;
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
e.Graphics.DrawString(pageCourante.ToString() +"/"+nombrePageTotal.ToString(), printFont, Brushes.Black, 400 , 1125);
}
}
} |