Impression

MINDONGO - 21 févr. 2013 à 14:10
BasicInstinct Messages postés 1470 Date d'inscription mardi 5 février 2002 Statut Membre Dernière intervention 20 octobre 2014 - 22 févr. 2013 à 14:36
salut,

je suis encore devant vous pour savoir faire ceci:
void LOADING()
        {
            OdbcDataReader dtr;
            OdbcConnection cnx = new OdbcConnection("DSN=KINGMINDONGO");
            OdbcDataAdapter adptr = new OdbcDataAdapter("SELECT num_facture,prix_ht,prix_totale FROM facture", cnx);
            OdbcCommand cmd = new OdbcCommand("SELECT * FROM devis", cnx);
            cnx.Open();
            DataSet dtst = new DataSet();
            try
{
                adptr.Fill(dtst, "facture");
                KING_facture.SetDataBinding(dtst, "facture");
                MINDONGOrowCount = dtst.Tables["facture"].Rows.Count;
dtr=cmd.ExecuteReader();
while(dtr.Read())
        num_devis.Items.Add(dtr.GetInt32(0).ToString());
dtr.Close();
cmd=new OdbcCommand("SELECT num_facture,num_devis,prix_ht,prix_totale FROM facture", cnx);	
dtr=cmd.ExecuteReader();
dtr.Read();
num_facture.Text=dtr.GetInt32(0).ToString();
num_devis.Text=dtr.GetInt32(1).ToString();
total_ht.Text=dtr.GetInt32 (2).ToString();
total_ttc.Text=dtr.GetInt32(3).ToString();
cnx.Close();
                KING_facture.Select(0);
        	REXselecte =0;
}
            catch (Exception KING)
            {
                nom.Text = KING.ToString();
            }
            
        }

comment imprimer cette selection dans une imprimante rien qu'en cliquant sur un bouton

OdbcDataAdapter adptr = new OdbcDataAdapter("SELECT num_facture,prix_ht,prix_totale FROM facture", cnx);
            

Soyons Toujours à la disposition des autres

6 réponses

BasicInstinct Messages postés 1470 Date d'inscription mardi 5 février 2002 Statut Membre Dernière intervention 20 octobre 2014 12
21 févr. 2013 à 16:59
Salut,

Vaste sujet que l'impression.

si tu veux directement envoyer a l'imprimante le texte à imprimer :

voila un exemple sorti de la msdn.

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Printing;
using System.Windows.Forms;

 public class PrintingExample 
 {
     private Font printFont;
     private StreamReader streamToPrint;
     static string filePath;


     public PrintingExample() 
     {
         Printing();
     }

     // The PrintPage event is raised for each page to be printed.
     private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
     {
         float linesPerPage = 0;
         float yPos =  0;
         int count = 0;
         float leftMargin = ev.MarginBounds.Left;
         float topMargin = ev.MarginBounds.Top;
         String line=null;

         // Calculate the number of lines per page.
         linesPerPage = ev.MarginBounds.Height  / 
            printFont.GetHeight(ev.Graphics) ;

         // Iterate over the file, printing each line.
         while (count < linesPerPage && 
            ((line=streamToPrint.ReadLine()) != null)) 
         {
            yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString (line, printFont, Brushes.Black, 
               leftMargin, yPos, new StringFormat());
            count++;
         }

         // If more lines exist, print another page.
         if (line != null) 
            ev.HasMorePages = true;
         else 
            ev.HasMorePages = false;
     }

     // Print the file.
     public void Printing()
     {
         try 
         {
            streamToPrint = new StreamReader (filePath);
            try 
            {
               printFont = new Font("Arial", 10);
               PrintDocument pd = new PrintDocument(); 
               pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
               // Print the document.
               pd.Print();
            } 
            finally 
            {
               streamToPrint.Close() ;
            }
        } 
        catch(Exception ex) 
        { 
            MessageBox.Show(ex.Message);
        }
     }

     // This is the main entry point for the application.
     public static void Main(string[] args) 
     {
        string sampleName = Environment.GetCommandLineArgs()[0];
        if(args.Length != 1)
        {
           Console.WriteLine("Usage: " + sampleName +" <file path>");
           return;
        }
        filePath = args[0];
        new PrintingExample();
     }
 }






BasicInstinct
0
Merci mais ou introduire ça pour qu'il soit imprimer?
("SELECT num_facture,prix_ht,prix_totale FROM facture", cnx);



Soyons Toujours à la disposition des autres
0
BasicInstinct Messages postés 1470 Date d'inscription mardi 5 février 2002 Statut Membre Dernière intervention 20 octobre 2014 12
22 févr. 2013 à 09:58
dans le printpage

// Iterate over the file, printing each line.
au lieu de lire le fichier tu lis ton datareader, et tu construits ta string.

Je vois pas ce qui pose problème.

BasicInstinct
0
est-ce que c'est de la sorte?
// Iterate over the file, printing each line.
         while (count < linesPerPage && 
            ((line=adptr.Tostring()) != null)) 
         


ou comment si c'est n'est pas le cas Veuillez m'introduire dans le bain svp

Soyons Toujours à la disposition des autres
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
quelqu'un d'autre ne peut pas?


Soyons Toujours à la disposition des autres
0
BasicInstinct Messages postés 1470 Date d'inscription mardi 5 février 2002 Statut Membre Dernière intervention 20 octobre 2014 12
22 févr. 2013 à 14:36
plutôt un truc dans le style
adptr étant une variable globale comme dans l'exemple donnée haut dessus

while (count < linesPerPage  && adptr.read())
{
//tu crées la ligne à imprimer
line=adptr["champ"].tostring() + ...	
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
            ev.Graphics.DrawString (line, printFont, Brushes.Black, 
               leftMargin, yPos, new StringFormat());
            count++;

}





BasicInstinct
0
Rejoignez-nous