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
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
namespace taxatel
{
public partial class SuitePayer : Form
{
private Font printFont;
private StreamReader streamToPrint;
public string Prenom, Nom;
public static string Ancien;
public static string Nouveau;
string TotalPrix;
Email frmEmail = new Email();
public SuitePayer()
{
InitializeComponent();
}
private void Annuler_Click(object sender, EventArgs e)
{
this.Hide();
}
private void Email_Click(object sender, EventArgs e)
{
Ancien = "C:\\Projet\\Facture_detail.txt";
Nouveau = "C:\\Projet\\" + Nom + "_" + Prenom + ".txt";
File.Move(Ancien, Nouveau);
frmEmail.Show();
this.Hide();
}
private void SuitePayer_Load(object sender, EventArgs e)
{
TotalPrix = Convert.ToString(Payer.TotalCost);
NumPoste.Text = Payer.NumPoste;
NbrComunication.Text = Payer.compteur;
Cout.Text = TotalPrix;
PrenomSuitePayer.Text = "";
NomSuitePayer.Text = "";
}
private void PrenomSuitePayer_TextChanged(object sender, EventArgs e)
{
Prenom = PrenomSuitePayer.Text;
}
private void NomSuitePayer_TextChanged(object sender, EventArgs e)
{
Nom = NomSuitePayer.Text;
}
private void Imprimer_Click(object sender, EventArgs e)
{
Ancien = "C:\\Projet\\Facture_detail.txt";
Nouveau = "C:\\Projet\\" + Nom + "_" + Prenom + ".txt";
try
{
streamToPrint = new StreamReader (Nouveau);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
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);
// Print each line of the file.
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;
}
// The Windows Forms Designer requires the following procedure.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Imprimer = new System.Windows.Forms.Button();
this.ClientSize = new System.Drawing.Size(504, 381);
this.Text = "Print Example";
Imprimer.ImageAlign =
System.Drawing.ContentAlignment.MiddleLeft;
Imprimer.Location = new System.Drawing.Point(32, 110);
Imprimer.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
Imprimer.TabIndex = 0;
Imprimer.Text = "Print the file.";
Imprimer.Size = new System.Drawing.Size(136, 40);
Imprimer.Click += new System.EventHandler(Imprimer_Click);
this.Controls.Add(Imprimer);
}
}
} |
Partager