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
| public class PrintCommandeEngine : PrintDocument
{
private string mNoCommande;
private string mRMA;
private string mDate;
private bool mDehold;
private string mTech;
private string mActualCodeS;
private string mActualCodeR;
private bool mPrinted;
private Font mPrintFont = new Font("Arial", 9);
private Font mPrintFontBold = new Font("Arial", 16, FontStyle.Bold);
private Font mBarcodeFont;
private DataGridView mArticles;
Brush vBrush;
Pen vPen;
public PrintCommandeEngine(string pNoCommande, string pRMA, string pDate, bool pDehold, string pTech, DataGridView pArticles, string pActualCodeS, string pActualCodeR)
{
mNoCommande = pNoCommande;
mRMA = pRMA;
mDate = pDate;
mDehold = pDehold;
mTech = pTech;
mArticles = pArticles;
mActualCodeS = pActualCodeS;
mActualCodeR = pActualCodeR;
this.DocumentName = "Commande no " + pNoCommande;
PrivateFontCollection privateFonts = new PrivateFontCollection();
privateFonts.AddFontFile("ressources\\3OF9.TTF");
mBarcodeFont = new Font(privateFonts.Families[0], 16);
// Le pinceau pour les Fonts
vBrush = new SolidBrush(Color.Black);
vPen = new Pen(vBrush);
// On place la feuille en mode paysage et en noir seulement
this.DefaultPageSettings = this.PrinterSettings.DefaultPageSettings;
this.DefaultPageSettings.Landscape = true;
this.DefaultPageSettings.Color = false;
// On active l'event d'impression
this.PrintPage += new PrintPageEventHandler(PrintEngine_PrintPage);
}
public bool Impression()
{
this.Print();
return mPrinted;
}
void PrintEngine_PrintPage(object pSender, PrintPageEventArgs pPrintEventArgs)
{
try
{
// Le numéro de commande
pPrintEventArgs.Graphics.DrawString(mNoCommande, mPrintFont, vBrush, 30, 30);
// Le RMA de commande
pPrintEventArgs.Graphics.DrawString("*" + mRMA + "*", mBarcodeFont, vBrush, 100, 30);
pPrintEventArgs.Graphics.DrawString(mRMA, mPrintFont, vBrush, 100, 50);
// Le tech
pPrintEventArgs.Graphics.DrawString("*" + mTech + "*", mBarcodeFont, vBrush, 500, 30);
pPrintEventArgs.Graphics.DrawString(mTech, mPrintFont, vBrush, 500, 50);
// La date
pPrintEventArgs.Graphics.DrawString(mDate, mPrintFont, vBrush, 820, 30);
// Si c'est une DEHOLD, on l'affiche
if (mDehold)
{
pPrintEventArgs.Graphics.DrawString("DEHOLD", mPrintFontBold, vBrush, 1000, 25);
}
// Le code symptôme
pPrintEventArgs.Graphics.DrawString("*" + mActualCodeS + "*", mBarcodeFont, vBrush, 300, 80);
pPrintEventArgs.Graphics.DrawString(mActualCodeS, mPrintFont, vBrush, 300, 100);
// Le code remède
pPrintEventArgs.Graphics.DrawString("*" + mActualCodeR + "*", mBarcodeFont, vBrush, 650, 80);
pPrintEventArgs.Graphics.DrawString(mActualCodeR, mPrintFont, vBrush, 650, 100);
// On affiche les entêtes de commandes
pPrintEventArgs.Graphics.DrawString("RMA", mPrintFont, vBrush, 20, 130);
pPrintEventArgs.Graphics.DrawString("Empl.", mPrintFont, vBrush, 290, 130);
pPrintEventArgs.Graphics.DrawString("Code panne", mPrintFont, vBrush, 360, 130);
pPrintEventArgs.Graphics.DrawString("Code répa.", mPrintFont, vBrush, 580, 130);
pPrintEventArgs.Graphics.DrawString("Code PCDoc", mPrintFont, vBrush, 750, 130);
pPrintEventArgs.Graphics.DrawString("Quantité", mPrintFont, vBrush, 850, 130);
pPrintEventArgs.Graphics.DrawString("Propriété", mPrintFont, vBrush, 950, 130);
pPrintEventArgs.Graphics.DrawString("Stock", mPrintFont, vBrush, 1050, 130);
// On trace une ligne pour les articles
pPrintEventArgs.Graphics.DrawLine(vPen, 0, 150, 1250, 150);
int debut = 155;
for (int i = 0; i < mArticles.Rows.Count; i++)
{
// Le code barre du RMA
pPrintEventArgs.Graphics.DrawString("*" + mArticles["RefAxapta", i].Value.ToString() + "*", mBarcodeFont, vBrush, 20, debut);
pPrintEventArgs.Graphics.DrawString(mArticles["RefAxapta", i].Value.ToString(), mPrintFont, vBrush, 20, debut + 20);
// L'emplacement
pPrintEventArgs.Graphics.DrawString(mArticles["Emplacement", i].Value.ToString(), mPrintFont, vBrush, 290, debut);
// Le code barre du code panne
pPrintEventArgs.Graphics.DrawString("*" + mArticles["CPanne", i].Value.ToString() + "*", mBarcodeFont, vBrush, 360, debut);
pPrintEventArgs.Graphics.DrawString(mArticles["CPanne", i].Value.ToString(), mPrintFont, vBrush, 360, debut + 20);
// Le code barre du code répa
pPrintEventArgs.Graphics.DrawString("*" + mArticles["CRepa", i].Value.ToString() + "*", mBarcodeFont, vBrush, 580, debut);
pPrintEventArgs.Graphics.DrawString(mArticles["CRepa", i].Value.ToString(), mPrintFont, vBrush, 580, debut + 20);
// Le code PC Doctor
pPrintEventArgs.Graphics.DrawString(mArticles["CPCDoc", i].Value.ToString(), mPrintFont, vBrush, 750, debut);
// La quantité
pPrintEventArgs.Graphics.DrawString(mArticles["Quantite", i].Value.ToString(), mPrintFont, vBrush, 850, debut);
// La propriété du compo (DOA, ANO)
if (mArticles["FLAG", i].Value.ToString() == "DOA")
{
pPrintEventArgs.Graphics.DrawString("DOA", mPrintFont, vBrush, 950, debut);
}
else if (mArticles["FLAG", i].Value.ToString() == "ANO")
{
pPrintEventArgs.Graphics.DrawString("ANO", mPrintFont, vBrush, 950, debut);
}
// Le type de stock à prélever
if ((bool)mArticles["OOW", i].Value)
{
pPrintEventArgs.Graphics.DrawString("OW", mPrintFont, vBrush, 1050, debut);
}
else
{
pPrintEventArgs.Graphics.DrawString("IW", mPrintFont, vBrush, 1050, debut);
}
debut = debut + 40;
}
mPrinted = true;
}
catch (Exception e)
{
Logger.Write("Erreur levée dans le module d'impression : " + e.Message, "errors.txt");
mPrinted = false;
}
}
} |
Partager