public static int k = 0; //alt contor public static void PrintListaFacturiSiIncasariPerioada(PrintPageEventArgs e, Firma f, DateTime inceput, DateTime sfarsit) { int leftMargin = 50; int inaltimeRand = 18; int maxRanduriPePagina = 52; int inceputTabel = 100; int yTabelCurent = 0; //inaltimea din tabel la care ma aflu - cand se face o pagina noua incepe din nou de la 0 f.FacturiClient = DbaseConnection.DBFCitesteFacturiClientFirma(f, Settings.Ani_InUz); f.Tranzactii = DbaseConnection.DBFCitesteTranzactiiFirma(f, Settings.Ani_InUz); List <Factura> facPer = f.FacturiClientPePerioada(inceput, sfarsit); List <Tranzactie> incasari = f.IncasariPePerioada(inceput, sfarsit); decimal totalFara = 0; decimal totalTVA = 0; decimal totalCu = 0; int totalPagini = 1 + facPer.Count / maxRanduriPePagina; decimal totalIncasari = 0; foreach (Factura fa in facPer) { totalFara += fa.Valoare; totalTVA += fa.TVA; totalCu += fa.Valoare_Cu_TVA; } foreach (Tranzactie t in incasari) { totalIncasari += t.Valoare; } #region toatePaginile e.Graphics.DrawString(f.Nume, new Font("Calibri", 13, FontStyle.Bold), Brushes.Black, new Point(leftMargin, 40)); e.Graphics.DrawString("Lista facturilor platite din perioada " + inceput.ToShortDateString() + " - " + sfarsit.ToShortDateString(), new Font("Calibri", 11, FontStyle.Italic), Brushes.Black, new Point(380, 42)); e.Graphics.DrawString("Data tiparirii: " + DateTime.Now, new Font("Calibri", 10, FontStyle.Italic), Brushes.Black, new Point(leftMargin, e.MarginBounds.Bottom + 20)); e.Graphics.DrawString("pag. " + p + @"/" + totalPagini, new Font("Calibri", 10, FontStyle.Italic), Brushes.Black, new Point(e.MarginBounds.Right, e.MarginBounds.Bottom + 20)); #endregion #region tabel - pe fiecare pagina apare e.Graphics.DrawString("Serie doc.", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin, inceputTabel - 20)); e.Graphics.DrawString("Data emit.", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 100, inceputTabel - 20)); e.Graphics.DrawString("Data scad.", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 180, inceputTabel - 20)); e.Graphics.DrawString("Valoare", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 260, inceputTabel - 20)); e.Graphics.DrawString("TVA", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 350, inceputTabel - 20)); e.Graphics.DrawString("Val. cu TVA", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 430, inceputTabel - 20)); if (facPer.Count > 0) { while (i < facPer.Count) { if (i % 2 == 0) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(242, 242, 242)), 50, inceputTabel - 1 + yTabelCurent, 700, inaltimeRand); } e.Graphics.DrawString(facPer[i].Seria + facPer[i].Numar_Document, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin, inceputTabel + yTabelCurent)); e.Graphics.DrawString(facPer[i].Data_Emitere.ToShortDateString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 100, inceputTabel + yTabelCurent)); e.Graphics.DrawString(facPer[i].Data_Scadenta.ToShortDateString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 180, inceputTabel + yTabelCurent)); e.Graphics.DrawString(facPer[i].Valoare.ToString("0.00"), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 260, inceputTabel + yTabelCurent)); e.Graphics.DrawString(facPer[i].TVA.ToString("0.00"), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 350, inceputTabel + yTabelCurent)); e.Graphics.DrawString(facPer[i].Valoare_Cu_TVA.ToString("0.00"), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 430, inceputTabel + yTabelCurent)); // e.Graphics.DrawString(facPer[i].Valoare_Cu_TVA.ToString(), new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(leftMargin + 520, inceputTabel + yTabelCurent)); i++; //incrementez contorul general in orice caz, cu asta se trece peste toate, neavand importanta cate intrari vreau in pagina yTabelCurent += inaltimeRand; //trec pe urmatorul rand if (j < maxRanduriPePagina) // verific daca am trecut cu contorul care merge pana la maximul de randuri din pagina { j++; //daca nu, il incrementez e.HasMorePages = false; // si ii spun ca nu va fi o alta pagina } else // daca da { j = 0; //resetez contorul e.HasMorePages = true; //si ii spun sa creeaze o pagina noua p++; return; //returnand aici, functia se va mai executa o data, cu variabilele globale in starea adecvata } } } #endregion #region ultimaPagina - poate fi prima si ultima e.Graphics.DrawString("Totaluri", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 180, inceputTabel + yTabelCurent + inaltimeRand)); e.Graphics.DrawString(totalFara.ToString("0.00"), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 260, inceputTabel + yTabelCurent + inaltimeRand)); e.Graphics.DrawString(totalTVA.ToString("0.00"), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 350, inceputTabel + yTabelCurent + inaltimeRand)); e.Graphics.DrawString(totalCu.ToString("0.00"), new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(leftMargin + 430, inceputTabel + yTabelCurent + inaltimeRand)); #endregion }