Advertisement
touhid_xml

3-4 days work

Dec 5th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.77 KB | None | 0 0
  1. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  2.         {
  3.            
  4.  
  5.             /** Head Column 1**/
  6.             string colorcode = "#2F2F30";
  7.             int argb = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
  8.             Color clr = Color.FromArgb(argb);
  9.             //System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#2F2F30");
  10.             Pen blackPen = new Pen(Color.DimGray, 1);
  11.             int primaryHeight = 45;
  12.             e.Graphics.DrawRectangle(blackPen, 40, primaryHeight, 750, 90);
  13.             e.Graphics.DrawLine(blackPen, 460, 135, 460, primaryHeight);
  14.             primaryHeight += 0;
  15.             e.Graphics.DrawString("Check Up Diagnostic & Hospital ", new Font("Calibri", 14, FontStyle.Bold), new SolidBrush(Color.Black), new Point(45, primaryHeight));
  16.             primaryHeight += 25;
  17.             e.Graphics.DrawString("Balubari, Dinajpur", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(45, primaryHeight));
  18.             e.Graphics.DrawString("Tel:  +8801738765544", new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(250, primaryHeight));
  19.             primaryHeight += 20;
  20.             e.Graphics.DrawString("Money Receipt / Voucher", new Font("Calibri", 12, FontStyle.Bold), Brushes.Black, new Point(130, primaryHeight));
  21.             primaryHeight += 20;
  22.             e.Graphics.DrawString("Ref. By: ", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, primaryHeight));
  23.             e.Graphics.DrawString(lblDoctorName.Text, new Font("Calibri",10, FontStyle.Bold), Brushes.Black, new Point(110, primaryHeight));
  24.  
  25.             /** End of Head Column 1**/
  26.  
  27.             /** Head Colum2**/
  28.             Random r = new Random();
  29.             int height2 = 45;
  30.             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));
  31.             height2 += 15;
  32.             e.Graphics.DrawString("Name:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
  33.             e.Graphics.DrawString(this.patientName, new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(540, height2));
  34.             height2 += 15;
  35.             e.Graphics.DrawString("Reg. No:", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
  36.             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));
  37.             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));
  38.             height2 += 15;
  39.             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));
  40.             e.Graphics.DrawString("Age:  " + this.PatientAge.ToString() + " yrs.", new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(670, height2));
  41.  
  42.             height2 += 15;
  43.             e.Graphics.DrawString("Delivery:  " + DateTime.Now.ToString("dd/MM/yyyy"), new Font("Calibri", 10, FontStyle.Regular), new SolidBrush(Color.Black), new Point(470, height2));
  44.  
  45.             /** End of Head Colum2**/
  46.  
  47.  
  48.             /**** Bar Code ***/
  49.             height2 += 35;
  50.             //var barcodeImg = System.Drawing.Image.FromFile(@"img\barcode.gif");
  51.            // var barcodeImg2 = System.Drawing.Image.FromFile(@"img\barcode2.gif");
  52.            // var barcodeImg3 = System.Drawing.Image.FromFile(@"img\barcode3.gif");
  53.  
  54.             e.Graphics.DrawImage(Properties.Resources.barcode, 45, height2, 200, 15);
  55.             e.Graphics.DrawString("CN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(250, height2));
  56.  
  57.             e.Graphics.DrawImage(Properties.Resources.barcode, 310, height2, 200, 15);
  58.             e.Graphics.DrawString("HN", new Font("Calibri", 10, FontStyle.Bold), new SolidBrush(Color.Black), new Point(550, height2));
  59.  
  60.             e.Graphics.DrawImage(Properties.Resources.barcode, 585, height2, 200, 15);
  61.  
  62.  
  63.             /** End of barcode**/
  64.  
  65.             /** Column Rectangle**/
  66.             height2 += 20;
  67.             e.Graphics.DrawRectangle(blackPen, 40, height2, 750, 25);
  68.             /** end of Column Rectangle**/
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.            
  77.             /* Bill To*/
  78.            // e.Graphics.DrawString("BILL TO", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(40, 200));
  79.          //   e.Graphics.DrawString("#2016-11-"+patientID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 220));
  80.           //  e.Graphics.DrawString(patientName.ToString().ToUpper(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 240));
  81.           //  e.Graphics.DrawString(patientMobile, new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(40, 260));
  82.             /* Bill to End*/
  83.  
  84.             /* Invoice*/
  85.           //  e.Graphics.DrawString("INVOICE SUMMARY", new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(650, 200));
  86.           //  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));
  87.           //  e.Graphics.DrawString("INVOICE: # " + this.BillingID.ToString(), new Font("Arial", 11, FontStyle.Regular), Brushes.Black, new Point(650, 240));
  88.             /* Invoice  End*/
  89.  
  90.             height2 += 5;
  91.  
  92.             /* Column Header */
  93.             e.Graphics.DrawString("SL", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(45, height2));
  94.             e.Graphics.DrawString("Item Description", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(75, height2));
  95.             e.Graphics.DrawString("Price", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(500, height2));
  96.             e.Graphics.DrawString("Discount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(600, height2));
  97.             e.Graphics.DrawString("Amount", new Font("Arial", 10, FontStyle.Regular), Brushes.Black, new Point(700, height2));
  98.            
  99.             /* Column Header  End*/
  100.  
  101.  
  102.  
  103.  
  104.  
  105.             int lineHeight = height2 + 25;
  106.             int lineHeight2 = lineHeight + 200;
  107.             int i = 1;
  108.             foreach (DataGridViewRow row in dataGridView1.Rows)
  109.             {
  110.                 // MessageBox.Show(row.Cells[1].Value.ToString());
  111.                 if (row.Cells[1].Value != null)
  112.                 {
  113.                     e.Graphics.DrawString(i.ToString(), new Font("Arial", 11, FontStyle.Bold), Brushes.Black, new Point(45,lineHeight));
  114.                     e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(75, lineHeight));
  115.                     e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(500, lineHeight));
  116.                     e.Graphics.DrawString(row.Cells[2].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(600, lineHeight));
  117.                     e.Graphics.DrawString(row.Cells[4].Value.ToString(), new Font("Calibri", 11, FontStyle.Regular), Brushes.Black, new Point(700, lineHeight));
  118.                 }
  119.                 lineHeight += 20;
  120.                 i++;
  121.             }
  122.  
  123.             e.Graphics.DrawRectangle(blackPen, 40, lineHeight2, 750, 120);
  124.             e.Graphics.DrawLine(blackPen, 600, lineHeight2, 600, lineHeight2 + 90);
  125.             lineHeight2 += 5;
  126.  
  127.             /** Footer Column 1**/
  128.             int ftColLineHeigh1 = lineHeight2;
  129.             e.Graphics.DrawString("Subtotal:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
  130.             e.Graphics.DrawString(this.tbxSubTotal.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
  131.  
  132.             ftColLineHeigh1 += 20;
  133.             e.Graphics.DrawString("Discount:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
  134.             e.Graphics.DrawString(this.tbxDiscount.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
  135.  
  136.             ftColLineHeigh1 += 20;
  137.             e.Graphics.DrawString("Advance:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
  138.             e.Graphics.DrawString(this.tbxGrandTotal.Text, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
  139.  
  140.  
  141.             ftColLineHeigh1 += 20;
  142.             e.Graphics.DrawString("Due:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(500, ftColLineHeigh1));
  143.             e.Graphics.DrawString("0", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(720, ftColLineHeigh1));
  144.            
  145.  
  146.  
  147.            
  148.  
  149.  
  150.  
  151.  
  152.             /** Footer Column 1 end**/
  153.  
  154.             e.Graphics.DrawString("Payment Types:  (Cash)", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
  155.             e.Graphics.DrawString(this.tbxSubTotal.Text, new Font("Calibri", 10, FontStyle.Bold), Brushes.Black, new Point(220, lineHeight2));
  156.             lineHeight2 += 20;
  157.             int totalAmount = decimal.ToInt32(Decimal.Parse(tbxGrandTotal.Text));
  158.             string amountInWords = this.NumberToWords(totalAmount).ToUpper() + " ONLY";
  159.             e.Graphics.DrawString(amountInWords, new Font("Calibri", 9, FontStyle.Regular), Brushes.Black, new Point(45, lineHeight2));
  160.             lineHeight2 += 40;
  161.  
  162.             e.Graphics.DrawString("(This is computer generated signature, no need to sign.)", new Font("Calibri", 9, FontStyle.Bold), Brushes.Black, new Point(100, lineHeight2));
  163.  
  164.             ftColLineHeigh1 += 25;
  165.             // Create points that define line.
  166.             Point point1 = new Point(40, ftColLineHeigh1);
  167.             Point point2 = new Point(790, ftColLineHeigh1);
  168.  
  169.             // Draw line to screen.
  170.             e.Graphics.DrawLine(blackPen, point1, point2);
  171.             e.Graphics.DrawLine(blackPen, 450, ftColLineHeigh1, 450, ftColLineHeigh1 + 30);
  172.  
  173.             ftColLineHeigh1 += 5;
  174.             e.Graphics.DrawString("Cashier Signature:", new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(45, ftColLineHeigh1));
  175.             e.Graphics.DrawString(fullName, new Font("Calibri", 10, FontStyle.Regular), Brushes.Black, new Point(160, ftColLineHeigh1));
  176.  
  177.             e.Graphics.DrawString("Total Amount: ", new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(470, ftColLineHeigh1));
  178.             e.Graphics.DrawString(tbxGrandTotal.Text, new Font("Calibri", 11, FontStyle.Bold), Brushes.Black, new Point(720, ftColLineHeigh1));
  179.  
  180.  
  181.            
  182.            
  183.  
  184.         }
  185.  
  186.         private  string NumberToWords(int number)
  187.         {
  188.             if (number == 0)
  189.                 return "zero";
  190.  
  191.             if (number < 0)
  192.                 return "minus " + NumberToWords(Math.Abs(number));
  193.  
  194.             string words = "";
  195.  
  196.             if ((number / 1000000) > 0)
  197.             {
  198.                 words += NumberToWords(number / 1000000) + " million ";
  199.                 number %= 1000000;
  200.             }
  201.  
  202.             if ((number / 1000) > 0)
  203.             {
  204.                 words += NumberToWords(number / 1000) + " thousand ";
  205.                 number %= 1000;
  206.             }
  207.  
  208.             if ((number / 100) > 0)
  209.             {
  210.                 words += NumberToWords(number / 100) + " hundred ";
  211.                 number %= 100;
  212.             }
  213.  
  214.             if (number > 0)
  215.             {
  216.                 if (words != "")
  217.                     words += "and ";
  218.  
  219.                 var unitsMap = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
  220.                 var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
  221.  
  222.                 if (number < 20)
  223.                     words += unitsMap[number];
  224.                 else
  225.                 {
  226.                     words += tensMap[number / 10];
  227.                     if ((number % 10) > 0)
  228.                         words += "-" + unitsMap[number % 10];
  229.                 }
  230.             }
  231.  
  232.             return words;
  233.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement