private void BtnOpen_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            int     i        = 0;
            Boolean findPaid = false;

            lItm        = new List <String>();
            lPaid       = new List <String>();
            lPaidCntErr = new List <int>();
            lPaidCnt    = new List <int>();
            const Int32 BufferSize = 4096;

            dtChk.Clear();
            using (var fileStream = File.OpenRead(txtPath.Text))
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    lItm.Clear();
                    String line;
                    try
                    {
                        while ((line = streamReader.ReadLine()) != null)
                        {
                            findPaid = false;
                            String[] line1 = line.Split('|');
                            if (line1.Length <= 1)
                            {
                                continue;
                            }
                            if (i == 17939)
                            {
                                String sql = "";
                            }
                            String hn = "", date = "", year = "", month = "", date1 = "", paidtype = "", labcode = "", name = "", fntype = "", price = "", labname = "", netprice = "", col1 = "";
                            if (i == 0)
                            {
                                int day = 0;
                                hn    = line1[2];
                                date  = line1[1];
                                year  = date.Substring(date.Length - 4);
                                month = date.Substring(3, 2);
                                date1 = date.Substring(0, 2);
                                int.TryParse(date1, out day);
                                if (hn.Substring(0, 1).Equals("1"))
                                {
                                    chkBn1.Checked = true;
                                    chkBn2.Checked = false;
                                    chkBn5.Checked = false;
                                }
                                else if (hn.Substring(0, 1).Equals("2"))
                                {
                                    chkBn1.Checked = false;
                                    chkBn2.Checked = true;
                                    chkBn5.Checked = false;
                                }
                                else if (hn.Substring(0, 1).Equals("5"))
                                {
                                    chkBn1.Checked = false;
                                    chkBn2.Checked = false;
                                    chkBn5.Checked = true;
                                }
                                cboYear.Text  = year;
                                cboMonth.Text = bc.getMonth(month);
                                if (day <= 15)
                                {
                                    cboPeriod.Text = "1";
                                }
                                else
                                {
                                    cboPeriod.Text = "2";
                                }
                            }
                            col1     = line1[0];
                            hn       = line1[2];
                            date     = line1[1];
                            name     = line1[3];
                            paidtype = line1[4];
                            price    = line1[5];
                            labcode  = line1[7];
                            labname  = line1[8];
                            netprice = line1[6];
                            foreach (String paid in lPaid)
                            {
                                if (paid.Equals(paidtype))
                                {
                                    findPaid = true;
                                }
                            }
                            if (!findPaid)
                            {
                                lPaid.Add(paidtype);
                                lPaidCntErr.Add(0);
                                lPaidCnt.Add(0);
                            }
                            DataRow row1 = dtChk.NewRow();
                            row1["row1"]       = i;
                            row1["lab_code"]   = labcode;
                            row1["lab_name"]   = labname;
                            row1["qty"]        = 1;
                            row1["price"]      = price;
                            row1["net_price"]  = netprice;
                            row1["amount"]     = labcode;
                            row1["paidtype"]   = paidtype;
                            row1["status_chk"] = "0";
                            row1["ptt_name"]   = name;
                            row1["date"]       = date;
                            row1["hn"]         = hn;
                            row1["col1"]       = col1;
                            //dtChk.Columns.Add("lab_name", typeof(String));
                            //dtChk.Columns.Add("qty", typeof(int));
                            //dtChk.Columns.Add("price", typeof(String));
                            //dtChk.Columns.Add("net_price", typeof(String));
                            //dtChk.Columns.Add("amount", typeof(String));
                            //dtChk.Rows.InsertAt(row1, i);
                            dtChk.Rows.Add(row1);
                            listBox1.Items.Add(line + "|0|0");
                            lItm.Add(line + "|0|0");
                            i++;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("error i = " + i + " " + ex.Message, "");
                    }

                    btnCheck.Enabled = true;
                    label6.Text      = "จำนวนข้อมูล " + i;
                }
            if (lPaid.Count > 0)
            {
                C1DockingTabPage tabsum  = new C1DockingTabPage();
                C1DockingTabPage tabsum1 = new C1DockingTabPage();
                tabsum.Text  = "สรุป";
                tabsum.Name  = "tabsum";
                tabsum1.Text = "สรุป";
                tabsum1.Name = "tabsum1";
                tC1.TabPages.Add(tabsum1);
                tC3.TabPages.Add(tabsum);
                ListBox listsum = new ListBox();
                listsum.BackColor         = System.Drawing.Color.White;
                listsum.Dock              = System.Windows.Forms.DockStyle.Fill;
                listsum.ForeColor         = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
                listsum.FormattingEnabled = true;
                listsum.Name              = "listBoxSum3";
                theme1.SetTheme(listsum, "(default)");
                ListBox listsum1 = new ListBox();
                listsum1.BackColor         = System.Drawing.Color.White;
                listsum1.Dock              = System.Windows.Forms.DockStyle.Fill;
                listsum1.ForeColor         = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
                listsum1.FormattingEnabled = true;
                listsum1.Name              = "listBoxSum1";
                theme1.SetTheme(listsum1, "(default)");

                tabsum.Controls.Add(listsum);
                tabsum1.Controls.Add(listsum1);
                int ii = 0;
                foreach (String paid in lPaid)
                {
                    int cnt = 0;
                    //C1DockingTabPage tab = new C1DockingTabPage();
                    C1DockingTabPage tab1 = new C1DockingTabPage();
                    //tab.Text = paid;
                    tab1.Text = paid;
                    tC1.TabPages.Add(tab1);
                    //tC3.TabPages.Add(tab);
                    //ListBox list = new ListBox();
                    //list.BackColor = System.Drawing.Color.White;
                    //list.Dock = System.Windows.Forms.DockStyle.Fill;
                    //list.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
                    //list.FormattingEnabled = true;
                    //list.Name = "listBox1"+ paid;
                    //theme1.SetTheme(list, "(default)");
                    ListBox list1 = new ListBox();
                    list1.BackColor         = System.Drawing.Color.White;
                    list1.Dock              = System.Windows.Forms.DockStyle.Fill;
                    list1.ForeColor         = System.Drawing.Color.FromArgb(((int)(((byte)(68)))), ((int)(((byte)(68)))), ((int)(((byte)(68)))));
                    list1.FormattingEnabled = true;
                    list1.Name              = "listBox1" + paid;
                    theme1.SetTheme(list1, "(default)");

                    //tab.Controls.Add(list);
                    tab1.Controls.Add(list1);
                    foreach (String txt in lItm)
                    {
                        String[] line1 = txt.Split('|');
                        String   hn = "", date = "", year = "", month = "", date1 = "", paidtype = "";
                        paidtype = line1[4];
                        if (paid.Equals(paidtype))
                        {
                            //findPaid = true;
                            //list.Items.Add(txt);
                            list1.Items.Add(txt);
                            cnt++;
                        }
                    }
                    lPaidCnt[ii] = cnt;
                    listsum.Items.Add(paid + "  จำนวน " + cnt);
                    listsum1.Items.Add(paid + "  จำนวน " + cnt);
                    ii++;
                }
            }
            panel8.Show();
        }
Beispiel #2
0
        private void getPDF()
        {
            System.Drawing.Font          font = new System.Drawing.Font("Microsoft Sans Serif", 12);
            iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB;
            iTextSharp.text.BaseColor    clrBlack = new iTextSharp.text.BaseColor(0, 0, 0);
            //MemoryStream ms = new MemoryStream();
            string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf";
            string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf";
            String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = "";

            decimal total = 0;

            bfR  = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack);

            String[] aa = dsDate.Split(',');
            if (aa.Length > 1)
            {
                dsDate = aa[0];
                an     = aa[1];
            }
            String[] bb = dsDate.Split('*');
            if (bb.Length > 1)
            {
                dsDate = bb[0];
                dsTime = bb[1];
            }

            var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg");

            logo.SetAbsolutePosition(30, PageSize.A4.Height - 90);
            logo.ScaleAbsoluteHeight(70);
            logo.ScaleAbsoluteWidth(70);

            FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");

            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36);
            try
            {
                FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + hn + ".pdf", FileMode.Create);
                PdfWriter  writer = PdfWriter.GetInstance(doc, output);
                doc.Open();
                //PdfContentByte cb = writer.DirectContent;
                //ColumnText ct = new ColumnText(cb);
                //ct.Alignment = Element.ALIGN_JUSTIFIED;

                //Paragraph heading = new Paragraph("Chapter 1", fntHead);
                //heading.Leading = 30f;
                //doc.Add(heading);
                //Image L = Image.GetInstance(imagepath + "/l.gif");
                //logo.SetAbsolutePosition(doc.Left, doc.Top - 180);
                doc.Add(logo);

                //doc.Add(new Paragraph("Hello World", fntHead));

                Chunk  c;
                String foobar = "Foobar Film Festival";
                //float width_helv = bfR.GetWidthPoint(foobar, 12);
                //c = new Chunk(foobar + ": " + width_helv, fntHead);
                //doc.Add(new Paragraph(c));

                //if (dt.Rows.Count > 24)
                //{
                //    doc.NewPage();
                //    doc.Add(new Paragraph(string.Format("This is a page {0}", 2)));
                //}
                int i = 0, r = 0, row2 = 0, rowEnd = 24;
                //r = dt.Rows.Count;
                int            next = r / 24;
                int            linenumber = 800, colCenter = 200, fontSize1 = 14, fontSize2 = 14;
                PdfContentByte canvas = writer.DirectContent;
                //canvas.SaveState();
                //canvas.SetLineWidth(0.05f);
                //canvas.MoveTo(400, 806);
                //canvas.LineTo(400, 626);
                //canvas.MoveTo(508.7f, 806);
                //canvas.LineTo(508.7f, 626);
                //canvas.MoveTo(280, 788);
                //canvas.LineTo(520, 788);
                //canvas.MoveTo(280, 752);
                //canvas.LineTo(520, 752);
                //canvas.MoveTo(280, 716);
                //canvas.LineTo(520, 716);
                //canvas.MoveTo(280, 680);
                //canvas.LineTo(520, 680);
                //canvas.MoveTo(280, 644);
                //canvas.LineTo(520, 644);
                //canvas.Stroke();
                //canvas.RestoreState();
                // Adding text with PdfContentByte.showTextAligned()
                canvas.BeginText();
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5  55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL  55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 20, 0);
                canvas.EndText();
                linenumber = 720;
                canvas.BeginText();
                canvas.SetFontAndSize(bfR, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "MEDICAL CERTIFICATE", PageSize.A4.Width / 2, linenumber, 0);
                canvas.EndText();
                linenumber = 680;
                canvas.BeginText();
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ตรวจ " + dtpDate.Value.Day.ToString() + " เดือน " + bc.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), 375, linenumber + 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้า ", 80, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................................................................................................................................", 110, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text.Trim(), 113, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ปริญญาใบอนุญาตประกอบวิชาชีพเวชกรรม เลขที่ ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................. ", 270, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorId.Text.Trim(), 273, linenumber, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ได้ทำการตรวจร่างกาย ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................................................................................................... ", 150, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 153, linenumber + 2, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏว่า ไม่เป็นผู้ทุพพลภาพ ไร้ความสามารถ จิตฟั่นเฟือน ไม่สมประกอบ ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0);
                linenumber = 580;
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "1.	โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", 150, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "2.	วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", 150, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "3.	โรคติดยาเสพติดให้โทษ (Drug addiction) ", 150, linenumber   -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "4.	โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", 150, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "5.	โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", 150, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "6.	ซิฟิลิสในระยะที่ 2 (Syphilis Secondary)", 150, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "7.	โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", 150, linenumber -= 20, 0);

                linenumber -= 20;
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เห็นว่า  ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "............................................................................................................................................................................................", 100, linenumber - 3, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, cboResult.Text.Trim(), colCenter, linenumber + 5, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ตรวจสมรรถภาพการทำงานของปอด  ", 60, linenumber -= 20, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLung.Text.Trim(), 160, linenumber, 0);

                canvas.SetFontAndSize(bfR, fontSize1);
                if (!txtXRay.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ X-Ray ปอด ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtXRay.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtCBC.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ CBC ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtCBC.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtAmp.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจหาสารเสพติดในปัสสาวะ (Amphetamine) ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAmp.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtPrag.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Pragnancy ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPrag.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtHbsAg.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Hbs Ag ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHbsAg.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtUA.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ UA ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtUA.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtHIV.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Anti HIV ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHIV.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtEye.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ วัดสายตา ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtEye.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtEar.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ การได้ยิน ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtEar.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtVDRL.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ VDRL  ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtVDRL.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtBloodG.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ กรุ๊ปเลือด  ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodG.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtFBS.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจหาน้ำตาลในเลือด (FBS)  ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtFBS.Text, colCenter + 70, linenumber, 0);
                }
                if (!txt1.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ อุจจาระ  ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txt1.Text, colCenter + 70, linenumber, 0);
                }
                if (!txtLead.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจ Lead  ", 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLead.Text, colCenter + 70, linenumber, 0);
                }


                linenumber -= 5;
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "บันทึกสัญญาณชีพ  ", 60, linenumber -= 20, 0);
                String aaaa           = "H.Rate: ครั้ง/min  BP:  mmHg ";
                if (!txtPulse.Text.Equals(""))
                {
                    //String[] aaa = txtPulse.Text.Split('/');
                    aaaa = "H.Rate: " + txtPulse.Text + " ครั้ง/min R.Rate: " + txtBreath.Text + " ครั้ง/min  BP: " + txtBloodPressure.Text + " mmHg ";
                }
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................................................................................................", colCenter + 70, linenumber - 3, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, aaaa, colCenter + 70, linenumber + 2, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "WT: " + txtWeight.Text + " Kgs  HT:  " + txtHeight.Text + " Cms", colCenter + 70, (linenumber -= 20) + 2, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);


                if (!txtT1.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, cboL1.Text.Trim(), 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT1.Text, colCenter + 70, linenumber + 1, 0);
                }
                if (!txtT2.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL2.Text.Trim(), 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT2.Text, colCenter + 70, linenumber + 1, 0);
                }
                if (!txtT3.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL3.Text.Trim(), 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT3.Text, colCenter + 70, linenumber + 1, 0);
                }
                if (!txtT4.Text.Equals(""))
                {
                    canvas.SetFontAndSize(bfR, fontSize1);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtL4.Text.Trim(), 60, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................................................................", colCenter + 70, linenumber - 3, 0);
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtT4.Text, colCenter + 70, linenumber + 1, 0);
                }


                linenumber = 100;
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "มีอายุการใช้งาน 3 เดือน (VALID FOR THREE MONTHS)  ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลายมือชื่อ ....................................................... ", 370, linenumber - 3, 0);
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผ่านการรับรองมาตรฐาน  ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "Signature  " + txtDoctorName.Text.Trim(), 370, linenumber, 0);
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ISO 9001:2000 ทุกหน่วยงาน  ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(แพทย์ผู้ตรวจ)  ", 420, linenumber, 0);
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "FM-NUR-001/3 (แก้ไขครั้งที่ 00 15/02/53)  ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "Attending physician  ", 420, linenumber, 0);
                canvas.EndText();

                //canvas.BeginText();
                //canvas.SetFontAndSize(bfR, 16);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "วัน/เวลา", 50, 620, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "รายการ", 250, 620, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "จำนวน", 405, 620, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ราคา", 460, 620, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "รวมราคา", 510, 620, 0);
                ////canvas.ShowTextAlignedKerned(Element.ALIGN_LEFT, "ชื่อแพทย์ผู้รักษา "+ 60, 660, 644, 0);
                ////canvas.ShowTextAlignedKerned(Element.ALIGN_LEFT, "ชื่อแพทย์ผู้รักษา " + 60, 640, 644, 0);
                //canvas.EndText();

                //canvas.MoveTo(520, 640);//vertical Amount
                //canvas.LineTo(520, 110);
                canvas.Stroke();
                canvas.RestoreState();
                //pB1.Maximum = dt.Rows.Count;
            }
            catch (Exception ex)
            {
                //Log(ex.Message);
            }
            finally
            {
                doc.Close();
                Process          p = new Process();
                ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + hn + ".pdf");
                //s.Arguments = "/c dir *.cs";
                p.StartInfo = s;
                //p.StartInfo.Arguments = "/c dir *.cs";
                //p.StartInfo.UseShellExecute = false;
                //p.StartInfo.RedirectStandardOutput = true;
                p.Start();

                //string output = p.StandardOutput.ReadToEnd();
                //p.WaitForExit();
                //Application.Exit();
            }
        }
        private void genPDF()
        {
            System.Drawing.Font          font = new System.Drawing.Font("Microsoft Sans Serif", 12);
            iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB;
            iTextSharp.text.BaseColor    clrBlack = new iTextSharp.text.BaseColor(0, 0, 0);
            //MemoryStream ms = new MemoryStream();
            string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf";
            string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf";
            String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = "";

            decimal total = 0;

            bfR  = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack);

            String[] aa = dsDate.Split(',');
            if (aa.Length > 1)
            {
                dsDate = aa[0];
                an     = aa[1];
            }
            String[] bb = dsDate.Split('*');
            if (bb.Length > 1)
            {
                dsDate = bb[0];
                dsTime = bb[1];
            }

            var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg");

            logo.SetAbsolutePosition(10, PageSize.A4.Height - 90);
            logo.ScaleAbsoluteHeight(70);
            logo.ScaleAbsoluteWidth(70);

            FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");

            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36);
            try
            {
                FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf", FileMode.Create);
                PdfWriter  writer = PdfWriter.GetInstance(doc, output);
                doc.Open();
                //PdfContentByte cb = writer.DirectContent;
                //ColumnText ct = new ColumnText(cb);
                //ct.Alignment = Element.ALIGN_JUSTIFIED;

                //Paragraph heading = new Paragraph("Chapter 1", fntHead);
                //heading.Leading = 30f;
                //doc.Add(heading);
                //Image L = Image.GetInstance(imagepath + "/l.gif");
                //logo.SetAbsolutePosition(doc.Left, doc.Top - 180);
                doc.Add(logo);

                //doc.Add(new Paragraph("Hello World", fntHead));

                Chunk  c;
                String foobar = "Foobar Film Festival";
                //float width_helv = bfR.GetWidthPoint(foobar, 12);
                //c = new Chunk(foobar + ": " + width_helv, fntHead);
                //doc.Add(new Paragraph(c));

                //if (dt.Rows.Count > 24)
                //{
                //    doc.NewPage();
                //    doc.Add(new Paragraph(string.Format("This is a page {0}", 2)));
                //}
                int i = 0, r = 0, row2 = 0, rowEnd = 24;
                //r = dt.Rows.Count;
                int            next = r / 24;
                int            linenumber = 820, colCenter = 200, fontSize0 = 8, fontSize1 = 14, fontSize2 = 16, fontSize3 = 18;
                PdfContentByte canvas = writer.DirectContent;

                canvas.BeginText();
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5  55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL  55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 15, 0);
                canvas.EndText();
                linenumber = 720;
                canvas.BeginText();
                canvas.SetFontAndSize(bfR, fontSize3);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 40, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ส่วนที่ 1", 50, linenumber += 10, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ของผู้ขอรับใบรับรองสุขภาพ", 100, linenumber, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้า นาย/นาง/นางสาว ", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................................................................  ", 170, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 173, linenumber, 0);

                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานที่อยู่ (ที่สามารถติดต่อได้)", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr1.Text, 172, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................................................................  ", 170, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................................................................................................................................................  ", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr2.Text, 55, linenumber + 5, 0);
                canvas.SetFontAndSize(bfR, fontSize1);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเลขบัตรประจำตัวประชาชน", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtId.Text, 172, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................... ", 170, linenumber - 5, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ข้าพเจ้าขอใบรับรองสุขภาพ โดยมีประวัติสุขภาพดังนี้", 330, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "1. โรคประจำตัว", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ไม่มี     [  ] มี  ระบุ ........................................................................................................................", 200, linenumber, 0);

                if (chk1Normal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0);
                }
                else if (chk1AbNormal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txt1AbNormal.Text, 290, linenumber + 5, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "2. อุบัติเหตุ และ ผ่าตัด", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ไม่มี     [  ] มี  ระบุ ........................................................................................................................", 200, linenumber, 0);
                if (chk2Normal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0);
                }
                else if (chk2AbNormal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txt2AbNormal.Text, 290, linenumber + 5, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "3. เคยเข้ารับการรักษาในโรงพยาบาล", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ไม่มี     [  ] มี  ระบุ ........................................................................................................................", 200, linenumber, 0);
                if (chk3Normal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 205, linenumber, 0);
                }
                else if (chk3AbNormal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 248, linenumber, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txt3AbNormal.Text, 290, linenumber + 5, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "4. ประวัติอื่นที่สำคัญ", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................................................................................................................................................................  ", 130, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtOther.Text, 133, linenumber, 0);

                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลงชื่อ .............................................................. วันที่ .............. เดือน .............................. พ.ศ. ...............", 150, linenumber -= 40, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 340, linenumber + 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 400, linenumber + 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 490, linenumber + 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "ในกรณีเด็กทีไม่สามารถรับรองตนเองได้ ให้ผู้ปกครองลงนามรับรองแทนได้", PageSize.A4.Width / 2, linenumber -= 20, 0);

                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ส่วนที่ 2   ของแพทย์", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานที่ตรวจ", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................................................................................................  ", 100, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, TxtHospitalName.Text, 110, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ ", 380, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..........", 398, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 401, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, " เดือน", 420, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".........................", 445, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 448, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, " พ.ศ. ", 500, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "............", 520, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 523, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(1) ข้าพเจ้า นายแพทย์/แพทย์หญิง", 40, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".....................................................................................................................  ", 175, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text, 178, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ใบอนุญาตประกอบวิชาชีพเวชกรรมเลขที่", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".....................................  ", 205, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorId.Text, 208, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานพยาบาลชื่อ", 292, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".........................................................................................  ", 355, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, TxtHospitalName.Text, 358, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัดสมุทรปราการ 10540", 77, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "....................................................................................................................................................................................................................  ", 72, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ได้ตรวจร่างกาย นาย/นาง/นางสาว", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text, 187, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................................................................................................................  ", 182, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "แล้วเมื่อ     วันที่", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..........", 120, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("dd"), 123, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, " เดือน", 142, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".........................", 167, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.getMonth(DateTime.Now.ToString("MM")), 170, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, " พ.ศ. ", 230, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "............", 250, linenumber - 5, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, DateTime.Now.ToString("yyyy"), 253, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, " มีรายละเอียดดังนี้ ", 290, linenumber, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "น้ำหนักตัว", 50, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtWeight.Text, 105, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 88, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "กก. ความสูง", 140, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHeight.Text, 205, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 190, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เซนติเมตร ความดันโลหิต", 240, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodPressure.Text, 345, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "......................", 340, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "มม.ปรอท ชีพจร ", 400, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPulse.Text, 480, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................", 468, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ครั้ง/นาที ", 520, linenumber, 0);

                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สภาพร่างกายทั่วไปอยู่ในเกณฑ์  [  ] ปกติ   [  ] ผิดปกติ  ระบุ", 50, linenumber -= 20, 0);
                if (chkNormal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 173, linenumber, 0);
                }
                else if (chkAbNormal.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 214, linenumber, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAbnormal.Text, 287, linenumber, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "....................................................................................................................", 280, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ขอรับรองว่า บุคคลดังกล่าว ไม่เป็นผู้มีร่างกายทุพพลภาพจนไม่สามารถปฏิบัติหน้าที่ได้ ไม่ปรากฏอาการของโรคจิต ", 100, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "หรือจิตฟั่นเฟือน หรือปัญญาอ่อน ไม่ปรากฏอาการของการติดยาเสพติดให้โทษ และอาการของโรคพิษสุราเรื้อรัง และไม่", 50, linenumber   -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏอาการและอาการแสดงของโรคต่อไปนี้", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(1) โรคเรื้อนในระยะติดต่อ หรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม", 80, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(2) วัณโรคในระยะอันตราย", 80, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(3) โรคเท้าช้างในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม", 80, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(4) ถ้าจำเป็นต้องตรวจหาโรคที่เกี่ยวข้องกับการปฏิบัติงานของผูัรับการตรวจให้ระบุข้อนี้ ", 80, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................", 400, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สรุปความเห็นและข้อแนะนำของแพทย์ ", 100, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ]  " + chk1.Text, 120, linenumber -= 20, 0);
                if (chk1.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ]  " + chk2.Text, 120, linenumber -= 20, 0);
                if (chk2.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ]  " + chk3.Text, 120, linenumber -= 20, 0);
                if (chk3.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ]  " + chk4.Text, 120, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................", 178, linenumber - 5, 0);
                if (chk4.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 124, linenumber, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, txt4Other.Text, 180, linenumber, 0);
                }
                canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................................................................................................", 50, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลงชื่อ ", 270, linenumber -= 40, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................................................", 290, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ผู้ตรวจร่างกาย", 480, linenumber, 0);
                //canvas.SetFontAndSize(bfRB, fontSize2);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text, 213, linenumber, 0);

                canvas.SetFontAndSize(bfR, fontSize0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเหตุ (1) ต้องเป็นแพทย์ซึ่งได้ขึ้นทะเบียนรับใบอนุญาตประกอบวิชาชีพเวชกรรม ", 50, linenumber -= 10, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(2) ให้แสดงว่าเป็นผู้มีร่างกายสมบูรณ์เพียงใด ใบรับรองแพทย์ฉบับนี้ให้ใช้ได้ 1 เดือน นับแต่วันที่ตรวจร่างกาย ", 72, linenumber -= 10, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(3) คำรับรองนี้เป็นการตรวจวินิจฉัยเบื้องต้น ", 72, linenumber -= 10, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "แบบฟอร์มนี้ได้รับการรับรองจากมติคณะกรรมการแพทยสภาในการประชุมครั้งที่ ค/2561 วันที่ 14 สิงหาคม 2561 ", 50, linenumber -= 10, 0);

                canvas.EndText();

                canvas.Stroke();
                //canvas.RestoreState();
                //pB1.Maximum = dt.Rows.Count;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                doc.Close();
                Process          p = new Process();
                ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf");
                //s.Arguments = "/c dir *.cs";
                p.StartInfo = s;
                //p.StartInfo.Arguments = "/c dir *.cs";
                //p.StartInfo.UseShellExecute = false;
                //p.StartInfo.RedirectStandardOutput = true;
                p.Start();

                //string output = p.StandardOutput.ReadToEnd();
                //p.WaitForExit();
                //Application.Exit();
            }
        }
        private void getPDF()
        {
            System.Drawing.Font          font = new System.Drawing.Font("Microsoft Sans Serif", 12);
            iTextSharp.text.pdf.BaseFont bfR, bfR1, bfRB;
            iTextSharp.text.BaseColor    clrBlack = new iTextSharp.text.BaseColor(0, 0, 0);
            //MemoryStream ms = new MemoryStream();
            string myFont = Environment.CurrentDirectory + "\\THSarabun.ttf";
            string myFontB = Environment.CurrentDirectory + "\\THSarabun Bold.ttf";
            String hn = "", name = "", doctor = "", fncd = "", birthday = "", dsDate = "", dsTime = "", an = "";

            decimal total = 0;

            bfR  = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfR1 = BaseFont.CreateFont(myFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            bfRB = BaseFont.CreateFont(myFontB, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

            iTextSharp.text.Font fntHead = new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack);

            String[] aa = dsDate.Split(',');
            if (aa.Length > 1)
            {
                dsDate = aa[0];
                an     = aa[1];
            }
            String[] bb = dsDate.Split('*');
            if (bb.Length > 1)
            {
                dsDate = bb[0];
                dsTime = bb[1];
            }

            var logo = iTextSharp.text.Image.GetInstance(Environment.CurrentDirectory + "\\LOGO-BW-tran.jpg");

            logo.SetAbsolutePosition(10, PageSize.A4.Height - 90);
            logo.ScaleAbsoluteHeight(70);
            logo.ScaleAbsoluteWidth(70);

            FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");

            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 36, 36, 36, 36);
            try
            {
                FileStream output = new FileStream(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf", FileMode.Create);
                PdfWriter  writer = PdfWriter.GetInstance(doc, output);
                doc.Open();
                //PdfContentByte cb = writer.DirectContent;
                //ColumnText ct = new ColumnText(cb);
                //ct.Alignment = Element.ALIGN_JUSTIFIED;

                //Paragraph heading = new Paragraph("Chapter 1", fntHead);
                //heading.Leading = 30f;
                //doc.Add(heading);
                //Image L = Image.GetInstance(imagepath + "/l.gif");
                //logo.SetAbsolutePosition(doc.Left, doc.Top - 180);
                doc.Add(logo);

                //doc.Add(new Paragraph("Hello World", fntHead));

                Chunk  c;
                String foobar = "Foobar Film Festival";
                //float width_helv = bfR.GetWidthPoint(foobar, 12);
                //c = new Chunk(foobar + ": " + width_helv, fntHead);
                //doc.Add(new Paragraph(c));

                //if (dt.Rows.Count > 24)
                //{
                //    doc.NewPage();
                //    doc.Add(new Paragraph(string.Format("This is a page {0}", 2)));
                //}
                int i = 0, r = 0, row2 = 0, rowEnd = 24;
                //r = dt.Rows.Count;
                int            next = r / 24;
                int            linenumber = 800, colCenter = 200, fontSize1 = 14, fontSize2 = 14;
                PdfContentByte canvas = writer.DirectContent;

                canvas.BeginText();
                canvas.SetFontAndSize(bfR, 12);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "โรงพยาบาล บางนา5  55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, linenumber, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "55 หมู่4 ถนนเทพารักษ์ ตำบลบางพลีใหญ่ อำเภอบางพลี จังหวัด สมุทรปราการ 10540", 100, 780, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "BANGNA 5 GENERAL HOSPITAL  55 M.4 Theparuk Road, Bangplee, Samutprakan Thailand0", 100, linenumber - 20, 0);
                canvas.EndText();
                linenumber = 720;
                canvas.BeginText();
                canvas.SetFontAndSize(bfR, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "ใบรับรองแพทย์", PageSize.A4.Width / 2, linenumber + 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "การตรวจสุขภาพแรงงานต่างด้าว", PageSize.A4.Width / 2, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "สถานที่ตรวจ  โรงพยาบาลบางนา 5", PageSize.A4.Width / 2, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_CENTER, "วันที่ตรวจ  " + dtpDate.Value.Day.ToString() + " " + bc.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), PageSize.A4.Width / 2, linenumber -= 20, 0);
                canvas.EndText();
                linenumber = 660;
                canvas.BeginText();
                canvas.SetFontAndSize(bfRB, fontSize2);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ตรวจ " + dtpDate.Value.Day.ToString() + " เดือน " + bc.cf.getMonth(dtpDate.Value.Month.ToString("00")) + " พ.ศ. " + (dtpDate.Value.Year + 543), 400, linenumber + 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชื่อ ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................  ", 75, linenumber - 5, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 93, linenumber, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "เพศ  [  ]ชาย   [  ]หญิง     สถานภาพ  [  ]โสด   [  ]สมรส   [  ]อื่นๆ ", 300, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เพศ ", 355, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ]ชาย   [  ]หญิง  ", 380, linenumber, 0);
                if (txtSex.Text.ToUpper().Equals("M"))
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                else
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 420, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เลขที่บัตรประจำตัวบุคลผู้ไม่มีสัญชาติไทย ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR1, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".......................................................... ", 218, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtId.Text.Trim(), 221, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เลข Passport ", 355, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "............................................................. ", 410, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPassport.Text.Trim(), 413, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สัญชาติ ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................... ", 90, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, cboNation.Text.Trim(), 93, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "เชื้อชาติ ", 220, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................ ", 253, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, cboRace.Text.Trim(), 253, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สถานภาพ ", 385, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "...................................................... ", 425, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, cboMar.Text.Trim(), 428, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "วัน/เดือน/ปี เกิด ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................ ", 122, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, bc.datetoShow2(txtDOB.Text), 125, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "อายุ ", 220, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................................. ", 240, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAge.Text + " ปี", 243, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชื่อนายจ้าง (บริษัท) ", 320, linenumber, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".................................................................... ", 395, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, cboCompany.Text, 418, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่ของนายจ้าง ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR1, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................................................................................... ", 125, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr1.Text, 128, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "....................................................................................................................................................................................................................... ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddr2.Text, 63, linenumber + 3, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ที่อยู่ต่างประเทศ ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "........................................................................................................................................................................................... ", 125, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtAddress.Text, 128, linenumber, 0);

                linenumber -= 20;
                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจสุขภาพ ", (PageSize.A4.Width / 2) - 30, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ความสูง ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, ".............. ", 93, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtHeight.Text, 96, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ชม.   น้ำหนัก ", 125, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................... ", 180, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtWeight.Text, 183, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "กก.   ความดันโลหิต ", 225, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "..................... ", 303, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtBloodPressure.Text, 306, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "มม.ปรอท   ชีพจร ", 350, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "................... ", 420, linenumber - 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPulse.Text, 423, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ครั้ง / นาที ", 465, linenumber, 0);

                linenumber -= 20;
                canvas.SetFontAndSize(bfRB, fontSize2);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtPatientName.Text.Trim(), 153, linenumber + 2, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ปรากฏว่า ไม่เป็นผู้ทุพพลภาพ ไร้ความสามารถ จิตฟั่นเฟือน ไม่สมประกอบ และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "และปราศจากโรคเหล่านี้ ", 60, linenumber -= 20, 0);
                //linenumber = 580;
                if (truestar.Equals("truestar"))
                {
                    leftp = 60;
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "1.	โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ    [  ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0);
                    if (chk1Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk1AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    else if (chk1Repeat.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    }
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "2.	วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ    [  ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0);
                    if (chk2Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk2AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    else if (chk2Repeat.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    }
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "3.	โรคติดยาเสพติดให้โทษ (Drug addiction) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ    [  ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0);
                    if (chk3Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk3AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    else if (chk3Repeat.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    }
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "4.	โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ", 380, linenumber, 0);
                    if (chk4Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk4AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    //else if (chk4Repeat.Checked)
                    //{
                    //    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    //}
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "5.	โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ    [  ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0);
                    if (chk5Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk5AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    else if (chk5Repeat.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    }
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "6.	ซิฟิลิสในระยะที่ 3 (Syphilis Latent)", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ    [  ] ให้ตรวจยืนยันรักษา", 380, linenumber, 0);
                    if (chk6Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk6AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    else if (chk6Repeat.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    }
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "7.	โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ปกติ    [  ] ผิดปกติ", 380, linenumber, 0);
                    if (chk7Normal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 384, linenumber, 0);
                    }
                    else if (chk7AbNormal.Checked)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 428, linenumber, 0);
                    }
                    //else if (chk7Repeat.Checked)
                    //{
                    //    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 482, linenumber, 0);
                    //}
                }
                else
                {
                    leftp = 150;
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "1.	โรคเรื้อนในระยะติดต่อหรือในระยะที่ปรากฏอาการเป็นที่รังเกียจแก่สังคม (Leprosy) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "2.	วัณโรคปอดในระยะติดต่อ (Active pulmonary tuberculosis) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "3.	โรคติดยาเสพติดให้โทษ (Drug addiction) ", leftp, linenumber   -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "4.	โรคพิษสุราเรื้อรัง (Chronic alcoholism) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "5.	โรคเท้าช้างในระยะที่ปรากฏอาการที่เป็นที่รังเกียจแก่สังคม (Filariasis) ", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "6.	ซิฟิลิสในระยะที่ 3 (Syphilis Latent)", leftp, linenumber -= 20, 0);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "7.	โรคจิตฟั่นเฟือนหรือปัญญาอ่อน (Schizophrenia or Mental Retardation)", leftp, linenumber -= 20, 0);
                }

                canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "หมายเหตุ : สำหรับสตรี", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผลการตรวจตั้งครรภ์ [  ]ไม่พบการตั้งครรภ์  [  ]พบการตั้งครรภ์", 170, linenumber, 0);
                canvas.SetFontAndSize(bfRB, fontSize2);
                if (chkPregOn.Checked)
                {
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 252, linenumber, 0);
                }
                else if (chkPregOff.Checked)
                {
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 335, linenumber, 0);
                }
                //canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.SetFontAndSize(bfRB, fontSize2);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "สรุปผลการตรวจ", 60, linenumber -= 20, 0);
                canvas.SetFontAndSize(bfR, fontSize1);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] สุขภาพสมบูรณ์ดี", 200, linenumber -= 20, 0);
                if (chk1.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ผ่านการตรวจสุขภาพ แต่ต้องติดตามผลการตรวจยืนยัน และให้การรักษา", 200, linenumber -= 20, 0);
                if (chk2.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] ไม่ผ่านเพราะ....................................................................", 200, linenumber -= 20, 0);
                if (chk3.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] สุขภาพไม่สมบูรณ์แข็งแรง ที่เป็นอุปสรรคต่อการทำงาน", 200, linenumber -= 20, 0);
                if (chk4.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "[  ] เป็นโรคต้องห้ามมิให้ทำงาน (ตามประกาศกระทรวงสาธารณสุข)", 200, linenumber -= 20, 0);
                if (chk5.Checked)
                {
                    canvas.SetFontAndSize(bfRB, fontSize2);
                    canvas.ShowTextAligned(Element.ALIGN_LEFT, "/ ", 204, linenumber, 0);
                    canvas.SetFontAndSize(bfR, fontSize1);
                }

                canvas.EndText();

                //canvas.BeginText();
                //canvas.SaveState();
                canvas.SetLineWidth(0.05f);
                canvas.MoveTo(80, 140);  //vertical
                canvas.LineTo(80, 225);
                canvas.MoveTo(80, 140);  //Hericental
                canvas.LineTo(150, 140);
                canvas.MoveTo(80, 225);  //Hericental
                canvas.LineTo(150, 225);
                canvas.MoveTo(150, 140); //vertical
                canvas.LineTo(150, 225);

                //canvas.MoveTo(560, 640);//vertical
                //canvas.LineTo(560, 110);
                //canvas.Stroke();
                //canvas.RestoreState();

                canvas.BeginText();
                linenumber -= 20;
                linenumber -= 20;
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ผู้เข้ารับการตรวจ ...................................................  ", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "แพทย์ผู้ตรวจ ...................................................", colCenter + 180, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(.....................................................)", 120, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "(.........................................................)", colCenter + 220, linenumber, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, txtDoctorName.Text.Trim(), colCenter + 225, linenumber + 3, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "ใบรับรองแพทย์ฉบับนี้ให้ใช้ได้ 60 วันนับแต่วันที่ตรวจร่างกาย", 60, linenumber -= 20, 0);
                canvas.ShowTextAligned(Element.ALIGN_LEFT, "วันที่ .........................................................", colCenter + 200, linenumber, 0);
                //canvas.SetFontAndSize(bfRB, fontSize2);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, cboCompany.Text.Trim(), colCenter, linenumber + 5, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ตรวจสมรรถภาพการทำงานของปอด  ", 60, linenumber -= 20, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, txtLung.Text.Trim(), 160, linenumber, 0);



                //linenumber -= 5;
                //canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "บันทึกสัญญาณชีพ  ", 60, linenumber -= 20, 0);
                //String aaaa = "H.Rate: ครั้ง/min  BP:  mmHg ";
                //if (!txtPulse.Text.Equals(""))
                //{
                //    //String[] aaa = txtPulse.Text.Split('/');
                //    aaaa = "H.Rate: " + txtPulse.Text + " ครั้ง/min R.Rate: " + txtBreath.Text + " ครั้ง/min  BP: " + txtBloodPressure.Text + " mmHg ";
                //}
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "...............................................................................................", colCenter + 70, linenumber - 3, 0);
                //canvas.SetFontAndSize(bfRB, fontSize2);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, aaaa, colCenter + 70, linenumber + 2, 0);

                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "WT: " + txtWeight.Text + " Kgs  HT:  " + txtHeight.Text + " Cms", colCenter + 70, (linenumber -= 20) + 2, 0);
                //canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "...............................................................................................", colCenter + 70, linenumber - 3, 0);


                //linenumber = 100;
                ////canvas.SetFontAndSize(bfR, 12);
                ////canvas.ShowTextAligned(Element.ALIGN_LEFT, "มีอายุการใช้งาน 3 เดือน (VALID FOR THREE MONTHS)  ", 60, linenumber -= 20, 0);
                //canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "ลายมือชื่อ ....................................................... ", 370, linenumber - 3, 0);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "Signature  " + txtDoctorName.Text.Trim(), 370, linenumber, 0);
                ////canvas.SetFontAndSize(bfR, 12);
                ////canvas.ShowTextAligned(Element.ALIGN_LEFT, "ISO 9001:2000 ทุกหน่วยงาน  ", 60, linenumber -= 20, 0);
                ////canvas.SetFontAndSize(bfR, fontSize1);
                //canvas.ShowTextAligned(Element.ALIGN_LEFT, "(แพทย์ผู้ตรวจ)  ", 420, linenumber, 0);

                canvas.EndText();

                canvas.Stroke();
                //canvas.RestoreState();
                //pB1.Maximum = dt.Rows.Count;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                doc.Close();
                Process          p = new Process();
                ProcessStartInfo s = new ProcessStartInfo(Environment.CurrentDirectory + "\\" + txtHn.Text.Trim() + ".pdf");
                //s.Arguments = "/c dir *.cs";
                p.StartInfo = s;
                //p.StartInfo.Arguments = "/c dir *.cs";
                //p.StartInfo.UseShellExecute = false;
                //p.StartInfo.RedirectStandardOutput = true;
                p.Start();

                //string output = p.StandardOutput.ReadToEnd();
                //p.WaitForExit();
                //Application.Exit();
            }
        }