Ejemplo n.º 1
0
        private void BtnPrint_Click(object sender, EventArgs e)
        {
            int  gapLine = 40, gapX = 40, gapY = 20, xCol2 = 130, xCol1 = 20, xCol3 = 300, xCol4 = 390, xCol5 = 1030;
            Size size = new Size();

            String statusOPD = "", vsDate = "", vn = "", an = "", anDate = "", doccd = "", docno = "", anyr = "", vn1 = "", pathFolder = "", datetick = "", filename = "", docyr = "", amt2 = "";
            String doc = "", datestart = "";
            //DataTable dt = new DataTable();
            DataTable dt = new DataTable();

            dt = bc.bcDB.pttscDB.SelectByDoc(txtPaidType.Text.Trim());

            DateTime dtstart = new DateTime();

            DateTime.TryParse(txtDateStart.Text, out dtstart);
            if (bc.iniC.windows.Equals("windosxp"))
            {
                if (dtstart.Year > 2500)
                {
                    dtstart = dtstart.AddYears(-543);
                }
                else if (dtstart.Year < 2000)
                {
                    dtstart = dtstart.AddYears(543);
                }
            }
            datestart = dtstart.ToString("dd-MM-yyyy", new CultureInfo("en-US"));

            //throw new NotImplementedException();
            C1PdfDocument       pdf = new C1PdfDocument();
            C1PdfDocumentSource pds = new C1PdfDocumentSource();
            StringFormat        _sfRight, _sfRightCenter;

            //Font _fontTitle = new Font("Tahoma", 15, FontStyle.Bold);
            _sfRight                     = new StringFormat();
            _sfRight.Alignment           = StringAlignment.Far;
            _sfRightCenter               = new StringFormat();
            _sfRightCenter.Alignment     = StringAlignment.Far;
            _sfRightCenter.LineAlignment = StringAlignment.Center;

            //RectangleF rc = GetPageRect(pdf);
            Font titleFont = new Font(bc.iniC.pdfFontName, 18, FontStyle.Bold);
            Font hdrFont   = new Font(bc.iniC.pdfFontName, 14, FontStyle.Regular);
            Font hdrFontB  = new Font(bc.iniC.pdfFontName, 16, FontStyle.Bold);
            Font ftrFont   = new Font(bc.iniC.pdfFontName, 8);
            Font txtFont   = new Font(bc.iniC.pdfFontName, 10, FontStyle.Regular);

            //pdf.Clear();
            pdf.FontType = FontTypeEnum.Embedded;

            //newPagePDFSummaryBorder(pdf, dt, titleFont, hdrFont, ftrFont, txtFont, false);

            //get page rectangle, discount margins
            RectangleF rcPage = pdf.PageRectangle;

            rcPage = RectangleF.Empty;
            rcPage.Inflate(-72, -92);
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            rcPage.Height   = gapLine;

            gapY += gapLine;
            gapY += gapLine;

            String space2 = "    ", space3 = "      ", space4 = "        ", space5 = "          ", space = "";
            int    rowline = 0, i = 0;

            rowline = 205;

            String txt = "ใบนำส่งรายชื่อ ผู้มาตรวจ COVID " + (bc.iniC.branchId.Equals("001") ? "บางนา 1" : bc.iniC.branchId.Equals("002") ? "บางนา 2" : "ไม่ระบุ");

            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            gapY           += gapLine;
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            txt             = " ประจำวันที่ " + datestart + " จำนวนผู้มาตรวจ " + dt.Rows.Count;
            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            gapY           += gapLine;
            rcPage.Location = new PointF(rcPage.X, rcPage.Y + titleFont.SizeInPoints + 10);
            rcPage.Size     = new SizeF(0, titleFont.SizeInPoints + 3);
            rcPage.Width    = 610;
            txt             = " เลขที่ " + txtPaidType.Text.Trim();
            pdf.DrawString(txt, titleFont, Brushes.Black, rcPage);

            datetick = DateTime.Now.Ticks.ToString();
            if (!Directory.Exists("report"))
            {
                Directory.CreateDirectory("report");
            }
            filename = "report\\" + datetick + ".pdf";
            pdf.Save(filename);
            pdf.Clear();
            pdf.Dispose();

            if (File.Exists(filename))
            {
                //bool isExists = System.IO.File.Exists(filename);
                //if (isExists)
                System.Diagnostics.Process.Start(filename);
            }
        }