Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- /** Head Column 1**/
- string colorcode = "#2F2F30";
- int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
- Color clr = Color.FromArgb(argb);
- //System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#2F2F30");
- Pen blackPen = new Pen(Color.DimGray, 1);
- int primaryHeight = 45;
- e.Graphics.DrawRectangle(blackPen, 40, primaryHeight, 750, 90);
- e.Graphics.DrawLine(blackPen, 460, 135, 460, primaryHeight);
- primaryHeight += 0;
- e.Graphics.DrawString("Check Up Diagnostic & Hospital ", new Font("Calibri", 14, FontStyle.Bold), new SolidBrush(Color.Black), new Point(45, primaryHeight));
- primaryHeight += 25;
- e.Graphics.DrawString("Balubari, Dinajpur", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString("Tel: +8801738765544", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(250, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Money Receipt / Voucher", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, new Point(130, primaryHeight));
- primaryHeight += 20;
- e.Graphics.DrawString("Ref. By: ", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, primaryHeight));
- e.Graphics.DrawString(lblDoctorName.Text, new Font("Calibri",10, FontStyle.Bold), Brushes.Black, new Point(110, primaryHeight));
- /** End of Head Column 1**/
- /** Head Colum2**/
- Random r = new Random();
- int height2 = 45;
- e.Graphics.DrawString("Voucher No: " + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- height2 += 15;
- e.Graphics.DrawString("Name:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString(this.patientName, new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(540, height2));
- height2 += 15;
- e.Graphics.DrawString("Reg. No:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + BillingID.ToString(), new Font("Calibri", 11, FontStyle.Regular), new SolidBrush(Color.Black), new Point(540, height2));
- e.Graphics.DrawString("CN: C-" + r.Next(1000, 9999) + "-" + r.Next(1000, 9999), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(650, height2));
- height2 += 15;
- e.Graphics.DrawString("Date: " + DateTime.Now.ToString("dd/MM/yyyy h:mm tt"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- e.Graphics.DrawString("Age: " + this.PatientAge.ToString() + " yrs.", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(670, height2));
- height2 += 15;
- e.Graphics.DrawString("Delivery: " + DateTime.Now.ToString("dd/MM/yyyy"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
- /** End of Head Colum2**/
- /**** Bar Code ***/
- height2 += 35;
- //var barcodeImg = System.Drawing.Image.FromFile(@"img\barcode.gif");
- // var barcodeImg2 = System.Drawing.Image.FromFile(@"img\barcode2.gif");
- // var barcodeImg3 = System.Drawing.Image.FromFile(@"img\barcode3.gif");
- e.Graphics.DrawImage(Properties.Resources.barcode, 45, height2, 200, 15);
- e.Graphics.DrawString("CN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(250, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 310, height2, 200, 15);
- e.Graphics.DrawString("HN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(550, height2));
- e.Graphics.DrawImage(Properties.Resources.barcode, 585, height2, 200, 15);
- /** End of barcode**/
- /** Column Rectangle**/
- height2 += 20;
- e.Graphics.DrawRectangle(blackPen, 40, height2, 750, 25);
- /** end of Column Rectangle**/
- /* Bill To*/
- // e.Graphics.DrawString("BILL TO", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(40, 200));
- // e.Graphics.DrawString("#2016-11-"+patientID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 220));
- // e.Graphics.DrawString(patientName.ToString().ToUpper(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 240));
- // e.Graphics.DrawString(patientMobile, new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 260));
- /* Bill to End*/
- /* Invoice*/
- // e.Graphics.DrawString("INVOICE SUMMARY", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(650, 200));
- // e.Graphics.DrawString(String.Format("DATE: {0}-{1}-{2}", dateTimePicker1.Value.Day, dateTimePicker1.Value.Month, dateTimePicker1.Value.Year), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 220));
- // e.Graphics.DrawString("INVOICE: # " + this.BillingID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 240));
- /* Invoice End*/
- height2 += 5;
- /* Column Header */
- e.Graphics.DrawString("SL", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(45, height2));
- e.Graphics.DrawString("Item Description", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(75, height2));
- e.Graphics.DrawString("Price", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(500, height2));
- e.Graphics.DrawString("Discount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(600, height2));
- e.Graphics.DrawString("Amount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(700, height2));
- /* Column Header End*/
- int lineHeight = height2 + 25;
- int lineHeight2 = lineHeight + 200;
- int i = 1;
- foreach (DataGridViewRow row in dataGridView1.Rows)
- {
- // MessageBox.Show(row.Cells[1].Value.ToString());
- if (row.Cells[1].Value != null)
- {
- e.Graphics.DrawString(i.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(45,lineHeight));
- e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(75, lineHeight));
- e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(500, lineHeight));
- e.Graphics.DrawString(row.Cells[2].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(600, lineHeight));
- e.Graphics.DrawString(row.Cells[4].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(700, lineHeight));
- }
- lineHeight += 20;
- i++;
- }
- e.Graphics.DrawRectangle(blackPen, 40, lineHeight2, 750, 120);
- e.Graphics.DrawLine(blackPen, 600, lineHeight2, 600, lineHeight2 + 90);
- lineHeight2 += 5;
- /** Footer Column 1**/
- int ftColLineHeigh1 = lineHeight2;
- e.Graphics.DrawString("Subtotal:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(this.tbxSubTotal.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Discount:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(this.tbxDiscount.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Advance:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString(this.tbxGrandTotal.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
- ftColLineHeigh1 += 20;
- e.Graphics.DrawString("Due:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
- e.Graphics.DrawString("0", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
- /** Footer Column 1 end**/
- e.Graphics.DrawString("Payment Types: (Cash)", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- e.Graphics.DrawString(this.tbxSubTotal.Text, new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(220, lineHeight2));
- lineHeight2 += 20;
- int totalAmount = decimal.ToInt32(Decimal.Parse(tbxGrandTotal.Text));
- string amountInWords = this.NumberToWords(totalAmount).ToUpper() + " ONLY";
- e.Graphics.DrawString(amountInWords, new Font("Calibri", 9, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
- lineHeight2 += 40;
- e.Graphics.DrawString("(This is computer generated signature, no need to sign.)", new Font("Calibri", 9, FontStyle.Bold), Brushes.Black, new Point(100, lineHeight2));
- ftColLineHeigh1 += 25;
- // Create points that define line.
- Point point1 = new Point(40, ftColLineHeigh1);
- Point point2 = new Point(790, ftColLineHeigh1);
- // Draw line to screen.
- e.Graphics.DrawLine(blackPen, point1, point2);
- e.Graphics.DrawLine(blackPen, 450, ftColLineHeigh1, 450, ftColLineHeigh1 + 30);
- ftColLineHeigh1 += 5;
- e.Graphics.DrawString("Cashier Signature:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, ftColLineHeigh1));
- e.Graphics.DrawString(fullName, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(160, ftColLineHeigh1));
- e.Graphics.DrawString("Total Amount: ", new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(470, ftColLineHeigh1));
- e.Graphics.DrawString(tbxGrandTotal.Text, new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(720, ftColLineHeigh1));
- }
- private string NumberToWords(int number)
- {
- if (number == 0)
- return "zero";
- if (number < 0)
- return "minus " + NumberToWords(Math.Abs(number));
- string words = "";
- if ((number / 1000000) > 0)
- {
- words += NumberToWords(number / 1000000) + " million ";
- number %= 1000000;
- }
- if ((number / 1000) > 0)
- {
- words += NumberToWords(number / 1000) + " thousand ";
- number %= 1000;
- }
- if ((number / 100) > 0)
- {
- words += NumberToWords(number / 100) + " hundred ";
- number %= 100;
- }
- if (number > 0)
- {
- if (words != "")
- words += "and ";
- var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
- var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
- if (number < 20)
- words += unitsMap[number];
- else
- {
- words += tensMap[number / 10];
- if ((number % 10) > 0)
- words += "-" + unitsMap[number % 10];
- }
- }
- return words;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement