protected void AddButton_Click(object sender, EventArgs e) { if (NameOfPatientTextBox.Text == String.Empty || MobileNumberTextBox.Text == String.Empty || DateOfBirthTextBox.Text == String.Empty) { ConfirmationLabel.Text = "Please fill up all the fields"; FeeTextBox.Text = String.Empty; ResetDropdown(); } else { Test aTest = (Test)ViewState["Test"]; tests.Add(aTest); ShowTestsGridView.DataSource = tests; ShowTestsGridView.DataBind(); ShowTestsGridView.RowStyle.Height = 35; double sum = 0; foreach (Test test in tests) { sum += Convert.ToDouble(test.Fee); } TotalTextBox.Text = sum.ToString(); TotalLabel.Visible = true; TotalTextBox.Visible = true; SaveButton.Visible = true; ConfirmationLabel.Text = String.Empty; FeeTextBox.Text = String.Empty; SelectTestDropDownList.Items.Remove(SelectTestDropDownList.SelectedItem); } }
private void GeneratePdf() { Patient aPatient = (Patient)ViewState["patient"]; string printDate = DateTime.Now.ToString("F"); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=" + aPatient.MobileNumber + ".pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); ShowTestsGridView.RenderControl(hw); ShowTestsGridView.HeaderRow.Style.Add("width", "15%"); ShowTestsGridView.HeaderRow.Style.Add("font-size", "10px"); ShowTestsGridView.Style.Add("text-decoration", "none"); ShowTestsGridView.Style.Add("font-family", "Arial, Helvetica, sans-serif;"); ShowTestsGridView.Style.Add("font-size", "8px"); Paragraph paragraph1 = new Paragraph("XXX Diagnostic Center\n\n"); paragraph1.Font.Size = 30; Paragraph paragraph2 = new Paragraph("Print Date: " + printDate + "\n\n"); Paragraph paragraph3 = new Paragraph(" Bill Number: " + aPatient.BillNumber + "\n Invoice Date: " + aPatient.InvoiceDate.ToString("d") + "\n Patient Name: " + aPatient.Name + "\n Date of Birth: " + aPatient.DateOfBirth.ToString("d") + "\n Mobile Number: " + aPatient.MobileNumber + "\n\n"); Paragraph paragraph4 = new Paragraph("Total Fee: " + aPatient.Fee + ""); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 10f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); pdfDoc.Add(paragraph1); pdfDoc.Add(paragraph2); pdfDoc.Add(paragraph3); htmlparser.Parse(sr); pdfDoc.Add(paragraph4); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); ShowTestsGridView.AllowPaging = true; ShowTestsGridView.DataBind(); }