Bonjour à tous et à toutes,
J'ai un problème avec mon printdocument :
Mon code complet est le suivant :
public bool b=false;
public int compteur=0;
public int compteur_tiers=0;
public int x=30;
public int y=30;
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
printDocument1.DefaultPageSettings.Landscape=true;
Font f5= new Font("Tahoma", 24, FontStyle.Regular);
Font f10= new Font("Tahoma", 24, FontStyle.Regular);
Font f6= new Font("Tahoma", 16, FontStyle.Regular);
Font f4= new Font("Tahoma", 20, FontStyle.Underline);
Font f7= new Font("Tahoma", 14, FontStyle.Bold);
Font f8= new Font("Tahoma", 12, FontStyle.Bold);
Font f3= new Font("Tahoma", 10, FontStyle.Regular);
Font f1= new Font("Tahoma", 8, FontStyle.Regular);
LinearGradientBrush myBrush = new LinearGradientBrush(ClientRectangle, Color.Black,Color.Black, LinearGradientMode.Horizontal);
string date_paiement,date_recup;
DateTime d_paiement,d_recup;
string chemin;
chemin=Path.Combine(Application.StartupPath,"amecspie2_logo.gif");
if(code_societe=="ele") e.Graphics.DrawString("ELECAM",f5,myBrush,40,100);
else
if(code_societe=="mlb") e.Graphics.DrawString("MELB",f5,myBrush,40,100);
Image myImage=Image.FromFile(chemin);
e.Graphics.DrawImage(myImage,950,30);
e.Graphics.DrawString("BROUILLARD DE SAISIE",f7,myBrush,260,150);
string mois_saisie=textBox1.Text;
int inf=int.Parse(textBox3.Text.ToString());
int sup=int.Parse(textBox4.Text.ToString());
e.Graphics.DrawString("Mois de saisie :"+mois_saisie,f8,myBrush,270,170);
e.Graphics.DrawString("C.G : "+textBox2.Text.ToString(),f8,myBrush,40,200);
DataSet ds_tiers=new DataSet("facture");
string order_tiers="select ntiers_tva,sum(montanttva)"+
" from facture f left join fournisseur fo on fo.code_four=f.code_four left join rubrique_test r on r.id_rubrique=f.id_rubrique left join banque b on b.code_banque=f.code_banque join mode_paiement mp on mp.code_paiement=f.code_paiement and f.code_societe='"+code_societe+"' and date_saisie<'"+s2+"' and date_saisie >='"+s1+"' and ncg_tva='"+textBox2.Text.ToString()+"' and ntiers_tva>="+inf+" and ntiers_tva<="+sup+""+
" group by ntiers_tva";
oAcces_Donnees.execute_requete_select(order_tiers,ds_tiers,"facture");
if(compteur<ds_facture_consultation.Tables["facture"].Rows.Count)
{
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,240),new Point(1150,240));
e.Graphics.DrawString("Code-Four",f8,myBrush,45,250);
e.Graphics.DrawString("Abrégé",f8,myBrush,135,250);
e.Graphics.DrawString("Num-Fact",f8,myBrush,225,250);
e.Graphics.DrawString("Taux(%)",f8,myBrush,320,250);
e.Graphics.DrawString("MontanTVA",f8,myBrush,425,250);
e.Graphics.DrawString("Date-Paiement",f8,myBrush,560,250);
e.Graphics.DrawString("Mode-Paiement",f8,myBrush,690,250);
e.Graphics.DrawString("Banque",f8,myBrush,820,250);
e.Graphics.DrawString("Date_Recup",f8,myBrush,900,250);
e.Graphics.DrawString("Tiers",f8,myBrush,1005,250);
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,270),new Point(1150,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,240),new Point(40,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(130,240),new Point(130,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(225,240),new Point(225,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(315,240),new Point(315,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(420,240),new Point(420,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(555,240),new Point(555,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(685,240),new Point(685,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(820,240),new Point(820,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(895,240),new Point(895,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1000,240),new Point(1000,270));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1150,240),new Point(1150,270));
}
//calcul du total TVA
string partie_relative_total_tva="";
string partie_entiere_total_tva="";
x=30;
for(int i=compteur;i<ds_facture_consultation.Tables["facture"].Rows.Count;i++)
{
if(150+x<e.MarginBounds.Height)
{
string partie_relative="";
string partie_entiere="";
decimal d=0;
d=decimal.Parse(ds_facture_consultation.Tables["facture"].Rows[i][4].ToString());
string chaine=d.ToString();
partie_entiere=oTraitementFacture.partie_entiere(d);
partie_relative=oTraitementFacture.partie_relative(d);
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][0].ToString(),f3,myBrush,45,270+20*(i-compteur)+x);
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][1].ToString(),f1,myBrush,135,270+20*(i-compteur)+x);
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][2].ToString(),f3,myBrush,225,270+20*(i-compteur)+x);
StringFormat objFormat3=new StringFormat();
objFormat3.FormatFlags=StringFormatFlags.DirectionRightToLeft;
PointF objPoint_taux=new PointF(415,270+20*(i-compteur)+x);
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][3].ToString(),f3,myBrush,objPoint_taux,objFormat3);
StringFormat objFormat=new StringFormat();
objFormat.FormatFlags=StringFormatFlags.DirectionRightToLeft;
PointF objPoint_partie_relative=new PointF(550,270+20*(i-compteur)+x);
PointF objPoint_partie_entiere=new PointF(530,270+20*(i-compteur)+x);
e.Graphics.DrawString(partie_relative+".",f3,myBrush,objPoint_partie_relative,objFormat);
if(partie_entiere.StartsWith("-"))
{
partie_entiere=partie_entiere.Replace("-","");
e.Graphics.DrawString(partie_entiere+"-",f3,myBrush,objPoint_partie_entiere,objFormat);
}
else
{
e.Graphics.DrawString(partie_entiere,f3,myBrush,objPoint_partie_entiere,objFormat);
}
date_paiement=ds_facture_consultation.Tables["facture"].Rows[i][5].ToString();
if(date_paiement=="") e.Graphics.DrawString(""+date_paiement,f3,myBrush,560,270+20*(i-compteur)+x);
else
{
d_paiement=DateTime.Parse(date_paiement);
date_paiement=d_paiement.Day.ToString()+"/"+d_paiement.Month.ToString()+"/"+d_paiement.Year.ToString();
e.Graphics.DrawString(""+date_paiement,f3,myBrush,560,270+20*(i-compteur)+x);
}
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][6].ToString(),f3,myBrush,690,270+20*(i-compteur)+x);
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][7].ToString(),f3,myBrush,820,270+20*(i-compteur)+x);
date_recup=ds_facture_consultation.Tables["facture"].Rows[i][8].ToString();
if(date_recup=="") e.Graphics.DrawString(""+date_recup,f3,myBrush,900,270+20*(i-compteur)+x);
else
{
d_recup=DateTime.Parse(date_recup);
date_recup=d_recup.Day.ToString()+"/"+d_recup.Month.ToString()+"/"+d_recup.Year.ToString();
e.Graphics.DrawString(""+date_recup,f3,myBrush,900,270+20*(i-compteur)+x);
}
e.Graphics.DrawString(""+ds_facture_consultation.Tables["facture"].Rows[i][9].ToString(),f3,myBrush,1005,270+20*(i-compteur)+x);
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,270+((i-compteur)+1)*20+x),new Point(1150,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,240),new Point(40,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(130,240),new Point(130,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(225,240),new Point(225,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(315,240),new Point(315,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(420,240),new Point(420,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(555,240),new Point(555,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(685,240),new Point(685,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(820,240),new Point(820,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(895,240),new Point(895,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1000,240),new Point(1000,270+((i-compteur)+1)*20+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1150,240),new Point(1150,270+((i-compteur)+1)*20+x));
compteur++;
x+=30;
}
else break;
}
if(compteur>=ds_facture_consultation.Tables["facture"].Rows.Count) //e.HasMorePages=false;
{
e.HasMorePages=false;
if(compteur_tiers<ds_tiers.Tables["facture"].Rows.Count)
{
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1150,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1150,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawString("Tiers",f8,myBrush,45,350+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x);
e.Graphics.DrawString("Total T.V.A",f8,myBrush,425,350+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x);
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(40,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(130,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(130,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(225,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(225,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(315,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(315,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(420,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(420,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(555,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(555,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(685,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(685,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(820,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(820,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(895,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(895,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1000,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1000,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1150,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1150,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x));
}
y=30;
for(int k=compteur_tiers;k<ds_tiers.Tables["facture"].Rows.Count;k++)
{
if(250+y+x<e.MarginBounds.Height)
{
e.Graphics.DrawString(""+ds_tiers.Tables["facture"].Rows[k][0].ToString(),f3,myBrush,45,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k-compteur_tiers)+y);
//pas d'entier
string partie_entiere_tiers="";
string partie_relative_tiers="";
decimal d_tiers=decimal.Parse(ds_tiers.Tables["facture"].Rows[k][1].ToString());
partie_entiere_tiers=oTraitementFacture.partie_entiere(d_tiers);
partie_relative_tiers=oTraitementFacture.partie_relative(d_tiers);
StringFormat objFormat2=new StringFormat();
objFormat2.FormatFlags=StringFormatFlags.DirectionRightToLeft;
PointF objPoint_partie_relative_tiers=new PointF(550,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k-compteur_tiers)+y);
PointF objPoint_partie_entiere_tiers=new PointF(530,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k-compteur_tiers)+y);
e.Graphics.DrawString(""+partie_relative_tiers+".",f3,myBrush,objPoint_partie_relative_tiers,objFormat2);
if(partie_entiere_tiers.StartsWith("-"))
{
partie_entiere_tiers=partie_entiere_tiers.Replace("-","");
e.Graphics.DrawString(partie_entiere_tiers+"-",f3,myBrush,objPoint_partie_entiere_tiers,objFormat2);
}
else
{
e.Graphics.DrawString(partie_entiere_tiers,f3,myBrush,objPoint_partie_entiere_tiers,objFormat2);
}
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y),new Point(1150,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(40,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(40,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(130,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(130,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(225,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(225,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(315,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(315,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(420,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(420,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(555,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(555,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(685,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(685,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(820,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(820,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(895,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(895,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1000,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1000,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
/*e.Graphics.DrawLine(new Pen(Color.Black),new Point(255,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(255,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
e.Graphics.DrawLine(new Pen(Color.Black),new Point(345,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(345,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));*/
e.Graphics.DrawLine(new Pen(Color.Black),new Point(1150,340+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x),new Point(1150,370+20*(ds_facture_consultation.Tables["facture"].Rows.Count+1-compteur)+x+20*(k+1-compteur_tiers)+y));
compteur_tiers++;
y+=30;
}
else break;
}/////////////////////////////////////////
if(compteur_tiers>=ds_tiers.Tables["facture"].Rows.Count)
{
e.HasMorePages=false;
}
else
{
e.HasMorePages=true;
}
}
else
{
e.HasMorePages=true;
}
}
private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
compteur=0;
compteur_tiers=0;
x=30;
y=30;
b=false;
}
Et je veux que la partie en rouge soit imprimée dans une nouvelle page et je sais pas comment faire.
Merci d'avance.
Choukri175
Afficher la suite