コード例 #1
0
        private void Generate_PDF()
        {
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter hw  = new HtmlTextWriter(sw);
            StringBuilder  sb  = new StringBuilder();
            StringBuilder  sb1 = new StringBuilder();

            //Generate Invoice (Bill) Header.
            sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>");
            sb.Append("<tr><td align='center' style='background-color:blue colspan = '2'><b>Bill Report</b></td></tr>");
            sb.Append("<tr><td colspan = '2'></td></tr>");
            sb.Append("<tr><td><b>Bill No: </b>");
            sb.Append(HiddenField1.Value);
            sb.Append("</td><td align = 'right'><b>Date: </b>");
            sb.Append(DateTime.Now);
            sb.Append(" </td></tr>");
            sb.Append("</table>");
            sb.Append("<br />");


            GridOfTestRequest.RenderControl(hw);

            StringReader sr  = new StringReader(sw.ToString());
            StringReader sr1 = new StringReader(sb.ToString());

            sb1.Append("<table border='1'>");
            sb1.Append("<tr><td align = 'right' colspan = '");
            sb1.Append(GridOfTestRequest.HeaderRow.Cells.Count - 1);
            sb1.Append("'>Total</td>");
            sb1.Append("<td>");
            sb1.Append(testList.Sum(x => x.testFee));
            sb1.Append("</td>");
            sb1.Append("</tr></table>");


            StringReader sr2 = new StringReader(sb1.ToString());


            Document   pdfDoc     = new Document(PageSize.A5, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

            pdfDoc.Open();
            htmlparser.Parse(sr1);
            htmlparser.Parse(sr);

            htmlparser.Parse(sr2);

            pdfDoc.Close();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Sharp.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.Write(pdfDoc);

            Response.Flush();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
コード例 #2
0
 private void Clear()
 {
     txtPatientName.Text          = "";
     txtMobileNo.Text             = "";
     txtDateOfBirth.Text          = "";
     txtFeeOfTest.Text            = "";
     txtTotalTestAmount.Text      = "";
     ddlTestName.SelectedIndex    = 0;
     GridOfTestRequest.DataSource = null;
     GridOfTestRequest.DataBind();
     testList.Clear();
     ViewState["Test"] = null;
 }
コード例 #3
0
        public void AddToGrid()
        {
            if (ViewState["Test"] != null)
            {
                testList = (List <Tests>)ViewState["Test"];
            }
            Tests testReq = new Tests();

            testReq.tName   = ddlTestName.SelectedItem.Text;
            testReq.ID      = Convert.ToInt32(ddlTestName.SelectedValue);
            testReq.testFee = Convert.ToDecimal(txtFeeOfTest.Text);

            testList.Add(testReq);
            decimal total = 0;

            total = testList.Sum(x => x.testFee);
            txtTotalTestAmount.Text      = total.ToString();
            ViewState["Test"]            = testList;
            GridOfTestRequest.DataSource = testList;
            GridOfTestRequest.DataBind();
        }
コード例 #4
0
        private void Generate_PDF()
        {
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter hw  = new HtmlTextWriter(sw);
            StringBuilder  sb  = new StringBuilder();
            StringBuilder  sb1 = new StringBuilder();

            string name     = txtPatientName.Text;
            string phone    = txtMobileNo.Text;
            string dateTime = DateTime.Today.ToString();

            sb.Append("<table width = '100%' cellspacing='0' cellpadding ='2'>");
            sb.Append("<tr><td align='center' colspan = '3' style='background-color: #18B5F0' colspan = '2'><b><h1>Unknown Diagnostic Center</h1></b></td></tr>");
            sb.Append("<tr><td align='center' colspan = '3' style='background-color: #18B5F0' colspan = '2'><b>Address : 102/A , Rongdhonu towar,Mirpur-2, Dhaka-1216. </b></td></tr>");
            sb.Append("<tr><td align='center' colspan = '3' style='background-color: #18B5F0' colspan = '2'><b>Contract No: 01732 349823 ,01932 349823,01532 349823</b></td></tr>");
            sb.Append("<tr><td align='center' colspan = '3' style='background-color: #18B5F0;color:Blue;' colspan = '2'><b>Website: www.unknown.com</b></td></tr>");
            sb.Append("<tr><td align='center' colspan = '3' style='background-color: #18B5F0;color:Red;' colspan = '2'></br><b><h3></br></h3></b></td></tr>");
            sb.Append("<tr><td>Name : ");
            sb.Append(name);
            sb.Append("</td> ");
            sb.Append("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </td");
            sb.Append("<td> Bill No : ");
            sb.Append(HiddenField1.Value);
            sb.Append("</td></tr>");

            sb.Append("<tr><td> Contract No : ");
            sb.Append(phone);
            sb.Append("</td> ");
            sb.Append("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </td");
            sb.Append("<td> Date : ");
            sb.Append(dateTime);
            sb.Append("</td></tr></table>");

            GridOfTestRequest.RenderControl(hw);
            StringReader sr  = new StringReader(sw.ToString());
            StringReader sr1 = new StringReader(sb.ToString());

            sb1.Append("<table border = '1'>");
            sb1.Append("<tr><td align = 'right' colspan = '");
            sb1.Append(GridOfTestRequest.HeaderRow.Cells.Count - 1);
            sb1.Append("'>Total</td>");
            sb1.Append("<td>");
            sb1.Append(testList.Sum(x => x.testFee));
            sb1.Append("</td>");
            sb1.Append("</tr></table>");


            StringReader sr2 = new StringReader(sb1.ToString());

            testList.Clear();
            GridOfTestRequest.DataSource = null;
            GridOfTestRequest.DataBind();
            Document   pdfDoc     = new Document(PageSize.A5, 10f, 10f, 10f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

            pdfDoc.Open();
            htmlparser.Parse(sr1);
            htmlparser.Parse(sr);
            htmlparser.Parse(sr2);

            pdfDoc.Close();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=invoice.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.Write(pdfDoc);

            Response.Flush();
            Response.ClearContent();
            Response.Clear();
            Response.Cookies.Clear();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }