Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 2.61 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Print multiple pages in WinForms doesn't work
  2. public static void printDokument()
  3.    {
  4.        if (result == DialogResult.OK)
  5.        {
  6.  
  7.            DbDataPostavke = checkDB("SELECT * FROM " + tipDokumenta + "_postavke WHERE ID_" + tipDokumenta + " = " + stDokumenta);
  8.  
  9.            list = DbDataPostavke.Tables[0].AsEnumerable().ToList();                            
  10.            printDocument.Print();
  11.        }      
  12.    }
  13.  
  14.    static void printDocument_PrintPage(object sender, PrintPageEventArgs e)
  15.    {
  16.        graphic = e.Graphics;
  17.  
  18.        e.PageSettings.PaperSize = ps;
  19.  
  20.        stranSirina = e.PageSettings.PrintableArea.Width;
  21.        stranVisina = e.PageSettings.PrintableArea.Height;
  22.  
  23.        fontHeight = font.GetHeight();
  24.  
  25.        //this works/prints
  26.        printDocument_PrintHeader();
  27.  
  28.        //this works/prints
  29.        printDocument_PrintDocumentInfo();
  30.  
  31.        if (firstPage) printDocument_PrintSupplierInfo();    
  32.  
  33.        //Lines that I take from DB, amount of this lines is variable //it only prints one page, then it stops printing
  34.        printDocument_PrintProductLines(e);
  35.  
  36.        //Sum of lines
  37.        if(zadnjaStran) printDocument_printSum();
  38.  
  39.        //prints comment on document
  40.        if (zadnjaStran) printDocument_PrintComment();
  41.  
  42.        //footer
  43.        printDocument_PrintFooter();
  44.    }
  45.  
  46.    static void printDocument_PrintProductLines(PrintPageEventArgs e)
  47.    {
  48.        //I print some stuff here (header, etc..)
  49.  
  50.        String stranArtikliVrstica = String.Empty; // string for one line of data
  51.        DataRow dataRow1 = null;
  52.        DataRow dr = null;
  53.  
  54.        for(int i = 0; i < list.Count(); i++)
  55.        {
  56.            dr = list[i];
  57.            dataRow1 = poglejBazo("SELECT ime, EM, opis FROM Sifrant WHERE ID = " + dr[2].ToString()).Tables[0].Rows[0];
  58.  
  59.            stranArtikliVrstica = String.Format("{0,-38}  {1,10}  {2,5}  {3,9:C}  {4,9:C}", dataRow1[0].ToString() + " - " + dataRow1[2].ToString(), dr[3].ToString(), dataRow1[1].ToString(), dr[4], Convert.ToInt16(dr[3]) * Convert.ToInt16(dr[4]));
  60.  
  61.            list.Remove(dr);
  62.  
  63.            graphic.DrawString(stranArtikliVrstica, font, brush, startX + offsetX, startY + offsetY);
  64.            offsetY += (int)font.GetHeight();
  65.  
  66.            //if there is less then 35 "lines" remaining, we have enough space for printing some other stuff, otherwise, that stuff doesn't print..
  67.            if (list.Count() < 35) zadnjaStran = true;
  68.            else zadnjaStran = false;
  69.  
  70.            if (offsetY > stranVisina - 50)
  71.            {
  72.                prvaStran = false;
  73.                stevecStrani++;
  74.                offsetY = 0;
  75.                e.HasMorePages = true;
  76.                return;
  77.            }
  78.        }
  79.  
  80.    }