コード例 #1
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            g.PageUnit = GraphicsUnit.Millimeter;
            Font messageFont = new Font("Times New Roman", 14, System.Drawing.GraphicsUnit.Point);
            int  total;

            if (j == 1)
            {
                g.DrawString("INSTITUTE DISPENSARY", messageFont, Brushes.Black, 75, 9);
                g.DrawString("INDIAN INSTITUTE OF TECHNOLOGY ROORKEE, SAHARANPUR CAMPUS", messageFont, Brushes.Black, 22, 15);
                messageFont = new Font("Times New Roman", 20, System.Drawing.GraphicsUnit.Point);
                g.DrawString("DAILY REPORT", messageFont, Brushes.Black, 75, 25);
                messageFont = new Font("Times New Roman", 12, System.Drawing.GraphicsUnit.Point);
                g.DrawString("Dated: " + dateTimePicker1.Value.Date.ToString("dd MMM, yyyy"), messageFont, Brushes.Black, 160, 30);
                Pen blackPen = new Pen(Color.Black, 1);
                g.DrawLine(blackPen, 5, 38, 205, 38);
                total = 38;
            }
            else
            {
                total = 5;
            }
            messageFont = new Font("Times New Roman", 15, System.Drawing.GraphicsUnit.Point);
            g.DrawString("----------------------------------------------------------------------------------------------------------", messageFont, Brushes.Black, 7, total + 2);
            g.DrawString("----------------------------------------------------------------------------------------------------------", messageFont, Brushes.Black, 7, total + 12);
            messageFont = new Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            g.DrawString("Sno.", messageFont, Brushes.Black, 10, total + 8);
            g.DrawString("OPD", messageFont, Brushes.Black, 20, total + 8);
            g.DrawString("Booklet No.", messageFont, Brushes.Black, 35, total + 8);
            g.DrawString("Patient Name", messageFont, Brushes.Black, 60, total + 8);
            g.DrawString("Age", messageFont, Brushes.Black, 115, total + 8);
            g.DrawString("Gender", messageFont, Brushes.Black, 125, total + 8);
            g.DrawString("Family Head", messageFont, Brushes.Black, 140, total + 8);
            g.DrawString("Amt.", messageFont, Brushes.Black, 165, total + 8);
            g.DrawString("Doctor", messageFont, Brushes.Black, 178, total + 8);
            total += 17;
            opd       opd = new opd();
            dbconnect db  = new dbconnect();

            opd.dailyReportRegistration(dateTimePicker1.Value.Date.ToString("yyyy-MM-dd"), db);
            int i = 1;

            while (opd.dr.Read())
            {
                if (i < j)
                {
                    i++;
                    continue;
                }
                if (total >= 270)
                {
                    e.HasMorePages = true;
                    return;
                }
                g.DrawString(i + ")", messageFont, Brushes.Black, 10, total);
                g.DrawString(opd.dr[0].ToString(), messageFont, Brushes.Black, 20, total);
                g.DrawString(opd.dr[1].ToString(), messageFont, Brushes.Black, 35, total);
                g.DrawString(opd.dr[2].ToString(), messageFont, Brushes.Black, 60, total);
                int age2 = DateTime.Today.Year - Convert.ToInt32(db.dr[3].ToString().Substring(0, 4));
                if (Convert.ToInt32(db.dr[3].ToString().Substring(5, 2)) > DateTime.Today.Month)
                {
                    age2--;
                }
                g.DrawString(age2.ToString(), messageFont, Brushes.Black, 115, total);
                g.DrawString(opd.dr[4].ToString(), messageFont, Brushes.Black, 125, total);
                g.DrawString(opd.dr[5].ToString(), messageFont, Brushes.Black, 140, total);
                int amt = 0;
                if (opd.dr[6].ToString() == "general")
                {
                    amt          = 1;
                    totalAmount += 1;
                }
                g.DrawString(amt.ToString(), messageFont, Brushes.Black, 165, total);
                g.DrawString(opd.dr[7].ToString(), messageFont, Brushes.Black, 178, total);
                total += 5;
                i++;
                j++;
                e.HasMorePages = false;
            }
            messageFont = new Font("Times New Roman", 12, System.Drawing.GraphicsUnit.Point);
            g.DrawString("Total Amount :" + totalAmount.ToString(), messageFont, Brushes.Black, 139, total + 2);
            messageFont = new Font("Times New Roman", 15, System.Drawing.GraphicsUnit.Point);
            g.DrawString("----------------------------------------------------------------------------------------------------------", messageFont, Brushes.Black, 7, total + 5);
            messageFont = new Font("Times New Roman", 8, System.Drawing.GraphicsUnit.Point);
            g.DrawString("© IMG Labs, IIT Roorkee, SRE", messageFont, Brushes.Black, 87, total + 10);
        }