using System; using System.Drawing; using System.Drawing.Printing; using System.Reflection; using System.Windows.Forms; using Student_Account_Management.Model; using Student_Account_Management.NumberToWords; namespace Student_Account_Management.View { public partial class PaymentReceiptForm : Form { private Students student; private Payments payment; private Users user; private string amountinwords1; private string amountinwords2; public PaymentReceiptForm(Students st, Payments py, Users us) { InitializeComponent(); SetDoubleBuffer(ReceiptForm, true); this.student = st; this.payment = py; this.user = us; this.amountinwords1 = ""; this.amountinwords2 = ""; } private void PaymentReceiptForm_Load(object sender, EventArgs e) { MapPaymentReceiptInfo(student, payment, user); } private void ReceiptForm_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Black); e.Graphics.DrawLine(pen, 470, 110, 550, 110); e.Graphics.DrawLine(pen, 106, 110, 445, 110); e.Graphics.DrawLine(pen, 120, 132, 550, 132); e.Graphics.DrawLine(pen, 120, 155, 550, 155); e.Graphics.DrawLine(pen, 123, 200, 490, 200); e.Graphics.DrawLine(pen, 275, 220, 490, 220); e.Graphics.DrawLine(pen, 142, 220, 250, 220); e.Graphics.DrawLine(pen, 100, 277, 350, 277); e.Graphics.DrawLine(pen, 120, 300, 350, 300); Pen pen2 = new Pen(Color.Black); pen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; Rectangle rect = new Rectangle(2, 2, ReceiptForm.Width - 5, ReceiptForm.Height - 5); e.Graphics.DrawRectangle(pen2, rect); } private void SetDoubleBuffer(Control cont, bool DoubleBuffered) { typeof(Control).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null, cont, new object[] { DoubleBuffered }); } private void doc_PrintPage(object sender, PrintPageEventArgs e) { Bitmap bmp = new Bitmap(ReceiptForm.Width, ReceiptForm.Height); ReceiptForm.DrawToBitmap(bmp, new Rectangle(0, 0, ReceiptForm.Width, ReceiptForm.Height)); RectangleF bounds = e.PageSettings.PrintableArea; float factor = ((float)bmp.Height / (float)bmp.Width); e.Graphics.DrawImage(bmp, bounds.Left, bounds.Top, bounds.Width, factor * bounds.Width); } public void MapPaymentReceiptInfo(Students student, Payments payment, Users user) { SetAmountInWords(); lblRecieptNo.Text = payment.PaymentID.ToString(); lblPayer.Text = payment.Payer.ToUpper(); lblAmouninWords1.Text = amountinwords1; lblAmountinWords2.Text = amountinwords2; lblAmount.Text = payment.Amount.ToString("#,###,##0.00"); lblPurpose.Text = payment.Description.ToUpper(); lblStudentID.Text = student.StudentID.ToString(); lblStudentName.Text = student.FullName.ToUpper(); lblDate.Text = payment.PaymentDate.ToString(); lblUser.Text = user.ShortName.ToLower(); PrintDocument doc = new PrintDocument(); PrintController controller = new StandardPrintController(); doc.PrintController = controller; doc.PrintPage += new PrintPageEventHandler(doc_PrintPage); doc.Print(); this.Close(); } private void SetAmountInWords() { int integerunit = (int)payment.Amount; int decimalunit = (int)(((decimal)payment.Amount % 1) * 100); string words1 = Converter.Format((long)integerunit, unit: UnitOfMeasure.Peso).ToUpper(); if (decimalunit > 0) { string[] temp = (Converter.Format((long)decimalunit, unit: UnitOfMeasure.Peso).ToUpper()).Split(' '); if (temp.Length > 2) { words1 += $" and {temp[0]} {temp[1]} CENTAVO"; } else { words1 += $" and {temp[0]} CENTAVO"; } } words1 += " ONLY"; if (words1.Length <= 60) { amountinwords1 = words1; return; } int lenght = 0; bool valid = true; foreach (string word in words1.Split(' ')) { if ((lenght + word.Length + 1) <= 60 && valid) { amountinwords1 += $"{word} "; lenght += ($"{word} ").Length; } else { valid = false; amountinwords2 += $"{word} "; } } } } }